Esempio n. 1
0
        public override void OnGUI(Rect rect)
        {
            if (localVariableInfoList == null || localVariableInfoList.Count == 0)
            {
                GUILayout.Label("还没有定义变量,在 编辑器/技能/技能变量编辑器 中添加变量", Utility.GetGuiStyle("Title"));
                return;
            }

            //draw title
            GUILayout.Label("选择一个变量", Utility.GetGuiStyle("Title"));
            GUILayout.Space(10);

            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

            for (int i = 0; i < localVariableInfoList.Count; i++)
            {
                GraphVariableInfo graphVariableInfo = localVariableInfoList[i];

                if (DrawVariableItemButton(graphVariableInfo))
                {
                    if (selectCallback != null)
                    {
                        selectCallback(graphVariableInfo.id);
                    }

                    editorWindow.Close();
                    break;
                }

                GUILayout.Space(10);
            }

            GUILayout.EndScrollView();
        }
Esempio n. 2
0
        /// <summary>
        /// 载入完成时,如果是<see cref="GetVariableNode"/>或者<see cref="SetVariableNode"/> 则需要初始化更新对应端口的类型
        /// </summary>
        public override void OnLoadFinish()
        {
            base.OnLoadFinish();

            //初始化读写节点的端口类型
            //如果input port端口的类型是VariableWrapper,则看是否设置的有值,有值的话更新整个端口的类型
            VariableWrapper variableWrapper = inputPortReflectionInfo.GetInputNodeVariableValue() as VariableWrapper;

            if (variableWrapper == null)
            {
                return;
            }

            int               variableId        = variableWrapper.variableId;
            GraphEditorData   data              = NodeView.graph.data;
            GraphVariableInfo graphVariableInfo = data.GetGraphVariableInfo(variableId);

            if (graphVariableInfo != null)
            {
                NodeView.UpdateGraphVariableNodeIOPortType(graphVariableInfo.valueType, true);
            }
            else
            {
                NodeView.UpdateGraphVariableNodeIOPortType(null, true);
            }
        }
Esempio n. 3
0
        public void OnGraphVariableListChange()
        {
            if (inputPortReflectionInfo.inputValueType != typeof(VariableWrapper))
            {
                return;
            }

            VariableWrapper variableWrapper = inputPortReflectionInfo.GetInputNodeVariableValue() as VariableWrapper;

            if (variableWrapper == null)
            {
                //这里不要直接检查连线合法性,所有读写技能变量的节点类型都改变后,统一检查一次连线合法性。下同
                NodeView.UpdateGraphVariableNodeIOPortType(null, false);
                return;
            }

            GraphVariableInfo graphVariableInfo =
                GraphEditorWindow.instance.data.GetGraphVariableInfo(variableWrapper.variableId);

            if (graphVariableInfo == null)
            {
                NodeView.UpdateGraphVariableNodeIOPortType(null, false);
                return;
            }

            NodeView.UpdateGraphVariableNodeIOPortType(graphVariableInfo.valueType, false);
        }
Esempio n. 4
0
        private bool DrawVariableItemButton(GraphVariableInfo graphVariableInfo)
        {
            GUILayout.BeginVertical(Utility.GetGuiStyle("LocalVariableItemBg"));

            GUILayout.BeginHorizontal();

            GUIStyle variableNameStyle = EditorStyles.label;

            variableNameStyle.alignment = TextAnchor.MiddleLeft;
            GUILayout.Label("变量: " + graphVariableInfo.name, variableNameStyle, GUILayout.MinHeight(30));
            if (GUILayout.Button("选择", GUILayout.MinHeight(30)))
            {
                return(true);
            }

            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            return(false);
        }
Esempio n. 5
0
        private void DrawLocalVariableItemList()
        {
            if (data.CurrentGraphVariableInfoList == null)
            {
                return;
            }

            scrollPosition = GUILayout.BeginScrollView(scrollPosition);
            for (int i = 0; i < data.CurrentGraphVariableInfoList.Count; i++)
            {
                GraphVariableInfo variableInfo = data.CurrentGraphVariableInfoList[i];

                if (DrawLocalVariableItem(variableInfo))
                {
                    data.CurrentGraphVariableInfoList.RemoveAt(i);
                    GraphEditorWindow.instance.data.OnGraphVariableListChange();
                    break;
                }

                GUILayout.Space(10);
            }

            GUILayout.EndScrollView();
        }
