コード例 #1
0
        //======================================================
        //## TODO
        //======================================================
        public void CopyNode()
        {
            if (selectNode == null)
            {
                return;
            }

            if (selectNode.myData.type == NodeType.STATE)
            {
                AdvancedStateMachine.AdvancedState state = new AdvancedStateMachine.AdvancedState();
                //state.ID = "copy_" + selectNode.myData.state.ID;


                Target.advancedStates.Add(state);

                InitializePropertyData();

                InitializeStateNames();

                //serializedObject.Update();
                //serializedObject.Co
                //SerializedProperty test2 = propertyStates.GetEndProperty();
                //test2 = propertyStates.GetArrayElementAtIndex(FindStateIndexByNode(selectNode)).Copy();

                serializedObject.ApplyModifiedProperties();

                EditorNode <NodeData> node = CreateStateNode(state, new Vector2(selectNode.rect.position.x + 15, selectNode.rect.position.y + 15), state.ID);
                SelectNode(node);
            }
            else if (selectNode.myData.type == NodeType.TRANSITION)
            {
            }
        }
コード例 #2
0
        public void DeleteNode(EditorNode <AdvancedStateMachineEditorWindow.NodeData> node)
        {
            if (node == null)
            {
                return;
            }

            if (node.myData.type == NodeType.STATE)
            {
                if (node.parentNodes != null)
                {
                    for (int i = 0; i < node.parentNodes.Count; i++)
                    {
                        node.parentNodes[i].myData.transition.stateID = string.Empty;
                    }
                }

                selected.advancedStates.Remove(node.myData.state);
            }

            node.Relese();

            editorNodes.Remove(node);

            SelectNode(null);

            InitializePropertyData();

            SaveData();
        }
コード例 #3
0
 private void MakeTransition(EditorNode <NodeData> node)
 {
     if (workView != null)
     {
         workView.MakeTransition(node);
     }
 }
コード例 #4
0
        public void SelectNode(EditorNode <NodeData> node)
        {
            if (selectNode != null)
            {
                selectNode.isSelected = false;

                if (selectNode != node)
                {
                    isModifyViewOpen = false;
                }
            }

            selectNode = node;
            if (selectNode != null)
            {
                selectNode.isSelected = true;

                if (!isModifyViewOpen)
                {
                    InitializeStateNames();

                    switch (selectNode.myData.type)
                    {
                    case NodeType.STATE: SetDataInStateModifyView(selectNode); break;

                    case NodeType.TRANSITION: SetDataInTransitionModifyView(selectNode); break;
                    }
                    isModifyViewOpen = true;
                }
            }
            else
            {
                isModifyViewOpen = false;
            }
        }
コード例 #5
0
        private bool ProcessMouseDownEventByNode(EditorNode <AdvancedStateMachineEditorWindow.NodeData> node, Event e)
        {
            if (node.ProcessEventByEventType(zoomCoordsOrigin, e, EventType.MouseDown))
            {
                if (!isConnectionStart)
                {
                    EditorNode <AdvancedStateMachineEditorWindow.NodeData> temp = node;
                    AdvancedStateMachineEditorWindow.EditorNodes.Remove(node);

                    AdvancedStateMachineEditorWindow.EditorNodes.Add(temp);

                    AdvancedStateMachineEditorWindow.Instance.SelectNode(temp);
                }
                else
                {
                    node.isSelected = false;
                    AdvancedStateMachineEditorWindow.Instance.selectNode.isSelected = true;

                    AdvancedStateMachineEditorWindow.Instance.CreateConnection(AdvancedStateMachineEditorWindow.Instance.selectNode, node);

                    ClearConnectionSelection();
                }
                return(true);
            }

            return(false);
        }
