public override void DoInspectorGUI()
        {
            using (new NamedVerticalScope("Shape Editor Brush"))
            {
                GUILayout.BeginHorizontal(EditorStyles.toolbar);
                GUIStyle createBrushStyle = new GUIStyle(EditorStyles.toolbarButton);
                if (GUILayout.Button(new GUIContent(" Shape Editor", SabreCSGResources.ButtonShapeEditorTexture, "Show 2D Shape Editor"), createBrushStyle))
                {
                    // display the 2d shape ditor.
                    ShapeEditorWindow.Init();
                }
                if (GUILayout.Button(new GUIContent(" Restore Project", SabreCSGResources.ShapeEditorRestoreTexture, "Load Embedded Project Into 2D Shape Editor"), createBrushStyle))
                {
                    if (EditorUtility.DisplayDialog("2D Shape Editor", "Are you sure you wish to restore the embedded project?\r\nAny unsaved work in the 2D Shape Editor will be lost!", "Yes", "No"))
                    {
                        // display the 2d shape ditor.
                        ShapeEditorWindow window = ShapeEditorWindow.InitAndGetHandle();
                        // load a copy of the embedded project into the editor.
                        window.LoadProject(BrushTarget.GetComponent <ShapeEditorBrush>().GetEmbeddedProject());
                    }
                }
                GUILayout.EndHorizontal();
            }

            base.DoInspectorGUI();
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the closest point from a position, returns null point if the position is too far
        /// </summary>
        /// <param name="position"></param>
        /// <param name="editor"></param>
        /// <param name="maximumDistance"></param>
        /// <returns></returns>
        public static int GetClosestPointIndex(Vector2 position, ShapeEditorWindow editor, float maximumDistance = SELECTION_DISTANCE)
        {
            float closestDistance = Mathf.Infinity;
            int   closestId       = 0;

            //Convert the position to the point space dimensions
            Vector2 pointSpacePos = editor.WindowSpaceToPointSpace(position);

            //Check all point distances and keep the closest one
            for (int i = 0; i < editor.Asset.shape.PointCount; i++)
            {
                float distance = Vector2.Distance(pointSpacePos, editor.Asset.shape.GetVerticePosition(i));
                if (distance < closestDistance)
                {
                    closestId       = i;
                    closestDistance = distance;
                }
            }

            //Convert the point position to window space to calculate distance relatively to the screen
            Vector2 selectedPointScreenPos = editor.Asset.shape.GetVerticePosition(closestId);

            selectedPointScreenPos = editor.PointSpaceToWindowSpace(selectedPointScreenPos);

            //Returns the point if this one is close enough
            if (Vector2.Distance(selectedPointScreenPos, position) <= maximumDistance)
            {
                return(closestId);
            }
            return(NONE);
        }
Esempio n. 3
0
 public void SetEditor(ShapeEditorWindow editor)
 {
     if (editor != null)
     {
         _editor = editor;
     }
     else
     {
         Debug.LogWarning("Cannot set the current editor to null, ensure to set a corect reference");
     }
 }
Esempio n. 4
0
        public override void OnInspectorGUI()
        {
            GUILayout.Space(5.0f);

            EditorGUILayout.BeginHorizontal();
            ShapeAsset shapeAsset = (ShapeAsset)EditorGUILayout.ObjectField(
                "Shape", _currentPath.shapeAsset, typeof(ShapeAsset), false);

            _currentPath.shapeAsset = shapeAsset;

            if (shapeAsset != null)
            {
                if (GUILayout.Button("Edit", GUILayout.Width(60)))
                {
                    ShapeEditorWindow.Edit(shapeAsset);
                }
            }
            else
            {
                if (GUILayout.Button("Create", GUILayout.Width(60)))
                {
                    ShapeAsset newShapeAsset = CreateShapeAsset();
                    if (newShapeAsset != null)
                    {
                        _currentPath.shapeAsset = newShapeAsset;
                    }
                }
            }

            EditorGUILayout.EndHorizontal();

            GUILayout.Space(15);

            EditorGUI.BeginChangeCheck();

            Vector2 scale        = EditorGUILayout.Vector2Field("Scale", _currentPath.scale);
            int     subdivisions = EditorGUILayout.IntField("Subdivisions", Mathf.Clamp(_currentPath.subdivisions, 1, 100));
            float   uvResolution = EditorGUILayout.Slider("Uv resolution", _currentPath.uvResolution, 0.2f, 10.0f);
            bool    loopCurve    = EditorGUILayout.Toggle("Loop curve", _currentPath.loopCurve);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(_currentPath, "Modify Path Settings");
                EditorUtility.SetDirty(_currentPath);
                _currentPath.scale        = scale;
                _currentPath.subdivisions = subdivisions;
                _currentPath.uvResolution = uvResolution;
                _currentPath.loopCurve    = loopCurve;
            }

            GUILayout.Space(20);

            for (int i = 0; i < _currentPath.pathData.Length; i++)
            {
                if (PathPointEditor.selectedId == i)
                {
                    PathPointEditor.EditPointGUI(i);
                }
            }

            if (GUILayout.Button("Add Point"))
            {
                Undo.RecordObject(_currentPath, "Add point");
                EditorUtility.SetDirty(_currentPath);
                _currentPath.pathData.AddPoint(_currentPath.transform.position);
                SceneView.RepaintAll();
            }

            if (GUILayout.Button("Remove Point") && _currentPath.pathData.Length > 1)
            {
                Undo.RecordObject(_currentPath, "Remove point");
                EditorUtility.SetDirty(_currentPath);
                _currentPath.pathData.RemovePoint(PathPointEditor.selectedId);
                SceneView.RepaintAll();
            }

            GUILayout.Space(20);

            _autoGenerateRoad = EditorGUILayout.Toggle("Auto Generate", _autoGenerateRoad);

            if (!_autoGenerateRoad && GUILayout.Button("Generate Road"))
            {
                _currentPath.UpdatePath();
                SceneView.RepaintAll();
            }
        }
 public void Setup()
 {
     m_Window = ShapeEditorWindow.CreateInstance <ShapeEditorWindow>();
     m_Window.Show(true);
 }
Esempio n. 6
0
    static void Init()
    {
        ShapeEditorWindow window = (ShapeEditorWindow)EditorWindow.GetWindow(typeof(ShapeEditorWindow));

        window.Show();
    }