예제 #1
0
        private static void refreshData()
        {
            mConfig = XConfig.GetConfig <TSConfig>(TSConst.ConfigPath_Resources, AssetLoadType.Resources, false);



            mDataRefreshed = true;
        }
예제 #2
0
        private static void refreshData()
        {
            mConfig = XConfig.GetConfig <I18NConfig>(I18NConst.ConfigPath_Resources, AssetLoadType.Resources, false);
            if (mConfig != null)
            {
                mConfig_SerObj = new SerializedObject(mConfig);
            }

            mDataRefreshed = true;
        }
예제 #3
0
        /*
         * 启动顺序:
         * - 注册CLR重定向
         * - 注册委托适配器
         * - 注册跨域适配器
         * - 注册CLR绑定
         * - 加载Assembly和它的小伙伴们
         *
         */
        public async Task <XException> StartAsync()
        {
            if (m_Inited)
            {
                return(null);
            }
            m_Config = XConfig.GetConfig <XILRTConfig>(XILConst.ConfigPath_Resources);
            if (m_Config == null)
            {
                return(new XILRTException("Config file not found :" + XILConst.ConfigPath_Resources));
            }

            if (!m_Config.Enable)
            {
                return(null);
            }

            //注册CLR重定向
            registerCLRMethodRedirections();

            //注册委托适配器
            registerDelegates();

            //注册跨域适配器
            registerCrossBindingAdaptors();

            //注册CLR绑定
            registerGeneratorCLRBindingCode();

            //加载Assemblies
            var e_load = await this.loadAssemblies(m_Config.LoadAssemblies);

            if (e_load != null)
            {
                return(e_load);
            }


            m_Inited = true;
            return(null);
        }
예제 #4
0
    static void CopyDLL()
    {
        var config = XConfig.GetConfig <XILRTConfig>(XILConst.ConfigPath_Resources);

        if (config == null)
        {
            Debug.LogError("Config file not found :" + XILConst.ConfigPath_Resources);
            return;
        }

        var dll = System.Environment.CurrentDirectory + "/" + config.LoadAssemblies[0].AssemblyPath;
        var pdb = System.Environment.CurrentDirectory + "/" + config.LoadAssemblies[0].SymbolPath;

        var srcDll = System.Environment.CurrentDirectory + "/Library/ScriptAssemblies/GameBrick.dll";
        var srcPdb = System.Environment.CurrentDirectory + "/Library/ScriptAssemblies/GameBrick.pdb";

        System.IO.File.Copy(srcDll, dll, true);
        System.IO.File.Copy(srcPdb, pdb, true);

        Debug.Log("GameScript DLL updated.");
    }
예제 #5
0
        public static void RefreshConfig()
        {
            refresh = true;
            if (Config == null)
            {
                Config = XConfig.GetConfig <UIConfig>(UIConst.ConfigPath_Resources, AssetLoadType.Resources, false);
            }
            if (Config == null)
            {
                return;
            }

            ui_folders.Clear();
            if (Config.UI_Image_Folders == null)
            {
                return;
            }
            foreach (var item in Config.UI_Image_Folders)
            {
                if (!item.Path.StartsWith("Assets/"))
                {
                    continue;
                }

                string path = item.Path;
                if (!path.EndsWith("/"))
                {
                    path = path + "/";
                }
                if (!ui_folders.Any(i => i.Path == path))
                {
                    ui_folders.Add(new UIConfig.UIFolderItem()
                    {
                        Path = path, Atlas = item.Atlas
                    });
                }
            }
        }
예제 #6
0
        public static void Build(bool isDebug)
        {
            var assemblyName = "GameBrick";
            var workDir      = Directory.GetParent(Application.dataPath).ToString();
            var projPath     = Path.Combine(workDir, assemblyName + ".csproj");

            var dllList = FindDllFromCsProj(workDir, projPath);

            foreach (var dll in dllList)
            {
                Debug.LogWarning(dll);
            }
            Debug.LogError(dllList.Count);

            var csList = FindCsharpFromCsProj(workDir, projPath);

            foreach (var cs in csList)
            {
                Debug.LogWarning(cs);
            }
            Debug.LogError(csList.Count);


            var config = XConfig.GetConfig <XILRTConfig>(XILConst.ConfigPath_Resources);

            if (config == null)
            {
                Debug.LogError("Config file not found :" + XILConst.ConfigPath_Resources);
                return;
            }

            var dllPath = workDir + "/" + config.LoadAssemblies[0].AssemblyPath;
            var pdbPath = workDir + "/" + config.LoadAssemblies[0].SymbolPath;

            BuildingGameDllWithRoslyn(assemblyName, dllPath, pdbPath,
                                      csList, dllList, isDebug);
        }
