internal static PathRunner Create(SimpleCamPath path) { GameObject ownerObject = new GameObject("KerbCam.PathRunner"); UnityEngine.Object.DontDestroyOnLoad(ownerObject); PathRunner runner = ownerObject.AddComponent <PathRunner>(); runner.path = path; runner.ownerObject = ownerObject; // Don't use GUI layout, just input events and frame updates. runner.useGUILayout = false; runner.enabled = false; return(runner); }
private void DoKeyEditing() { if (selectedKeyIndex < 0 || selectedKeyIndex >= path.Count) { return; } bool remove = false; float keyTime = path.TimeAt(selectedKeyIndex); bool keyTimeChanged = false; TransformPoint trnPoint = path[selectedKeyIndex]; bool trnPointChanged = false; // Vertical time slider for selected key time. // This is a key editing control, but uses the vertical space // between path and key editing controls, so it's not put into // the key editing buttons layout region. { float newKeyTime = GUILayout.VerticalSlider(keyTime, 0f, path.MaxTime); if (Math.Abs(keyTime - newKeyTime) > 1e-5) { keyTime = newKeyTime; keyTimeChanged = true; } } GUILayout.BeginVertical(); // BEGIN key editing buttons GUILayout.Label(string.Format("Key #{0}", selectedKeyIndex)); { // Direct editing of key time. GUILayout.BeginHorizontal(); // BEGIN key time editing GUILayout.Label("@"); string newSelectedKeyTimeString = GUILayout.TextField(selectedKeyTimeString); if (newSelectedKeyTimeString != selectedKeyTimeString) { selectedKeyTimeString = newSelectedKeyTimeString; float newKeyTime; if (float.TryParse(selectedKeyTimeString, out newKeyTime)) { keyTime = newKeyTime; keyTimeChanged = true; } } GUILayout.Label("s"); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); // END key time editing } if (path.ScaleTime) { // Editing key timescale. float oldTimescale = trnPoint.timescale; GUILayout.Label(string.Format("Timescale: {0:0.00}\u00d7", oldTimescale)); float newTimescale = GUILayout.HorizontalSlider(oldTimescale, 0f, 4f); if (Math.Abs(oldTimescale - newTimescale) > 1e-5) { trnPoint.timescale = newTimescale; } if (GUILayout.Button("Reset timescale")) { trnPoint.timescale = 1f; } trnPointChanged = true; } if (GUILayout.Button("Set")) { trnPoint = SimpleCamPath.MakeTransformPoint( StateHandler.camControl.SecondTransform, StateHandler.camControl.transform, trnPoint.timescale); trnPointChanged = true; } if (GUILayout.Button("View")) { path.Runner.StopRunning(); StateHandler.manCamControl.TakeControl(); path.UpdateTransform( StateHandler.camControl.FirstTransform, StateHandler.camControl.SecondTransform, path.TimeAt(selectedKeyIndex)); } if (GUILayout.Button("Remove", WindowStyles.DeleteButtonStyle)) { remove = true; } GUILayout.EndVertical(); // END key editing buttons if (remove) { path.RemoveKey(selectedKeyIndex); if (selectedKeyIndex >= path.Count) { selectedKeyIndex = 0; } UpdateSelectedKeyTime(); // Don't make any other potential changes to the key. return; } if (keyTimeChanged) { selectedKeyIndex = path.MoveKeyAt(selectedKeyIndex, keyTime); UpdateSelectedKeyTime(); } if (trnPointChanged) { path[selectedKeyIndex] = trnPoint; } }
public bool IsForPath(SimpleCamPath path) { return(this.path == path); }
public SimpleCamPathEditor(SimpleCamPath path) { this.path = path; }