Пример #1
0
        public override void OnHeaderGUI()
        {
            if (favoriteIcon == null)
            {
                favoriteIcon = GetFavoriteIcon();
            }

            node  = target as NodeBase_State;
            graph = node.graph as Graph_State;
            DrawOnHeaderGUI(graph, node, favoriteIcon);
        }
Пример #2
0
        private void Draw_CreateVariablePanel()
        {
            Graph_State graph = (Graph_State)target;

            if (graph == null)
            {
                show_newVarPanel = false; return;
            }


            if (show_newVarPanel == false)
            {
                if (GUILayout.Button("Create New Variable"))
                {
                    ClearNewVarProperties(true);
                }
            }
            else if (show_newVarPanel)
            {
                if (GUILayout.Button("Cancel"))
                {
                    ClearNewVarProperties();
                }


                //Create Pannel
                EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);

                //NewVar field name
                new_varName = EditorGUILayout.TextField(new_varName);
                //NewVar field type
                new_varType = (GraphVarType)EditorGUILayout.EnumPopup(new_varType);
                //Create newVariable at fsm componnent and reply the tag at graph
                if (GUILayout.Button("Create"))
                {
                    GraphVarAddErrorsType error = graph.AddTagVariable(new_varName, new_varType);

                    if (error != GraphVarAddErrorsType.none)
                    {
                        show_defaultErrorPanel = true;
                        new_varErrorMsg        = "Error: " + error.ToString();
                    }

                    new_varType      = GraphVarType.Integer;
                    new_varName      = FSMGUtility.StringTag_Undefined;
                    show_newVarPanel = false;
                }

                EditorGUILayout.EndHorizontal();
            }
        }
Пример #3
0
        /// <summary>
        /// Chamado somente em modo editor sempre que o gráfico é modificado para este componente.
        /// Tenha emmente que ao modificar o grafico as variaveis origem são perdidas e subistituidas pelas variaveis
        /// do grafico destino.
        /// </summary>
        /// <param name="oldGraph">Grafico origem</param>
        /// <param name="newGraph">Grafico destino</param>
        protected virtual void OnGraphChangedInEditor(Graph_State oldGraph, Graph_State newGraph)
        {
            if (oldGraph == newGraph)
            {
                return;
            }

            if (newGraph == null)
            {
                ClearVariablesAndTargets();
                return;
            }

            SyncVariablesAndTargets();
        }
Пример #4
0
        public override void OnCreate()
        {
            // Undo.ClearAll();

            if (graph == null)
            {
                graph = (Graph_State)target;
            }

            graph.SetSettings(FSMGSettingsPreferences.GetOrCreateSettings());


            base.OnCreate();

            //   Undo.RecordObject(graph, "OnCreate");
        }
Пример #5
0
        private void ShowContextMenuAtMouse(SerializedProperty property, Graph_State currentStateGraph)
        {
            GenericMenu menu = new GenericMenu();

            //StateNodeBase target = (StateNodeBase)PropertyUtility.GetTargetObjectWithProperty(property);
            object target = PropertyUtility.GetTargetObjectWithProperty(property);


            menu.AddItem(new GUIContent("None"), currentStateGraph == null, () => SelectMatInfo(property, null, target));

            string[] guids = AssetDatabase.FindAssets("t:Graph_State");
            for (int i = 0; i < guids.Length; i++)
            {
                string      path    = AssetDatabase.GUIDToAssetPath(guids[i]);
                Graph_State matInfo = AssetDatabase.LoadAssetAtPath(path, typeof(Graph_State)) as Graph_State;
                if (matInfo != null)
                {
                    bool isOwn = false;
                    if (target is Graph_State)
                    {
                        if ((Graph_State)target == matInfo)
                        {
                            isOwn = true;
                        }
                    }

                    //if (matInfo.ParentGraph == null && isOwn == false)
                    if (isOwn == false)//Não mostra o proprio grafico.
                    {
                        GUIContent content   = new GUIContent(matInfo.name);
                        string[]   nameParts = matInfo.name.Split(' ');
                        if (nameParts.Length > 1)
                        {
                            content.text = nameParts[0] + "/" + matInfo.name.Substring(nameParts[0].Length + 1);
                        }
                        menu.AddItem(content, matInfo == currentStateGraph, () => SelectMatInfo(property, matInfo, target));
                    }
                }
            }

            menu.ShowAsContext();
        }