예제 #7
0
        public static void RefreshManager(bool Normalization = false)
        {
            mConfig = XConfig.GetConfig <VFSConfigModel>(VFSConst.ConfigFilePath_Resources);
            if (mConfig == null)
            {
                return;
            }
            if (Normalization)
            {
                VFSUtil.NormalizationConfig(mConfig);
            }

            if (!VFSUtil.CheckConfiguration(mConfig, out var errorCode, out var folderError))
            {
                string log_str = string.Empty;
                //配置文件校验未通过
                switch (errorCode)
                {
                case VFSErrorCode.ConfigureGroupsConflict:
                    //资源组规则未通过,log提示出来
                    log_str = VFSManagerEditorI18N.Log_ConfigureGroupsConflict;
                    if (folderError != null && folderError.Length > 0)
                    {
                        foreach (var f in folderError)
                        {
                            log_str += $"\nGroup [{f.GroupName}] , FolderPath: {f.FolderPath}";
                        }
                    }
                    Debug.LogError(log_str);
                    return;     //直接不继续往下执行了

                case VFSErrorCode.NoneGroup:
                    //没有配置任何资源组
                    //这个问题不报Error
                    return;

                case VFSErrorCode.SameGroupName:
                    log_str = VFSManagerEditorI18N.Log_SameGroupName;
                    Debug.LogError(log_str);
                    return;
                }
            }

            Groups.Clear();
            if (!mConfig.EnableVFS)
            {
                return;
            }

            //VFS Profile
            XDirectory.CreateIfNotExists(XEditorConst.EditorProjectSettingRootFolder);
            var profile_path = Path.Combine(XEditorConst.EditorProjectSettingRootFolder, VFSEditorConst.VFSProfileProjectSettingFileName);

            if (File.Exists(profile_path))
            {
                //load
                VFSProfileEditor = XConfig.GetJson <VFSProfileModel>(profile_path, AssetLoadType.SystemIO, false);
            }
            else
            {
                //create profile editor file in "ProjectSetting"
                initProfileRecord();
                //var json_text = JsonUtility.ToJson(VFSProfileEditor);
                XConfig.SaveJson(VFSProfileEditor, profile_path, AssetLoadType.SystemIO);
            }

            foreach (var group_opt in mConfig.Groups)
            {
                var _group_obj = new VFSEditorGroup(group_opt);
                Groups.Add(_group_obj);
                FolderPaths.AddRange(_group_obj.FolderPaths);
                foreach (var assetPath in _group_obj.AssetPaths)
                {
                    if (!AssetPaths.Contains(assetPath))
                    {
                        AssetPaths.Add(assetPath);
                    }
                }
            }

            LastRefreshManagerTime = System.DateTime.UtcNow;
        }
