static int __CreateInstance(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                if (LuaAPI.lua_gettop(L) == 1)
                {
                    var gen_ret = new MonoBehaviourAdapter.Adaptor();
                    translator.Push(L, gen_ret);

                    return(1);
                }
                if (LuaAPI.lua_gettop(L) == 3 && translator.Assignable <ILRuntime.Runtime.Enviorment.AppDomain>(L, 2) && translator.Assignable <ILRuntime.Runtime.Intepreter.ILTypeInstance>(L, 3))
                {
                    ILRuntime.Runtime.Enviorment.AppDomain      _appdomain = (ILRuntime.Runtime.Enviorment.AppDomain)translator.GetObject(L, 2, typeof(ILRuntime.Runtime.Enviorment.AppDomain));
                    ILRuntime.Runtime.Intepreter.ILTypeInstance _instance  = (ILRuntime.Runtime.Intepreter.ILTypeInstance)translator.GetObject(L, 3, typeof(ILRuntime.Runtime.Intepreter.ILTypeInstance));

                    var gen_ret = new MonoBehaviourAdapter.Adaptor(_appdomain, _instance);
                    translator.Push(L, gen_ret);

                    return(1);
                }
            }
            catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(LuaAPI.luaL_error(L, "invalid arguments to MonoBehaviourAdapter.Adaptor constructor!"));
        }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        MonoBehaviourAdapter.Adaptor clr = target as MonoBehaviourAdapter.Adaptor;
        var instance = clr.ILInstance;

        if (instance != null)
        {
            EditorGUILayout.LabelField("Script", clr.ILInstance.Type.FullName);

            int index = 0;
            foreach (var i in instance.Type.FieldMapping)
            {
                //这里是取的所有字段,没有处理不是public的
                var name = i.Key;
                var type = instance.Type.FieldTypes[index];//在这里不能用i.Value,因为Unity有HideInInspector方法,隐藏序列化的值,但是还是会被计数
                index++;

                var cType = type.TypeForCLR;
                if (cType.IsPrimitive)//如果是基础类型
                {
                    if (cType == typeof(float))
                    {
                        instance[i.Value] = EditorGUILayout.FloatField(name, (float)instance[i.Value]);
                    }
                    else if (cType == typeof(int))
                    {
                        instance[i.Value] = EditorGUILayout.IntField(name, (int)instance[i.Value]);
                    }
                    else
                    {
                        throw new System.NotImplementedException();//剩下的大家自己补吧
                    }
                }
                else
                {
                    object obj = instance[i.Value];
                    if (typeof(UnityEngine.Object).IsAssignableFrom(cType))
                    {
                        //处理Unity类型
                        var res = EditorGUILayout.ObjectField(name, obj as UnityEngine.Object, cType, true);
                        instance[i.Value] = res;
                    }
                    else
                    {
                        //其他类型现在没法处理
                        if (obj != null)
                        {
                            EditorGUILayout.LabelField(name, obj.ToString());
                        }
                        else
                        {
                            EditorGUILayout.LabelField(name, "(null)");
                        }
                    }
                }
            }
        }
    }
        static int _s_set_AppDomain(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                MonoBehaviourAdapter.Adaptor gen_to_be_invoked = (MonoBehaviourAdapter.Adaptor)translator.FastGetCSObj(L, 1);
                gen_to_be_invoked.AppDomain = (ILRuntime.Runtime.Enviorment.AppDomain)translator.GetObject(L, 2, typeof(ILRuntime.Runtime.Enviorment.AppDomain));
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(0);
        }
        static int _g_get_AppDomain(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                MonoBehaviourAdapter.Adaptor gen_to_be_invoked = (MonoBehaviourAdapter.Adaptor)translator.FastGetCSObj(L, 1);
                translator.Push(L, gen_to_be_invoked.AppDomain);
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(1);
        }
