private void setColors(AMCameraFade cf, int firstTargetType, int secondTargetType, bool isReversed, AMCameraSwitcherAction action) { //if(firstTargetType != 1 && secondTargetType != 1) return; Color firstColor = (isReversed ? action.endColor : action.startColor); Color secondColor = (isReversed ? action.startColor : action.endColor); if (firstTargetType == 1) { cf.colorTex = firstColor; cf.hasColorTex = true; } else { cf.hasColorTex = false; } if (secondTargetType == 1) { cf.colorBG = secondColor; cf.hasColorBG = true; } else { cf.hasColorBG = false; } // send event to game view to repaint OnGUI if (!Application.isPlaying && (firstTargetType == 1 || secondTargetType == 1)) { cf.transform.position = new Vector3(cf.transform.position.x, cf.transform.position.y, cf.transform.position.z); } }
public static void destroyAndReload(bool isPreview) { if (_cf != null) { _cf.destroyImmediate(); } _cf = null; getCameraFade(isPreview); }
public override AnimatorTimeline.JSONAction getJSONAction(int frameRate) { if (endFrame == -1 || !hasTargets() || targetsAreEqual()) { return(null); } AnimatorTimeline.JSONAction a = new AnimatorTimeline.JSONAction(); a.method = "camerafade"; a.delay = getWaitTime(frameRate, 0f); a.time = getTime(frameRate); setupJSONActionEase(a); a.ints = new int[] { cameraFadeType, startTargetType, endTargetType }; List <string> strings = new List <string>(); List <AnimatorTimeline.JSONColor> colors = new List <AnimatorTimeline.JSONColor>(); if (startTargetType == 0) { strings.Add(startCamera.gameObject.name); colors.Add(null); } else { AnimatorTimeline.JSONColor c = new AnimatorTimeline.JSONColor(); c.setValue(startColor); colors.Add(c); strings.Add(null); } if (endTargetType == 0) { strings.Add(endCamera.gameObject.name); colors.Add(null); } else { AnimatorTimeline.JSONColor c = new AnimatorTimeline.JSONColor(); c.setValue(endColor); colors.Add(c); strings.Add(null); } a.strings = strings.ToArray(); a.colors = colors.ToArray(); // reversed, rendertex a.bools = new bool[] { isReversed(), !still }; // textures if (AMCameraFade.needsTexture(cameraFadeType)) { a.stringsExtra = new string[] { irisShape.name } } ; //hash.Add("texture",irisShape); // parameters a.floats = cameraFadeParameters.ToArray(); return(a); } }
// set render texture or colors if render texture is used (stills handled in AMTake) private void setRenderTexture(AMCameraFade cf, float frame, int firstTargetType, int secondTargetType, bool isReversed, AMCameraSwitcherAction action, bool isPreview) { Camera firstCamera = (isReversed ? action.endCamera : action.startCamera); Camera secondCamera = (isReversed ? action.startCamera : action.endCamera); if (isReversed && frame == action.startFrame) { if (firstTargetType == 0) { AMTween.SetTopCamera(firstCamera, cachedAllCameras); } } else { if (secondTargetType == 0) { AMTween.SetTopCamera(secondCamera, cachedAllCameras); } } if (action.still || (firstTargetType != 0 && secondTargetType != 0)) { return; } bool isPro = AMTake.isProLicense; // first target is camera, set render texture if (firstTargetType == 0) { // if should update render texture if (/*!cf.tex ||*/ cf.shouldUpdateRenderTexture || (isPro && (!firstCamera.targetTexture || !cf.isRenderTextureSetupFor(firstCamera) /*|| firstCamera.targetTexture != cf.tex*/))) { if (isPro) { cf.setupRenderTexture(firstCamera); } else { cf.useRenderTexture = false; // show place-holder if non-pro cf.colorTex = Color.white; cf.tex2d = (Texture2D)Resources.Load("am_indie_placeholder"); cf.hasColorTex = false; if (!cf.placeholder) { cf.placeholder = true; } } } } }
public Texture[] getAllTextures() { List <Texture> lsTextures = new List <Texture>(); foreach (AMCameraSwitcherKey key in keys) { if (key.irisShape && (AMCameraFade.needsTexture(key.cameraFadeType))) { lsTextures.Add(key.irisShape); } } return(lsTextures.Distinct().ToArray()); }
public void execute(int frameRate, float delay, Camera[] allCameras) { // if targets are equal do nothing if (endFrame == -1 || !hasTargets() || targetsAreEqual()) { return; } float[] parameters = cameraFadeParameters.ToArray(); Hashtable hash = new Hashtable(); hash.Add("time", getTime(frameRate)); hash.Add("delay", getWaitTime(frameRate, delay)); if (easeType == 32) { hash.Add("easecurve", easeCurve); } else { hash.Add("easetype", (AMTween.EaseType)easeType); } hash.Add("reversed", AMTween.isTransitionReversed(cameraFadeType, parameters)); hash.Add("allcameras", allCameras); if (startTargetType == 0) { hash.Add("camera1", startCamera); } else { hash.Add("color1", startColor); } if (endTargetType == 0) { hash.Add("camera2", endCamera); } else { hash.Add("color2", endColor); } if (AMCameraFade.needsTexture(cameraFadeType)) { hash.Add("texture", irisShape); } AMTween.CameraFade(cameraFadeType, !still, parameters, hash); }
public void destroy() { AMTween.Stop(this.gameObject); if (_tex) { if (renderTextureCamera && renderTextureCamera.targetTexture == _tex) { renderTextureCamera.targetTexture = null; } Destroy(_tex); } /*if(_matIris) { * Destroy(_matIris.shader); * Destroy(_matIris); * }*/ _cf = null; Destroy(this.gameObject); }
public static AMCameraFade getCameraFade(bool preview = false) { if (_cf) { _cf.preview = preview; return(_cf); } AMCameraFade cf = null; GameObject go = GameObject.Find("AMCamera" + (preview ? "FadePreview" : "Fade")); if (go) { cf = (AMCameraFade)go.GetComponent(typeof(AMCameraFade)); } if (!cf) { cf = (AMCameraFade) new GameObject("AMCamera" + (preview ? "FadePreview" : "Fade"), typeof(AMCameraFade)).GetComponent(typeof(AMCameraFade)); } _cf = cf; _cf.preview = preview; return(_cf); }
private void showColor(Color color, bool isPreview) { AMCameraFade cf = AMCameraFade.getCameraFade(isPreview); bool shouldRepaint = false; if (!cf.hasColorTex || cf.colorTex != color) { cf.colorTex = color; cf.hasColorTex = true; shouldRepaint = true; } if (cf.isReset) { cf.isReset = false; shouldRepaint = true; } if (cf.hasColorBG) { cf.hasColorBG = false; shouldRepaint = true; } if (cf.value != 1f) { cf.value = 1f; cf.percent = 0f; shouldRepaint = true; } if (cf.mode != 0) { cf.mode = 0; shouldRepaint = true; } // send event to game view to repaint OnGUI if (!Application.isPlaying && shouldRepaint) { cf.transform.position = new Vector3(cf.transform.position.x, cf.transform.position.y, cf.transform.position.z); } }
private void setColors(AMCameraFade cf, int firstTargetType, int secondTargetType, bool isReversed, AMCameraSwitcherAction action) { //if(firstTargetType != 1 && secondTargetType != 1) return; Color firstColor = (isReversed ? action.endColor : action.startColor); Color secondColor = (isReversed ? action.startColor : action.endColor); if(firstTargetType == 1) { cf.colorTex = firstColor; cf.hasColorTex = true; } else { cf.hasColorTex = false; } if(secondTargetType == 1) { cf.colorBG = secondColor; cf.hasColorBG = true; } else { cf.hasColorBG = false; } // send event to game view to repaint OnGUI if(!Application.isPlaying && (firstTargetType == 1 || secondTargetType == 1)) { cf.transform.position = new Vector3(cf.transform.position.x,cf.transform.position.y,cf.transform.position.z); } }
public void destroyImmediate() { AMTween.Stop(this.gameObject); if(_tex) { if(renderTextureCamera && renderTextureCamera.targetTexture == _tex) { renderTextureCamera.targetTexture = null; } DestroyImmediate (_tex); } /*if(_matIris) { DestroyImmediate(_matIris.shader); DestroyImmediate(_matIris); }*/ _cf = null; DestroyImmediate (this.gameObject); }
// set render texture or colors if render texture is used (stills handled in AMTake) private void setRenderTexture(AMITarget itarget, AMCameraFade cf, float frame, int firstTargetType, int secondTargetType, bool isReversed, AMCameraSwitcherKey action) { Camera firstCamera = (isReversed ? action.getCameraEnd(itarget) : action.getCamera(itarget)); Camera secondCamera = (isReversed ? action.getCamera(itarget) : action.getCameraEnd(itarget)); if(isReversed && frame == action.frame) { if(firstTargetType == 0) AMUtil.SetTopCamera(firstCamera, GetCachedCameras(itarget)); } else { if(secondTargetType == 0) AMUtil.SetTopCamera(secondCamera, GetCachedCameras(itarget)); } if(action.still || (firstTargetType != 0 && secondTargetType != 0)) return; bool isPro = AMTakeData.isProLicense; // first target is camera, set render texture if(firstTargetType == 0) { // if should update render texture if(/*!cf.tex ||*/ cf.shouldUpdateRenderTexture || (isPro && (!firstCamera.targetTexture || !cf.isRenderTextureSetupFor(firstCamera)/*|| firstCamera.targetTexture != cf.tex*/))) { if(isPro) { cf.setupRenderTexture(firstCamera); } else { cf.useRenderTexture = false; // show place-holder if non-pro cf.colorTex = Color.white; cf.hasColorTex = false; cf.clearScreenTex(); cf.placeholder = true; } } } }
void OnDestroy() { if(_tex) { if(renderTextureCamera && renderTextureCamera.targetTexture == _tex) { renderTextureCamera.targetTexture = null; } DestroyImmediate(_tex); } if(_blankTexture) DestroyImmediate(_blankTexture); if(_placeholderTexture) DestroyImmediate(_placeholderTexture); clearScreenTex(); if(_cf == this) _cf = null; }
public static AMCameraFade getCameraFade() { bool preview = !Application.isPlaying; if(_cf) { _cf.preview = preview; return _cf; } AMCameraFade cf = null; GameObject go = GameObject.Find("AMCameraFade"); if(go) { cf = (AMCameraFade)go.GetComponent(typeof(AMCameraFade)); } if(!cf) { go = new GameObject("AMCameraFade", typeof(AMCameraFade)); if(preview) go.hideFlags = HideFlags.DontSave; cf = (AMCameraFade)go.GetComponent(typeof(AMCameraFade)); } _cf = cf; _cf.preview = preview; return _cf; }
public static AMCameraFade getCameraFade(bool preview=false) { if(_cf) { _cf.preview = preview; return _cf; } AMCameraFade cf = null; GameObject go = GameObject.Find("AMCamera" + (preview ? "FadePreview" : "Fade" )); if(go) { cf = (AMCameraFade) go.GetComponent(typeof(AMCameraFade)); } if(!cf) { cf = (AMCameraFade) new GameObject("AMCamera"+(preview ? "FadePreview" : "Fade" ),typeof(AMCameraFade)).GetComponent(typeof(AMCameraFade)); } _cf = cf; _cf.preview = preview; return _cf; }
// set render texture or colors if render texture is used (stills handled in AMTake) private void setRenderTexture(AMCameraFade cf, float frame, int firstTargetType, int secondTargetType, bool isReversed, AMCameraSwitcherAction action, bool isPreview) { Camera firstCamera = (isReversed ? action.endCamera : action.startCamera); Camera secondCamera = (isReversed ? action.startCamera : action.endCamera); if(isReversed && frame == action.startFrame) { if(firstTargetType == 0) AMTween.SetTopCamera(firstCamera,cachedAllCameras); } else { if(secondTargetType == 0) AMTween.SetTopCamera(secondCamera,cachedAllCameras); } if(action.still || (firstTargetType != 0 && secondTargetType != 0)) return; bool isPro = AMTake.isProLicense; // first target is camera, set render texture if(firstTargetType == 0) { // if should update render texture if(/*!cf.tex ||*/ cf.shouldUpdateRenderTexture || (isPro && (!firstCamera.targetTexture || !cf.isRenderTextureSetupFor(firstCamera)/*|| firstCamera.targetTexture != cf.tex*/))) { if(isPro) { cf.setupRenderTexture(firstCamera); } else { cf.useRenderTexture = false; // show place-holder if non-pro cf.colorTex = Color.white; cf.tex2d = (Texture2D)Resources.Load("am_indie_placeholder"); cf.hasColorTex = false; if(!cf.placeholder) cf.placeholder = true; } } } }
private void previewCameraFade(float frame, AMCameraSwitcherAction action, bool isPreview) { // if transition is None, show end camera / color if (action.cameraFadeType == (int)AMTween.Fade.None) { // reset camera fade if visible // camera if (action.endTargetType == 0) { if (action.endCamera) { AMTween.SetTopCamera(action.endCamera, cachedAllCameras); } AMCameraFade.reset(); } else { showColor(action.endColor, isPreview); } return; } // Get camerafade AMCameraFade cf = AMCameraFade.getCameraFade(isPreview); if (Application.isPlaying) { cf.keepAlivePreview = true; } cf.isReset = false; bool isReversed = action.isReversed(); int firstTargetType = (isReversed ? action.endTargetType : action.startTargetType); int secondTargetType = (isReversed ? action.startTargetType : action.endTargetType); // Set render texture or colors if render texture is used setRenderTexture(cf, frame, firstTargetType, secondTargetType, isReversed, action, isPreview); setColors(cf, firstTargetType, secondTargetType, isReversed, action); if (cf.irisShape != action.irisShape) { cf.irisShape = action.irisShape; } cf.mode = action.cameraFadeType; cf.setupMaterials(); cf.r = action.cameraFadeParameters.ToArray(); // calculate and set value AMTween.EasingFunction ease; AnimationCurve curve = null; if (action.hasCustomEase()) { ease = AMTween.customEase; curve = action.easeCurve; } else { ease = AMTween.GetEasingFunction((AMTween.EaseType)action.easeType); } float percentage = (float)(frame - action.startFrame) / (float)(action.endFrame - action.startFrame); float value = ease(1f, 0f, percentage, curve); cf.value = value; cf.percent = percentage; }
public override void previewFrame(float frame, AMTrack extraTrack = null) { if (cache == null || cache.Count <= 0) { return; } bool isPreview = !Application.isPlaying; //GameObject go = GameObject.Find ("AMCameraFade"); //AMCameraFade cf = null; //if(go) cf = (AMCameraFade) go.GetComponent(typeof(AMCameraFade)); for (int i = 0; i < cache.Count; i++) { // before first frame if (frame <= (cache[i] as AMCameraSwitcherAction).startFrame) { //if(cf) DestroyImmediate(cf.gameObject); AMCameraFade.reset(); if (!(cache[i] as AMCameraSwitcherAction).hasStartTarget()) { return; } if ((cache[i] as AMCameraSwitcherAction).startTargetType == 0) { //(cache[i] as AMCameraSwitcherAction).startCamera.targetTexture = null; AMTween.SetTopCamera((cache[i] as AMCameraSwitcherAction).startCamera, cachedAllCameras); } else { showColor((cache[i] as AMCameraSwitcherAction).startColor, isPreview); // or color # TO DO # } return; // between first and last frame } else if (frame <= (cache[i] as AMCameraSwitcherAction).endFrame) { if (!(cache[i] as AMCameraSwitcherAction).hasStartTarget() || !(cache[i] as AMCameraSwitcherAction).hasEndTarget()) { return; } // targets are equal if ((cache[i] as AMCameraSwitcherAction).targetsAreEqual()) { //if(cf) DestroyImmediate(cf.gameObject); AMCameraFade.reset(); if ((cache[i] as AMCameraSwitcherAction).startTargetType == 0) { // use camera (cache[i] as AMCameraSwitcherAction) startTarget //(cache[i] as AMCameraSwitcherAction).startCamera.targetTexture = null; // if not first frame, set top camera AMTween.SetTopCamera((cache[i] as AMCameraSwitcherAction).startCamera, cachedAllCameras); } else { showColor((cache[i] as AMCameraSwitcherAction).startColor, isPreview); // or color # TO DO # } } else { //if((cache[i] as AMCameraSwitcherAction).endTargetType == 0) (cache[i] as AMCameraSwitcherAction).endCamera.targetTexture = null; AMCameraFade.clearRenderTexture(); // preview transition: (cache[i] as AMCameraSwitcherAction).cameraFadeType previewCameraFade(frame, (cache[i] as AMCameraSwitcherAction), isPreview); } return; // after last frame } else if (i == cache.Count - 2) { //if(cf) DestroyImmediate(cf.gameObject); AMCameraFade.reset(); if (!(cache[i] as AMCameraSwitcherAction).hasEndTarget()) { return; } // use camera (cache[i] as AMCameraSwitcherAction) endTarget if ((cache[i] as AMCameraSwitcherAction).endTargetType == 0) { // use camera (cache[i] as AMCameraSwitcherAction) startTarget //(cache[i] as AMCameraSwitcherAction).endCamera.targetTexture = null; AMTween.SetTopCamera((cache[i] as AMCameraSwitcherAction).endCamera, cachedAllCameras); } else { showColor((cache[i] as AMCameraSwitcherAction).endColor, isPreview); // or color # TO DO # } return; } } }
public override string ToString(int codeLanguage, int frameRate) { if (endFrame == -1 || !hasStartTarget() || targetsAreEqual()) { return(null); } string s; bool noFade = (cameraFadeType == (int)AMTween.Fade.None); if (codeLanguage == 0) { // implement to string // c# s = "AMTween.CameraFade (AMTween.Fade." + Enum.GetName(typeof(AMTween.Fade), cameraFadeType) + ", " + ((noFade ? false : !still)).ToString().ToLower() + ", " + getParametersString(codeLanguage) + ", " + "AMTween.Hash (\"delay\", " + getWaitTime(frameRate, 0f) + "f, \"time\", " + getTime(frameRate) + "f, "; if (!noFade) { s += getEaseString(codeLanguage) + ", "; } if (isReversed()) { s += "\"reversed\", true, "; } if (AMCameraFade.needsTexture(cameraFadeType)) { s += "\"texture\", AMTween.LoadTexture2D(\"" + irisShape.name + "\"), "; } if (!noFade) { if (startTargetType == 0) { if (startCamera) { s += "\"camera1\", GameObject.Find(\"" + startCamera.gameObject.name + "\").camera, "; } else { s += "\"camera1\", null /* Missing Camera */"; } } else { s += "\"color1\", new Color(" + startColor.r + "f, " + startColor.g + "f, " + startColor.b + "f, " + startColor.a + "f), "; } } if (endTargetType == 0) { if (endCamera) { s += "\"camera2\", GameObject.Find(\"" + endCamera.gameObject.name + "\").camera"; } else { s += "\"camera2\", null /* Missing Camera */"; } } else { s += "\"color2\", new Color(" + endColor.r + "f, " + endColor.g + "f, " + endColor.b + "f, " + endColor.a + "f)"; } if ((!noFade && startTargetType == 0) || endTargetType == 0) { s += ", \"allcameras\", csCameras"; } s += "));"; } else { // js s = "AMTween.CameraFade (AMTween.Fade." + Enum.GetName(typeof(AMTween.Fade), cameraFadeType) + ", " + ((noFade ? false : !still)).ToString().ToLower() + ", " + getParametersString(codeLanguage) + ", " + "{\"delay\": " + getWaitTime(frameRate, 0f) + ", \"time\": " + getTime(frameRate) + ", "; if (!noFade) { s += getEaseString(codeLanguage) + ", "; } if (isReversed()) { s += "\"reversed\": true, "; } if (AMCameraFade.needsTexture(cameraFadeType)) { s += "\"texture\": AMTween.LoadTexture2D(\"" + irisShape.name + "\"), "; } if (!noFade) { if (startTargetType == 0) { if (startCamera) { s += "\"camera1\": GameObject.Find(\"" + startCamera.gameObject.name + "\").camera, "; } else { s += "\"camera1\", null /* Missing Camera */"; } } else { s += "\"color1\": Color(" + startColor.r + ", " + startColor.g + ", " + startColor.b + ", " + startColor.a + "), "; } } if (endTargetType == 0) { if (endCamera) { s += "\"camera2\", GameObject.Find(\"" + endCamera.gameObject.name + "\").camera"; } else { s += "\"camera2\", null /* Missing Camera */"; } } else { s += "\"color2\": Color(" + endColor.r + ", " + endColor.g + ", " + endColor.b + ", " + endColor.a + ")"; } if ((!noFade && startTargetType == 0) || endTargetType == 0) { s += ", \"allcameras\", csCameras"; } s += "));"; } return(s); }
// update cache public virtual void updateCache() { AMCameraFade.doShouldUpdateStill(); }
public static void destroyAndReload(bool isPreview) { if(_cf != null) _cf.destroyImmediate(); _cf = null; getCameraFade(isPreview); }