예제 #8
0
        public async Task <bool> Start()
        {
            if (mInited)
            {
                return(true);
            }
            mConfig = XConfig.GetConfig <I18NConfig>(I18NConst.ConfigPath_Resources, AssetLoadType.Resources);
            if (mConfig == null)
            {
                mStartException = new XException("[TinaX.I18N]Load I18N config file failed. please cheak in ProjectSettings window.");
                return(false);
            }
            if (!mConfig.EnableI18N)
            {
                return(true);
            }
            if (mAssets == null)
            {
                mStartException = new XException("[TinaX.I18N]No service implements the built-in asset loading interface in Framework");
                return(false);
            }

            if (mConfig.Regions != null && mConfig.Regions.Count > 0)
            {
                bool    check_default       = !mConfig.DefaultRegion.IsNullOrEmpty();
                string  default_region_name = check_default ? mConfig.DefaultRegion.ToLower() : string.Empty;
                XRegion _default_region     = null;
                foreach (var item in mConfig.Regions)
                {
                    if (item.Name.IsNullOrEmpty())
                    {
                        continue;
                    }

                    bool _flag_1 = false;
                    if (check_default && _default_region == null)
                    {
                        if (item.Name.ToLower().Equals(default_region_name))
                        {
                            _default_region = item;
                            _flag_1         = true;
                        }
                    }

                    if (mConfig.AutomaticMatchingBySystemLanaguage)
                    {
                        bool flag_2 = false;
                        if (item.BindLanguage != null && item.BindLanguage.Count > 0)
                        {
                            foreach (var lang in item.BindLanguage)
                            {
                                if (lang == Application.systemLanguage)
                                {
                                    flag_2          = true;
                                    _default_region = item;
                                    break;
                                }
                            }
                        }
                        if (flag_2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (_flag_1)
                        {
                            break;
                        }
                    }
                }
                if (_default_region != null)
                {
                    try
                    {
                        await this.useRegion(_default_region);
                    }
                    catch (XException e)
                    {
                        mStartException = e;
                        return(false);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }

            //Debug code
            //foreach(var item in mDicts)
            //{
            //    item.Key.LogConsole();
            //    foreach(var kv in item.Value)
            //    {
            //        ("    " + kv.Key + "  |  " + kv.Value).LogConsole();
            //    }
            //}

            mInited = true;
            return(true);
        }
예제 #9
0
        public async Task <bool> Start()
        {
            if (mInited)
            {
                return(true);
            }
            mConfig = XConfig.GetConfig <LuaConfig>(LuaConst.ConfigPath_Resources);
            if (mConfig == null)
            {
                mStartException = new XException("[TinaX.ILRuntime] Connot found config file.");;
                return(false);
            }
            if (!mConfig.EnableLua)
            {
                return(true);
            }

            mInternal_Lua_Folder_Load_Path = mConfig.FrameworkInternalLuaFolderLoadPath;
            if (!mInternal_Lua_Folder_Load_Path.IsNullOrEmpty())
            {
                if (mInternal_Lua_Folder_Load_Path.EndsWith("/"))
                {
                    mInternal_Lua_Folder_Load_Path = mInternal_Lua_Folder_Load_Path.Substring(0, mInternal_Lua_Folder_Load_Path.Length - 1);
                }
                mInternal_Lua_Folder_Load_Path_withSlash = mInternal_Lua_Folder_Load_Path + "/";
            }
            mLuaExtension = mConfig.LuaFileExtensionName;
            if (!mLuaExtension.StartsWith("."))
            {
                mLuaExtension = "." + mLuaExtension;
            }

            if (!XCore.MainInstance.TryGetBuiltinService(out Assets))
            {
                mStartException = new XException("[TinaX.ILRuntime]" + (IsChinese? "没有任何服务实现了Framework中的内置的资产加载接口": "No service implements the built-in asset loading interface in Framework"));
                return(false);
            }

            mLoader = LoadLuaFiles;
            mLuaVM.AddLoader(mLoader);

            try
            {
                await InitInternalEntry();
            }
            catch (XException e)
            {
                mStartException = e;
                return(false);
            }

            //准备好入口文件
            if (!mConfig.EntryLuaFileLoadPath.IsNullOrEmpty())
            {
                try
                {
                    TextAsset entry_ta = await Assets.LoadAsync <TextAsset>(mConfig.EntryLuaFileLoadPath);

                    mEntryFunc = mLuaVM.LoadString <LuaFunction>(entry_ta.bytes, mConfig.EntryLuaFileLoadPath);
                    Assets.Release(entry_ta);
                }
                catch (XException e)
                {
                    mStartException = e;
                    return(false);
                }
            }

            if (mUpdateTicket != null)
            {
                mUpdateTicket.Unregister();
            }
            mUpdateTicket = TimeMachine.RegisterUpdate(OnUpdate);

            await Task.Yield();

            mInited = true;
            return(true);
        }
예제 #10
0
        public static void RefreshData()
        {
            cache.Config = XConfig.GetConfig <I18NConfig>(I18NConst.ConfigPath_Resources, AssetLoadType.Resources, false);
            if (cache.Config == null)
            {
                return;
            }

            cache.RegionNames.Clear();
            if (cache.Config.Regions != null && cache.Config.Regions.Count > 0)
            {
                foreach (var item in cache.Config.Regions)
                {
                    cache.RegionNames.Add(item.Name);
                }

                if (!cache.Editor_CurRegion.IsNullOrEmpty())
                {
                    if (!cache.Config.Regions.Any(r => r.Name.ToLower() == cache.Editor_CurRegion.ToLower()))
                    {
                        cache.Editor_CurRegion = string.Empty;
                    }
                }

                if (cache.Editor_CurRegion.IsNullOrEmpty())
                {
                    //检查config里的default
                    if (!cache.Config.DefaultRegion.IsNullOrEmpty())
                    {
                        var regions = cache.Config.Regions.Where(r => r.Name.ToLower() == cache.Config.DefaultRegion.ToLower());
                        if (regions.Count() > 0)
                        {
                            cache.Editor_CurRegion = regions.First().Name;
                        }
                    }

                    if (cache.Editor_CurRegion.IsNullOrEmpty())
                    {
                        foreach (var item in cache.Config.Regions)
                        {
                            if (item.BindLanguage == null || item.BindLanguage.Count == 0)
                            {
                                continue;
                            }

                            bool flag = false;
                            foreach (var lang in item.BindLanguage)
                            {
                                if (lang == Application.systemLanguage)
                                {
                                    flag = true;
                                    cache.Editor_CurRegion = item.Name;
                                    break;
                                }
                            }
                            if (flag)
                            {
                                break;
                            }
                        }
                    }

                    if (cache.Editor_CurRegion.IsNullOrEmpty())
                    {
                        cache.Editor_CurRegion = cache.Config.Regions.First().Name;
                    }
                }

                //--------------
                if (!cache.Editor_CurRegion.IsNullOrEmpty())
                {
                    RefreshDataByRegionName(cache.Editor_CurRegion);
                }
            }
        }
예제 #11
0
        public static void RefreshDataByRegionName(string regionName)
        {
            if (cache.Config == null)
            {
                cache.Config = XConfig.GetConfig <I18NConfig>(I18NConst.ConfigPath_Resources, AssetLoadType.Resources, false);
            }
            if (cache.Config == null)
            {
                return;
            }
            if (cache.Config.Regions == null || cache.Config.Regions.Count == 0)
            {
                return;
            }

            var regions = cache.Config.Regions.Where(r => r.Name.ToLower() == regionName.ToLower());

            if (regions.Count() == 0)
            {
                return;
            }

            cache.mDicts.Clear();
            var region = regions.First();

            if (region.JsonDicts != null && region.JsonDicts.Count > 0)
            {
                foreach (var item in region.JsonDicts)
                {
                    if (item.EditorLoadPath.IsNullOrEmpty() || item.LoadPath.IsNullOrEmpty())
                    {
                        continue;
                    }
                    var ta = AssetDatabase.LoadAssetAtPath <TextAsset>(item.EditorLoadPath);
                    if (ta == null)
                    {
                        continue;
                    }
                    if (ta.text.IsNullOrEmpty())
                    {
                        continue;
                    }
                    try
                    {
                        var json_obj = JsonUtility.FromJson <I18NTable>(ta.text);
                        if (json_obj != null && json_obj.data != null && json_obj.data.Count > 0)
                        {
                            string groupName = item.GroupName;
                            if (groupName.IsNullOrEmpty())
                            {
                                groupName = I18NConst.DefaultGroupName;
                            }
                            foreach (var kv in json_obj.data)
                            {
                                if (!cache.mDicts.ContainsKey(groupName))
                                {
                                    cache.mDicts.Add(groupName, new Dictionary <string, string>());
                                }
                                if (!cache.mDicts[groupName].ContainsKey(kv.k))
                                {
                                    if (item.Base64Value)
                                    {
                                        try
                                        {
                                            string _value = kv.v.DecodeBase64();
                                            cache.mDicts[groupName].Add(kv.k, _value);
                                        }
                                        catch
                                        {
                                            Debug.LogError($"[TinaX.I18N] Decode base64 error: Json: {item.EditorLoadPath}   | Key: {kv.k}");
                                        }
                                    }
                                    else
                                    {
                                        cache.mDicts[groupName].Add(kv.k, kv.v);
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
            }

            if (region.AssetDicts != null && region.AssetDicts.Count > 0)
            {
                foreach (var item in region.AssetDicts)
                {
                    if (item.Asset == null || item.Asset.data == null || item.Asset.data.Count == 0)
                    {
                        continue;
                    }
                    string groupName = item.GroupName;
                    if (groupName.IsNullOrEmpty())
                    {
                        groupName = I18NConst.DefaultGroupName;
                    }
                    foreach (var kv in item.Asset.data)
                    {
                        if (!cache.mDicts.ContainsKey(groupName))
                        {
                            cache.mDicts.Add(groupName, new Dictionary <string, string>());
                        }
                        if (!cache.mDicts[groupName].ContainsKey(kv.k))
                        {
                            cache.mDicts[groupName].Add(kv.k, kv.v);
                        }
                    }
                }
            }

            cache.Editor_CurRegion = region.Name;

            // Debug used.
            //foreach(var item in cache.mDicts)
            //{
            //    item.Key.LogConsole();
            //    foreach(var kv in item.Value)
            //    {
            //        ($"    {kv.Key} | {kv.Value}").LogConsole();
            //    }
            //}
        }
예제 #12
0
        public async Task <XException> Start()
        {
            if (m_Inited)
            {
                return(null);
            }
            m_Config = XConfig.GetConfig <TSConfig>(TSConst.ConfigPath_Resources);
            if (m_Config == null)
            {
                return(new XException($"[{TSConst.ServiceName}] Connot found config file."));
            }

            if (!m_Config.Enable)
            {
                return(null);
            }

            //框架内部Js文件加载路径
            m_Internal_Js_Folder_Load_Path = m_Config.FrameworkInternalJsFolderLoadPath;
            if (!m_Internal_Js_Folder_Load_Path.IsNullOrEmpty())
            {
                if (m_Internal_Js_Folder_Load_Path.EndsWith("/"))
                {
                    m_Internal_Js_Folder_Load_Path = m_Internal_Js_Folder_Load_Path.Substring(0, m_Internal_Js_Folder_Load_Path.Length - 1);
                }
                m_Internal_Js_Folder_Load_Path_withSlash = m_Internal_Js_Folder_Load_Path + "/";
            }
            //Js文件加载名称
            m_JsExtension = m_Config.JsFileExtensionName;
            if (!m_JsExtension.StartsWith("."))
            {
                m_JsExtension = "." + m_JsExtension;
            }

            if (m_Assets == null)
            {
                return(new XException($"[{TSConst.ServiceName}]" + (m_Core.IsCmnHans() ? "没有任何服务实现了Framework中的内置的资产加载接口" : "No service implements the built-in asset loading interface in Framework")));
            }

            //初始化Js的运行环境
            m_JsEnv = new JsEnv(new XTSLoader(m_Assets, c_InternalJsSign, c_Internal_Js_Extension, m_Internal_Js_Folder_Load_Path, m_JsExtension));

            //try
            //{
            //    await InitInternalEntry();
            //}
            //catch(XException e)
            //{
            //    return e;
            //}

            //准备好入口文件
            if (!m_Config.EntryJsFileLoadPath.IsNullOrEmpty())
            {
                try
                {
                    TextAsset entry_ta = await m_Assets.LoadAsync <TextAsset>(m_Config.EntryJsFileLoadPath);

                    m_EntryCodeContent = entry_ta.text;
                    //m_EntryFunc = m_JsEnv.LoadString<LuaFunction>(entry_ta.bytes, m_Config.EntryLuaFileLoadPath);
                    m_Assets.Release(entry_ta);
                }
                catch (XException e)
                {
                    return(e);
                }
            }

            if (m_UpdateTicket != null)
            {
                m_UpdateTicket.Unregister();
            }
            m_UpdateTicket = TimeMachine.RegisterUpdate(OnUpdate);

            m_Inited = true;
            return(null);
        }
        public static void GenCodeByTypes()
        {
            var config = XConfig.GetConfig <TinaX.XILRuntime.Internal.XILRTConfig>(XILConst.ConfigPath_Resources);

            if (config == null)
            {
                Debug.LogError($"[{XILConst.ServiceName}] Generate CLRBinding code failed: config file not found.");
                return;
            }
            string output_path = config.EditorCLRBindingCodeOutputPath;

            if (!output_path.StartsWith("Assets/"))
            {
                Debug.LogError($"[{XILConst.ServiceName}]Generate failed: Output folder path is invalid :" + output_path);
                return;
            }

            List <Type>          gen_types           = new List <Type>(s_InternalDefineTypes);
            HashSet <MethodBase> gen_exclude_methods = new HashSet <MethodBase>(s_InternalExcludeMethods);
            HashSet <FieldInfo>  gen_exclude_fields  = new HashSet <FieldInfo>(s_InternalExcludeFields);
            List <Type>          gen_valueTypes      = new List <Type>(s_InternalValueTypes);
            List <Type>          gen_delegates       = new List <Type>(s_InternalDelegateTypes);


            Type t_define = typeof(ICLRGenerateDefine);
            var  types    = AppDomain.CurrentDomain.GetAssemblies()
                            .SelectMany(a => a.GetTypes().Where(t => t.GetInterfaces().Contains(t_define)))
                            .ToArray();

            if (types.Length > 0)
            {
                foreach (var type in types)
                {
                    ICLRGenerateDefine define_obj = (ICLRGenerateDefine)Activator.CreateInstance(type);
                    var _types = define_obj.GetCLRBindingTypes();
                    if (_types != null && _types.Count > 0)
                    {
                        foreach (var __type in _types)
                        {
                            if (!gen_types.Contains(__type))
                            {
                                gen_types.Add(__type);
                            }
                        }
                    }

                    var _exclude_methods = define_obj.GetCLRBindingExcludeMethods();
                    if (_exclude_methods != null && _exclude_methods.Count > 0)
                    {
                        foreach (var __method in _exclude_methods)
                        {
                            if (!gen_exclude_methods.Contains(__method))
                            {
                                gen_exclude_methods.Add(__method);
                            }
                        }
                    }

                    var _exclude_fields = define_obj.GetCLRBindingExcludeFields();
                    if (_exclude_fields != null && _exclude_fields.Count > 0)
                    {
                        foreach (var __field in _exclude_fields)
                        {
                            if (!gen_exclude_fields.Contains(__field))
                            {
                                gen_exclude_fields.Add(__field);
                            }
                        }
                    }

                    var _valueTypes = define_obj.GetValueTypeBinders();
                    if (_valueTypes != null && _valueTypes.Count > 0)
                    {
                        foreach (var __valueType in _valueTypes)
                        {
                            if (!gen_valueTypes.Contains(__valueType))
                            {
                                gen_valueTypes.Add(__valueType);
                            }
                        }
                    }

                    var _delegates = define_obj.GetDelegateTypes();
                    if (_delegates != null && _delegates.Count > 0)
                    {
                        foreach (var __delegate in _delegates)
                        {
                            if (!gen_delegates.Contains(__delegate))
                            {
                                gen_delegates.Add(__delegate);
                            }
                        }
                    }
                }
            }


            BindingCodeGenerator.GenerateBindingCode(gen_types, output_path, gen_exclude_methods, gen_exclude_fields, gen_valueTypes, gen_delegates);
            Debug.Log($"<color=#{TinaX.Internal.XEditorColorDefine.Color_Safe_16}>Generate code finish.</color>");
            AssetDatabase.Refresh();
        }
        public static void GenCodeByAssemblies()
        {
            var config = XConfig.GetConfig <TinaX.XILRuntime.Internal.XILRTConfig>(XILConst.ConfigPath_Resources);

            if (config == null)
            {
                Debug.LogError($"[{XILConst.ServiceName}] Generate CLRBinding code failed: config file not found.");
                return;
            }
            string output_path = config.EditorCLRBindingCodeOutputPath;

            if (!output_path.StartsWith("Assets/"))
            {
                Debug.LogError($"[{XILConst.ServiceName}]Generate failed: Output folder path is invalid :" + output_path);
                return;
            }

            ILAppDomain     domain   = new ILAppDomain();
            DisposableGroup disGroup = new DisposableGroup();

            foreach (var path in config.EditorLoadAssemblyPaths)
            {
                if (!path.AssemblyPath.IsNullOrEmpty())
                {
                    var fs = new FileStream(path.AssemblyPath, FileMode.Open, FileAccess.Read);
                    disGroup.Register(fs);
                    domain.LoadAssembly(fs);
                }
            }

            List <Type> gen_valueTypes = new List <Type>(s_InternalValueTypes);
            List <Type> gen_delegates  = new List <Type>(s_InternalDelegateTypes);

            Type t_define = typeof(ICLRGenerateDefine);
            var  types    = AppDomain.CurrentDomain.GetAssemblies()
                            .SelectMany(a => a.GetTypes().Where(t => t.GetInterfaces().Contains(t_define)))
                            .ToArray();

            if (types.Length > 0)
            {
                foreach (var type in types)
                {
                    ICLRGenerateDefine define_obj = (ICLRGenerateDefine)Activator.CreateInstance(type);
                    define_obj.GenerateByAssemblies_InitILRuntime(domain);

                    var _valueTypes = define_obj.GetValueTypeBinders();
                    if (_valueTypes != null && _valueTypes.Count > 0)
                    {
                        foreach (var __valueType in _valueTypes)
                        {
                            if (!gen_valueTypes.Contains(__valueType))
                            {
                                gen_valueTypes.Add(__valueType);
                            }
                        }
                    }

                    var _delegates = define_obj.GetDelegateTypes();
                    if (_delegates != null && _delegates.Count > 0)
                    {
                        foreach (var __delegate in _delegates)
                        {
                            if (!gen_delegates.Contains(__delegate))
                            {
                                gen_delegates.Add(__delegate);
                            }
                        }
                    }
                }
            }


            Internal_HandleBeforeGenCodeByAssemblies(domain);
            BindingCodeGenerator.GenerateBindingCode(domain, output_path, gen_valueTypes, gen_delegates);
            disGroup.Dispose();
            Debug.Log($"<color=#{TinaX.Internal.XEditorColorDefine.Color_Safe_16}>Generate code finish.</color>");
            AssetDatabase.Refresh();
        }
예제 #15
0
        public async Task <XException> Start()
        {
            #region config
            if (mInited)
            {
                return(null);
            }
            mConfig = XConfig.GetConfig <UIConfig>(UIConst.ConfigPath_Resources);
            if (mConfig == null)
            {
                return(new XException("[TinaX.UIKit] Connot found config file."));
            }

            if (!mConfig.EnableUIKit)
            {
                return(null);
            }

            if (mConfig.UINameMode == UINameMode.UIGroup)
            {
                mCurUIGroup = mConfig.DefaultUIGroup;
            }
            else
            {
                mUIRootDirLoadPath = mConfig.UIRootDirectoryLoadPath;
                if (!mUIRootDirLoadPath.IsNullOrEmpty())
                {
                    if (mUIRootDirLoadPath.EndsWith("/"))
                    {
                        mUIRootDirLoadPath = mUIRootDirLoadPath.Substring(0, mUIRootDirLoadPath.Length - 1);
                    }
                    mUIRootDirLoadPath_withSlash = mUIRootDirLoadPath + "/";
                }
            }
            mUINameMode = mConfig.UINameMode;

            #endregion


            //Init UIKit GameObjects
            #region UIKit GameObjects
            mUIKit_Root_Go = XCore.GetMainInstance().BaseGameObject
                             .FindOrCreateGameObject("UIKit")
                             .SetPosition(new Vector3(-9999, -9999, -9999));

            if (mConfig.UseUICamera)
            {
                var camera_config = mConfig.UICameraConfig;
                if (camera_config == null)
                {
                    camera_config = new UICameraConfig();
                }

                mScreenUICamera = mUIKit_Root_Go.FindOrCreateGameObject("UICamera")
                                  .AddComponent <Camera>();
                mScreenUICamera.clearFlags          = camera_config.clearFlags;
                mScreenUICamera.backgroundColor     = camera_config.backgroundColor;
                mScreenUICamera.cullingMask         = camera_config.cullingMask;
                mScreenUICamera.orthographic        = camera_config.orthographic;
                mScreenUICamera.orthographicSize    = camera_config.orthographicSize;
                mScreenUICamera.nearClipPlane       = camera_config.nearClipPlane;
                mScreenUICamera.farClipPlane        = camera_config.farClipPlane;
                mScreenUICamera.depth               = camera_config.depth;
                mScreenUICamera.renderingPath       = camera_config.renderingPath;
                mScreenUICamera.targetTexture       = camera_config.targetTexture;
                mScreenUICamera.useOcclusionCulling = camera_config.useOcclusionCulling;
                mScreenUICamera.allowHDR            = camera_config.allowHDR;
                mScreenUICamera.allowMSAA           = camera_config.allowMSAA;
            }

            //Default UIRoot
            refreshUIRoot(0);

            //EventSystem
#if ENABLE_LEGACY_INPUT_MANAGER
            if (mConfig.AutoCreateEventSystem)
            {
                var es_go        = GameObjectHelper.FindOrCreateGameObject("EventSystem");
                var event_system = es_go.GetComponentOrAdd <UnityEngine.EventSystems.EventSystem>();
                event_system.sendNavigationEvents = true;
                event_system.pixelDragThreshold   = 10;
                var input_module = es_go.GetComponentOrAdd <UnityEngine.EventSystems.StandaloneInputModule>();
            }
#endif

            #endregion

            await Task.Yield();

            return(null);
        }
예제 #16
0
        public async Task <bool> Start()
        {
            if (mInited)
            {
                return(true);
            }
            mConfig = XConfig.GetConfig <XRuntimeConfig>(XRuntimeConst.ConfigPath_Resources, AssetLoadType.Resources, false);
            if (mConfig == null)
            {
                mStartException = new XRTException("[TinaX.ILRuntime] Connot found config file.", XRuntimeErrorCode.ConfigFileInvalid);;
                return(false);
            }

            #region config
            if (!mConfig.EnableILRuntime)
            {
                return(true);
            }

            if (mConfig.EntryMethod.IsNullOrEmpty())
            {
                mStartException = new XRTException("[TinaX.ILRuntime] Entry method is empty", XRuntimeErrorCode.InvalidEntryMethod);
                return(false);
            }
            int _method_last_index = mConfig.EntryMethod.LastIndexOf('.');
            if (_method_last_index <= 0)
            {
                mStartException = new XRTException("[TinaX.ILRuntime] Entry method is invalid:" + mConfig.EntryMethod, XRuntimeErrorCode.InvalidEntryMethod);
                return(false);
            }
            mEntryMethod_Type   = mConfig.EntryMethod.Substring(0, _method_last_index);
            mEntryMethod_Method = mConfig.EntryMethod.Substring(_method_last_index + 1, mConfig.EntryMethod.Length - _method_last_index - 1);

            #endregion

            bool success = await TryInitILAppDomain();

            if (success)
            {
                registerCLR();

                //cli binding
                string type_name   = "ILRuntime.Runtime.Generated.CLRBindings";
                string method_name = "Initialize";
                var    assemblys   = AppDomain.CurrentDomain.GetAssemblies();
                Type   type        = null;
                foreach (var asm in assemblys)
                {
                    type = asm.GetType(type_name);
                    if (type != null)
                    {
                        break;
                    }
                }
                if (type != null)
                {
                    var method = type.GetMethod(method_name, new Type[] { typeof(ILAppDomain) });
                    if (method != null)
                    {
                        method.Invoke(null, new object[] { mAppDomain });
                    }
                    else
                    {
                        Debug.LogError("[TinaX.ILRuntime] CLR binding failed. the method \"Initialize\" not found");
                    }
                }
                else
                {
                    Debug.LogWarning("[TinaX.ILRuntime] CLRBindings code not found. Please generate CLR binding code in Menu or ProjectSettings.");
                }
            }

            mInited = true;
            return(true);
        }
예제 #17
0
 /// <summary>
 /// 获取缓存信息
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="key"></param>
 /// <returns></returns>
 public Config <T> GetConfig <T>(string key)
 {
     return(configService.GetConfig <T>(key));
 }