示例#5
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        MonoBehaviourAdapter.Adaptor clr = target as MonoBehaviourAdapter.Adaptor;
        if (clr is null)
        {
            return;
        }

        var instance = clr.ILInstance;

        if (instance != null)
        {
            EditorGUILayout.LabelField("Script", clr.ILInstance.Type.Name);
            SerializeILTypeInstance.SerializeJBehaviourType(_fadeGroup, instance);

            int index = 0;
            foreach (var i in instance.Type.FieldMapping)
            {
                //这里是取的所有字段,没有处理不是public的
                var type    = instance.Type.FieldTypes[index];
                var cType   = type.TypeForCLR;
                var objName = i.Key;
                GUI.enabled = true;
                index++;

                if (SerializeILTypeInstance.NeedToHide(instance, objName))
                {
                    continue;
                }

                foreach (var method in SerializeILTypeInstance.GetSerializeMethods())
                {
                    System.Object[] parameters = { _fadeGroup, cType, type, instance, i, objName };
                    var             result     = method.Value.Invoke(null, parameters);
                    if ((bool)result)
                    {
                        break;
                    }

                    if (method.Key == 0)
                    {
                        EditorGUILayout.LabelField(objName, "(null)");
                    }
                }
            }
        }
        // 应用属性修改
        serializedObject.ApplyModifiedProperties();
    }
        static int _m_Awake(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                MonoBehaviourAdapter.Adaptor gen_to_be_invoked = (MonoBehaviourAdapter.Adaptor)translator.FastGetCSObj(L, 1);



                {
                    gen_to_be_invoked.Awake(  );



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
        static int _m_ToString(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                MonoBehaviourAdapter.Adaptor gen_to_be_invoked = (MonoBehaviourAdapter.Adaptor)translator.FastGetCSObj(L, 1);



                {
                    var gen_ret = gen_to_be_invoked.ToString(  );
                    LuaAPI.lua_pushstring(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
示例#8
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        MonoBehaviourAdapter.Adaptor clr = target as MonoBehaviourAdapter.Adaptor;
        var instance = clr.ILInstance;

        if (instance != null)
        {
            EditorGUILayout.LabelField("Script", clr.ILInstance.Type.Name);

            //如果JBehaviour
            var JBehaviourType = Init.appdomain.LoadedTypes["JEngine.Core.JBehaviour"];
            var t = instance.Type.ReflectionType;
            if (t.IsSubclassOf(JBehaviourType.ReflectionType))
            {
                var f  = t.GetField("_instanceID", BindingFlags.NonPublic);
                var id = f.GetValue(instance).ToString();
                EditorGUILayout.TextField("InstanceID", id);

                this.fadeGroup[0].target = EditorGUILayout.Foldout(this.fadeGroup[0].target,
                                                                   "JBehaviour Stats", true);
                if (EditorGUILayout.BeginFadeGroup(this.fadeGroup[0].faded))
                {
                    var  fm        = t.GetField("FrameMode", BindingFlags.Public);
                    bool frameMode = EditorGUILayout.Toggle("FrameMode", (bool)fm.GetValue(instance));
                    fm.SetValue(instance, frameMode);

                    var fq        = t.GetField("Frequency", BindingFlags.Public);
                    int frequency = EditorGUILayout.IntField("Frequency", (int)fq.GetValue(instance));
                    fq.SetValue(instance, frequency);

                    GUI.enabled = false;

                    var paused = t.GetField("Paused", BindingFlags.NonPublic);
                    EditorGUILayout.Toggle("Paused", (bool)paused.GetValue(instance));

                    var totalTime = t.GetField("TotalTime", BindingFlags.Public);
                    EditorGUILayout.FloatField("TotalTime", (float)totalTime.GetValue(instance));

                    var loopDeltaTime = t.GetField("LoopDeltaTime", BindingFlags.Public);
                    EditorGUILayout.FloatField("LoopDeltaTime", (float)loopDeltaTime.GetValue(instance));

                    var loopCounts = t.GetField("LoopCounts", BindingFlags.Public);
                    EditorGUILayout.LongField("LoopCounts", (long)loopCounts.GetValue(instance));

                    GUI.enabled = true;

                    var timeScale = t.GetField("TimeScale", BindingFlags.Public);
                    var ts        = EditorGUILayout.FloatField("TimeScale", (float)timeScale.GetValue(instance));
                    timeScale.SetValue(instance, ts);
                }
                EditorGUILayout.EndFadeGroup();

                if (instance.Type.FieldMapping.Count > 0)
                {
                    EditorGUILayout.Space(10);
                    EditorGUILayout.HelpBox($"{t.Name} variables", MessageType.Info);
                }
            }

            int index = 0;
            foreach (var i in instance.Type.FieldMapping)
            {
                //这里是取的所有字段,没有处理不是public的
                var name = i.Key;
                var type = instance.Type.FieldTypes[index];
                index++;

                var    cType = type.TypeForCLR;
                object obj   = instance[i.Value];
                if (cType.IsPrimitive) //如果是基础类型
                {
                    try
                    {
                        if (cType == typeof(float))
                        {
                            instance[i.Value] = EditorGUILayout.FloatField(name, (float)instance[i.Value]);
                        }
                        else if (cType == typeof(double))
                        {
                            instance[i.Value] = EditorGUILayout.DoubleField(name, (float)instance[i.Value]);
                        }
                        else if (cType == typeof(int))
                        {
                            instance[i.Value] = EditorGUILayout.IntField(name, (int)instance[i.Value]);
                        }
                        else if (cType == typeof(long))
                        {
                            instance[i.Value] = EditorGUILayout.LongField(name, (long)instance[i.Value]);
                        }
                        else if (cType == typeof(bool))
                        {
                            var result = bool.TryParse(instance[i.Value].ToString(), out var value);
                            if (!result)
                            {
                                value = instance[i.Value].ToString() == "1";
                            }
                            instance[i.Value] = EditorGUILayout.Toggle(name, value);
                        }
                        else
                        {
                            EditorGUILayout.LabelField(name, instance[i.Value].ToString());
                        }
                    }
                    catch (Exception e)
                    {
                        Log.PrintError($"无法序列化{name},{e.Message}");
                        EditorGUILayout.LabelField(name, instance[i.Value].ToString());
                    }
                }
                else
                {
                    if (cType == typeof(string))
                    {
                        if (obj != null)
                        {
                            instance[i.Value] = EditorGUILayout.TextField(name, (string)instance[i.Value]);
                        }
                        else
                        {
                            instance[i.Value] = EditorGUILayout.TextField(name, "");
                        }
                    }
                    else if (cType == typeof(JsonData))//可以折叠显示Json数据
                    {
                        if (instance[i.Value] != null)
                        {
                            this.fadeGroup[1].target = EditorGUILayout.Foldout(this.fadeGroup[1].target, name, true);
                            if (EditorGUILayout.BeginFadeGroup(this.fadeGroup[1].faded))
                            {
                                instance[i.Value] = EditorGUILayout.TextArea(
                                    ((JsonData)instance[i.Value]).ToString()
                                    );
                            }
                            EditorGUILayout.EndFadeGroup();
                            EditorGUILayout.Space();
                        }
                        else
                        {
                            EditorGUILayout.LabelField(name, "暂无值的JsonData");
                        }
                    }
                    else if (typeof(UnityEngine.Object).IsAssignableFrom(cType))
                    {
                        if (obj == null && cType == typeof(MonoBehaviourAdapter.Adaptor))
                        {
                            EditorGUILayout.LabelField(name, "未赋值的热更类");
                            break;
                        }

                        if (cType == typeof(MonoBehaviourAdapter.Adaptor))
                        {
                            try
                            {
                                var clrInstance = ClassBindMgr.FindObjectsOfTypeAll <MonoBehaviourAdapter.Adaptor>()
                                                  .Find(adaptor =>
                                                        adaptor.ILInstance == instance[i.Value]);
                                GUI.enabled = true;
                                EditorGUILayout.ObjectField(name, clrInstance.gameObject, typeof(GameObject), true);
                                GUI.enabled = false;
                            }
                            catch
                            {
                                EditorGUILayout.LabelField(name, "未赋值的热更类");
                            }

                            break;
                        }

                        //处理Unity类型
                        var res = EditorGUILayout.ObjectField(name, obj as UnityEngine.Object, cType, true);
                        instance[i.Value] = res;
                    }
                    //可绑定值,可以尝试更改
                    else if (type.ReflectionType.ToString().Contains("BindableProperty") && obj != null)
                    {
                        PropertyInfo fi  = type.ReflectionType.GetProperty("Value");
                        object       val = fi.GetValue(obj);

                        string genericTypeStr = type.ReflectionType.ToString().Split('`')[1].Replace("1<", "")
                                                .Replace(">", "");
                        Type genericType = Type.GetType(genericTypeStr);
                        if (genericType == null || (!genericType.IsPrimitive && genericType != typeof(string))) //不是基础类型或字符串
                        {
                            EditorGUILayout.LabelField(name, val.ToString());                                   //只显示字符串
                        }
                        else
                        {
                            //可更改
                            var data = ConvertSimpleType(EditorGUILayout.TextField(name, val.ToString()), genericType);
                            if (data != null)//尝试更改
                            {
                                fi.SetValue(obj, data);
                            }
                        }
                    }
                    else
                    {
                        //其他类型现在没法处理
                        if (obj != null)
                        {
                            var clrInstance = ClassBindMgr.FindObjectsOfTypeAll <MonoBehaviourAdapter.Adaptor>()
                                              .Find(adaptor =>
                                                    adaptor.ILInstance.Equals(instance[i.Value]));
                            if (clrInstance != null)
                            {
                                GUI.enabled = true;
                                EditorGUILayout.ObjectField(name, clrInstance.gameObject, typeof(GameObject), true);
                                GUI.enabled = false;
                            }
                            else
                            {
                                EditorGUILayout.LabelField(name, obj.ToString());
                            }
                        }
                        else
                        {
                            EditorGUILayout.LabelField(name, "(null)");
                        }
                    }
                }
            }
        }

        // 应用属性修改
        this.serializedObject.ApplyModifiedProperties();
    }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        MonoBehaviourAdapter.Adaptor clr = target as MonoBehaviourAdapter.Adaptor;
        var instance = clr.ILInstance;

        if (instance != null)
        {
            EditorGUILayout.LabelField("Script", clr.ILInstance.Type.FullName);
            foreach (var i in instance.Type.FieldMapping)
            {
                var             name = i.Key;
                var             type = instance.Type.FieldTypes[i.Value];
                FieldDefinition fd;
                instance.Type.GetField(i.Value, out fd);
                if (!fd.IsPublic)
                {
                    continue;
                }

                var cType = type.TypeForCLR;
                if (cType.IsPrimitive)//如果是基础类型
                {
                    if (cType == typeof(sbyte))
                    {
                        instance[i.Value] = (sbyte)EditorGUILayout.IntField(name, (sbyte)(int)instance[i.Value]);
                    }
                    else if (cType == typeof(short))
                    {
                        instance[i.Value] = (short)EditorGUILayout.IntField(name, (short)(int)instance[i.Value]);
                    }
                    else if (cType == typeof(int))
                    {
                        instance[i.Value] = EditorGUILayout.IntField(name, (int)instance[i.Value]);
                    }
                    else if (cType == typeof(long))
                    {
                        instance[i.Value] = EditorGUILayout.LongField(name, (long)instance[i.Value]);
                    }
                    else if (cType == typeof(byte))
                    {
                        instance[i.Value] = (byte)EditorGUILayout.IntField(name, (byte)(int)instance[i.Value]);
                    }
                    else if (cType == typeof(ushort))
                    {
                        instance[i.Value] = (ushort)EditorGUILayout.IntField(name, (ushort)(int)instance[i.Value]);
                    }
                    else if (cType == typeof(uint))
                    {
                        instance[i.Value] = (uint)EditorGUILayout.LongField(name, (uint)(int)instance[i.Value]);
                    }
                    else if (cType == typeof(ulong))
                    {
                        instance[i.Value] = (ulong)EditorGUILayout.LongField(name, (long)instance[i.Value]);
                    }
                    else if (cType == typeof(float))
                    {
                        instance[i.Value] = EditorGUILayout.FloatField(name, (float)instance[i.Value]);
                    }
                    else if (cType == typeof(double))
                    {
                        instance[i.Value] = EditorGUILayout.DoubleField(name, (double)instance[i.Value]);
                    }
                    else if (cType == typeof(bool))
                    {
                        instance[i.Value] = EditorGUILayout.Toggle(name, (int)instance[i.Value] == 1);
                    }
                    else if (cType == typeof(char))
                    {
                        var val = EditorGUILayout.TextField(name, ((char)(int)instance[i.Value]).ToString());
                        if (string.IsNullOrEmpty(val))
                        {
                            instance[i.Value] = ' ';
                        }
                        else
                        {
                            instance[i.Value] = val[0];
                        }
                    }
                    else
                    {
                        throw new System.NotImplementedException();
                    }
                }
                else
                {
                    object obj = instance[i.Value];
                    if (typeof(UnityEngine.Object).IsAssignableFrom(cType))
                    {
                        //处理Unity类型
                        var res = EditorGUILayout.ObjectField(name, obj as UnityEngine.Object, cType, true);
                        instance[i.Value] = res;
                    }
                    else
                    {
                        if (cType == typeof(string))
                        {
                            instance[i.Value] = EditorGUILayout.TextField(name, (string)instance[i.Value]);
                        }
                        else if (cType == typeof(UnityEngine.Vector2))
                        {
                            instance[i.Value] = EditorGUILayout.Vector2Field(name, (Vector2)instance[i.Value]);
                        }
                        else if (cType == typeof(UnityEngine.Vector3))
                        {
                            instance[i.Value] = EditorGUILayout.Vector3Field(name, (Vector3)instance[i.Value]);
                        }
                        else if (cType == typeof(UnityEngine.Vector4))
                        {
                            instance[i.Value] = EditorGUILayout.Vector4Field(name, (Vector4)instance[i.Value]);
                        }

                        /*else
                         * {
                         *  if (obj != null)
                         *      EditorGUILayout.LabelField(name, obj.ToString());
                         *  else
                         *      EditorGUILayout.LabelField(name, "(null)");
                         * }*/
                    }
                }
            }
        }
    }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        MonoBehaviourAdapter.Adaptor clr = target as MonoBehaviourAdapter.Adaptor;
        var instance = clr.ILInstance;

        if (instance != null)
        {
            EditorGUILayout.LabelField("Script", clr.ILInstance.Type.Name);

            int index = 0;
            foreach (var i in instance.Type.FieldMapping)
            {
                //这里是取的所有字段,没有处理不是public的
                var name = i.Key;
                var type = instance.Type.FieldTypes[index];
                index++;

                var    cType = type.TypeForCLR;
                object obj   = instance[i.Value];
                if (cType.IsPrimitive) //如果是基础类型
                {
                    try
                    {
                        if (cType == typeof(float))
                        {
                            instance[i.Value] = EditorGUILayout.FloatField(name, (float)instance[i.Value]);
                        }
                        else if (cType == typeof(double))
                        {
                            instance[i.Value] = EditorGUILayout.DoubleField(name, (float)instance[i.Value]);
                        }
                        else if (cType == typeof(int))
                        {
                            instance[i.Value] = EditorGUILayout.IntField(name, (int)instance[i.Value]);
                        }
                        else if (cType == typeof(long))
                        {
                            instance[i.Value] = EditorGUILayout.LongField(name, (long)instance[i.Value]);
                        }
                        else if (cType == typeof(bool))
                        {
                            var result = bool.TryParse(instance[i.Value].ToString(), out var value);
                            if (!result)
                            {
                                value = instance[i.Value].ToString() == "1";
                            }
                            instance[i.Value] = EditorGUILayout.Toggle(name, value);
                        }
                        else
                        {
                            EditorGUILayout.LabelField(name, instance[i.Value].ToString());
                        }
                    }
                    catch (Exception e)
                    {
                        Log.PrintError($"无法序列化{name},{e.Message}");
                        EditorGUILayout.LabelField(name, instance[i.Value].ToString());
                    }
                }
                else
                {
                    if (cType == typeof(string))
                    {
                        if (obj != null)
                        {
                            instance[i.Value] = EditorGUILayout.TextField(name, (string)instance[i.Value]);
                        }
                        else
                        {
                            instance[i.Value] = EditorGUILayout.TextField(name, "");
                        }
                    }
                    else if (cType == typeof(JsonData))
                    {
                        if (instance[i.Value] != null)
                        {
                            this.fadeGroup.target = EditorGUILayout.Foldout(this.fadeGroup.target, name, true);
                            if (EditorGUILayout.BeginFadeGroup(this.fadeGroup.faded))
                            {
                                EditorGUILayout.TextArea(
                                    ((JsonData)instance[i.Value]).ToString()
                                    );
                            }
                            EditorGUILayout.EndFadeGroup();
                            EditorGUILayout.Space();
                        }
                        else
                        {
                            EditorGUILayout.LabelField(name, "暂无值的JsonData");
                        }
                    }
                    else if (typeof(UnityEngine.Object).IsAssignableFrom(cType))
                    {
                        if (obj == null && cType == typeof(MonoBehaviourAdapter.Adaptor))
                        {
                            EditorGUILayout.LabelField(name, "未赋值或自动赋值的热更类");
                            break;
                        }

                        //处理Unity类型
                        var res = EditorGUILayout.ObjectField(name, obj as UnityEngine.Object, cType, true);
                        instance[i.Value] = res;
                    }
                    else if (type.ReflectionType.ToString().Contains("BindableProperty") && obj != null)
                    {
                        PropertyInfo fi  = type.ReflectionType.GetProperty("Value");
                        object       val = fi.GetValue(obj);
                        EditorGUILayout.LabelField(name, val.ToString());
                    }
                    else
                    {
                        //其他类型现在没法处理
                        if (obj != null)
                        {
                            EditorGUILayout.LabelField(name, obj.ToString());
                        }
                        else
                        {
                            EditorGUILayout.LabelField(name, "(null)");
                        }
                    }
                }
            }
        }

        // 应用属性修改
        this.serializedObject.ApplyModifiedProperties();
    }
示例#11
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        MonoBehaviourAdapter.Adaptor clr = target as MonoBehaviourAdapter.Adaptor;
        var instance = clr.ILInstance;

        if (instance != null)
        {
            EditorGUILayout.LabelField("Script", clr.ILInstance.Type.Name);

            int index = 0;
            foreach (var i in instance.Type.FieldMapping)
            {
                //这里是取的所有字段,没有处理不是public的
                var name = i.Key;
                var type = instance.Type.FieldTypes[index];
                index++;

                var cType = type.TypeForCLR;
                if (cType.IsPrimitive) //如果是基础类型
                {
                    if (cType == typeof(float))
                    {
                        instance[i.Value] = EditorGUILayout.FloatField(name, (float)instance[i.Value]);
                    }
                    else if (cType == typeof(int))
                    {
                        instance[i.Value] = EditorGUILayout.IntField(name, (int)instance[i.Value]);
                    }
                    else if (cType == typeof(long))
                    {
                        instance[i.Value] = EditorGUILayout.LongField(name, (long)instance[i.Value]);
                    }
                    else if (cType == typeof(string))
                    {
                        instance[i.Value] = EditorGUILayout.TextArea(name, (string)instance[i.Value]);
                    }
                    else
                    {
                        //剩下的大家自己补吧
                    }
                }
                else
                {
                    // if (cType == typeof(JsonData))
                    // {
                    //     if (instance[i.Value] != null)
                    //     {
                    //         // target控制动画开始播放
                    //         this.fadeGroup.target = EditorGUILayout.Foldout(this.fadeGroup.target, name, true);
                    //
                    //         // 系统使用tween渐变faded数值
                    //         if (EditorGUILayout.BeginFadeGroup(this.fadeGroup.faded))
                    //         {
                    //             EditorGUILayout.TextArea(
                    //                 ((JsonData) instance[i.Value]).ToString()
                    //             );
                    //         }
                    //         // begin - end 之间元素会进行动画
                    //         EditorGUILayout.EndFadeGroup();
                    //
                    //         EditorGUILayout.Space();
                    //
                    //     }
                    //     else
                    //     {
                    //         EditorGUILayout.LabelField(name, "暂无值的JsonData");
                    //     }
                    //
                    //     continue;
                    // }

                    object obj = instance[i.Value];
                    if (typeof(UnityEngine.Object).IsAssignableFrom(cType))
                    {
                        //处理Unity类型
                        var res = EditorGUILayout.ObjectField(name, obj as UnityEngine.Object, cType, true);
                        instance[i.Value] = res;
                    }
                    else
                    {
                        //其他类型现在没法处理
                        if (obj != null)
                        {
                            EditorGUILayout.LabelField(name, obj.ToString());
                        }
                        else
                        {
                            EditorGUILayout.LabelField(name, "(null)");
                        }
                    }
                }
            }
        }

        // 应用属性修改
        this.serializedObject.ApplyModifiedProperties();
    }
示例#12
0
        private void Bind()
        {
            var cb = this;

            foreach (var _class in cb.ScriptsToBind)
            {
                //添加脚本
                string classType = $"{_class.Namespace + (_class.Namespace == "" ? "" : ".")}{_class.Class}";
                if (!InitILrt.appDomain.LoadedTypes.ContainsKey(classType))
                {
                    Log.PrintError($"{this.name}-自动绑定:{classType}不存在,已跳过");
                    continue;
                }

                IType type        = InitILrt.appDomain.LoadedTypes[classType];
                var   instance    = new ILTypeInstance(type as ILType, false);
                var   clrInstance = cb.gameObject.AddComponent <MonoBehaviourAdapter.Adaptor>();
                clrInstance.enabled    = false;
                clrInstance.ILInstance = instance;
                clrInstance.AppDomain  = InitILrt.appDomain;
                instance.CLRInstance   = clrInstance;

                //绑定数据
                if (_class.RequireBindFields)
                {
                    _class.BoundData = false;

                    //获取实际属性
                    Type t = type.ReflectionType;

                    foreach (var field in _class.Fields)
                    {
                        object obj = new object();
                        try
                        {
                            if (field.fieldType == _ClassField.FieldType.Short)
                            {
                                obj = int.Parse(field.value);
                                _class.BoundData = true;
                            }
                            else if (field.fieldType == _ClassField.FieldType.UShort)
                            {
                                obj = ushort.Parse(field.value);
                                _class.BoundData = true;
                            }
                            else if (field.fieldType == _ClassField.FieldType.Int)
                            {
                                obj = short.Parse(field.value);
                                _class.BoundData = true;
                            }
                            else if (field.fieldType == _ClassField.FieldType.UInt)
                            {
                                obj = uint.Parse(field.value);
                                _class.BoundData = true;
                            }
                            else if (field.fieldType == _ClassField.FieldType.Long)
                            {
                                obj = long.Parse(field.value);
                                _class.BoundData = true;
                            }
                            else if (field.fieldType == _ClassField.FieldType.ULong)
                            {
                                obj = ulong.Parse(field.value);
                                _class.BoundData = true;
                            }
                            else if (field.fieldType == _ClassField.FieldType.Float)
                            {
                                obj = float.Parse(field.value);
                                _class.BoundData = true;
                            }
                            else if (field.fieldType == _ClassField.FieldType.Decimal)
                            {
                                obj = decimal.Parse(field.value);
                                _class.BoundData = true;
                            }
                            else if (field.fieldType == _ClassField.FieldType.Double)
                            {
                                obj = Double.Parse(field.value);
                                _class.BoundData = true;
                            }
                            else if (field.fieldType == _ClassField.FieldType.String)
                            {
                                obj = field.value;
                                _class.BoundData = true;
                            }
                            else if (field.fieldType == _ClassField.FieldType.Bool)
                            {
                                obj = field.value == "true";
                                _class.BoundData = true;
                            }
                            else if (field.fieldType == _ClassField.FieldType.GameObject)
                            {
                                GameObject go = null;
                                try
                                {
                                    go = field.value == "${this}"
                                        ? this.gameObject
                                        : GameObject.Find(field.value);
                                    if (go == null)//找父物体
                                    {
                                        go = FindSubGameObject(field);
                                        if (go == null) //如果父物体还不存在
                                        {
                                            continue;
                                        }
                                    }
                                }
                                catch (Exception ex)//找父物体(如果抛出空异常)
                                {
                                    go = FindSubGameObject(field);
                                    if (go == null) //如果父物体还不存在
                                    {
                                        continue;
                                    }
                                }

                                obj = go;
                                _class.BoundData = true;
                            }
                            else if (field.fieldType == _ClassField.FieldType.UnityComponent)
                            {
                                GameObject go = null;
                                try
                                {
                                    go = field.value.Substring(0, 7) == "${this}"
                                        ? this.gameObject
                                        : GameObject.Find(field.value.Substring(0, field.value.LastIndexOf('.')));
                                    if (go == null)//找父物体
                                    {
                                        go = FindSubGameObjectForScript(field);
                                        if (go == null) //如果父物体还不存在
                                        {
                                            continue;
                                        }
                                    }
                                }
                                catch (Exception ex)//找父物体(如果抛出空异常)
                                {
                                    go = FindSubGameObjectForScript(field);
                                    if (go == null) //如果父物体还不存在
                                    {
                                        continue;
                                    }
                                }

                                foreach (var component in go.GetComponents <Component>())
                                {
                                    string scriptName = field.value.Substring(field.value.LastIndexOf('.'));
                                    if (component.GetType() == typeof(MonoBehaviourAdapter.Adaptor))
                                    {
                                        MonoBehaviourAdapter.Adaptor c = (MonoBehaviourAdapter.Adaptor)component;
                                        if (c.ILInstance.Type.ToString().Contains(scriptName))
                                        {
                                            obj = c.ILInstance;
                                            _class.BoundData = true;
                                            break;
                                        }
                                    }

                                    if (component.GetType().ToString().Contains(scriptName))
                                    {
                                        obj = component;
                                        _class.BoundData = true;
                                        break;
                                    }
                                }
                            }
                            else if (field.fieldType == _ClassField.FieldType.HotUpdateResource)
                            {
                                obj = Assets.LoadAsset(field.value, typeof(UnityEngine.Object)).asset;
                                _class.BoundData = true;
                            }
                        }
                        catch (Exception except)
                        {
                            Log.PrintError($"{this.name}-自动绑定:{classType}.{field.fieldName}获取值{field.value}出错:{except.Message},已跳过");
                        }

                        //如果有数据再绑定
                        if (_class.BoundData)
                        {
                            if (t.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance |
                                            BindingFlags.Static).Contains(t.GetField(field.fieldName,
                                                                                     BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance |
                                                                                     BindingFlags.Static)))
                            {
                                try
                                {
                                    t.GetField(field.fieldName,
                                               BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance |
                                               BindingFlags.Static).SetValue(clrInstance.ILInstance, obj);
                                }
                                catch (Exception e)
                                {
                                    Log.PrintError($"{this.name}-自动绑定:{classType}.{field.fieldName}赋值出错:{e.Message},已跳过");
                                }
                            }
                            else
                            {
                                Log.PrintError($"{this.name}-自动绑定:{classType}不存在{field.fieldName},已跳过");
                            }
                        }
                    }
                }

                //是否激活
                if (_class.ActiveAfter)
                {
                    if (_class.BoundData == false && _class.RequireBindFields)
                    {
                        Log.PrintError($"{this.name}-自动绑定:{classType}没有成功绑定数据,无法自动激活,请手动!");
                        continue;
                    }

                    clrInstance.enabled = true;
                    clrInstance.Awake();
                }

                Destroy(cb);
            }
        }