private void Start() { EnsureUIComponentsLayout(); cameraPath = gameObject.AddComponent <CameraPath>(); camera = GameObject.Find("Main Camera").GetComponent <Camera>(); cameraController = camera.GetComponent <CameraController>(); unlimitedCamera = cameraController.m_unlimitedCamera; m_notificationAlpha = typeof(NotificationManager).GetField("m_notificationAlpha", BindingFlags.NonPublic | BindingFlags.Instance); if (mainButton == null) { UIView view = UIView.GetAView(); mainButton = view.AddUIComponent(typeof(UIMainButton)) as UIMainButton; mainWindow = view.AddUIComponent(typeof(UIMainWindow)) as UIMainWindow; } try { EZC_config = Type.GetType("EnhancedZoomContinued.EnhancedZoom, EnhancedZoom").GetField("config", BindingFlags.Public | BindingFlags.Static).GetValue(null); EZC_fovSmoothing = EZC_config.GetType().GetField("fovSmoothing"); } catch { } }
public void SetToTime(float time) { if (knots.m_size > 1) { CameraPath.scrubTime = Time.time; if (!CameraDirector.cameraController.enabled) { CameraPath.MoveCamera(time, 1f, CameraDirector.camera, knots, out time); return; } base.StartCoroutine(CameraPath.MoveCameraAsync(time, 1f, CameraDirector.camera, knots)); } }
public static System.Collections.IEnumerator MoveCameraAsync(float time, float speed, Camera camera, FastList <object> knots) { CameraDirector.cameraController.enabled = false; yield return(new WaitForSeconds(0.01f)); float num; CameraPath.MoveCamera(time, speed, camera, knots, out num); do { yield return(new WaitForSeconds(0.05f)); }while (Time.time - CameraPath.scrubTime < 0.03f || Input.GetMouseButton(0)); CameraDirector.cameraController.enabled = true; CameraPath.SetCitiesCameraTransform(currentTransfrom); yield break; }
public void Update() { if (playBack) { if (CameraDirector.useFps) { if (stepcount == 0) { startTime = Stopwatch.GetTimestamp(); } if (!CameraPath.MoveCamera(time, CameraDirector.mainWindow.playSpeed, CameraDirector.camera, knots, out time)) { Stop(); return; } else { simulationStep.Invoke(SimulationManager.instance, null); CameraDirector.camera.nearClipPlane = 1; } long expectedStart = startTime + (int)(waitTimeTarget * frequency * stepcount++); int wait = (int)(waitTimeTarget - ((Stopwatch.GetTimestamp() - expectedStart) / frequency)) - 1; if (wait > 0) { Thread.Sleep(wait); } while (playBack && (Stopwatch.GetTimestamp() - expectedStart) / frequency < waitTimeTarget) { ; } } else { if (!CameraPath.MoveCamera(time, CameraDirector.mainWindow.playSpeed, CameraDirector.camera, knots, out time)) { Stop(); } } } }
public static bool MoveCamera(float time, float speed, Camera camera, FastList <object> knots, out float timeOut) { bool result = true; int index = 0; float duration = 0f; for (int i = 0; i < knots.m_size; i++) { Knot knot = (Knot)knots.m_buffer[i]; float knotDuration = (knot.duration + knot.delay) / speed; if (time < duration + knotDuration) { index = i; break; } duration += knotDuration; } bool ended = false; if (index + 1 >= knots.m_size) { index = knots.m_size - 2; ended = true; if (time > duration + ((Knot)knots.m_buffer[knots.m_size - 1]).delay) { ended = false; result = false; index = 0; } } Knot currentKnot = (Knot)knots.m_buffer[index]; Knot nextKnot = (Knot)knots.m_buffer[index + 1]; float t = time - duration; if (t >= currentKnot.delay && result && !ended) { t -= currentKnot.delay; switch (currentKnot.mode) { case EasingMode.None: t /= currentKnot.duration / speed; break; case EasingMode.EaseIn: t = CameraPath.EaseInQuad(t, 0f, 1f, currentKnot.duration / speed); break; case EasingMode.EaseOut: t = CameraPath.EaseOutQuad(t, 0f, 1f, currentKnot.duration / speed); break; case EasingMode.EaseInOut: t = CameraPath.EaseInOutQuad(t, 0f, 1f, currentKnot.duration / speed); break; case EasingMode.Auto: t = Spline.CalculateSplineT(knots.m_buffer, knots.m_size, index, t / (currentKnot.duration / speed)); break; } } else { t = ended ? 1f : 0f; } float fov = Mathf.Lerp(currentKnot.fov, nextKnot.fov, t); float distance1 = currentKnot.size * (1f - currentKnot.height / CameraDirector.cameraController.m_maxDistance) / Mathf.Tan(0.0174532924f * fov); float distance2 = nextKnot.size * (1f - nextKnot.height / CameraDirector.cameraController.m_maxDistance) / Mathf.Tan(0.0174532924f * fov); float distance = Mathf.Lerp(distance1, distance2, t); Quaternion rotation = Spline.CalculateSplineRotationEuler(knots.m_buffer, knots.m_size, index, t); Vector3 position = Spline.CalculateSplinePosition(knots.m_buffer, knots.m_size, index, t) + rotation * new Vector3(0f, 0f, -distance); camera.transform.position = position; camera.transform.rotation = rotation; camera.fieldOfView = fov; float size = Mathf.Lerp(currentKnot.size, nextKnot.size, t); ChangeTiltShift(size); ChangeDoF(size); time += Time.deltaTime; timeOut = time; return(result); }