Esempio n. 6
0
        private static Offset <FlatNode.Runtime.Flat.GraphVariableInfo> ConvertToRuntimeGraphVariableInfo(FlatBufferBuilder fbb,
                                                                                                          GraphVariableInfo graphVariableInfo)
        {
            StringOffset typeNameStringOffset = fbb.CreateString(graphVariableInfo.typeName);
            StringOffset valueStringOffset    = fbb.CreateString(graphVariableInfo.valueString);

            FlatNode.Runtime.Flat.GraphVariableInfo.StartGraphVariableInfo(fbb);

            FlatNode.Runtime.Flat.GraphVariableInfo.AddId(fbb, graphVariableInfo.id);
            FlatNode.Runtime.Flat.GraphVariableInfo.AddValueString(fbb, valueStringOffset);
            FlatNode.Runtime.Flat.GraphVariableInfo.AddTypeName(fbb, typeNameStringOffset);

            return(FlatNode.Runtime.Flat.GraphVariableInfo.EndGraphVariableInfo(fbb));
        }
Esempio n. 7
0
        /// <summary>
        /// 根据不同类型,绘制不同的输入框
        /// </summary>
        /// <param name="graphVariableInfo"></param>
        private void DrawValueEditField(GraphVariableInfo graphVariableInfo)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("初始值: ", GUILayout.MaxWidth(60));

            Type   valueType   = graphVariableInfo.valueType;
            string valueString = graphVariableInfo.valueString;

            if (valueString == null)
            {
                graphVariableInfo.valueString = string.Empty;
                valueString = string.Empty;
            }

            if (valueType == typeof(int))
            {
                int intValue;
                if (!int.TryParse(valueString, out intValue))
                {
                    intValue = 0;
                }

                EditorGUI.BeginChangeCheck();
                intValue = EditorGUILayout.IntField(intValue);
                if (EditorGUI.EndChangeCheck())
                {
                    graphVariableInfo.valueString = intValue.ToString();
                }
            }
            else if (valueType == typeof(float))
            {
                float floatValue;
                if (!float.TryParse(valueString, out floatValue))
                {
                    floatValue = 0f;
                }

                EditorGUI.BeginChangeCheck();
                floatValue = EditorGUILayout.FloatField(floatValue);
                if (EditorGUI.EndChangeCheck())
                {
                    graphVariableInfo.valueString = floatValue.ToString("0.00");
                }
            }
            else if (valueType == typeof(bool))
            {
                bool boolValue;
                if (!bool.TryParse(valueString, out boolValue))
                {
                    boolValue = false;
                }

                EditorGUI.BeginChangeCheck();
                boolValue = EditorGUILayout.Toggle(boolValue);
                if (EditorGUI.EndChangeCheck())
                {
                    graphVariableInfo.valueString = boolValue.ToString();
                }
            }
            else if (valueType == typeof(string))
            {
                graphVariableInfo.valueString = EditorGUILayout.TextField(valueString);
            }
            else
            {
                EditorGUILayout.LabelField("无法设定初始值,需要运行时设置");
            }

            GUILayout.EndHorizontal();
        }
