예제 #1
0
        protected override void OnHeaderGUI()
        {
            if (line == null)
            {
                line = (StateTransitionArrowLine)target;
            }
            if (line.transitions.Count == 0)
            {
                return;
            }
            EditorGUIUtility.SetIconSize(Vector2.one * 32);
            GUIContent cc = EditorGUIUtility.IconContent("d_UnityEditor.VersionControl");

            cc.text = "";
            GUILayout.BeginHorizontal("LargeButton");
            GUILayout.Space(5);
            GUILayout.Label(cc);

            GUILayout.BeginVertical();
            GUILayout.Space(2);
            MachineStateGUI mag0 = MachineStateGUIDataControl.GetMachineStateGUI(line.transitions[0].fromState);
            MachineStateGUI mag1 = MachineStateGUIDataControl.GetMachineStateGUI(line.transitions[0].toState);

            GUILayout.Label(mag0.name + " -> " + mag1.name);
            GUILayout.Space(2);
            GUILayout.Label(line.transitions.Count + " Transitions");
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        }
        protected override void OnHeaderGUI()
        {
            if (state == null)
            {
                state = (MachineStateGUI)target;
            }

            if (state.state == null)
            {
                return;
            }

            EditorGUIUtility.SetIconSize(Vector2.one * 32);
            GUIContent cc = EditorGUIUtility.IconContent("Animation Icon");

            cc.text = "";
            GUILayout.BeginHorizontal("LargeButton");
            GUILayout.Space(5);
            GUILayout.Label(cc);

            GUILayout.BeginVertical();
            GUILayout.Space(2);
            GUILayout.Label("ID : " + state.state.id);
            GUILayout.Space(2);
            state.name = EditorGUILayout.TextField(state.name);
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            GUILayout.Space(10);
        }
예제 #3
0
        static public void CreateNewModel(MachineStateGUI msg)
        {
            LogicObject          r  = CreateLogicObject("新建逻辑模块", msg.position);
            LogicObjectBehaviour be = new LogicObjectBehaviour();

            be.logicObj = r;
            msg.state.stateBaseBehaviours.Add(be);
            msg.name = r.name;
        }
예제 #4
0
        public static MachineStateGUI AddNewMachineStateGUI(Vector2 postion, string name = null, bool isTriggerCreateEvent = true)
        {
            MachineState    ms  = StateMachineDataControl.AddNewMachineState();
            MachineStateGUI msg = MachineStateGUIDataControl.AddNewMachineStateGUI(ms, postion, name);

            if (isTriggerCreateEvent && StateMachineEditorWindow.OnCreateMachineStateGUI != null)
            {
                StateMachineEditorWindow.OnCreateMachineStateGUI(msg);
            }
            return(msg);
        }
