UnityPhotoTool
UnityPhotoTool copied to clipboard
Scripts for taking screenshots with countdown animation and chroma keying in Unity. 🏳🌈
UnityPhotoTool
Features
- Take screenshots with your desired size and position.
- Count down and flash light effect animation. (DOTween required)
- Chroma keying and basic brightness, contrast, and saturation adjustment with the help of ProcAmp by Keijiro, HSV Color Picker by judah4, and PlayerPrefsX by Eric Haines.
There are 3 sample scenes in this project:
- Test_PhotoTool takes a screenshot and display it on a GUI Raw Image.
- Test_PhotoAnim demonstrates how to set up simple count down and flash light animation.
- Test_Keying applies chroma keying and color adjustment onto textures.
🌟 While the above scenes demonstrate how I use the scripts individually, UnityPhotoBooth is a complete photo booth game using all these scripts together. Please check it out if you need it.
How to Use
PhotoTool.cs

Settings in the Inspector
- Set
startX,startY,width, andheightfor the region you want to take screenshots with. You can view the region you've set by checkingDebug On GUI.
Scripting Reference
Init()initializes a Texture2D for screenshots with startX, startY, width, and height. There's also an overload functionInit(int _startX, int _startY, int _width, int _height)for overriding the settings.TakePhoto()takes a screenshot and apply it totex2d_photo.OnPhotoTaken(tex2d_photo)is called after the screenshot is taken.
PhotoAnimController.cs

Settings in the Inspector
- Drag some Transform components into the
countDownElementsarray. These GameObjects will be used in the countdown animation, which is driven by a DOTween Sequence. - Type in
duration_countDown(in seconds). It's the duration of eachcountDownElements's scaling animation. - Assign a UI Image to
Img_shot. It'll be used in a "flash" animation driven by DOTween, too.duration_shotis the duration of the animation. - (Optional) You can also assign an AudioSource to
audio_shotand it will be played with the flash animation.
Scripting Reference
Init()MUST be called to initialize the DOTween tweeners/sequences.PlayCountDownAnim()plays the countdown animation.OnCountDownFinish()is called when the animation finishes.PlayShotAnim()plays the flash light animation (along with theaudio_shotsound effect if it's assigned).OnShotFinish()is called when the animation finishes.
KeyingColorPickers.cs, KeyingSliders.cs, and KeyingToggle.cs

These scripts are used to control values on materials using ProcAmp shader.
- Assign a material using Klak/Video/ProcAmp shader to
keyingMaterial - Type in
propertyNameeg. _KEYING, _Brightness. They are internally used by some functions such as Material.SetFloat and PlayerPref.SetFloat. - (Optional) If
btn_resetDefaultis assigned, value of the color picker, sliders, and toggle will be set to default whenbtn_resetDefaultis pressed. - (Optional) There is a Panel-Keying Prefab inside gm_PhotoTool/Prefab/Panel-Keying. It's a UI Panel which already contains a color picker, a toggle, and sliders. You can put it onto a UI Canvas and then set up values followng steps above.
Notes
This project uses Git submodule gm_PhotoTool. If you want to clone this reposiory, you need to call
git clone --recurse-submodules <URL>
License
MIT
Acknowledgement
This project uses ProcAmp by Keijiro and HSV Color Picker by judah4 to achieve chroma keying. Also uses PlayerPrefsX by Eric Haines to save colors with PlayerPrefs! 🙇♀️