Esempio n. 8
0
        /// <summary>
        /// 绘制单个变量内容
        /// </summary>
        /// <param name="graphVariableInfo"></param>
        /// <returns>true:玩家对这个item进行了删除操作</returns>
        private bool DrawLocalVariableItem(GraphVariableInfo graphVariableInfo)
        {
            GUILayout.BeginVertical(Utility.GetGuiStyle("LocalVariableItemBg"));

            GUILayout.BeginHorizontal();
            //变量id
            GUILayout.Label("id: " + graphVariableInfo.id);

            GUILayout.FlexibleSpace();

            //删除当前变量
            if (GUILayout.Button("X"))
            {
                return(true);
            }

            GUILayout.EndHorizontal();

            //类型选择
            GUILayout.BeginHorizontal();
            GUILayout.Label("类型: ", GUILayout.MaxWidth(30));
            int typeIndex = GetTypeIndex(graphVariableInfo.valueType);

            if (typeIndex < 0)
            {
                typeIndex = 0;
                graphVariableInfo.valueType = supportTypeList[0];
            }

            EditorGUI.BeginChangeCheck();
            int selectIndex =
                EditorGUILayout.Popup(typeIndex, supportTypeNames, GUILayout.MinHeight(20), GUILayout.MaxWidth(150));

            if (EditorGUI.EndChangeCheck())
            {
                Type selectedType = GetTypeAtIndex(selectIndex);
                if (selectedType == null)
                {
                    return(false);
                }

                graphVariableInfo.valueType = selectedType;

                //更改了类型之后,也需要检查连线是否还合法
                GraphEditorWindow.instance.data.OnGraphVariableListChange();
            }

            GUILayout.EndHorizontal();

            //变量名称
            string valueName = graphVariableInfo.name;

            if (valueName == null)
            {
                valueName = string.Empty;
            }

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("变量备注: ", GUILayout.MaxWidth(50));

            EditorGUI.BeginChangeCheck();
            valueName = EditorGUILayout.TextField(valueName);
            if (EditorGUI.EndChangeCheck())
            {
                graphVariableInfo.name = valueName;
            }

            GUILayout.EndHorizontal();

            //变量初始值编辑
            DrawValueEditField(graphVariableInfo);

            GUILayout.EndVertical();

            return(false);
        }