예제 #5
0
        public static void DeleteMachineStateGUI(MachineStateGUI state)
        {
            bool res = MachineStateGUIDataControl.DeleteMachineStateGUI(state);

            if (res)
            {
                if (StateMachineEditorWindow.OnDeleteMachineStateGUI != null)
                {
                    StateMachineEditorWindow.OnDeleteMachineStateGUI(state);
                }
            }
        }
        void CreateItem(MessageString ms)
        {
            LogicObject lo = JsonUtils.JsonToClassOrStruct <LogicObject>(ms.value);

            MachineStateGUI      msg = MachineDataController.AddNewMachineStateGUI(new Vector2(500, 450), lo.name, false);
            LogicObjectBehaviour be  = new LogicObjectBehaviour();

            be.logicObj = lo;
            msg.state.stateBaseBehaviours.Add(be);
            msg.name = lo.name;
            LogicSystemEditorWindow.AddLogicObject(lo);
        }
        public static MachineStateGUI AddNewMachineStateGUI(MachineState state, Vector2 pos, string name)
        {
            MachineStateGUI ms = ScriptableObject.CreateInstance <MachineStateGUI>();

            ms.state    = state;
            ms.position = pos;
            ms.name     = name;
            if (string.IsNullOrEmpty(name))
            {
                ms.name = "New State " + state.id;
            }
            allMachineStateGUI.Add(ms);
            return(ms);
        }
        protected override void OnInspectorGUI()
        {
            if (state.state == null)
            {
                return;
            }
            GUILayout.BeginVertical("box");
            foreach (var item in state.ToArrowLines)
            {
                MachineStateGUI fromState = MachineStateGUIDataControl.GetMachineStateGUI(item.transitions[0].fromState);
                MachineStateGUI toState   = MachineStateGUIDataControl.GetMachineStateGUI(item.transitions[0].toState);
                GUILayout.Label(fromState.name + " -> " + toState.name, "box");
            }
            GUILayout.EndVertical();
            GUILayout.Space(5);
            for (int i = 0; i < state.state.stateBaseBehaviours.Count; i++)
            {
                StateBaseBehaviour item      = state.state.stateBaseBehaviours[i];
                object             eInstance = null;
                if (!editorInstance.ContainsKey(item) || editorInstance[item] == null)
                {
                    eInstance = EditorExtendAttributeUtils.GetEditorExtend(typeof(StateBehaviourGUIBase), item.GetType());
                    editorInstance.Add(item, eInstance);
                }
                else
                {
                    eInstance = editorInstance[item];
                }
                GUILayout.BeginVertical("IN GameObjectHeader");
                GUIContent cc = EditorGUIUtility.IconContent("cs Script Icon");
                cc.text = item.GetType().Name;
                GUILayout.Label(cc);
                GUILayout.EndVertical();
                GUILayout.Space(7);
                if (eInstance == null)
                {
                    item = (StateBaseBehaviour)EditorDrawGUIUtil.DrawClassData("", item);
                }
                else
                {
                    StateBehaviourGUIBase temp = (StateBehaviourGUIBase)eInstance;
                    temp.target   = item;
                    temp.stateGUI = state;

                    temp.OnInspectorGUI();
                }
            }
        }
예제 #9
0
        public static void DrawAllStateMachineGUI()
        {
            stateMachineMaxRange = Rect.zero;
            foreach (var ms in MachineStateGUIDataControl.allMachineStateGUI)
            {
                Rect range = ms.GUIRect;
                stateMachineMaxRange.xMin = stateMachineMaxRange.xMin > range.xMin ? range.xMin : stateMachineMaxRange.xMin;
                stateMachineMaxRange.xMax = stateMachineMaxRange.xMax < range.xMax ? range.xMax : stateMachineMaxRange.xMax;
                stateMachineMaxRange.yMin = stateMachineMaxRange.yMin > range.yMin ? range.yMin : stateMachineMaxRange.yMin;
                stateMachineMaxRange.yMax = stateMachineMaxRange.yMax < range.yMax ? range.yMax : stateMachineMaxRange.yMax;
            }


            StateTransitionGUI.OnGUI();

            MachineStateGUI.OnGUI();
        }
 public static bool DeleteMachineStateGUI(MachineStateGUI state)
 {
     if (allMachineStateGUI.Contains(state))
     {
         List <StateTransitionArrowLine> lineList = new List <StateTransitionArrowLine>();
         lineList.AddRange(state.FromArrowLines);
         lineList.AddRange(state.ToArrowLines);
         foreach (var item in lineList)
         {
             StateTransitionArrowLineDataControl.DeleteStateTransitionArrowLine(item);
         }
         lineList.Clear();
         StateMachineDataControl.DeleteMachineState(state.state);
         allMachineStateGUI.Remove(state);
         return(true);
     }
     return(false);
 }
