private void previewCameraFade(AMITarget itarget, float frame, AMCameraSwitcherKey action) { // if transition is None, show end camera / color if (action.cameraFadeType == (int)AMCameraSwitcherKey.Fade.None) { // reset camera fade if visible // camera if (action.typeEnd == 0) { Camera endCam = action.getCameraEnd(itarget); if (endCam) { Utility.SetTopCamera(endCam, GetCachedCameras(itarget)); } AMCameraFade.reset(); } else { showColor(action.colorEnd); } return; } // Get camerafade AMCameraFade cf = AMCameraFade.getCameraFade(); cf.isReset = false; bool isReversed = action.isReversed(); int firstTargetType = (isReversed ? action.typeEnd : action.type); int secondTargetType = (isReversed ? action.type : action.typeEnd); // Set render texture or colors if render texture is used setRenderTexture(itarget, cf, frame, firstTargetType, secondTargetType, isReversed, action); 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(); float t = (float)(frame - action.frame) / (float)(action.endFrame - action.frame); float percentage; if (action.hasCustomEase()) { percentage = Utility.EaseCustom(0.0f, 1.0f, t, action.easeCurve); } else { var ease = Utility.GetEasingFunction((Ease)action.easeType); percentage = ease(t, 1.0f, action.amplitude, action.period); } cf.value = 1.0f - percentage; cf.percent = percentage; }
void ShowColor(Color color) { AMCameraFade cf = AMCameraFade.getCameraFade(); cf.keepAliveColor = true; cf.colorTex = color; cf.hasColorTex = true; cf.hasColorBG = false; cf.mode = 0; cf.value = 1f; cf.isReset = false; }
void CameraEnd(bool isReversed, Camera cam, Camera camEnd, Camera[] allCams) { if (isReversed) { //set camEnd to top if (camEnd) { AMUtil.SetTopCamera(cam, allCams); } } if (typeEnd == 0) { AMCameraFade.reset(); } else { AMCameraFade cf = AMCameraFade.getCameraFade(); cf.keepAliveColor = true; cf.hasColorTex = true; cf.hasColorBG = false; cf.colorTex = colorEnd; cf.mode = 0; cf.value = 1.0f; } if (!still) { if (cam) { cam.targetTexture = null; } if (camEnd) { camEnd.targetTexture = null; } } if (AMCameraFade.hasInstance()) { AMCameraFade cf = AMCameraFade.getCameraFade(); cf.clearScreenTex(); cf.clearTexture(); if (cf.keepAlives > 0) { cf.keepAlives--; } } }
void AMITarget.SequenceComplete(AMSequence seq) { //end camera fade if (AMCameraFade.hasInstance()) { AMCameraFade cf = AMCameraFade.getCameraFade(); cf.playParam = null; } mLastPlayingTakeIndex = mNowPlayingTakeIndex; mNowPlayingTakeIndex = -1; if (takeCompleteCallback != null) { takeCompleteCallback(this, seq.take); } }
public void Stop() { AMTakeData take = mCurrentPlayingTake; if (take == null) { return; } take.Stop(this); //end camera fade if (AMCameraFade.hasInstance()) { AMCameraFade cf = AMCameraFade.getCameraFade(); cf.playParam = null; } mSequences[mNowPlayingTakeIndex].Reset(); mLastPlayingTakeIndex = mNowPlayingTakeIndex; mNowPlayingTakeIndex = -1; }
public override void build(AMSequence seq, AMTrack track, int index, UnityEngine.Object target) { // if targets are equal do nothing if (endFrame == -1 || !hasTargets(seq.target) || targetsAreEqual(seq.target)) { return; } Camera[] allCameras = (track as AMCameraSwitcherTrack).GetCachedCameras(seq.target); int frameRate = seq.take.frameRate; float frameCount = getNumberOfFrames(frameRate); var itarget = seq.target; var _seq = seq.sequence; var tween = DOTween.To(new FloatPlugin(), () => 0f, (x) => { AMCameraFade cf = AMCameraFade.getCameraFade(); AMCameraSwitcherKey.PlayParam param = cf.playParam; if (param == null) { param = cf.playParam = new AMCameraSwitcherKey.PlayParam(); } param.Apply(this, frameRate, itarget, allCameras, _seq.IsBackwards()); cf.percent = x / frameCount; cf.value = 1.0f - cf.percent; }, frameCount, frameCount / frameRate); if (hasCustomEase()) { tween.SetEase(easeCurve); } else { tween.SetEase((Ease)easeType, amplitude, period); } seq.Insert(this, tween); }
private void showColor(Color color) { AMCameraFade cf = AMCameraFade.getCameraFade(); 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); } }
void CameraGenerateFadeTargets(bool isReversed, Camera cam, Camera camEnd, Camera[] allCams, float[] parameters) { AMCameraFade cf = AMCameraFade.getCameraFade(); cf.incrementKeepAlives(true); if (cf.keepAliveColor) { cf.keepAliveColor = false; } cf.isReset = false; Camera firstCamera = null; Camera secondCamera = null; Color? firstColor = null; Color? secondColor = null; if (isReversed) { if (camEnd) { firstCamera = camEnd; } else if (typeEnd == 1) { firstColor = colorEnd; } if (cam) { secondCamera = cam; } else if (type == 1) { secondColor = color; } } else { if (cam) { firstCamera = cam; } else if (type == 1) { firstColor = color; } if (camEnd) { secondCamera = camEnd; } else if (typeEnd == 1) { secondColor = colorEnd; } } // setup first target if (firstCamera) { // camera if (!still) { cf.setupRenderTexture(firstCamera); } else { AMUtil.SetTopCamera(firstCamera, allCams); firstCamera.Render(); cf.refreshScreenTex(); cf.useRenderTexture = false; cf.hasColorTex = false; } } else { // color cf.colorTex = (Color)firstColor; cf.hasColorTex = true; } // setup second target if (secondCamera) { // camera AMUtil.SetTopCamera(secondCamera, allCams); cf.hasColorBG = false; } else { // color cf.colorBG = (Color)secondColor; cf.hasColorBG = true; } // iris shape if (irisShape) { cf.irisShape = irisShape; //cf.setupMaterials(); } cf.mode = cameraFadeType; // setup camera fade cf.setupMaterials(); cf.r = parameters; cf.value = 1f; cf.percent = 0f; }
public override void previewFrame(AMITarget itarget, float frame, int frameRate, bool play, float playSpeed) { if (keys == null || keys.Count <= 0) { return; } AMCameraFade.getCameraFade(); // if before or equal to first frame, or is the only frame AMCameraSwitcherKey firstKey = keys[0] as AMCameraSwitcherKey; if (firstKey.endFrame == -1 || (frame <= (float)firstKey.frame && !firstKey.canTween)) { AMCameraFade.reset(); if (!firstKey.hasStartTarget(itarget)) { return; } if (firstKey.type == 0) { Utility.SetTopCamera(firstKey.getCamera(itarget), GetCachedCameras(itarget)); } else { showColor(firstKey.color); } return; } for (int i = 0; i < keys.Count; i++) { AMCameraSwitcherKey key = keys[i] as AMCameraSwitcherKey; AMCameraSwitcherKey keyNext = i + 1 < keys.Count ? keys[i + 1] as AMCameraSwitcherKey : null; if (frame >= (float)key.endFrame && keyNext != null && (!keyNext.canTween || keyNext.endFrame != -1)) { continue; } // if no ease if (!key.canTween || keyNext == null) { AMCameraFade.reset(); if (!key.hasStartTarget(itarget)) { return; } if (key.type == 0) { Utility.SetTopCamera(key.getCamera(itarget), GetCachedCameras(itarget)); } else { showColor(key.color); } return; } // else find t using easing function if (!key.hasStartTarget(itarget) || !key.hasEndTarget(itarget)) { return; } //targets are equal if (key.targetsAreEqual(itarget)) { AMCameraFade.reset(); if (key.type == 0) { Utility.SetTopCamera(key.getCamera(itarget), GetCachedCameras(itarget)); } else { showColor(key.color); } } else { AMCameraFade.clearRenderTexture(); previewCameraFade(itarget, frame, key); } return; } }
private void renderCameraSwitcherStill(AMITarget itarget, float _frame) { if (!cameraSwitcher) { return; } AMCameraSwitcherTrack.cfTuple tuple = cameraSwitcher.getCameraFadeTupleForFrame(itarget, (int)_frame); if (tuple.frame != 0) { AMCameraFade cf = AMCameraFade.getCameraFade(); cf.isReset = false; // create render texture still //bool isPro = PlayerSettings.advancedLicense; bool isPro = isProLicense; if (!cf.screenTex || cf.shouldUpdateStill || (isPro && cf.cachedStillFrame != tuple.frame)) { if (isPro) { int firstTargetType = (tuple.isReversed ? tuple.type2 : tuple.type1); int secondTargetType = (tuple.isReversed ? tuple.type1 : tuple.type2); if (firstTargetType == 0) { if (cf.screenTex) { Object.DestroyImmediate(cf.screenTex); } previewFrame(itarget, tuple.frame, false, false); // set top camera //bool isReversed = tuple.isReversed; Camera firstCamera = (tuple.isReversed ? tuple.camera2 : tuple.camera1); Utility.SetTopCamera(firstCamera, cameraSwitcher.getAllCameras(itarget)); // set cached frame to 0 if bad frame if (cf.width <= 0 || cf.height <= 0) { if (Application.isPlaying) { cf.width = Screen.width; cf.height = Screen.height; } else { cf.width = 200; cf.height = 100; cf.shouldUpdateStill = true; } } else { cf.shouldUpdateStill = false; } cf.refreshScreenTex(firstCamera); cf.cachedStillFrame = tuple.frame; cf.placeholder = false; if (secondTargetType == 0) { Camera secondCamera = (tuple.isReversed ? tuple.camera1 : tuple.camera2); Utility.SetTopCamera(secondCamera, cameraSwitcher.getAllCameras(itarget)); } } } else { cf.clearScreenTex(); cf.placeholder = true; } } cf.useRenderTexture = false; } }