Beispiel #1
0
            public override void OnInspectorGUI()
            {
                JSONObjectEditorGUI <T> editorGUI = (JSONObjectEditorGUI <T>)target;

                if (editorGUI != null && editorGUI.IsValid())
                {
                    EditorGUILayout.Separator();
                    EditorGUILayout.Separator();

                    EditorGUILayout.BeginVertical(EditorStyles.inspectorFullWidthMargins);


                    editorGUI.RenderProperties();

                    if (editorGUI.GetEditor().NeedsRepaint())
                    {
                        editorGUI.GetEditor().GetEditorWindow().DoRepaint();
                    }

                    EditorGUILayout.EndVertical();
                }
                else
                {
                    Selection.activeObject = null;
                }
            }
            private GenericMenu GetRightMouseMenu(JSONObjectEditorGUI <T> clickedObject)
            {
                GenericMenu menu = new GenericMenu();

                if (clickedObject != null)
                {
                    RightClickData copyData = new RightClickData();
                    copyData._operation      = eRightClickOperation.Copy;
                    copyData._editableObject = clickedObject;
                    menu.AddItem(new GUIContent("Copy"), false, ContextMenuCallback, copyData);
                    RightClickData cutData = new RightClickData();
                    cutData._operation      = eRightClickOperation.Cut;
                    cutData._editableObject = clickedObject;
                    menu.AddItem(new GUIContent("Cut"), false, ContextMenuCallback, cutData);
                    RightClickData removeData = new RightClickData();
                    removeData._operation      = eRightClickOperation.Remove;
                    removeData._editableObject = clickedObject;
                    menu.AddItem(new GUIContent("Remove"), false, ContextMenuCallback, removeData);
                }
                else
                {
                    AddContextMenu(menu);

                    RightClickData pasteData = null;
                    if (_copiedObjects.Count > 0)
                    {
                        pasteData                 = new RightClickData();
                        pasteData._operation      = eRightClickOperation.Paste;
                        pasteData._editableObject = clickedObject;
                        menu.AddItem(new GUIContent(_copiedObjects.Count == 1 ? "Paste" : "Paste"), false, ContextMenuCallback, pasteData);
                    }
                }

                return(menu);
            }
 protected void RemoveObject(JSONObjectEditorGUI <T> editorGUI)
 {
     GetEditorWindow().OnDeselectObject(editorGUI);
     _editableObjects.Remove(editorGUI);
     _selectedObjects.Remove(editorGUI);
     UpdateCachedObjectList();
 }
            protected virtual void OnLeftMouseDown(Event inputEvent)
            {
                JSONObjectEditorGUI <T> clickedOnObject = null;

                Vector2 gridPosition = GetEditorPosition(inputEvent.mousePosition);

                for (int i = 0; i < _editableObjects.Count; i++)
                {
                    JSONObjectEditorGUI <T> evnt = (JSONObjectEditorGUI <T>)_editableObjects[i];
                    if (evnt.GetBounds().Contains(gridPosition))
                    {
                        clickedOnObject = evnt;
                        break;
                    }
                }

                if (inputEvent.shift || inputEvent.control)
                {
                    if (clickedOnObject != null)
                    {
                        if (_selectedObjects.Contains(clickedOnObject))
                        {
                            _selectedObjects.Remove(clickedOnObject);
                            clickedOnObject = null;
                        }
                        else
                        {
                            _selectedObjects.Add(clickedOnObject);
                        }
                    }
                }
                else if (clickedOnObject == null)
                {
                    _selectedObjects.Clear();
                }
                else if (!_selectedObjects.Contains(clickedOnObject))
                {
                    _selectedObjects = new List <ScriptableObject>()
                    {
                        clickedOnObject
                    };
                }

                //Dragging
                {
                    GetEditorWindow().OnSelectObject(clickedOnObject);

                    _draggedObject = clickedOnObject;
                    _dragMode      = eDragType.LeftClick;
                    _dragPos       = inputEvent.mousePosition;
                    _dragAreaRect  = new Rect(-1.0f, -1.0f, 0.0f, 0.0f);

                    //Save state before dragging
                    foreach (JSONObjectEditorGUI <T> evnt in _selectedObjects)
                    {
                        evnt.SaveUndoState();
                    }
                }
            }
            protected void CreateAndAddNewObject(Type type)
            {
                Undo.RegisterCompleteObjectUndo(this, "Create Object");
                T newObject = Activator.CreateInstance(type) as T;

                OnCreatedNewObject(newObject);
                JSONObjectEditorGUI <T> editorGUI = AddNewObject(newObject);

                GetEditorWindow().OnSelectObject(editorGUI);
                _selectedObjects.Clear();
                _selectedObjects.Add(editorGUI);
                SetObjectPosition(editorGUI, _dragPos);
            }
            protected JSONObjectEditorGUI <T> AddNewObject(T obj)
            {
                JSONObjectEditorGUI <T> editorGUI = CreateObjectEditorGUI(obj);

                editorGUI.SetEditableObject(obj);

                _editableObjects.Add(editorGUI);
                SortObjects();

                UpdateCachedObjectList();

                return(editorGUI);
            }
