Exemplo n.º 1
0
    public override void Deserialize(XmlNode node, SkillData _data)
    {
        base.Deserialize(node, _data);

        string[] data = Base_Obj.Split('-');
        if (data!=null&&data.Length>0)
        {
            Base_Obj = data[1];
            BaseObj = _data.GetVariable(data[1]) as SharedGameObject;
            BaseObj.IsShared = true;

        }
    }
Exemplo n.º 2
0
    public bool drawVariables(SkillData _data)
    {
        if (_data == null)
        {
            return false;
        }
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        GUILayout.Label("Name", new GUILayoutOption[0]);
        GUI.SetNextControlName("Name");
        this.variableName = GUILayout.TextField(this.variableName, new GUILayoutOption[]
            {
                GUILayout.Width(220f)
            });
        if (this.mFocusNameField)
        {
            GUI.FocusControl("Name");
            this.mFocusNameField = false;
        }
        GUILayout.EndHorizontal();
        GUILayout.Space(2f);
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        GUILayout.Label("Type", new GUILayoutOption[0]);
        this.variableTypeIndex = EditorGUILayout.Popup(this.variableTypeIndex, this.sharedValueTypes, EditorStyles.toolbarPopup, new GUILayoutOption[]
            {
                GUILayout.Width(169f)
            });
        GUILayout.Space(8f);
        bool flag = false;
        //List<SharedVariable> list = _data.Variables;
        bool flag2 = !this.variableName.Equals("") && _data.GetVariable(this.variableName) == null;
        GUI.enabled = flag2;
        if (GUILayout.Button("Add", EditorStyles.toolbarButton, new GUILayoutOption[]{GUILayout.Width(40f)}) && flag2)
        {
            if (!_data.Variables.ContainsKey(this.variableName))
            {
                SharedVariable sharedVariable = ScriptableObject.CreateInstance(string.Format("Shared{0}", this.sharedValueTypes[this.variableTypeIndex])) as SharedVariable;
                sharedVariable.name = this.variableName;
                sharedVariable.IsShared = true;
                _data.Variables.Add(sharedVariable.name, sharedVariable);
                this.variableName = "";
                flag = true;
            }
        }
        GUI.enabled = true;
        GUILayout.Space(6f);
        GUILayout.EndHorizontal();
        //BehaviorDesignerUtility.DrawContentSeperator(2);
        GUILayout.Space(4f);
        this.mScrollPosition = GUILayout.BeginScrollView(this.mScrollPosition, new GUILayoutOption[0]);
        if (_data.Variables != null)
        {
            List<string> removekeys = new List<string>();
            foreach (var item in _data.Variables.Values)
            {
                EditorGUI.BeginChangeCheck();
                //SharedVariable sharedVariable2 = item;
                //if (sharedVariable2 == null)
                //{
                //    list = null;
                //    flag = true;
                //    break;
                //}
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                if (GUILayout.Button("—", new GUILayoutOption[]{GUILayout.Width(16f)}))
                {
                    removekeys.Add(item.name);
                    flag = true;
                    break;
                }
                GUILayout.Label(item.name, new GUILayoutOption[]
                    {
                        GUILayout.Width(128f)
                    });
                bool flag3 = false;
                switch (item.ValueType)
                {
                    case SharedVariableTypes.Vector2:
                    case SharedVariableTypes.Vector3:
                    case SharedVariableTypes.Vector4:
                    case SharedVariableTypes.Quaternion:
                    case SharedVariableTypes.Rect:
                        GUILayout.EndHorizontal();
                        flag3 = true;
                        break;
                }
                VariableInspector.DrawSharedVariableValue(item, 160);
                if (!flag3)
                {
                    GUILayout.EndHorizontal();
                }
                GUILayout.Space(4f);
                if (EditorGUI.EndChangeCheck())
                {
                    flag = true;
                }
            }
            if(removekeys.Count>0)
            {
                for(int i=0;i<removekeys.Count;i++)
                {
                    _data.Variables.Remove(removekeys[i]);
                }
                removekeys.Clear();
            }

        }
        GUILayout.EndScrollView();
        return flag;
    }
