Esempio n. 1
0
    /// <summary>
    /// 初始化ILR,可主动调用
    /// </summary>
    public void ILRObjInit()
    {
        if (ilinstance == null && !string.IsNullOrEmpty(hotfixClassPath))
        {
#if ILRuntime
            ilinstance = HotfixILRManager.GetInstance().appdomain.Instantiate <UIControllerILRObject>(hotfixClassPath);
#else
            var type = HotfixILRManager.GetInstance().assembly.GetType(hotfixClassPath);
            ilinstance = System.Activator.CreateInstance(type) as UIControllerILRObject;
#endif

            ilinstance.SetUIController(this);

            BindingParam();

            base.Awake();
            if (ilinstance != null)
            {
                ilinstance.Awake();

                if (IsFixShader)
                {
                    //修正Shader
                    GM.AssetUtils.FixShaderInEditor(this);
                }
            }
        }
    }
Esempio n. 2
0
    public static void AutoBinding()
    {
#if !ILRuntime
        UIControllerILR current = UnityEditor.Selection.activeGameObject.GetComponent <UIControllerILR>();

        UIControllerILRObject instance = current.ilinstance;
        bool release = false;
        if (!string.IsNullOrEmpty(current.hotfixClassPath))
        {
            var type = HotfixILRManager.GetInstance().assembly.GetType(current.hotfixClassPath);
            if (instance == null)
            {
                instance = System.Activator.CreateInstance(type) as UIControllerILRObject;
                release  = true;
            }

            FieldInfo[] fields = type.GetFields();
            TextAsset   script = AssetDatabase.LoadAssetAtPath <TextAsset>(string.Concat("Assets/", current.FilePath));
            if (script == null || script.text == String.Empty)
            {
                Debug.LogError("Could not read text by " + string.Concat("Assets/", current.FilePath));
                return;
            }

            string[] rows      = script.text.Split(new string[] { "\n" }, StringSplitOptions.None);
            string   targetRow = string.Empty;

            foreach (FieldInfo f in fields)
            {
                System.Type fieldType = f.FieldType;
                Debug.LogFormat("field.Name = {0},field.Type.Name = {1}", f.Name, fieldType.Name);
                UIControllerILR.ParmType fieldEnumType;
                if (System.Enum.TryParse(fieldType.Name, out fieldEnumType))
                {
                    if (!current.ParmPathList.Exists(p => p.Name == f.Name))
                    {
                        UIControllerILR.ParmStruct structural = new UIControllerILR.ParmStruct();
                        structural.Name = f.Name;
                        structural.Type = fieldEnumType;

                        for (int i = 0; i < rows.Length; i++)
                        {
                            string row = rows[i];
                            if (row.Contains(f.Name + " = t.") || row.Contains(f.Name + " = controller.transform."))
                            {
                                targetRow = row;
                                break;
                            }
                        }
                        if (string.IsNullOrEmpty(targetRow))
                        {
                            Debug.Log("<color=yellow>this filed has not found or got by awake method!</color>"); continue;
                        }

                        string[] parts = targetRow.TrimAll('"').Split('(');
                        if (parts.Length > 1)
                        {
                            string text = parts[1].TrimAll('(', ')', ';', '.').Replace("gameObject", String.Empty).TrimEnd();
                            if (!string.IsNullOrEmpty(text))
                            {
                                structural.Path = text.Replace(String.Format("GetComponent<{0}>", structural.Type.ToString()), "");
                            }
                            Debug.LogFormat("Create ParmStruct: <color=purple>Name = {0},Type = {1},Path = {2}</color>", structural.Name, structural.Type, structural.Path);
                        }

                        current.ParmPathList.Add(structural);
                        EditorUtility.SetDirty(current);
                    }
                }
                else
                {
                    Debug.Log("<color=red>field type is not feasible!</color>");
                }
            }
        }

        if (release)
        {
            instance = null;
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
#else
        EB.Debug.LogError("ILR模式下不存在assembly,会报错!请自行解决后再去掉这个宏。");
#endif
    }