Пример #6
0
        public override void OnGUI()
        {
            base.OnGUI();

            if (graph == null)
            {
                graph = (Graph_State)target;
            }

            GUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true));

            //if (GUILayout.Button("Play", EditorStyles.toolbarButton)) { graph.UpdateGraph(null); }
            if (GUILayout.Button("Globals", EditorStyles.toolbarButton))
            {
                FSMGSettingsPreferences.OpenSeetingsWindows();
            }


            GUILayout.EndHorizontal();

            NodeGraphEditorUtility.DrawNoodleLabels(window);
        }
Пример #7
0
        public static void DrawOnHeaderGUI(Graph_State _graph, NodeBase_State _state, GUIContent _headerFavoriteIcon)
        {
            GUI.color = Color.white;


            if (_state.IsCurrentState)
            {
                GUI.color = Color.green;
            }

            string title = _state.name;

            GUILayout.Label(title, NodeEditorResources.styles.nodeHeader, GUILayout.Height(30), GUILayout.MinWidth(0), GUILayout.ExpandWidth(true));
            Rect labelRect = GUILayoutUtility.GetLastRect();

            if (_state.IsRootState)
            {
                GUI.color = Color.black;
                EditorGUI.LabelField(labelRect, _headerFavoriteIcon);
            }
            GUI.color = Color.white;
        }
Пример #8
0
        private void SelectMatInfo(SerializedProperty property, Graph_State stateNode, object target)
        {
            GraphStateAttribute nodeFilter = (GraphStateAttribute)attribute;

            property.objectReferenceValue = stateNode;
            FieldInfo fi       = ReflectionUtility.GetField(target, property.name);
            object    oldValue = fi.GetValue(target);

            property.serializedObject.ApplyModifiedProperties(); // We must apply modifications so that the new value is updated in the serialized object
            object newValue = fi.GetValue(target);

            property.serializedObject.Update();

            if (stateNode)
            {
                EditorGUIUtility.PingObject(stateNode);
            }

            MethodInfo callbackMethod = ReflectionUtility.GetMethod(target, nodeFilter.CallbackName);

            PropertyUtility.InvoKeCallback(callbackMethod, property, target, fieldInfo, oldValue, newValue);
        }
Пример #9
0
        private void ContextPopUp(Rect position, SerializedProperty property, GUIContent label)
        {
            // Throw error on wrong type
            if (property.propertyType != SerializedPropertyType.ObjectReference)
            {
                throw new ArgumentException("Parameter selected must be of type System.Enum");
            }

            // Add label
            // position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);


            EditorGUI.BeginChangeCheck();

            // Store old indent level and set it to 0, the PrefixLabel takes care of it

            position = EditorGUI.PrefixLabel(position, label);

            //int indent = EditorGUI.indentLevel;
            //EditorGUI.indentLevel = 0;

            Rect buttonRect = position;
            Rect buttonGo   = position;

            string      buttonLabel       = "Select";
            Graph_State currentStateGraph = property.objectReferenceValue as Graph_State;


            if (currentStateGraph != null)
            {
                buttonRect.width   -= 30;
                buttonRect.position = new Vector2(position.x + 30, position.y);
                buttonGo.width      = 30;

                buttonLabel = currentStateGraph.name;
            }

            if (GUI.Button(buttonRect, buttonLabel))
            {
                GraphStateAttribute attr = (GraphStateAttribute)attribute;

                if (attr.UseNodeEnum)
                {
                    NodeEditorWindow.current.onLateGUI += () => ShowContextMenuAtMouse(property, currentStateGraph);
                }
                else
                {
                    ShowContextMenuAtMouse(property, currentStateGraph);
                }
            }

            if (currentStateGraph != null)
            {
                if (GUI.Button(buttonGo, gotoIcon))
                {
                    EditorGUIUtility.PingObject(currentStateGraph);
                    NodeEditorWindow.Open(currentStateGraph);
                    Selection.activeObject = currentStateGraph;
                }
            }



            // position.x += buttonRect.width + 4;
            // position.width -= buttonRect.width + 4;
            //EditorGUI.ObjectField(position, property, typeof(StateNode), GUIContent.none);

            if (EditorGUI.EndChangeCheck())
            {
                property.serializedObject.ApplyModifiedProperties();
            }

            //EditorGUI.indentLevel = indent;
        }