Example #1
0
        private void OnHierarchySelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.NewItem != null && e.NewItem is SplineBase)
            {
                SplineBase newSpline = (SplineBase)e.NewItem;
                if (!newSpline.IsSelected)
                {
                    newSpline.Select();
                }

#if UNITY_EDITOR
                if (UnityEditor.Selection.activeGameObject == null || UnityEditor.Selection.activeGameObject.GetComponentInParent <SplineBase>() != m_hierarchy.SelectedItem)
                {
                    UnityEditor.Selection.activeObject = m_hierarchy.SelectedItem;
                }
#endif
            }
            else if (e.OldItem != null && e.OldItem is SplineBase)
            {
                SplineBase oldSpline = (SplineBase)e.OldItem;
                if (oldSpline.IsSelected)
                {
                    oldSpline.Unselect();
                }

#if UNITY_EDITOR
                if (UnityEditor.Selection.activeObject == (UnityEngine.Object)e.OldItem)
                {
                    UnityEditor.Selection.activeObject = null;
                }
#endif
            }
        }
Example #2
0
 public static void Separate(SplineBase spline, int controlPointIndex)
 {
     RecordHierarchy(spline.Root, "Battlehub.Spline.Separate");
     spline.Unselect();
     spline.Disconnect(controlPointIndex);
     spline.Select();
     EditorUtility.SetDirty(spline.Root);
 }
        private void OnEnable()
        {
            OnEnableOverride();

            SplineBase spline = GetTarget();

            if (spline)
            {
                spline.Select();
            }
        }
Example #4
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();
                    }
                }
            }
        }
 private void LateUpdate()
 {
     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();
             }
         }
     }
 }
Example #6
0
        private void OnEnable()
        {
            OnEnableOverride();

            SplineBase spline = GetTarget();

            if (spline)
            {
                spline.Select();
            }

            m_greenLabelStyle.normal.textColor = Color.green;
            m_addButton                  = new GUIStyle();
            m_addButton.alignment        = TextAnchor.UpperLeft;
            m_addButton.contentOffset    = new Vector2(-4, -10);
            m_addButton.normal.textColor = Color.green;


            m_branchButton                  = new GUIStyle();
            m_branchButton.alignment        = TextAnchor.UpperLeft;
            m_branchButton.contentOffset    = new Vector2(-4, -10);
            m_branchButton.normal.textColor = m_branchColor;
        }
 public static void Separate(SplineBase spline, int controlPointIndex)
 {
     spline.Unselect();
     spline.Disconnect(controlPointIndex);
     spline.Select();
 }
        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 = HitTestRecursive(spline.Root, 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();
                        }
                    }
                }
            }
        }