Пример #1
0
        void OnGUI()
        {
            SplineEditor splineEditor = SplineEditor.current;

            if (splineEditor == null)
            {
                Close();
                return;
            }

            if (GUILayout.Button(splineEditor.hideHandles ? "Show\nHandles" : "Hide\nHandles"))
            {
                splineEditor.hideHandles = !splineEditor.hideHandles;
                EditorPrefs.SetBool(SplineEditor.HIDE_HANDLE_KEY, splineEditor.hideHandles);
                SceneView.RepaintAll();
            }

            if (GUILayout.Button(splineEditor.hideArrows ? "Show\nArrows" : "Hide\nArrows"))
            {
                splineEditor.hideArrows = !splineEditor.hideArrows;
                EditorPrefs.SetBool(SplineEditor.HIDE_ARROW_KEY, splineEditor.hideArrows);
                SceneView.RepaintAll();
            }

            if (GUILayout.Button(splineEditor.showIndex ? "Hide\nIndex" : "Show\nIndex"))
            {
                splineEditor.showIndex = !splineEditor.showIndex;
                EditorPrefs.SetBool(SplineEditor.SHOW_INDEX_KEY, splineEditor.showIndex);
                SceneView.RepaintAll();
            }
        }
Пример #2
0
        /// <summary>
        /// initilize the tool
        /// </summary>
        void OnEnable()
        {
            current = this;
            // getting saved data form player prefs
            hideHandles = EditorPrefs.GetBool(HIDE_HANDLE_KEY);
            isDragMode  = EditorPrefs.GetBool(IS_DRAG_MODE_KEY);
            hideArrows  = EditorPrefs.GetBool(HIDE_ARROW_KEY);
            showIndex   = EditorPrefs.GetBool(SHOW_INDEX_KEY);

            DefaultHandles.Hidden = hideDefaultHandles;
            if (SplineTools.Instance)
            {
                SplineTools.Instance.Repaint();
            }

            EditorUtility.SetDirty(target);
        }