Exemplo n.º 3
0
    public bool drawTaskFields(SkillData _data, Task task)
    {
        if (task == null)
            {
                return false;
            }
            this.mScrollPosition = GUILayout.BeginScrollView(this.mScrollPosition, new GUILayoutOption[0]);

            bool result = false;
            EditorGUIUtility.labelWidth = TaskPropertiesLabelWidth;
            EditorGUI.BeginChangeCheck();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            EditorGUILayout.LabelField("Name", new GUILayoutOption[]
            {
                GUILayout.Width(90f)
            });
            task.NodeData.FriendlyName = EditorGUILayout.TextField(task.NodeData.FriendlyName, new GUILayoutOption[0]);

            if (GUILayout.Button("编辑", new GUILayoutOption[0]))
            {
                GenericMenu genericMenu = new GenericMenu();
                genericMenu.AddItem(new GUIContent("Edit Script"), false, new GenericMenu.MenuFunction2(this.openInFileEditor), task);
                genericMenu.AddItem(new GUIContent("Reset"), false, new GenericMenu.MenuFunction2(this.resetTask), task);
                genericMenu.ShowAsContext();
            }
            GUILayout.EndHorizontal();

            EditorGUILayout.LabelField("Comment", new GUILayoutOption[0]);
            task.NodeData.Comment = EditorGUILayout.TextArea(task.NodeData.Comment,  new GUILayoutOption[]{GUILayout.Height(48f)});
            if (EditorGUI.EndChangeCheck())
            {
                result = true;
            }
            //BehaviorDesignerUtility.DrawContentSeperator(2);
            GUILayout.Space(6f);
            HideFlags hideFlags = task.hideFlags;
            task.hideFlags = 0;
            SerializedObject serializedObject = new SerializedObject(task);
            serializedObject.Update();
            FieldInfo[] fields = task.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            for (int i = 0; i < fields.Length; i++)
            {
                if (fields[i].GetCustomAttributes(typeof(NonSerializedAttribute), false).Length <= 0 && ((!fields[i].IsPrivate && !fields[i].IsFamily) || fields[i].GetCustomAttributes(typeof(SerializeField), false).Length != 0))
                {
                    SerializedProperty serializedProperty = serializedObject.FindProperty(fields[i].Name);
                    if (serializedProperty != null)
                    {
                        SkillEditor.Runtime.Tasks.TooltipAttribute[] array;
                        GUIContent gUIContent;
                        if ((array = (fields[i].GetCustomAttributes(typeof(SkillEditor.Runtime.Tasks.TooltipAttribute), false) as SkillEditor.Runtime.Tasks.TooltipAttribute[])).Length > 0)
                        {
                            gUIContent = new GUIContent(fields[i].Name, array[0].Tooltip);
                        }
                        else
                        {
                            gUIContent = new GUIContent(fields[i].Name);
                        }
                        EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
                        if (fields[i].FieldType.IsSubclassOf(typeof(SharedVariable)))
                        {
                            EditorGUI.BeginChangeCheck();
                            SharedVariable sharedVariable = fields[i].GetValue(task) as SharedVariable;
                            GUILayout.BeginVertical(new GUILayoutOption[0]);
                            GUILayout.Space(2f);
                            GUILayout.Label(gUIContent, new GUILayoutOption[]
                            {
                                GUILayout.Width(146f)
                            });
                            GUILayout.EndVertical();
                            bool flag4 = false;
                            switch (sharedVariable.ValueType)
                            {
                                case SharedVariableTypes.Vector2:
                                case SharedVariableTypes.Vector3:
                                case SharedVariableTypes.Vector4:
                                case SharedVariableTypes.Quaternion:
                                case SharedVariableTypes.Rect:
                                    flag4 = true;
                                    break;
                            }
                            if (sharedVariable.IsShared)
                            {
                                string[] array3 = null;
                                int num = this.getVariablesOfType(sharedVariable, _data, out array3);
                                Color backgroundColor2 = GUI.backgroundColor;
                                if (num == 0)
                                {
                                    GUI.backgroundColor = Color.red;
                                }
                                int num2 = num;
                                num = EditorGUILayout.Popup(num, array3, EditorStyles.toolbarPopup, new GUILayoutOption[0]);
                                GUI.backgroundColor = backgroundColor2;
                                if (num != num2)
                                {//===========设置分享变量==============
                                    if (num == 0)
                                    {
                                        SharedVariable sharedVariable2 = ScriptableObject.CreateInstance(fields[i].FieldType) as SharedVariable;
                                        sharedVariable2.IsShared = true;
                                        fields[i].SetValue(task, sharedVariable2);
                                    }
                                    else
                                    {
                                        fields[i].SetValue(task, _data.GetVariable(array3[num]));
                                    }
                                }
                                GUILayout.Space(8f);
                            }
                            if (!sharedVariable.IsShared && !flag4)
                            {
                                VariableInspector.DrawSharedVariableValue(sharedVariable, 121);
                                fields[i].SetValue(task, sharedVariable);
                            }
                            if (GUILayout.Button(sharedVariable.IsShared ? "-" : "@"))
                            {
                                bool isShared = !sharedVariable.IsShared;
                                sharedVariable = (ScriptableObject.CreateInstance(fields[i].FieldType) as SharedVariable);
                                sharedVariable.IsShared = isShared;//设置是否为分享变量
                                fields[i].SetValue(task, sharedVariable);
                            }
                            GUILayout.Space(4f);
                            GUILayout.EndHorizontal();
                            if (!sharedVariable.IsShared && flag4)
                            {
                                VariableInspector.DrawSharedVariableValue(sharedVariable, 100);
                                fields[i].SetValue(task, sharedVariable);
                            }
                            if (EditorGUI.EndChangeCheck())
                            {
                                result = true;
                            }
                            GUILayout.Space(4f);
                        }
                        else
                        {
                            EditorGUI.BeginChangeCheck();
                            EditorGUILayout.PropertyField(serializedProperty, gUIContent, true, new GUILayoutOption[0]);
                            if (EditorGUI.EndChangeCheck())
                            {
                                serializedObject.ApplyModifiedProperties();
                                result = true;
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
            }
            task.hideFlags = hideFlags;
            GUILayout.EndScrollView();
            return result;
    }