コード例 #6
0
        private void DrawTransitionList()
        {
            transitionProperty.serializedObject.Update();

            EditorGUI.BeginChangeCheck();
            {
                popupIndex = EditorGUILayout.Popup(popupIndex, popupList);
            }
            if (EditorGUI.EndChangeCheck())
            {
                EditorNode <AdvancedStateMachineEditorWindow.NodeData> stateNode = AdvancedStateMachineEditorWindow.Instance.FindNodeByStateID(transition.stateID);
                if (stateNode != null)
                {
                    stateNode.RemoveParentNode(node);
                }

                node.RemoveChildNode(stateNode);

                if (popupIndex > 0)
                {
                    node.myData.transition.stateID = AdvancedStateMachineEditorWindow.Target.advancedStates[popupIndex - 1].ID;

                    AdvancedStateMachineEditorWindow.Instance.AttachChildNodeInParentNode(AdvancedStateMachineEditorWindow.Instance.FindNodeByStateID(transition.stateID), node);
                }
                else
                {
                    node.myData.transition.stateID = string.Empty;
                }

                AdvancedStateMachineEditorWindow.Instance.InitializePropertyData();
            }

            transitionProperty.serializedObject.ApplyModifiedProperties();
        }
コード例 #7
0
        public void CreateConnection(EditorNode <NodeData> startNode, EditorNode <NodeData> endNode)
        {
            if (startNode.myData.type == endNode.myData.type)
            {
                return;
            }

            if (startNode.myData.type == NodeType.STATE)
            {
                if (AttachTransitionInState(startNode, endNode))
                {
                    AttachChildNodeInParentNode(endNode, startNode);
                }
            }
            else if (startNode.myData.type == NodeType.TRANSITION)
            {
                startNode.myData.transition.stateID = endNode.myData.state.ID;

                if (startNode.childNodes != null)
                {
                    for (int i = 0; i < startNode.childNodes.Count; i++)
                    {
                        startNode.childNodes[i].parentNodes.Remove(startNode);
                    }

                    startNode.ClearChilds();
                }

                AttachChildNodeInParentNode(endNode, startNode);
            }
        }
コード例 #8
0
        private void DrawHightlightNode()
        {
            if (AdvancedStateMachineEditorWindow.Instance.selectNode == null || AdvancedStateMachineEditorWindow.Instance.selectNode.myData.type == AdvancedStateMachineEditorWindow.NodeType.TRANSITION)
            {
                DrawNormalNode();
            }
            else
            {
                EditorNode <AdvancedStateMachineEditorWindow.NodeData> node = AdvancedStateMachineEditorWindow.Instance.selectNode;

                //Connection
                node.DrawConnection(zoomCoordsOrigin);
                if (node.childNodes != null)
                {
                    for (int i = 0; i < node.childNodes.Count; i++)
                    {
                        node.childNodes[i].DrawConnection(zoomCoordsOrigin);
                    }
                }

                if (node.parentNodes != null)
                {
                    for (int i = 0; i < node.parentNodes.Count; i++)
                    {
                        node.parentNodes[i].DrawConnection(zoomCoordsOrigin);
                    }
                }


                //Node
                node.Draw(zoomCoordsOrigin);
                if (node.childNodes != null)
                {
                    for (int i = 0; i < node.childNodes.Count; i++)
                    {
                        node.childNodes[i].Draw(zoomCoordsOrigin);

                        if (node.childNodes[i].childNodes == null)
                        {
                            continue;
                        }

                        for (int j = 0; j < node.childNodes[i].childNodes.Count; j++)
                        {
                            node.childNodes[i].childNodes[j].Draw(zoomCoordsOrigin);
                        }
                    }
                }

                if (node.parentNodes != null)
                {
                    for (int i = 0; i < node.parentNodes.Count; i++)
                    {
                        node.parentNodes[i].Draw(zoomCoordsOrigin);
                    }
                }
            }
        }
コード例 #9
0
        private void SetDataInTransitionModifyView(EditorNode <NodeData> node)
        {
            if (node == null)
            {
                return;
            }

            //transitionModifyView.Initialize(propertyTransitions.GetArrayElementAtIndex(FindTransitionIndexByNode(node)), node);
        }
