private void OnSceneGUI() { SplineControlPoint controlPoint = (SplineControlPoint)target; SelectedIndex = controlPoint.Index; SceneGUIOverride(); }
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); }
protected override SplineBase GetTarget() { SplineControlPoint controlPoint = (SplineControlPoint)target; if (controlPoint) { SplineBase spline = controlPoint.GetComponentInParent <SplineBase>(); return(spline); } return(null); }
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 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 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 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 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 SetIsRigid(int index, bool isRigid) { if (target is SplineControlPoint) { for (int i = 0; i < targets.Length; ++i) { SplineControlPoint controlPoint = (SplineControlPoint)targets[i]; m_deformer.SetIsRigid(controlPoint.Index, isRigid); } } else { m_deformer.SetIsRigid(index, isRigid); } }
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 static void Insert() { GameObject selected = Selection.activeObject as GameObject; MeshDeformer deformer = selected.GetComponentInParent <MeshDeformer>(); Undo.RecordObject(deformer, "Battlehub.MeshDeformer.Prepend"); Scaffold[] scaffolds = deformer.GetComponentsInChildren <Scaffold>(); foreach (Scaffold scaffold in scaffolds) { Undo.RecordObject(scaffold, "Battlehub.MeshDeformer.Prepend"); } SplineControlPoint ctrlPoint = selected.GetComponent <ControlPoint>(); Undo.RegisterCreatedObjectUndo(deformer.Insert((ctrlPoint.Index + 2) / 3), "Battlehub.MeshDeformer.Insert"); EditorUtility.SetDirty(deformer); Selection.activeGameObject = deformer.GetComponentsInChildren <ControlPoint>(true).ElementAt(ctrlPoint.Index + 3).gameObject; }
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); } }
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; }
public override void Remove() { RunAction <SplineBase>((spline, go) => { MeshDeformer deformer = spline as MeshDeformer; if (deformer != null) { GameObject selection = RuntimeSelection.activeGameObject; if (selection != null) { SplineControlPoint ctrlPoint = selection.GetComponent <SplineControlPoint>(); if (ctrlPoint != null) { deformer.Remove((ctrlPoint.Index - 1) / 3); } RuntimeSelection.activeGameObject = deformer.gameObject; } } else { base.Remove(); } }); }
public override void Remove() { if (SplineRuntimeEditor.Instance != null) { MeshDeformer deformer = SplineRuntimeEditor.Instance.SelectedSpline as MeshDeformer; if (deformer != null) { GameObject selection = RuntimeSelection.activeGameObject; if (selection != null) { SplineControlPoint ctrlPoint = selection.GetComponent <SplineControlPoint>(); if (ctrlPoint != null) { deformer.Remove((ctrlPoint.Index - 1) / 3); } RuntimeSelection.activeGameObject = deformer.gameObject; } } else { base.Remove(); } } }
private void OnRuntimeSelectionChanged(UnityEngine.Object[] unselected) { SplineBase minSpline = null; int minIndex = -1; float minDistance = float.PositiveInfinity; if (unselected != null) { GameObject[] gameObjects = unselected.OfType <GameObject>().ToArray(); for (int i = 0; i < gameObjects.Length; ++i) { GameObject go = gameObjects[i]; if (go == null) { continue; } SplineBase spline = go.GetComponentInParent <SplineBase>(); if (spline == null) { continue; } spline.Select(); float distance = minDistance; SplineBase hitSpline; int selectedIndex = HitTest(spline, minDistance, out hitSpline, out distance); if (distance < minDistance && selectedIndex != -1) { minDistance = distance; minIndex = selectedIndex; minSpline = hitSpline; } spline.Unselect(); } if (minSpline != null) { SplineControlPoint ctrlPoint = minSpline.GetSplineControlPoints().Where(p => p.Index == minIndex).FirstOrDefault(); if (ctrlPoint != null) { RuntimeSelection.activeObject = ctrlPoint.gameObject; } minSpline.Select(); return; } } if (RuntimeSelection.gameObjects != null) { GameObject[] gameObjects = RuntimeSelection.gameObjects; if (gameObjects != null) { for (int i = 0; i < gameObjects.Length; ++i) { SplineBase spline = gameObjects[i].GetComponentInParent <SplineBase>(); if (spline != null) { spline.Select(); } } } } }
private void OnRuntimeSelectionChanged(UnityEngine.Object[] unselectedObjects) { m_controlPoint = GetSelectedControlPoint(); m_spline = GetSelectedSpline(); }
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); } }