コード例 #1
0
ファイル: SplineBase.cs プロジェクト: TwelveAxes/Speed
        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;
                }
            }
        }
コード例 #2
0
        private void OnSceneGUI()
        {
            SplineControlPoint controlPoint = (SplineControlPoint)target;

            SelectedIndex = controlPoint.Index;
            SceneGUIOverride();
        }
コード例 #3
0
 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();
     }
 }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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;
        }
コード例 #9
0
        protected override SplineBase GetTarget()
        {
            SplineControlPoint controlPoint = (SplineControlPoint)target;

            if (controlPoint)
            {
                SplineBase spline = controlPoint.GetComponentInParent <SplineBase>();
                return(spline);
            }
            return(null);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
ファイル: SplineBase.cs プロジェクト: TwelveAxes/Speed
 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);
         }
     }
 }
コード例 #12
0
        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;
            }
        }
コード例 #13
0
        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;
        }
コード例 #14
0
 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);
             }
         }
     });
 }
コード例 #15
0
 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);
     }
 }
コード例 #16
0
 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);
     }
 }
コード例 #17
0
 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);
     }
 }
コード例 #18
0
 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);
     }
 }
コード例 #19
0
        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();
                    }
                }
            }
        }
コード例 #20
0
 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;
         }
     });
 }
コード例 #21
0
        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);
                    }
                }
            }
        }
コード例 #22
0
        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();
                    }
                }
            }
        }
コード例 #23
0
        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);
            }
        }
コード例 #24
0
        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));
        }
コード例 #25
0
        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);
            }
        }
コード例 #26
0
ファイル: SplineBase.cs プロジェクト: TwelveAxes/Speed
        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;
                }
            }
        }
コード例 #27
0
        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;
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        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);
            }
        }
コード例 #30
0
        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();
        }