コード例 #1
0
ファイル: BaseNodeEditor.cs プロジェクト: sthagen/pxWorks-MVP
        public override void OnBodyGUI()
        {
            serializedObject.Update();
            if (buttonTexture == null)
            {
                buttonTexture = Resources.Load <Texture2D>("btCometUI");
            }
            if (buttonTexturePressed == null)
            {
                buttonTexturePressed = Resources.Load <Texture2D>("btCometUI_pressed");
            }
            if (editorLabelStyle == null)
            {
                editorLabelStyle = new GUIStyle(EditorStyles.label);
            }
            EditorStyles.label.normal.textColor  = Color.white;
            EditorStyles.label.focused.textColor = Color.yellow;

            editorButtonStyle = CreateButtonStyle();

            const int buttonSize = 15;

            //
            foreach (XNode.NodePort port in target.DynamicPorts.OrderBy(p => p.ValueType.GetPortInfo().Order))
            {
                if (NodeEditorGUILayout.IsDynamicPortListPort(port))
                {
                    continue;
                }

                GUILayout.BeginHorizontal();
                editorButtonStyle.alignment = port.IsInput ? TextAnchor.MiddleLeft : TextAnchor.MiddleRight;

                DrawPort(port);

                GUILayout.EndHorizontal();
            }

            //
            editorButtonStyle.alignment        = TextAnchor.MiddleCenter;
            editorButtonStyle.normal.textColor = editorButtonStyle.active.textColor = Color.white;

            GUILayout.BeginHorizontal();
            //GUILayout.FlexibleSpace();

            if (GUILayout.Button("+", editorButtonStyle, /*GUILayout.Width(buttonSize),*/ GUILayout.Height(buttonSize)))
            {
                ShowAddPortMenu();
            }
            GUILayout.EndHorizontal();

            //
            EditorStyles.label.normal  = editorLabelStyle.normal;
            EditorStyles.label.focused = editorLabelStyle.focused;

            serializedObject.ApplyModifiedProperties();
        }
コード例 #2
0
        void OriginalUI()
        {
            // Unity specifically requires this to save/update any serial object.
            // serializedObject.Update(); must go at the start of an inspector gui, and
            // serializedObject.ApplyModifiedProperties(); goes at the end.
            serializedObject.Update();
            string[] excludes =
            {
                "m_Script",
                "graph",
                "position",
                "ports",
                "TexturePosition",
                "Space",
                "tex",
                "size",
                "RenderTime"
            };

            // Iterate through serialized properties and draw them like the Inspector (But with ports)
            SerializedProperty iterator = serializedObject.GetIterator();
            bool enterChildren          = true;

            while (iterator.NextVisible(enterChildren))
            {
                enterChildren = false;
                if (excludes.Contains(iterator.name))
                {
                    continue;
                }
                NodeEditorGUILayout.PropertyField(iterator, true);
            }

            // Iterate through dynamic ports and draw them in the order in which they are serialized
            foreach (XNode.NodePort dynamicPort in target.DynamicPorts)
            {
                if (NodeEditorGUILayout.IsDynamicPortListPort(dynamicPort))
                {
                    continue;
                }
                NodeEditorGUILayout.PortField(dynamicPort);
            }

            serializedObject.ApplyModifiedProperties();
        }
コード例 #3
0
        /// <summary>
        /// Show the input/output port fields
        /// </summary>
        protected void ShowNodePorts(Dictionary <string, string> inputsNameOverride = null, Dictionary <string, string> outputsNameOverride = null, bool showOutputType = false)
        {
            if (NodeSubtitle != null)
            {
                GUILayout.Space(15);
            }
            else
            {
                GUILayout.Space(5);
            }


            // Iterate through dynamic ports and draw them in the order in which they are serialized
            // Init variables
            GUIContent inputPortLabel;
            GUIContent outputPortLabel;

            // Make sure port pair list is init
            if (m_PortPairs == null)
            {
                m_PortPairs = new List <IMLNodePortPair>();
            }

            bool updatePortPairs = false;

            // DIRTY CODE
            // If the node is an mls node, check if the output ports have been updated
            if (target is IMLConfiguration)
            {
                var mlsNode = (target as IMLConfiguration);
                updatePortPairs = mlsNode.OutputPortsChanged;
                // Set flag to false in mls node to not redraw every frame
                mlsNode.OutputPortsChanged = false;
            }
            // Generic check if the number ports changes to reduce the times we reserve memory
            if (m_NumInputs != target.Inputs.Count() || m_NumOutputs != target.Outputs.Count())
            {
                updatePortPairs = true;
            }

            // Get number of ports to avoid reserving memory twice
            if (updatePortPairs)
            {
                // Update known number of ports
                m_NumInputs  = target.Inputs.Count();
                m_NumOutputs = target.Outputs.Count();
                // Get inputs and outputs ports
                IEnumerator <NodePort> inputs  = target.Inputs.GetEnumerator();
                IEnumerator <NodePort> outputs = target.Outputs.GetEnumerator();
                // Add them to the list
                AddPairsToList(inputs, outputs, ref m_PortPairs);
            }



            // Go through port pairs to draw them together
            foreach (var pair in m_PortPairs)
            {
                // Will draw them in a horizontal pair
                GUILayout.BeginHorizontal();

                // Draw input (if any)
                if (pair.input != null)
                {
                    if (NodeEditorGUILayout.IsDynamicPortListPort(pair.input))
                    {
                        continue;
                    }
                    inputPortLabel = new GUIContent(pair.input.fieldName);
                    // Check if an override of the label is needed
                    if (inputsNameOverride != null)
                    {
                        if (inputsNameOverride.ContainsKey(pair.input.fieldName))
                        {
                            string newLabel = inputPortLabel.text;
                            inputsNameOverride.TryGetValue(pair.input.fieldName, out newLabel);
                            inputPortLabel.text = newLabel;
                        }
                    }
                    // Draw port
                    IMLNodeEditor.PortField(inputPortLabel, m_IMLNode.GetInputPort(pair.input.fieldName), m_NodeSkin.GetStyle("Port Label"), GUILayout.MinWidth(0));
                }
                // Draw output (if any)
                if (pair.output != null)
                {
                    if (NodeEditorGUILayout.IsDynamicPortListPort(pair.output))
                    {
                        continue;
                    }
                    outputPortLabel = new GUIContent(pair.output.fieldName);
                    // Check if an override of the label is needed
                    if (outputsNameOverride != null)
                    {
                        if (outputsNameOverride.ContainsKey(pair.output.fieldName))
                        {
                            string newLabel = outputPortLabel.text;
                            outputsNameOverride.TryGetValue(pair.output.fieldName, out newLabel);
                            outputPortLabel.text = newLabel;
                        }
                    }
                    // Check if we require to show the data type of the output
                    if (showOutputType == true)
                    {
                        string type = pair.output.ValueType.ToString();
                        // Remove namespace from string (if any)
                        if (type.Contains("."))
                        {
                            // Remove everything until "."
                            type = type.Remove(0, type.IndexOf(".") + 1);
                        }
                        // Add type to label text
                        outputPortLabel.text = string.Concat(outputPortLabel.text, " (", type, ")");
                    }
                    // Draw port
                    IMLNodeEditor.PortField(outputPortLabel, m_IMLNode.GetOutputPort(pair.output.fieldName), m_NodeSkin.GetStyle("Port Label"), GUILayout.MinWidth(0));
                }

                GUILayout.EndHorizontal();
            }

            serializedObject.ApplyModifiedProperties();
        }
