static SceneViewSmoothCamera() { s_TimeHelper.Begin(); Debug.Log("SceneViewSmoothCamera created"); SceneView.onSceneGUIDelegate += view => { if (!enabled) { return; } if (EditorWindow.focusedWindow != view || EditorWindow.mouseOverWindow == null) { Reset(); return; } if (!inited) { Init(); } pivotLocalPos = view.camera.transform.InverseTransformPoint(view.pivot); s_TimeHelper.Update(); float deltaTime = s_TimeHelper.deltaTime; var eventCurrent = Event.current; if (Event.current.button == 1) { if (eventCurrent.type == EventType.MouseDown) { Reset(); rightMouseDown = true; } else if (eventCurrent.type == EventType.MouseUp) { rightMouseDown = false; } } if (rightMouseDown) { if (eventCurrent.keyCode == KeyCode.W) { if (eventCurrent.type == EventType.KeyDown) { w = true; eventCurrent.Use(); } else if (eventCurrent.type == EventType.KeyUp) { w = false; eventCurrent.Use(); } } if (eventCurrent.keyCode == KeyCode.S) { if (eventCurrent.type == EventType.KeyDown) { s = true; eventCurrent.Use(); } else if (eventCurrent.type == EventType.KeyUp) { s = false; eventCurrent.Use(); } } if (eventCurrent.keyCode == KeyCode.A) { if (eventCurrent.type == EventType.KeyDown) { a = true; eventCurrent.Use(); } else if (eventCurrent.type == EventType.KeyUp) { a = false; eventCurrent.Use(); } } if (eventCurrent.keyCode == KeyCode.D) { if (eventCurrent.type == EventType.KeyDown) { d = true; eventCurrent.Use(); } else if (eventCurrent.type == EventType.KeyUp) { d = false; eventCurrent.Use(); } } if (eventCurrent.keyCode == KeyCode.Q) { if (eventCurrent.type == EventType.KeyDown) { q = true; eventCurrent.Use(); } else if (eventCurrent.type == EventType.KeyUp) { q = false; eventCurrent.Use(); } } if (eventCurrent.keyCode == KeyCode.E) { if (eventCurrent.type == EventType.KeyDown) { e = true; eventCurrent.Use(); } else if (eventCurrent.type == EventType.KeyUp) { e = false; eventCurrent.Use(); } } if (eventCurrent.shift) { speedMod = 5f; } else { speedMod = 1f; } if (eventCurrent.type == EventType.ScrollWheel) { TargetSpeed = Mathf.Clamp(TargetSpeed * (1f - eventCurrent.delta.y * 0.05f), 0f, MaxSpeed); //Debug.Log("targetSpeed " + targetSpeed); eventCurrent.Use(); } if (w || a || s || d || q || e) { currentSpeed = Mathf.Lerp(currentSpeed, TargetSpeed * speedMod, AccelerationRate * deltaTime); moveDirection = Vector3.zero; if (w) { moveDirection += Vector3.forward; } if (s) { moveDirection -= Vector3.forward; } if (a) { moveDirection -= Vector3.right; } if (d) { moveDirection += Vector3.right; } if (q) { moveDirection += -Vector3.up; } if (e) { moveDirection += Vector3.up; } } else { currentSpeed = Mathf.Lerp(currentSpeed, 0f, DecelerationRate * deltaTime); } pivotLocalPos += moveDirection * deltaTime * currentSpeed; view.pivot = view.camera.transform.TransformPoint(pivotLocalPos); } else { moveDirection = Vector3.zero; currentSpeed = 0f; } }; }