示例#1
0
        public override bool OnGUI()
        {
            if (ILReflectJsonImport.FsmClassInfoList == null)
            {
                ILReflectJsonImport.LoadJson();
            }

            if (ILReflectJsonImport.FsmClassInfoList == null)
            {
                return(false);
            }

            var action   = target as ILHotFsmProxy;
            int selected = 0;

            if (!string.IsNullOrEmpty(action._runtimeClassName))
            {
                selected = ILReflectJsonImport.FsmClassTypes.IndexOf(action._runtimeClassName);
            }

            selected = EditorGUILayout.Popup(selected, ILReflectJsonImport.FsmDisplayTypes);

            if (selected <= 0)
            {
                return(false);
            }

            if (action._runtimeClassName != ILReflectJsonImport.FsmClassTypes[selected])
            {
                GUI.changed = true;
            }

            string className = action._runtimeClassName = ILReflectJsonImport.FsmClassTypes[selected];

            if (className == "null" || string.IsNullOrEmpty(className))
            {
                FsmEditorGUILayout.ReadonlyTextField("Class name is empty");
                return(GUI.changed);
            }

            var classInfo = ILReflectJsonImport.FsmClassInfoList.Find(info => info.ClassName == className);

            if (classInfo == null)
            {
                FsmEditorGUILayout.ReadonlyTextField(string.Format("Class {0} is not exist", className));
                return(GUI.changed);
            }


            Dictionary <string, NamedVariable> previousVariableValueMapping = new Dictionary <string, NamedVariable>();
            Dictionary <string, NamedVariable> newVariableValueMapping      = new Dictionary <string, NamedVariable>();

            Dictionary <string, FsmEvent> previousEventValueMapping = new Dictionary <string, FsmEvent>();
            Dictionary <string, FsmEvent> newEventValueMapping      = new Dictionary <string, FsmEvent>();

            Dictionary <string, NamedVariable> previousExpandValues = new Dictionary <string, NamedVariable>();
            Dictionary <string, NamedVariable> newExpandValues      = new Dictionary <string, NamedVariable>();

            if (action.EventFieldNames != null)
            {
                for (var i = 0; i < action.StringFieldNames.Length; i++)
                {
                    if (i < action.StringValues.Length)
                    {
                        var v = action.StringValues[i];
                        previousVariableValueMapping.Add(action.StringFieldNames[i], v);
                    }
                }
                for (var i = 0; i < action.FloatFieldNames.Length; i++)
                {
                    if (i < action.FloatValues.Length)
                    {
                        var v = action.FloatValues[i];
                        previousVariableValueMapping.Add(action.FloatFieldNames[i], v);
                    }
                }
                for (var i = 0; i < action.BoolFieldNames.Length; i++)
                {
                    if (i < action.BoolValues.Length)
                    {
                        var v = action.BoolValues[i];
                        previousVariableValueMapping.Add(action.BoolFieldNames[i], v);
                    }
                }
                for (var i = 0; i < action.ObjectFieldNames.Length; i++)
                {
                    if (i < action.ObjectValues.Length)
                    {
                        var v = action.ObjectValues[i];
                        previousVariableValueMapping.Add(action.ObjectFieldNames[i], v);
                    }
                }
                for (var i = 0; i < action.ExpandNames.Length; i++)
                {
                    if (i < action.ExpandValues.Length)
                    {
                        var v = action.ExpandValues[i];
                        previousExpandValues.Add(action.ExpandNames[i], v);
                    }
                }
                for (var i = 0; i < action.EventFieldNames.Length; i++)
                {
                    var ev = action.EventValues[i];
                    previousEventValueMapping.Add(action.EventFieldNames[i], ev);
                }
            }

            DrawExpand(new ILHotFsmProxyStruct(
                           previousVariableValueMapping,
                           newVariableValueMapping,
                           previousEventValueMapping,
                           newEventValueMapping,
                           previousExpandValues,
                           newExpandValues
                           ), classInfo, "", true);

            var evNames = newEventValueMapping.Keys.ToArray();

            action.EventFieldNames = evNames;
            action.EventValues     = evNames.Select(n => newEventValueMapping[n]).ToArray();

            ConvertKeyValuesByType(typeof(FsmString), newVariableValueMapping,
                                   (keys, values) => { action.StringFieldNames = keys; action.StringValues = values.Cast <FsmString>().ToArray(); });

            ConvertKeyValuesByType(typeof(FsmFloat), newVariableValueMapping,
                                   (keys, values) => { action.FloatFieldNames = keys; action.FloatValues = values.Cast <FsmFloat>().ToArray(); });

            ConvertKeyValuesByType(typeof(FsmBool), newVariableValueMapping,
                                   (keys, values) => { action.BoolFieldNames = keys; action.BoolValues = values.Cast <FsmBool>().ToArray(); });

            ConvertKeyValuesByType(typeof(FsmObject), newVariableValueMapping,
                                   (keys, values) => { action.ObjectFieldNames = keys; action.ObjectValues = values.Cast <FsmObject>().ToArray(); });

            ConvertKeyValuesByType(typeof(FsmBool), newExpandValues, (keys, values) => { action.ExpandNames = keys; action.ExpandValues = values.Cast <FsmBool>().ToArray(); });

            return(GUI.changed);
        }
