예제 #1
0
        public static void ShowWindow(List <int> targetList, Action <List <int> > callback)
        {
            ListIntEditorWindow window = GetWindow <ListIntEditorWindow>();

            window.minSize      = new Vector2(200, 300);
            window.maxSize      = new Vector2(300, 400);
            window.titleContent = new GUIContent("List<int>编辑");
//            EditorWindow.GetWindow<>()

            if (targetList == null)
            {
                window.targetList = new List <int>();
            }
            else
            {
                window.targetList = new List <int>(targetList);
            }
            window.callback = callback;
        }
예제 #2
0
        private void OnGUI()
        {
            GUILayout.Label("编辑List<int>", Utility.GetGuiStyle("Title"), GUILayout.MinHeight(70f));
            GUILayout.Space(10);

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

            GUILayout.Label("增加节点");
            if (GUILayout.Button("+", GUILayout.MinWidth(30), GUILayout.MaxWidth(30)))
            {
                if (targetList == null)
                {
                    targetList = new List <int>();
                }

                targetList.Add(0);
                GUI.FocusControl(null);
            }

            GUILayout.EndHorizontal();

            scrollPosition = GUILayout.BeginScrollView(scrollPosition);
            if (targetList == null)
            {
                GUILayout.FlexibleSpace();
            }
            else
            {
                for (int i = 0; i < targetList.Count; i++)
                {
                    GUILayout.BeginHorizontal();

                    GUILayout.Space(20);
                    int value = targetList[i];

                    EditorGUI.BeginChangeCheck();
                    value = EditorGUILayout.IntField(value, GUILayout.MinWidth(150));
                    if (EditorGUI.EndChangeCheck())
                    {
                        targetList[i] = value;
                    }

                    GUILayout.Space(20);

                    if (GUILayout.Button("-", GUILayout.MinWidth(20)))
                    {
                        targetList.RemoveAt(i);
                        GUILayout.EndHorizontal();
                        GUI.FocusControl(null);
                        break;
                    }

                    GUILayout.EndHorizontal();
                }
            }
            GUILayout.EndScrollView();

            GUILayout.FlexibleSpace();
            if (GUILayout.Button("确认保存", GUILayout.MinHeight(50f)))
            {
                GUI.FocusControl(null);

                if (callback != null)
                {
                    callback(targetList);
                    ListIntEditorWindow window = GetWindow <ListIntEditorWindow>();
                    if (window != null)
                    {
                        window.Close();
                    }
                }
            }
        }
예제 #3
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);
            }
        }