public void Unselect() { if (GLRenderer.Instance != null) { GLRenderer.Instance.Remove(this); } SplineControlPoint[] ctrlPoints = GetControlPoints(); for (int i = 0; i < ctrlPoints.Length; ++i) { SplineControlPoint ctrlPoint = ctrlPoints[i]; if (ctrlPoint) { ctrlPoint.gameObject.SetActive(false); } } m_isSelected = false; if (SplineRuntimeEditor.Instance != null) { if (SplineRuntimeEditor.Instance.SelectedSpline == this) { SplineRuntimeEditor.Instance.SelectedSpline = null; } } }
private void OnSceneGUI() { SplineControlPoint controlPoint = (SplineControlPoint)target; SelectedIndex = controlPoint.Index; SceneGUIOverride(); }
private void OnRuntimeSelectionChanged(UnityEngine.Object[] unselectedObjects) { if (SplineBase.ConvergingSpline) { SplineControlPoint selectedControlPoint = GetSelectedControlPoint(); Spline selectedSpline = GetSelectedSpline(); if (selectedControlPoint == null || m_controlPoint == null || m_spline == null) { SplineBase.ConvergingSpline = null; } else { if (Converge(selectedSpline, m_spline, selectedControlPoint.Index, m_controlPoint.Index)) { SplineBase.ConvergingSpline = null; m_spline = selectedSpline; m_controlPoint = selectedControlPoint; } else { SplineBase.ConvergingSpline = null; } } } else { m_controlPoint = GetSelectedControlPoint(); m_spline = GetSelectedSpline(); } }
public static bool CanConverge() { if (SplineBaseEditor.ConvergingSpline) { return(false); } GameObject selected = Selection.activeObject as GameObject; if (selected == null) { return(false); } SplineControlPoint ctrlPoint = selected.GetComponent <SplineControlPoint>(); Spline spline = selected.GetComponentInParent <Spline>(); if (spline == null || ctrlPoint == null) { return(false); } if (ctrlPoint.Index == 0 && spline.PrevSpline == null || ctrlPoint.Index == spline.ControlPointCount - 1 && spline.NextSpline == null) { if (!spline.HasBranches(ctrlPoint.Index)) { return(true); } } return(false); }
public static void Separate() { GameObject selected = Selection.activeObject as GameObject; SplineControlPoint ctrlPoint = selected.GetComponent <SplineControlPoint>(); Spline spline = selected.GetComponentInParent <Spline>(); SplineControlPointEditor.Separate(spline, ctrlPoint.Index); }
public static void CreateInBranch() { GameObject selected = Selection.activeGameObject as GameObject; SplineControlPoint ctrlPoint = selected.GetComponent <SplineControlPoint>(); Spline spline = selected.GetComponentInParent <Spline>(); SplineControlPointEditor.CreateBranch(spline, ctrlPoint.Index, true); }
private static void Remove() { GameObject selected = Selection.activeObject as GameObject; SplineControlPoint ctrlPoint = selected.GetComponent <SplineControlPoint>(); Spline spline = selected.GetComponentInParent <Spline>(); Selection.activeGameObject = spline.gameObject; SplineControlPointEditor.Remove(spline, ctrlPoint.Index); }
private static void Insert() { GameObject selected = Selection.activeObject as GameObject; Spline spline = selected.GetComponentInParent <Spline>(); SplineControlPoint ctrlPoint = selected.GetComponent <SplineControlPoint>(); SplineEditor.Insert(spline, ctrlPoint.Index); Selection.activeGameObject = spline.GetSplineControlPoints().ElementAt(ctrlPoint.Index + 3).gameObject; }
protected override SplineBase GetTarget() { SplineControlPoint controlPoint = (SplineControlPoint)target; if (controlPoint) { SplineBase spline = controlPoint.GetComponentInParent <SplineBase>(); return(spline); } return(null); }
private static void Remove() { GameObject selected = Selection.activeObject as GameObject; SplineControlPoint ctrlPoint = selected.GetComponent <SplineControlPoint>(); Spline spline = selected.GetComponentInParent <Spline>(); Selection.activeGameObject = spline.gameObject; Undo.RecordObject(spline, "Battlehub.Spline.Remove"); spline.Remove((ctrlPoint.Index - 1) / 3); EditorUtility.SetDirty(spline); }
private void RemoveControlPoints() { EditorApplication.delayCall -= m_removeCallback; for (int i = 0; i < m_controlPointsToRemove.Length; ++i) { SplineControlPoint controlPoint = m_controlPointsToRemove[i]; if (controlPoint != null) { Undo.DestroyObjectImmediate(controlPoint.gameObject); } } }
private void InitActiveSpline() { if (m_spline == null) { m_spline = GetTarget() as Spline; SplineControlPoint controlPoint = (SplineControlPoint)target; SelectedIndex = controlPoint.Index; SplineBase.ActiveControlPointIndex = controlPoint.Index; SplineBase.ActiveSpline = m_spline; } }
private static void Insert() { GameObject selected = Selection.activeObject as GameObject; Spline spline = selected.GetComponentInParent <Spline>(); SplineControlPoint ctrlPoint = selected.GetComponent <SplineControlPoint>(); Undo.RecordObject(spline, "Battlehub.Spline.Insert"); spline.Insert((ctrlPoint.Index + 2) / 3); EditorUtility.SetDirty(spline); Selection.activeGameObject = spline.GetComponentsInChildren <SplineControlPoint>(true).ElementAt(ctrlPoint.Index + 3).gameObject; }
public virtual void Insert() { RunAction <Spline>((spline, go) => { if (go != null) { SplineControlPoint ctrlPoint = go.GetComponent <SplineControlPoint>(); if (ctrlPoint != null) { spline.Insert((ctrlPoint.Index + 2) / 3); } } }); }
private void SetThickness(int index, Thickness thickness) { if (target is SplineControlPoint) { for (int i = 0; i < targets.Length; ++i) { SplineControlPoint controlPoint = (SplineControlPoint)targets[i]; m_splineBase.SetThickness(controlPoint.Index, thickness); } } else { m_splineBase.SetThickness(index, thickness); } }
private void SetTwist(int index, Twist twist) { if (target is SplineControlPoint) { for (int i = 0; i < targets.Length; ++i) { SplineControlPoint controlPoint = (SplineControlPoint)targets[i]; m_splineBase.SetTwist(controlPoint.Index, twist); } } else { m_splineBase.SetTwist(index, twist); } }
private void SetControlPointMode(int index, ControlPointMode mode) { if (target is SplineControlPoint) { for (int i = 0; i < targets.Length; ++i) { SplineControlPoint controlPoint = (SplineControlPoint)targets[i]; m_splineBase.SetControlPointMode(controlPoint.Index, mode); } } else { m_splineBase.SetControlPointMode(index, mode); } }
private void SetWrap(int index, Wrap wrap) { if (target is SplineControlPoint) { for (int i = 0; i < targets.Length; ++i) { SplineControlPoint controlPoint = (SplineControlPoint)targets[i]; m_splineBase.SetWrap(controlPoint.Index, wrap); } } else { m_splineBase.SetWrap(index, wrap); } }
private void LateUpdate() { if (Application.isPlaying) { if (SelectedSpline != null) { if (Input.GetMouseButtonDown(0) && (EventSystem.current == null || !EventSystem.current.IsPointerOverGameObject())) { int selectedIndex = HitTest(); if (selectedIndex != -1) { SplineControlPoint ctrlPoint = SelectedSpline.GetComponentsInChildren <SplineControlPoint>().Where(p => p.Index == selectedIndex).FirstOrDefault(); RuntimeSelection.activeGameObject = ctrlPoint.gameObject; } else { if (RuntimeTools.Current != RuntimeTool.View) { if (RuntimeSelection.activeGameObject != null) { if (PositionHandle.Current != null && !PositionHandle.Current.IsDragging) { if (SelectedSpline != null) { RuntimeSelection.activeGameObject = SelectedSpline.gameObject; } } } } } } } } if (m_instance == null) { m_instance = this; SplineBase[] splines = FindObjectsOfType <SplineBase>(); for (int i = 0; i < splines.Length; ++i) { SplineBase spline = splines[i]; if (spline.IsSelected) { spline.Select(); } } } }
public virtual void Remove() { RunAction <Spline>((spline, go) => { if (go != null) { SplineControlPoint ctrlPoint = go.GetComponent <SplineControlPoint>(); if (ctrlPoint != null) { int curveIndex = Mathf.Min((ctrlPoint.Index + 1) / 3, spline.CurveCount - 1); spline.Remove(curveIndex); } RuntimeSelection.activeObject = spline.gameObject; } }); }
public virtual void Insert() { Spline spline = SplineRuntimeEditor.Instance.SelectedSpline as Spline; if (spline != null) { GameObject selection = RuntimeSelection.activeGameObject; if (selection != null) { SplineControlPoint ctrlPoint = selection.GetComponent <SplineControlPoint>(); if (ctrlPoint != null) { spline.Insert((ctrlPoint.Index + 2) / 3); } } } }
private void OnSceneGUI() { InitActiveSpline(); SplineControlPoint controlPoint = (SplineControlPoint)target; SelectedIndex = controlPoint.Index; SceneGUIOverride(); if (EditorWindow.focusedWindow == SceneView.lastActiveSceneView) { if (Event.current != null && (Event.current.type == EventType.MouseUp)) { SplineControlPoint[] controlPoints = m_spline.GetSplineControlPoints(); for (int i = 0; i < controlPoints.Length; ++i) { controlPoints[i].UpdateAngle(); } } } }
private static void SetMode(GameObject selected, ControlPointMode mode) { Spline spline = selected.GetComponentInParent <Spline>(); if (spline == null) { return; } SplineControlPoint selectedControlPoint = selected.GetComponent <SplineControlPoint>(); if (selectedControlPoint != null) { SplineBaseEditor.SetMode(spline, mode, selectedControlPoint.Index); } else { SplineBaseEditor.SetMode(spline, mode); } }
public static bool CanSeparate() { if (SplineBaseEditor.ConvergingSpline) { return(false); } GameObject selected = Selection.activeObject as GameObject; if (selected == null) { return(false); } SplineControlPoint ctrlPoint = selected.GetComponent <SplineControlPoint>(); Spline spline = selected.GetComponentInParent <Spline>(); if (spline == null || ctrlPoint == null) { return(false); } return(spline.HasBranches(ctrlPoint.Index)); }
private static void SetMode(GameObject selected, ControlPointMode mode) { Spline spline = selected.GetComponentInParent <Spline>(); if (spline == null) { return; } SplineControlPoint selectedControlPoint = selected.GetComponent <SplineControlPoint>(); Undo.RecordObject(spline, "Battlehub.Spline.SetMode"); EditorUtility.SetDirty(spline); if (selectedControlPoint != null) { spline.SetControlPointMode(selectedControlPoint.Index, mode); } else { spline.SetControlPointMode(mode); } }
public void Select() { if (GLRenderer.Instance != null) { GLRenderer.Instance.Add(this); } SplineControlPoint[] ctrlPoints = GetControlPoints(); for (int i = 0; i < ctrlPoints.Length; ++i) { SplineControlPoint ctrlPoint = ctrlPoints[i]; ctrlPoint.gameObject.SetActive(true); } m_isSelected = true; if (SplineRuntimeEditor.Instance != null) { if (SplineRuntimeEditor.Instance.SelectedSpline != this) { SplineRuntimeEditor.Instance.SelectedSpline = this; } } }
private void OnDestroy() { if (!Application.isPlaying) { DisableRuntimeEditing(); } bool enteringPlayMode = false; #if UNITY_EDITOR enteringPlayMode = UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode && !UnityEditor.EditorApplication.isPlaying; #endif if (!m_isApplicationQuit && !enteringPlayMode) { SplineControlPoint[] controlPoints = Resources.FindObjectsOfTypeAll <SplineControlPoint>(); for (int i = 0; i < controlPoints.Length; ++i) { SplineControlPoint controlPoint = controlPoints[i]; if (controlPoint != null) { controlPoint.DestroyRuntimeComponents(); } } } if (Destroyed != null) { Destroyed(this, EventArgs.Empty); } RuntimeSelection.SelectionChanged -= OnRuntimeSelectionChanged; m_instance = null; }
private void ShowPoint(SplineBase spline, int index, Vector3 point, Quaternion handleRotation) { if (!CanShowPoint(index)) { return; } bool hasBranches = spline.HasBranches(index); Handles.color = ModeColors[(int)spline.GetControlPointMode(index)]; if (index % 3 == 0) { if (hasBranches) { Handles.color = m_branchColor; } else { Handles.color = Color.green; } } float size = HandleUtility.GetHandleSize(point); Handles.CapFunction dcf = Handles.DotHandleCap; if (index == 0) { if (!hasBranches) { size *= 1.5f; } } if (Handles.Button(point, handleRotation, size * HandleSize, size * PickSize, dcf)) { SplineBase unselectedSpline = m_selectedSpline; m_selectedSpline = spline; int unselectedIndex = m_selectedIndex; m_selectedIndex = index; if (OnControlPointClick(unselectedIndex, m_selectedIndex)) { SplineControlPoint controlPoint = spline.GetSplineControlPoints().Where(cpt => cpt.Index == index).FirstOrDefault(); if (controlPoint != null) { Selection.activeGameObject = controlPoint.gameObject; } } else { m_selectedIndex = unselectedIndex; m_selectedSpline = unselectedSpline; } Repaint(); } if (m_selectedIndex == index && spline == m_splineBase) { ShowLengths(spline, index, true); } ShowPointOverride(spline, index, point, handleRotation, size); }
private void ShowPoint(int index, Vector3 point) { if (!CanShowPoint(index)) { return; } Handles.color = ModeColors[(int)m_splineBase.GetControlPointMode(index)]; if (index % 3 == 0) { Handles.color = Color.green; } float size = HandleUtility.GetHandleSize(point); Handles.CapFunction dcf = Handles.DotHandleCap; if (index == 0) { size *= 2f; } if (Handles.Button(point, m_handleRotation, size * HandleSize, size * PickSize, dcf)) { m_selectedIndex = index; SplineControlPoint controlPoint = m_splineBase.GetComponentsInChildren <SplineControlPoint>(true).Where(cpt => cpt.Index == index).FirstOrDefault(); if (controlPoint != null) { if (Event.current.control || Event.current.shift) { GameObject[] objects = Selection.gameObjects; Selection.activeGameObject = controlPoint.gameObject; if (!objects.Contains(controlPoint.gameObject)) { ArrayUtility.Add(ref objects, controlPoint.gameObject); } else { if (!Event.current.shift) { ArrayUtility.Remove(ref objects, controlPoint.gameObject); } } Selection.objects = objects; } else { Selection.activeGameObject = controlPoint.gameObject; } } Repaint(); } if (m_selectedIndex == index) { int curveIndex = (m_selectedIndex - 1) / 3; int prevCurveIndex = curveIndex - 1; int nextCurveIndex = curveIndex + 1; if (m_splineBase.Loop) { if (prevCurveIndex < 0) { prevCurveIndex = m_splineBase.CurveCount - 1; } if (nextCurveIndex > m_splineBase.CurveCount - 1) { nextCurveIndex = 0; } } GUIStyle style = new GUIStyle(); style.normal.textColor = Color.green; if (prevCurveIndex >= 0) { float prevLen = m_splineBase.EvalLength(prevCurveIndex); float prevCur = m_splineBase.EvalCurveLength(prevCurveIndex, GetStepsPerCurve()); Handles.Label(m_splineBase.GetPoint(0.5f, prevCurveIndex), string.Format("Len: {0:0.00} m, Cur: {1:0.00} m", prevLen, prevCur), style); } if (nextCurveIndex < m_splineBase.CurveCount) { float nextLen = m_splineBase.EvalLength(nextCurveIndex); float nextCur = m_splineBase.EvalCurveLength(nextCurveIndex, GetStepsPerCurve()); Handles.Label(m_splineBase.GetPoint(0.5f, nextCurveIndex), string.Format("Len: {0:0.00} m, Cur: {1:0.00} m", nextLen, nextCur), style); } float cur = m_splineBase.EvalCurveLength(curveIndex, GetStepsPerCurve()); float len = m_splineBase.EvalLength(curveIndex); Handles.Label(m_splineBase.GetPoint(0.5f, curveIndex), string.Format("Len: {0:0.00} m, Cur: {1:0.00} m", len, cur), style); } }
protected override void OnInspectorGUIOverride() { if (m_spline == null) { return; } if (ConvergingSpline) { if (GUILayout.Button("Cancel")) { ConvergingSpline = null; } return; } GUILayout.BeginHorizontal(); { GUILayout.BeginVertical(); int curveIndex = (SelectedIndex - 1) / 3; if (GUILayout.Button("OUT -> Branch")) { CreateBranch(m_spline, SelectedIndex, false); } if (curveIndex == m_spline.CurveCount - 1 && m_spline.NextSpline == null) { if (m_spline.NextSpline == null) { if (GUILayout.Button("Append")) { SplineEditor.Append(m_spline); Selection.activeGameObject = m_spline.GetSplineControlPoints().Last().gameObject; } } } if (curveIndex == 0 && m_spline.PrevSpline == null) { if (m_spline.PrevSpline == null) { if (GUILayout.Button("Prepend")) { SplineEditor.Prepend(m_spline); Selection.activeGameObject = m_spline.GetSplineControlPoints().First().gameObject; } } } if (GUILayout.Button("Insert")) { SplineEditor.Insert(m_spline, SelectedIndex); Selection.activeGameObject = m_spline.GetSplineControlPoints().ElementAt(SelectedIndex + 3).gameObject; } GUILayout.EndVertical(); GUILayout.BeginVertical(); if (GUILayout.Button("Branch -> IN")) { CreateBranch(m_spline, SelectedIndex, true); } if (curveIndex == m_spline.CurveCount - 1 && m_spline.NextSpline == null) { if (m_spline.NextSpline == null) { if (SceneView.lastActiveSceneView != null && SceneView.lastActiveSceneView.camera) { if (GUILayout.Button("To Cam")) { SplineEditor.AppendThrough(m_spline, SceneView.lastActiveSceneView.camera.transform); Selection.activeGameObject = m_spline.GetSplineControlPoints().Last().gameObject; } } } } if (curveIndex == 0 && m_spline.PrevSpline == null) { if (m_spline.PrevSpline == null) { if (SceneView.lastActiveSceneView != null && SceneView.lastActiveSceneView.camera) { if (GUILayout.Button("To Cam")) { SplineEditor.PrependThrough(m_spline, SceneView.lastActiveSceneView.camera.transform); Selection.activeGameObject = m_spline.GetSplineControlPoints().First().gameObject; } } } } if (SelectedIndex >= 0 && curveIndex < m_spline.CurveCount) { if (GUILayout.Button("Remove")) { Remove(m_spline, SelectedIndex); } } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); if (SelectedIndex == 0 && m_spline.PrevSpline == null || SelectedIndex == m_spline.ControlPointCount - 1 && m_spline.NextSpline == null) { if (!m_spline.HasBranches(SelectedIndex)) { if (GUILayout.Button("Converge")) { if (m_spline.Loop) { EditorUtility.DisplayDialog("Unable to converge", "Unable to converge. Selected spline has loop.", "OK"); } else { ConvergingSpline = m_spline; } } } } if (SelectedIndex < m_spline.ControlPointCount && SelectedIndex >= 0) { if (m_spline.HasBranches(SelectedIndex)) { if (GUILayout.Button("Separate")) { Separate(m_spline, SelectedIndex); } } } if (GUILayout.Button("Align View To Point")) { if (SceneView.lastActiveSceneView != null) { SplineControlPoint controlPoint = (SplineControlPoint)target; SceneView.lastActiveSceneView.AlignViewToObject(controlPoint.transform); SceneView.lastActiveSceneView.Repaint(); } } base.OnInspectorGUIOverride(); }