Esempio n. 9
0
        /// <summary>
        /// 绘制各种类型的输入框
        /// </summary>
        /// <param name="type"></param>
        void DrawInputFieldLabel(Type type)
        {
            if (type == typeof(float))
            {
                string typeName = Utility.BeautifyTypeName(type) + ": ";
                CalculateAndDrawLabelCommonElement(typeName, 100f);

                EditorGUI.BeginChangeCheck();
                float value = (float)inputPortReflectionInfo.GetInputNodeVariableValue();
                value = EditorGUI.FloatField(labelInputAreaRect, value);
                if (EditorGUI.EndChangeCheck())
                {
                    inputPortReflectionInfo.SetInputNodeVariableValue(value);
                }
            }
            else if (type == typeof(int))
            {
                string typeName = Utility.BeautifyTypeName(type) + ": ";
                CalculateAndDrawLabelCommonElement(typeName, 100f);

                EditorGUI.BeginChangeCheck();
                int value = (int)inputPortReflectionInfo.GetInputNodeVariableValue();
                value = EditorGUI.IntField(labelInputAreaRect, value);
                if (EditorGUI.EndChangeCheck())
                {
                    inputPortReflectionInfo.SetInputNodeVariableValue(value);
                }
            }
            else if (type == typeof(string))
            {
                string typeName = Utility.BeautifyTypeName(type) + ": ";
                CalculateAndDrawLabelCommonElement(typeName, 100f);

                EditorGUI.BeginChangeCheck();
                string value = (string)inputPortReflectionInfo.GetInputNodeVariableValue();
                if (GUI.Button(labelInputAreaRect, value))
                {
                    PopupWindow.Show(labelInputAreaRect,
                                     new StringEditPopupWindow(value,
                                                               stringContent => { inputPortReflectionInfo.SetInputNodeVariableValue(stringContent); }));
                }
            }
            else if (type == typeof(bool))
            {
                string typeName = Utility.BeautifyTypeName(type) + ": ";
                CalculateAndDrawLabelCommonElement(typeName, 20f);

                EditorGUI.BeginChangeCheck();
                bool value = (bool)inputPortReflectionInfo.GetInputNodeVariableValue();
                value = EditorGUI.Toggle(labelInputAreaRect, value);
                if (EditorGUI.EndChangeCheck())
                {
                    inputPortReflectionInfo.SetInputNodeVariableValue(value);
                }
            }
            else if (type.IsEnum)
            {
                if (maxEnumNeedWidth < 0)
                {
                    maxEnumNeedWidth = Utility.GetEnumMaxGuiWidth(type, 16);
                }

                string typeName = Utility.BeautifyTypeName(type) + ": ";
                CalculateAndDrawLabelCommonElement(typeName, maxEnumNeedWidth + 25); //25是enum选择框箭头的位置

                EditorGUI.BeginChangeCheck();
                Enum enumValue = (Enum)inputPortReflectionInfo.GetInputNodeVariableValue();
                enumValue = EditorGUI.EnumPopup(labelInputAreaRect, enumValue);
                if (EditorGUI.EndChangeCheck())
                {
                    inputPortReflectionInfo.SetInputNodeVariableValue(enumValue);
                }
            }
            //支持list<int>
            else if (type == typeof(List <int>))
            {
                string typeName = Utility.BeautifyTypeName(type) + ": ";
                CalculateAndDrawLabelCommonElement(typeName, 100f);

                List <int> list = inputPortReflectionInfo.GetInputNodeVariableValue() as List <int>;
                if (list == null)
                {
                    list = new List <int>();
                }

                string listHint = string.Join(",", list.Select(x => x.ToString()).ToArray());
                if (GUI.Button(labelInputAreaRect, listHint))
                {
                    ListIntEditorWindow.ShowWindow(list,
                                                   editedList => { inputPortReflectionInfo.SetInputNodeVariableValue(editedList); });
                }
            }
            else if (type == typeof(LayerMaskWrapper))
            {
                if (maxLayerMaskNeedWidth < 0)
                {
                    maxLayerMaskNeedWidth = Utility.GetLayerMaxGuiLength(8);
                }

                string typeName = Utility.BeautifyTypeName(type) + ": ";
                CalculateAndDrawLabelCommonElement(typeName, maxLayerMaskNeedWidth + 25);

                EditorGUI.BeginChangeCheck();
                LayerMaskWrapper layerMaskWrapperValue = (LayerMaskWrapper)inputPortReflectionInfo.GetInputNodeVariableValue();
                if (layerMaskWrapperValue == null)
                {
                    layerMaskWrapperValue = new LayerMaskWrapper();
                }

                string[] gameLayerNames = Utility.GetUnityLayerNames();

                int selectLayer = EditorGUI.MaskField(labelInputAreaRect, layerMaskWrapperValue.layer, gameLayerNames);
                if (EditorGUI.EndChangeCheck())
                {
                    layerMaskWrapperValue.layer = selectLayer;
//                    Debug.Log("select layer mask: " + layerMaskValue);
                    inputPortReflectionInfo.SetInputNodeVariableValue(layerMaskWrapperValue);
                }
            }
            //选择技能变量
            else if (type == typeof(VariableWrapper))
            {
                VariableWrapper variableWrapper = inputPortReflectionInfo.GetInputNodeVariableValue() as VariableWrapper;
                if (variableWrapper == null)
                {
                    variableWrapper = new VariableWrapper();
                }

                int               varibleId         = variableWrapper.variableId;
                GraphEditorData   data              = GraphEditorWindow.instance.data;
                GraphVariableInfo graphVariableInfo = data.GetGraphVariableInfo(varibleId);

                string buttonName;
                //当前没有选择任何一个变量
                if (graphVariableInfo == null)
                {
                    buttonName = "选择一个变量!";
                }
                else
                {
                    buttonName = graphVariableInfo.name;
                }

                CalculateAndDrawLabelCommonElement("变量: ", EditorStyles.label.CalcSize(new GUIContent(buttonName)).x + 20);
                if (GUI.Button(labelInputAreaRect, buttonName))
                {
                    PopupWindow.Show(labelInputAreaRect, new SelectGraphVariablePopupWindow(data.CurrentGraphVariableInfoList,
                                                                                            selectVariableId =>
                    {
                        variableWrapper.variableId = selectVariableId;
                        inputPortReflectionInfo.SetInputNodeVariableValue(variableWrapper);

                        Type variableType = GraphEditorWindow.instance.data
                                            .GetGraphVariableInfo(selectVariableId).valueType;
                        NodeView.UpdateGraphVariableNodeIOPortType(variableType, true);
                    }));
                }
            }
            //所有需要自定义Input标签的类型写在这个分支前面
            else if (type.IsClass)
            {
                string typeName = Utility.BeautifyTypeName(type) + ": ";
                CalculateAndDrawLabelCommonElement(typeName, 30f);

                GUI.Label(labelInputAreaRect, "(Null)", labelTextStyle);
            }
            else
            {
                string typeName = Utility.BeautifyTypeName(type) + ": ";
                string content  = string.Format("Default({0})", type.Name);
                CalculateAndDrawLabelCommonElement(typeName, Utility.GetStringGuiWidth(content, labelTextStyle.fontSize));

                GUI.Label(labelInputAreaRect, content, labelTextStyle);
            }
        }