Пример #1
0
        private IEnumerator LoadGameScene()
        {
            OnMessage("正在初始化");
            Assets.runtimeMode = !development;
            var init = Assets.Initialize();

            yield return(init);

            if (string.IsNullOrEmpty(init.error))
            {
                Assets.AddSearchPath("Assets/HotUpdateResources/Controller");
                Assets.AddSearchPath("Assets/HotUpdateResources/Dll");
                Assets.AddSearchPath("Assets/HotUpdateResources/Material");
                Assets.AddSearchPath("Assets/HotUpdateResources/Other");
                Assets.AddSearchPath("Assets/HotUpdateResources/Prefab");
                Assets.AddSearchPath("Assets/HotUpdateResources/Scene");
                Assets.AddSearchPath("Assets/HotUpdateResources/ScriptableObject");
                Assets.AddSearchPath("Assets/HotUpdateResources/TextAsset");
                Assets.AddSearchPath("Assets/HotUpdateResources/UI");
                init.Release();

                OnProgress(0);
                OnMessage("加载游戏场景");

                var scene = Assets.LoadSceneAsync(gameScene, false);
                scene.completed += (AssetRequest request) =>
                {
                    FindObjectOfType <Init>().Load();
                    ClassBindMgr.Instantiate();
                    FindObjectOfType <Init>().OnHotFixLoaded();
                };
                while (!scene.isDone)
                {
                    OnProgress(scene.progress);
                    yield return(null);
                }
            }
            else
            {
                init.Release();
                var mb = MessageBox.Show("提示", "初始化异常错误:" + init.error + "请联系技术支持");
                yield return(mb);

                Quit();
            }
        }
Пример #2
0
    private void Awake()
    {
        if (Instance != null)
        {
            Destroy(Instance.gameObject);
        }

        Instance = this;
        DontDestroyOnLoad(gameObject);

        GameStats.Initialize();
        GameStats.Debug   = debug;
        AssetMgr.Loggable = debug;

        Updater.OnAssetsInitialized = (gameScene, onProgress) =>
        {
            Assets.AddSearchPath("Assets/HotUpdateResources/Controller");
            Assets.AddSearchPath("Assets/HotUpdateResources/Dll");
            Assets.AddSearchPath("Assets/HotUpdateResources/Material");
            Assets.AddSearchPath("Assets/HotUpdateResources/Other");
            Assets.AddSearchPath("Assets/HotUpdateResources/Prefab");
            Assets.AddSearchPath("Assets/HotUpdateResources/Scene");
            Assets.AddSearchPath("Assets/HotUpdateResources/ScriptableObject");
            Assets.AddSearchPath("Assets/HotUpdateResources/TextAsset");
            Assets.AddSearchPath("Assets/HotUpdateResources/UI");

            AssetMgr.LoadSceneAsync(gameScene, false, onProgress, (b) =>
            {
                if (!b)
                {
                    return;
                }
                Instance.Load();
                ClassBindMgr.Instantiate();
                Instance.OnHotFixLoaded();
            });
        };
    }
Пример #3
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();
    }