示例#2
0
        public override void OnInspectorGUI()
        {
            if (ILReflectJsonImport.MonoClassInfoList == null)
            {
                ILReflectJsonImport.LoadJson();
            }

            if (ILReflectJsonImport.MonoClassInfoList == null)
            {
                EditorGUILayout.HelpBox("Can not find ILHot ", MessageType.Error);
                return;
            }

            var classNameProperty = serializedObject.FindProperty("_runtimeClassName");

            var selected = 0;

            if (!string.IsNullOrEmpty(classNameProperty.stringValue))
            {
                selected = ILReflectJsonImport.MonoClassTypes.FindIndex(t => t == classNameProperty.stringValue);
            }

            selected = EditorGUILayout.Popup("Class Name", selected, ILReflectJsonImport.MonoDisplayTypes);

            if (selected <= 0)
            {
                if (string.IsNullOrEmpty(classNameProperty.stringValue))
                {
                    EditorGUILayout.HelpBox("Please specify a type ", MessageType.Error);
                }
                else
                {
                    EditorGUILayout.HelpBox(string.Format("Type [{0}] is not exsit. Maybe deleted or name changed",
                                                          classNameProperty.stringValue), MessageType.Error);
                }
                return;
            }

            classNameProperty.stringValue = ILReflectJsonImport.MonoClassTypes[selected];

            var classInfo = ILReflectJsonImport.MonoClassInfoList.Find(info => info.ClassName == classNameProperty.stringValue);

            if (classInfo == null)
            {
                EditorGUILayout.HelpBox("Can not find type " + classNameProperty.stringValue, MessageType.Error);
                return;
            }

            var instance = (ILHotMonoProxy)target;
            Dictionary <string, string> stringValues    = GetValues(instance.StringNames, instance.StringValues);
            Dictionary <string, string> newStringValues = new Dictionary <string, string>();

            Dictionary <string, float> floatValues    = GetValues(instance.FloatNames, instance.FloatValues);
            Dictionary <string, float> newFloatValues = new Dictionary <string, float>();

            Dictionary <string, bool> boolValues    = GetValues(instance.BoolNames, instance.BoolValues);
            Dictionary <string, bool> newBoolValues = new Dictionary <string, bool>();

            Dictionary <string, UnityEngine.Object> objectValues    = GetValues(instance.ObjectNames, instance.ObjectValues);
            Dictionary <string, UnityEngine.Object> newObjectValues = new Dictionary <string, UnityEngine.Object>();

            Dictionary <string, bool> expandValues    = GetValues(instance.ExpandNames, instance.ExpandValues);
            Dictionary <string, bool> newExpandValues = new Dictionary <string, bool>();

            Dictionary <string, Component> componentValues    = GetValues(instance.ILObjectNames, instance.ILObjectValues);
            Dictionary <string, Component> newComponentValues = new Dictionary <string, Component>();

            DrawExpand(new ILHotMonoProxyStruct(
                           stringValues,
                           newStringValues,
                           floatValues,
                           newFloatValues,
                           boolValues,
                           newBoolValues,
                           objectValues,
                           newObjectValues,
                           expandValues,
                           newExpandValues,
                           componentValues,
                           newComponentValues), classInfo, "", classNameProperty, true);

            SetKeysAndValues(newStringValues, "_stringNames", "_stringValues", (p, v) => p.stringValue                 = v);
            SetKeysAndValues(newFloatValues, "_floatNames", "_floatValues", (p, v) => p.floatValue                     = v);
            SetKeysAndValues(newBoolValues, "_boolNames", "_boolValues", (p, v) => p.boolValue                         = v);
            SetKeysAndValues(newObjectValues, "_objectNames", "_objectValues", (p, v) => p.objectReferenceValue        = v);
            SetKeysAndValues(newExpandValues, "_expandNames", "_expandValues", (p, v) => p.boolValue                   = v);
            SetKeysAndValues(newComponentValues, "_ilObjectNames", "_ilObjectValues", (p, v) => p.objectReferenceValue = v);

            serializedObject.ApplyModifiedProperties();
        }