Beispiel #7
0
            protected override void OnHeaderGUI()
            {
                JSONObjectEditorGUI <T> editorGUI = (JSONObjectEditorGUI <T>)target;

                if (editorGUI != null && editorGUI.IsValid())
                {
                    EditorUtils.DrawSimpleInspectorHeader(StringUtils.FromCamelCase(editorGUI.GetEditableObject().GetType().Name));
                }
                else
                {
                    Selection.activeObject = null;
                }
            }
            protected virtual void OnDragging(Event inputEvent)
            {
                Vector2 currentPos = inputEvent.mousePosition;

                if (_dragMode == eDragType.LeftClick)
                {
                    _needsRepaint = true;

                    inputEvent.Use();

                    if (_draggedObject != null)
                    {
                        Vector2 delta = currentPos - _dragPos;
                        _dragPos = currentPos;

                        DragObjects(delta);
                    }
                    else
                    {
                        _dragAreaRect.x      = Math.Min(currentPos.x, _dragPos.x);
                        _dragAreaRect.y      = Math.Min(currentPos.y, _dragPos.y);
                        _dragAreaRect.height = Math.Abs(currentPos.y - _dragPos.y);
                        _dragAreaRect.width  = Math.Abs(currentPos.x - _dragPos.x);

                        _selectedObjects.Clear();

                        Rect gridDragRect = GetEditorRect(_dragAreaRect);

                        for (int i = 0; i < _editableObjects.Count; i++)
                        {
                            JSONObjectEditorGUI <T> editorGUI = (JSONObjectEditorGUI <T>)_editableObjects[i];
                            if (editorGUI.GetBounds().Overlaps(gridDragRect))
                            {
                                _selectedObjects.Add(editorGUI);
                            }
                        }
                    }
                }
                else if (_dragMode == eDragType.MiddleMouseClick)
                {
                    Vector2 delta = currentPos - _dragPos;
                    _dragPos = currentPos;

                    ScrollEditorView(delta);

                    SetNeedsRepaint();
                }
            }
Beispiel #9
0
            public virtual int CompareTo(object obj)
            {
                JSONObjectEditorGUI <T> editorGUI = obj as JSONObjectEditorGUI <T>;

                if (editorGUI == null)
                {
                    return(1);
                }

                if (editorGUI == this)
                {
                    return(0);
                }

                return(this.GetHashCode().CompareTo(editorGUI.GetHashCode()));
            }
            protected void ClearObjects()
            {
                foreach (JSONObjectEditorGUI <T> editorGUI in _editableObjects)
                {
                    Undo.ClearUndo(editorGUI);
                    GetEditorWindow().OnDeselectObject(editorGUI);
                }

                _editableObjects.Clear();
                _selectedObjects.Clear();
                _copiedObjects.Clear();
                _draggedObject = null;

                Undo.ClearUndo(this);

                ClearDirtyFlag();
            }
            private void Paste()
            {
                if (_copiedObjects.Count > 0)
                {
                    Undo.RegisterCompleteObjectUndo(this, "Paste Object(s)");

                    Vector2 pos = ((JSONObjectEditorGUI <T>)_copiedObjects[0]).GetPosition();


                    foreach (JSONObjectEditorGUI <T> editorGUI in _copiedObjects)
                    {
                        T copyObject = CreateCopyFrom(editorGUI);
                        JSONObjectEditorGUI <T> copyEditorGUI = AddNewObject(copyObject);
                        SetObjectPosition(copyEditorGUI, _dragPos + editorGUI.GetPosition() - pos);
                    }

                    MarkAsDirty();

                    _needsRepaint = true;
                }
            }
Beispiel #12
0
            protected void CenterCamera()
            {
                if (_editableObjects.Count > 0)
                {
                    Rect maxBounds = ((JSONObjectEditorGUI <T>)_editableObjects[0]).GetBounds();

                    for (int i = 1; i < _editableObjects.Count; i++)
                    {
                        JSONObjectEditorGUI <T> editorGUI = (JSONObjectEditorGUI <T>)_editableObjects[i];
                        maxBounds.xMin = Mathf.Min(maxBounds.xMin, editorGUI.GetBounds().xMin);
                        maxBounds.xMax = Mathf.Max(maxBounds.xMax, editorGUI.GetBounds().xMax);
                        maxBounds.yMin = Mathf.Min(maxBounds.yMin, editorGUI.GetBounds().yMin);
                        maxBounds.yMax = Mathf.Max(maxBounds.yMax, editorGUI.GetBounds().yMax);
                    }

                    _cameraPosition = -maxBounds.center;
                }
                else
                {
                    _cameraPosition = Vector2.zero;
                }
            }
            protected virtual void OnRightMouseDown(Event inputEvent)
            {
                JSONObjectEditorGUI <T> clickedNode = null;

                _dragPos = GetEditorPosition(inputEvent.mousePosition);

                //Check clicked on event
                Vector2 gridPosition = GetEditorPosition(inputEvent.mousePosition);

                foreach (JSONObjectEditorGUI <T> node in _editableObjects)
                {
                    if (node.GetBounds().Contains(gridPosition))
                    {
                        clickedNode = node;
                        break;
                    }
                }

                if (clickedNode != null)
                {
                    if (!_selectedObjects.Contains(clickedNode))
                    {
                        _selectedObjects = new List <ScriptableObject>()
                        {
                            clickedNode
                        }
                    }
                    ;

                    GetEditorWindow().DoRepaint();
                }

                // Now create the menu, add items and show it
                GenericMenu menu = GetRightMouseMenu(clickedNode);

                menu.ShowAsContext();
            }
 protected abstract void SetObjectPosition(JSONObjectEditorGUI <T> obj, Vector2 position);
 protected abstract T CreateCopyFrom(JSONObjectEditorGUI <T> editorGUI);
Beispiel #16
0
 protected void CenterCameraOn(JSONObjectEditorGUI <T> editorGUI)
 {
     _cameraPosition = -editorGUI.GetPosition();
 }