예제 #11
0
        //public EditorWindow animatorWindow;
        static void Init()
        {
            data = LogicObjectDataController.GetDataFromFile(logicDataName);
            if (data.logicObjs.Count == 0)
            {
                LogicObject r = CreateLogicObject("开始", new Vector2(500, 400));
                data.startId = r.id;
            }

            Dictionary <int, MachineStateGUI> allState = new Dictionary <int, MachineStateGUI>();

            foreach (var item in data.logicObjs)
            {
                MachineStateGUI      msg = MachineDataController.AddNewMachineStateGUI(item.editorPos, item.name);
                LogicObjectBehaviour be  = new LogicObjectBehaviour();
                msg.state.stateBaseBehaviours.Add(be);
                be.state    = msg.state;
                be.logicObj = item;
                bool isStartModel = LogicSystemEditorWindow.data.startId == item.id;
                msg.NormalStateColor = isStartModel ? UnityEditor.Graphs.Styles.Color.Yellow : UnityEditor.Graphs.Styles.Color.Gray;
                if (!isStartModel && item.isSupportAlwaysActive)
                {
                    msg.NormalStateColor = UnityEditor.Graphs.Styles.Color.Red;
                }
                allState.Add(item.id, msg);
            }
            foreach (var item in data.logicObjs)
            {
                foreach (var child in item.childObjects)
                {
                    MachineDataController.AddNewTransitionGUI(allState[item.id].state, allState[child].state);
                }
            }

            StateMachineEditorWindow.OnDrawLeftPartGUI       = OnGUI;
            StateMachineEditorWindow.OnCreateMachineStateGUI = CreateNewModel;

            internalValueTypeList.Add(typeof(string).FullName);
            internalValueTypeList.Add(typeof(int).FullName);
            internalValueTypeList.Add(typeof(float).FullName);
            internalValueTypeList.Add(typeof(Vector2).FullName);
            internalValueTypeList.Add(typeof(Vector3).FullName);
            internalValueTypeList.Add(typeof(bool).FullName);
        }
예제 #12
0
 protected override void OnInspectorGUI()
 {
     // base.OnInspectorGUI();
     GUILayout.BeginVertical("box");
     for (int i = 0; i < line.transitions.Count; i++)
     {
         StateTransition st   = line.transitions[i];
         MachineStateGUI mag0 = MachineStateGUIDataControl.GetMachineStateGUI(st.fromState);
         MachineStateGUI mag1 = MachineStateGUIDataControl.GetMachineStateGUI(st.toState);
         GUILayout.BeginHorizontal("box");
         GUILayout.Label(mag0.name + " -> " + mag1.name);
         if (line.transitions.Count > 1 && GUILayout.Button("-"))
         {
             MachineDataController.DeleteStateTransition(line, st);
             return;
         }
         GUILayout.EndHorizontal();
     }
     GUILayout.EndVertical();
 }
        private static void OnEndDragStateMachine()
        {
            if (isDragingStateItem)
            {
                Event e = Event.current;

                if (e.button == 0 && e.type == EventType.mouseDrag)
                {
                    Vector2 pos = StateMachineUtils.MousePos2MachineGridPos(e.mousePosition);
                    pos = pos - MachineStateGUI.size / 2f;
                    dragItem.position = pos;
                    e.Use();
                }
                else
                {
                    isDragingStateItem = false;
                    dragItem           = null;
                    StateMachineEditorWindow.Instance.wantsMouseMove = false;
                }
            }
        }
        private static void OnBeginDragStateMachine()
        {
            if (isDragingStateItem)
            {
                return;
            }
            Event e = Event.current;

            if (e.button == 0 && e.type == EventType.mouseDrag)
            {
                foreach (var item in MachineStateGUIDataControl.allMachineStateGUI)
                {
                    if (StateMachineUtils.MachineGridRectContainsMousePos(e.mousePosition, item.GUIRect))
                    {
                        dragItem           = item;
                        isDragingStateItem = true;
                        StateMachineEditorWindow.Instance.wantsMouseMove = true;
                        break;
                    }
                }
            }
        }