コード例 #10
0
        public void RemoveParentNode(EditorNode <T> node)
        {
            if (node == null || parentNodes == null)
            {
                return;
            }

            parentNodes.Remove(node);
        }
コード例 #11
0
        private void SetDataInStateModifyView(EditorNode <NodeData> node)
        {
            if (node == null)
            {
                return;
            }

            stateModifyView.Initialize(propertyStates.GetArrayElementAtIndex(FindStateIndexByNode(node)), node);
        }
コード例 #12
0
        public void MakeTransition(EditorNode <AdvancedStateMachineEditorWindow.NodeData> node)
        {
            if (isConnectionStart)
            {
                ClearConnectionSelection();
                return;
            }

            isConnectionStart = true;
            tempConnect       = new Connection();
        }
コード例 #13
0
        public void RemoveChildNode(EditorNode <T> node)
        {
            if (node == null || childNodes == null)
            {
                return;
            }

            childNodes.Remove(node);

            RemoveConnection();
        }
コード例 #14
0
        private void CreateConnection(EditorNode <T> startNode, EditorNode <T> endNode)
        {
            if (connections == null)
            {
                connections = new List <Connection>();
            }

            Connection connection = new Connection();

            connections.Add(connection);
        }
コード例 #15
0
        //안쓴다
        private void OnTransitionNodeGenericMenu(EditorNode <NodeData> node)
        {
            GenericMenu genericMenu = new GenericMenu();

            genericMenu.AddItem(new GUIContent("Connect State"), false, () => MakeTransition(node));
            genericMenu.AddItem(new GUIContent("Delete"), false, () => DeleteNode(node));

            genericMenu.ShowAsContext();

            Event.current.Use();
        }
コード例 #16
0
        public void Initialize(SerializedProperty data, EditorNode <AdvancedStateMachineEditorWindow.NodeData> node)
        {
            if (data == null || node == null)
            {
                return;
            }

            stateProperty = data;
            this.node     = node;

            InitalizeListItems();
        }
コード例 #17
0
        public void AttachChildNodeInParentNode(EditorNode <NodeData> childNode, EditorNode <NodeData> parentNode)
        {
            if (childNode != null && parentNode != null)
            {
                childNode.AddParentNode(parentNode);
            }

            if (parentNode != null && childNode != null)
            {
                parentNode.AddChildNode(childNode);
            }
        }
コード例 #18
0
        private EditorNode <NodeData> CreateTransitionNode(AdvancedTransition transition, Vector2 position, string title)
        {
            EditorNode <NodeData> node = new EditorNode <NodeData>(new NodeData(NodeType.TRANSITION, null, transition)
                                                                   , editorNodes.Count
                                                                   , new Rect(position.x - (NODE_WIDTH * 0.5f), position.y - (NODE_HEIGHT * 0.5f), NODE_WIDTH, NODE_HEIGHT)
                                                                   , title
                                                                   , (GUIStyle)"flow node hex 0", (GUIStyle)"flow node hex 0 on"
                                                                   , null);

            editorNodes.Add(node);

            return(node);
        }
コード例 #19
0
        private EditorNode <NodeData> CreateStateNode(AdvancedState state, Vector2 position, string title)
        {
            EditorNode <NodeData> node = new EditorNode <NodeData>(new NodeData(NodeType.STATE, state, null)
                                                                   , editorNodes.Count
                                                                   , new Rect(position.x - (NODE_WIDTH * 0.5f), position.y - (NODE_HEIGHT * 0.5f), NODE_WIDTH, NODE_HEIGHT)
                                                                   , title
                                                                   , (GUIStyle)"flow node hex 4", (GUIStyle)"flow node hex 4 on"
                                                                   , OnStateNodeGenericMenu);

            editorNodes.Add(node);

            return(node);
        }
コード例 #20
0
        public void AddParentNode(EditorNode <T> node)
        {
            if (node == null)
            {
                return;
            }

            if (parentNodes == null)
            {
                parentNodes = new List <EditorNode <T> >();
            }

            parentNodes.Add(node);
        }