Пример #3
0
        void OnGUI()
        {
            #region checkers
            if (Selection.activeGameObject == null)
            {
                NotSelectedOptions();
                return;
            }
            SplineWindow splineWindow = Selection.activeGameObject.GetComponent <SplineWindow>();
            if (splineWindow == null)
            {
                NotSelectedOptions();
                return;
            }
            Spline       spline       = splineWindow.spline;
            SplineEditor splineEditor = SplineEditor.current;
            if (spline == null || splineEditor == null)
            {
                NotSelectedOptions();
                return;
            }
            #endregion

            scrollView = GUILayout.BeginScrollView(scrollView);

            #region buttons
            if (GUILayout.Button("Show/Hide", GUILayout.Width(WIDTH), GUILayout.Height(HEIGHT / 2)))
            {
                if (showHidePopup != null)
                {
                    showHidePopup.Close();
                    showHidePopup = null;
                }
                else
                {
                    showHidePopup = ShowHidePopUp.CreateInstance <ShowHidePopUp>();
                    showHidePopup.ShowPopup();
                    showHidePopup.position = new Rect(Event.current.mousePosition.x + position.x, Event.current.mousePosition.y + position.y, 100, (HEIGHT / 2) * 3);
                }
            }

            if (GUILayout.Button("Deselect\nAll", GUILayout.Width(WIDTH), GUILayout.Height(HEIGHT / 2)))
            {
                splineEditor.selectedPoints = new List <int>();
                splineEditor.Repaint();
                SceneView.RepaintAll();
            }

            if (GUILayout.Button("Center\nPivot", GUILayout.Width(WIDTH), GUILayout.Height(HEIGHT / 2)))
            {
                splineEditor.CenterOnChildern();
                SceneView.RepaintAll();
            }

            if (GUILayout.Button(splineEditor.isDragMode ? "use\nhandles" : "use\ndrag", GUILayout.Width(WIDTH), GUILayout.Height(HEIGHT / 2)))
            {
                splineEditor.isDragMode = !splineEditor.isDragMode;
                EditorPrefs.SetBool(SplineEditor.IS_DRAG_MODE_KEY, splineEditor.isDragMode);
                SceneView.RepaintAll();
            }

            GUILayout.BeginHorizontal();

            if (GUILayout.Button(new GUIContent(delete, "Delets all points in spline"), GUILayout.Width(WIDTH / 2), GUILayout.Height(HEIGHT / 2)))
            {
                spline.waypoints = new Waypoint[] { };
                splineEditor.Repaint();
                SceneView.RepaintAll();
            }
            GUILayout.Space(-5);
            if (GUILayout.Button(new GUIContent(reload, "Reloads the spline"), GUILayout.Width(WIDTH / 2), GUILayout.Height(HEIGHT / 2)))
            {
                Undo.RecordObject(splineWindow.spline, "Undo reload");
                splineEditor.selectedPoints = new List <int>();
                splineWindow.spline         = Spline.CreateSpline(splineWindow.splineRefernce);
                splineEditor.Repaint();
                SceneView.RepaintAll();
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (!splineWindow.splineRefernce.Equals(spline))
            {
                GUI.color = Color.red;
            }
            if (GUILayout.Button(new GUIContent(save, "Saves the spline"), GUILayout.Width(WIDTH / 2), GUILayout.Height(HEIGHT / 2)))
            {
                splineEditor.Save();
            }
            GUI.color = Color.white;
            GUILayout.Space(-5);
            if (GUILayout.Button(new GUIContent(saveAs, "Save the spline in new path"), GUILayout.Width(WIDTH / 2), GUILayout.Height(HEIGHT / 2)))
            {
                //ScriptableObjectUtility.CreateAsset<Spline>();
                Spline temp      = Spline.CreateSpline();
                string assetName = AssetDatabase.GenerateUniqueAssetPath("Assets/" + splineWindow.splineRefernce.name + "_Copy.asset");
                AssetDatabase.CreateAsset(temp, assetName);
                Selection.activeObject = temp;
                AssetDatabase.SaveAssets();
                //temp.name = sw.splineRefernce.name + "_Copy";

                splineWindow.splineRefernce = temp;
                splineEditor.Save();
            }
            GUILayout.EndHorizontal();

            if (GUILayout.Button("stick to \n ground", GUILayout.Width(WIDTH), GUILayout.Height(HEIGHT / 2)))
            {
                Undo.RecordObject(spline, "stick to ground");
                for (int i = 0; i < spline.Length; i++)
                {
                    splineEditor.StickToGround(i);
                }

                SceneView.RepaintAll();
            }

            //clean button
            if (GUILayout.Button("Clean", GUILayout.Width(WIDTH), GUILayout.Height(HEIGHT / 2)))
            {
                Undo.RecordObject(spline, "Clean");
                spline.CleanSpline();

                splineEditor.Repaint();
                SceneView.RepaintAll();
            }

            if (splineEditor.selectedPoints.Count < 1)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button("Sharpen", GUILayout.Width(WIDTH), GUILayout.Height(HEIGHT / 2)))
            {
                Undo.RecordObject(spline, "Sharpen");

                foreach (int i in splineEditor.selectedPoints)
                {
                    spline.Sharpen(i);

                    splineWindow.SetLocalPositions();
                    SceneView.RepaintAll();
                }
            }
            GUI.enabled = true;
            #endregion

            #region buttons when 2 points are selected
            if (splineEditor.selectedPoints.Count != 2)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button(drawLine, GUILayout.Width(WIDTH), GUILayout.Height(HEIGHT)))
            {
                spline.DrawLine(splineEditor.selectedPoints[0], splineEditor.selectedPoints[1]);
                splineWindow.SetLocalPositions();

                splineEditor.Repaint();
                SceneView.RepaintAll();
            }

            // addpoint between button
            if (GUILayout.Button("subdivide", GUILayout.Width(WIDTH), GUILayout.Height(HEIGHT / 2)))
            {
                spline.Subdivide(splineEditor.selectedPoints[0], splineEditor.selectedPoints[1]);
                splineWindow.SetLocalPositions();

                splineEditor.Repaint();
                SceneView.RepaintAll();
            }

            if (GUILayout.Button("Merge", GUILayout.Width(WIDTH), GUILayout.Height(HEIGHT / 2)))
            {
                spline.Merge(splineEditor.selectedPoints[0], splineEditor.selectedPoints[1]);
                splineWindow.SetLocalPositions();

                splineEditor.Repaint();
                SceneView.RepaintAll();
            }

            if (GUILayout.Button("Remove\nline", GUILayout.Width(WIDTH), GUILayout.Height(HEIGHT / 2)))
            {
                spline.RemoveLine(splineEditor.selectedPoints[0], splineEditor.selectedPoints[1]);
                splineWindow.SetLocalPositions();

                splineEditor.Repaint();
                SceneView.RepaintAll();
            }
            #endregion

            GUILayout.EndScrollView();
        }