コード例 #4
0
        public override void OnBodyGUI()
        {
            if (chatNode == null)
            {
                chatNode = target as ChatNode;
            }



            // Debug.Log("操作chatnode中");
            // serializedObject.Update();
            // base.OnBodyGUI();
            // NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("ChatNodeID"));
            foreach (XNode.NodePort Port in target.Ports)
            {
                if (NodeEditorGUILayout.IsDynamicPortListPort(Port))
                {
                    continue;
                }
                NodeEditorGUILayout.PortField(Port);
            }

            //对对话列表进行序列化
            bool forceReset = false;

            //Debug.Log("我是最优先的吗");
            if (chatNode.lastIsMax != chatNode.IsMax)
            {
                forceReset         = true;
                chatNode.lastIsMax = chatNode.IsMax;
            }

            //姓名元素重载判定
            if (tAsset != null)
            {
                tAsset = dialogueGraph.GetAsset();
                bool isNameEqual = true;
                if (chatNode.tPersonNameList.Count == tAsset.persons.Count)
                {
                    for (int i = 0; i < tAsset.persons.Count; i++)
                    {
                        if (chatNode.tPersonNameList[i] != tAsset.persons[i].Name)
                        {
                            isNameEqual = false;
                            chatNode.tPersonNameList[i] = tAsset.persons[i].Name;
                        }
                    }

                    if (!isNameEqual)
                    {
                        forceReset = true;
                    }
                }
                else
                {
                    chatNode.tPersonNameList.Clear();

                    forceReset = true;
                }
            }

            if (chatNode.IsMax)
            {
                //  Debug.Log("重复渲染节点");
                NodeEditorGUILayout.DynamicPortList("chatslist", typeof(SingleChatClass), serializedObject, NodePort.IO.Output, Node.ConnectionType.Override, Node.TypeConstraint.None, DrawList, forceReset);



                if (GUILayout.Button("Minimize", EditorStyles.miniButton))
                {
                    chatNode.IsMax = false;
                }

                //serializedObject.ApplyModifiedProperties();
            }
            else
            {
                NodeEditorGUILayout.DynamicPortList("chatslist", typeof(SingleChatClass), serializedObject, NodePort.IO.Output, Node.ConnectionType.Override, Node.TypeConstraint.None, SimpleDrawList, forceReset);
                if (GUILayout.Button("Maximize", EditorStyles.miniButton))
                {
                    chatNode.IsMax = true;
                }
            }

            #region Old
            //GUI.color = Color.white;
            //serializedObject.Update();
            //if (chatNode == null)
            //chatNode = target as ChatNode;

            //foreach (XNode.NodePort dynamicPort in target.DynamicPorts)
            //{
            //    if (NodeEditorGUILayout.IsDynamicPortListPort(dynamicPort)) continue;
            //    NodeEditorGUILayout.PortField(dynamicPort);
            //}
            //NodeEditorGUILayout.DynamicPortList("chatslist", typeof(SingleChatClass), serializedObject, NodePort.IO.Output, Node.ConnectionType.Override);
            ////  NodeEditorGUILayout.PortField(Port);

            //NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("chatslist"));

            //aaa.DoLayoutList();
            //serializedObject.ApplyModifiedProperties();
            //base.OnBodyGUI();
            #endregion
        }