private void ReloadProperties() { _IgnoreChanges = true; Keyframe3D key = _Path.Keys[_Path.SelectedIndex]; _FFTime.Value = key.Time; _VFValue.Value = key.Value; _VFInTangent.Value = key.InTangent; _VFOutTangent.Value = key.OutTangent; _IgnoreChanges = false; }
void _BtnSmoothPoint_Click(object sender, System.EventArgs e) { if (_Curve3D != null && _Path.SelectedIndex >= 0) { Undo.RecordObject(_Path, string.Format("Smooth Point : {0}", _Path.SelectedIndex)); _Curve3D.SmoothTangents(_Path.SelectedIndex, _Path.SmoothValue); Keyframe3D smoothedKey = _Curve3D[_Path.SelectedIndex]; _Path.Keys[_Path.SelectedIndex] = smoothedKey; ReloadProperties(); RebuildPoints(); } }
void SelectedPoint_ValueChanged(object sender, System.EventArgs e) { if (_Path.SelectedIndex >= 0 && !_IgnoreChanges) { _IgnoreChanges = true; Keyframe3D key = _Path.Keys[_Path.SelectedIndex]; Keyframe3D prekey = _Path.Keys[Mathf.Max(0, _Path.SelectedIndex - 1)]; Keyframe3D nextkey = _Path.Keys[Mathf.Min(_Path.Keys.Length - 1, _Path.SelectedIndex + 1)]; if (prekey != key && _FFTime.Value <= prekey.Time) { _FFTime.Value = prekey.Time + 0.0001f; } if (nextkey != key && _FFTime.Value >= nextkey.Time) { _FFTime.Value = nextkey.Time - 0.0001f; } if (_FFTime.Value < 0) { _FFTime.Value = 0; } if (_FFTime.Value > _Path.PathTime) { _FFLinearTime.Value = _Path.PathTime = _FFTime.Value; } else if (_Path.SelectedIndex == _Path.Keys.Length - 1 && _FFTime.Value < _Path.PathTime) { _FFLinearTime.Value = _Path.PathTime = _FFTime.Value; } key.Time = _FFTime.Value; key.Value = _VFValue.Value; key.InTangent = _VFInTangent.Value; key.OutTangent = _VFOutTangent.Value; _IgnoreChanges = false; } }
void _BtnAdd_Click(object sender, System.EventArgs e) { if (_Path.SelectedIndex < 0 || _Path.SelectedIndex == _Path.Keys.Length - 1) { _Path.SelectedIndex = _Path.Keys.Length - 1; } _Path.SelectedIndex++; Keyframe3D[] preKeys = _Path.Keys; _Path.Keys = new Keyframe3D[preKeys.Length + 1]; for (int i = 0; i < _Path.SelectedIndex; i++) { _Path.Keys[i] = preKeys[i]; } for (int i = _Path.SelectedIndex + 1; i < _Path.Keys.Length; i++) { _Path.Keys[i] = preKeys[i - 1]; } _Path.Keys[_Path.SelectedIndex] = new Keyframe3D(_Path.Keys[_Path.SelectedIndex - 1]); Keyframe3D preKey = _Path.Keys[Mathf.Max(_Path.SelectedIndex - 1, 0)]; Keyframe3D nextKey = _Path.Keys[Mathf.Min(_Path.SelectedIndex + 1, _Path.Length - 1)]; _Path.Keys[_Path.SelectedIndex].Value = (preKey.Value + nextKey.Value) * 0.5f; _Path.Keys[_Path.SelectedIndex].Time = (preKey.Time + nextKey.Time) * 0.5f; if (_Path.SelectedIndex == _Path.Length - 1) { _Path.Keys[_Path.SelectedIndex].Time++; } ValidateGrid(); _BtnRemove.IsEnabled = _Path.Keys.Length > 2; _GridPoints.SelectedIndex = _Path.SelectedIndex; ReloadProperties(); RebuildPath(); }
void OnSceneGUI() { //if (Event.current != null) //{ // Event e = Event.current; // if (e.isMouse && e.type == EventType.mouseDown && e.button == 0) // _GridPoints.SelectedIndex = CheckSelectedIndexByMouse(e.mousePosition); //} if (_CurvePoints != null && _Path != null) { Handles.color = _Path.Color; Handles.DrawAAPolyLine(3, _CurvePoints); } int index = _Path.SelectedIndex; if (index >= 0) { bool changed = _Path.transform.hasChanged; Keyframe3D key = _Path.Keys[index]; Vector3 prePos = key.Value; if (!_Path.UseWorldSpace) { prePos = _Path.transform.TransformPoint(prePos); } Vector3 newPos = Handles.PositionHandle(prePos, Quaternion.identity); if (key.Value != newPos) { if (!_Path.UseWorldSpace) { newPos = _Path.transform.InverseTransformPoint(newPos); } _VFValue.Value = key.Value = newPos; changed = true; } if (_Path.ShowInTangent) { changed |= DrawTangentHandle(key.Value, Color.magenta, "In", ref key.InTangent); } if (_Path.ShowOutTangent) { changed |= DrawTangentHandle(key.Value, Color.magenta, "Out", ref key.OutTangent); } if (changed) { EditorUtility.SetDirty(_Path); RebuildPath(); ReloadProperties(); } } // ********************************* Simulation ************************************* if (_SimulationStarted) { if (_Curve3D != null) { _SimulationCurrectTime += _SimulationSpeed / 120.0f; if (_SimulationCurrectTime >= _Path.TimeLength) { StopSimulation(); } else { Vector3 pos; if (_Path.UseWorldSpace) { pos = _Curve3D.Evaluate(_SimulationCurrectTime); } else { pos = _Path.transform.TransformPoint(_Curve3D.Evaluate(_SimulationCurrectTime)); } Handles.color = Color.red; Handles.SphereCap(0, pos, Quaternion.identity, HandleUtility.GetHandleSize(pos) * 0.2f); SceneView.focusedWindow.Repaint(); } } } // ********************************* GUI ************************************* Handles.BeginGUI(); GUILayout.BeginArea(new Rect(Screen.width - 200, Screen.height - 90, 190, 120)); GUILayout.BeginVertical(); if (_SimulationStarted) { if (GUILayout.Button("Stop Simulation")) { StopSimulation(); } } else { if (GUILayout.Button("Start Simulation")) { StartSimulation(); } } GUILayout.BeginHorizontal(); GUILayout.Label(string.Format("Speed : {0:F2}", _SimulationSpeed), GUILayout.MaxWidth(80)); _SimulationSpeed = GUILayout.HorizontalSlider(_SimulationSpeed, 0.1f, 2.0f); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndArea(); Handles.EndGUI(); }