コード例 #21
0
        public void Initialize(SerializedProperty data, EditorNode <AdvancedStateMachineEditorWindow.NodeData> node)
        {
            if (data == null || node == null)
            {
                return;
            }

            this.node          = node;
            transitionProperty = data;
            transition         = node.myData.transition;

            popupList = AdvancedStateMachineEditorWindow.Instance.stateNames;

            popupIndex = FindTransitionIndex();
        }
        public AdvancedTransition FindTransitionByNode(EditorNode <NodeData> node)
        {
            if (node == null)
            {
                return(null);
            }

            for (int i = 0; i < Transitions.Length; i++)
            {
                if (Transitions[i].ID == node.myData.transition.ID)
                {
                    return(Transitions[i]);
                }
            }
            return(null);
        }
        public int FindTransitionIndexByNode(EditorNode <NodeData> node)
        {
            if (node == null)
            {
                return(-1);
            }

            for (int i = 0; i < Transitions.Length; i++)
            {
                if (Transitions[i].ID == node.myData.transition.ID)
                {
                    return(i);
                }
            }
            return(-1);
        }
コード例 #24
0
        public void AddChildNode(EditorNode <T> node)
        {
            if (node == null)
            {
                return;
            }

            if (childNodes == null)
            {
                childNodes = new List <EditorNode <T> >();
            }

            childNodes.Add(node);

            CreateConnection(this, node);
        }
コード例 #25
0
        //TODO : 동일한 ID 입력에 대한 예외처리 해주
        public void CreateState(Vector2 position)
        {
            AdvancedStateMachine.AdvancedState state = new AdvancedStateMachine.AdvancedState();
            //state.ID = "New State" + Target.advancedStates.Count;
            Target.advancedStates.Add(state);

            InitializePropertyData();

            InitializeStateNames();

            EditorNode <NodeData> node = CreateStateNode(state, position, state.ID);

            SelectNode(node);

            SaveData();
        }
        public int FindStateIndexByNode(EditorNode <NodeData> node)
        {
            if (node == null)
            {
                return(-1);
            }

            for (int i = 0; i < selected.advancedStates.Count; i++)
            {
                if (selected.advancedStates[i].ID == node.myData.state.ID)
                {
                    return(i);
                }
            }

            return(-1);
        }
コード例 #27
0
        private bool AttachTransitionInState(EditorNode <NodeData> stateNode, EditorNode <NodeData> transitionNode)
        {
            serializedObject.Update();

            for (int i = 0; i < stateNode.myData.state.Transition.ChildTransitions.Count; i++)
            {
                if (stateNode.myData.state.Transition.ChildTransitions[i] == transitionNode.myData.transition)
                {
                    return(false);
                }
            }

            stateNode.myData.state.Transition.ChildTransitions.Add(transitionNode.myData.transition);

            EditorUtility.SetDirty(Target);
            serializedObject.ApplyModifiedProperties();

            return(true);
        }
コード例 #28
0
        private void DecendingOrder()
        {
            if (AdvancedStateMachineEditorWindow.EditorNodes == null)
            {
                return;
            }

            int count = AdvancedStateMachineEditorWindow.EditorNodes.Count;

            for (int i = 0; i < count - 1; i++)
            {
                for (int j = 0; j < count - 1 - i; j++)
                {
                    if (AdvancedStateMachineEditorWindow.EditorNodes[j].rect.y > AdvancedStateMachineEditorWindow.EditorNodes[j + 1].rect.y)
                    {
                        EditorNode <AdvancedStateMachineEditorWindow.NodeData> temp = AdvancedStateMachineEditorWindow.EditorNodes[j];
                        AdvancedStateMachineEditorWindow.EditorNodes[j]     = AdvancedStateMachineEditorWindow.EditorNodes[j + 1];
                        AdvancedStateMachineEditorWindow.EditorNodes[j + 1] = temp;
                    }
                }
            }
        }