internal AssetLoadedParameters(string name, Il2CppSystem.Type type, AssetLoadType loadType)
#endif
        {
            Name     = name;
            Type     = type;
            LoadType = loadType;
        }
Esempio n. 2
0
 private void ParseInfo(string p, AssetLoadType loadType)
 {
     // path;objType
     if (loadType == AssetLoadType.Resources)
     {
         ParseInfoResources(p);
     }
     //path;md5;objType;assetName;assetBundleName
     else
     {
         ParseInfoStreaming(p);
     }
 }
Esempio n. 3
0
        IAssetLoad GetAssetLoad(AssetLoadType assetLoadType)
        {
            switch (assetLoadType)
            {
            case AssetLoadType.UnityDefault: return(new UnityDefault());

            case AssetLoadType.UnityLocalAssetBundle: return(new UnityLocalAssetBundle());

            case AssetLoadType.UnityDownloadAssetBundle:
            case AssetLoadType.DeviceLocalAssetBundle:
            case AssetLoadType.DeviceDownloadAssetBundle: return(new DeviceDownloadAssetBundle());
            }
            return(null);
        }
Esempio n. 4
0
        public static void SaveJson(object jsonContent, string jsonPath, AssetLoadType pathType)
        {
            //检查路径
            var final_unity_path = (pathType == AssetLoadType.Resources) ? (ConfigResourcesPath + "/" + jsonPath + ".json") : jsonPath;
            var system_path      = System.IO.Path.GetFullPath(final_unity_path);

            if (System.IO.File.Exists(system_path))
            {
                System.IO.File.Delete(system_path);
            }
            var json_text = JsonUtility.ToJson(jsonContent);

            TinaX.IO.XDirectory.CreateIfNotExists(System.IO.Path.GetDirectoryName(system_path));
            System.IO.File.WriteAllText(system_path, json_text, Encoding.UTF8);
        }
Esempio n. 5
0
 public AsyncAssetLoadInfo(
     string assetName,
     Type assetType,
     AssetLoadType loadType,
     AssetBundle bundle,
     bool skipAllPostfixes,
     AsyncAssetLoadingResolve resolveType,
     UnityEngine.Object[] assets)
 {
     AssetName        = assetName;
     AssetType        = assetType;
     LoadType         = loadType;
     Bundle           = bundle;
     SkipAllPostfixes = skipAllPostfixes;
     ResolveType      = resolveType;
     Assets           = assets;
 }
Esempio n. 6
0
        public static T CreateConfigIfNotExists <T>(string configPath, AssetLoadType pathType = AssetLoadType.Resources) where T : ScriptableObject
        {
            UnityEditor.AssetDatabase.ReleaseCachedFileHandles();
            //检查路径
            var final_path = (pathType == AssetLoadType.Resources) ? (ConfigResourcesPath + "/" + configPath + ".asset") : configPath;
            var asset      = UnityEditor.AssetDatabase.LoadAssetAtPath <T>(final_path);

            if (asset == null)
            {
                //create
                EnsureDirectory(final_path);
                var config = ScriptableObject.CreateInstance <T>();
                UnityEditor.AssetDatabase.CreateAsset(config, final_path);

                return(config);
            }
            else
            {
                return(asset);
            }
        }
 internal AssetLoadedParameters(string name, Type type, AssetLoadType loadType)
Esempio n. 8
0
        /// <summary>
        /// Get Unity Config
        /// </summary>
        /// <param name="configPath"></param>
        /// <param name="loadType"></param>
        /// <param name="cachePrior">优先从缓存中读取</param>
        /// <returns></returns>
        public static T GetConfig <T>(string configPath, AssetLoadType loadType = AssetLoadType.Resources, bool cachePrior = true) where T : UnityEngine.ScriptableObject
        {
            bool   cache_flag = false;
            string cache_key  = ((loadType == AssetLoadType.Resources) ? mPathHeadText_LoadByResources : mPathHeadText_LoadByVFS) + configPath;

            if (cachePrior && UnityEngine.Application.isPlaying)
            {
                //检查缓存
                if (mDict_ConfigCache.TryGetValue(cache_key, out object conf))
                {
                    return(conf as T);
                }
                else
                {
                    cache_flag = true; //加载之后要加入缓存字典
                }
            }

            T final_asset;

            //load asset
            if (loadType == AssetLoadType.Resources)
            {
#if UNITY_EDITOR
                if (Application.isPlaying)
                {
                    string _final_path = (configPath.StartsWith("/") ? ConfigRootFolderInResource + configPath : ConfigRootFolderInResource + "/" + configPath);
                    _final_path = RemoveExtNameIfExists(_final_path);
                    final_asset = Resources.Load <T>(_final_path);
                }
                else
                {
                    //在编辑器下应该使用AssetDatabase加载
                    if (configPath.IndexOf("Resources") != -1 && configPath.StartsWith("Assets/"))
                    {
                        //本来给定的就是unity asset path, 直接加载
                        final_asset = UnityEditor.AssetDatabase.LoadAssetAtPath <T>(configPath);
                    }
                    else
                    {
                        //本来的路径是Resources的路径,要还原成Unity的路径
                        string uPath = ConfigResourcesPath + "/" + configPath;
                        if (!uPath.EndsWith(".asset"))
                        {
                            uPath = uPath + ".asset";
                        }

                        final_asset = UnityEditor.AssetDatabase.LoadAssetAtPath <T>(uPath);
                    }
                }
#else
                string _final_path = (configPath.StartsWith("/") ? ConfigRootFolderInResource + configPath : ConfigRootFolderInResource + "/" + configPath);
                _final_path = RemoveExtNameIfExists(_final_path);
                final_asset = Resources.Load <T>(_final_path);
#endif
            }
            else if (loadType == AssetLoadType.VFS)
            {
#if UNITY_EDITOR
                if (Application.isPlaying && XCore.MainInstance != null && XCore.GetMainInstance().IsRunning)
                {
                    final_asset = XCore.GetMainInstance().GetService <TinaX.Services.IAssetService>().Load <T>(configPath);
                }
                else
                {
                    //editor only : load asset by assetdatabase.
                    final_asset = UnityEditor.AssetDatabase.LoadAssetAtPath <T>(configPath);
                }
#else
                final_asset = XCore.GetMainInstance()?.GetService <TinaX.Services.IAssetService>()?.Load <T>(configPath);
#endif
            }
            else
            {
                throw new Exception($"[TinaX] XConfig System can't load asset by \"{loadType.ToString()}\"loadtype.");
            }

            if (cache_flag)
            {
                if (mDict_ConfigCache.ContainsKey(cache_key))
                {
                    mDict_ConfigCache[cache_key] = final_asset;
                }
                else
                {
                    mDict_ConfigCache.Add(cache_key, final_asset);
                }
            }

            return(final_asset);
        }
Esempio n. 9
0
        public static T GetJson <T>(string jsonPath, AssetLoadType loadType = AssetLoadType.SystemIO, bool cachePrior = false)
        {
            bool   cache_flag = false;
            string cache_key  = jsonPath.ToLower();

            if (cachePrior && UnityEngine.Application.isPlaying)
            {
                //检查缓存
                if (mDict_JsonCache.TryGetValue(cache_key, out object conf))
                {
                    return((T)conf);
                }
                else
                {
                    cache_flag = true; //加载之后要加入缓存字典
                }
            }

            T final_asset;

            //load asset
            if (loadType == AssetLoadType.Resources)
            {
#if UNITY_EDITOR
                //在编辑器下应该使用AssetDatabase加载
                if (jsonPath.IndexOf("Resources") != -1 && jsonPath.StartsWith("Assets/"))
                {
                    //本来给定的就是unity asset path, 直接加载
                    var json_ta = UnityEditor.AssetDatabase.LoadAssetAtPath <TextAsset>(jsonPath);
                    final_asset = JsonUtility.FromJson <T>(json_ta.text);
                }
                else
                {
                    //本来的路径是Resources的路径,要还原成Unity的路径
                    string uPath = ConfigResourcesPath + "/" + jsonPath;
                    if (!uPath.EndsWith(".asset"))
                    {
                        uPath = uPath + ".asset";
                    }

                    var json_ta = UnityEditor.AssetDatabase.LoadAssetAtPath <TextAsset>(uPath);
                    final_asset = JsonUtility.FromJson <T>(json_ta.text);
                }
#else
                var json_ta = Resources.Load <TextAsset>(RemoveExtNameIfExists(jsonPath));
                final_asset = JsonUtility.FromJson <T>(json_ta.text);
#endif
            }
            else if (loadType == AssetLoadType.VFS)
            {
#if UNITY_EDITOR
                if (Application.isPlaying && XCore.MainInstance != null && XCore.GetMainInstance().IsRunning)
                {
                    var json_textAsset = XCore.GetMainInstance().GetService <TinaX.Services.IAssetService>().Load <TextAsset>(jsonPath);
                    final_asset = JsonUtility.FromJson <T>(json_textAsset.text);
                }
                else
                {
                    //editor only : load asset by assetdatabase.
                    var json_textAsset = UnityEditor.AssetDatabase.LoadAssetAtPath <TextAsset>(jsonPath);
                    final_asset = JsonUtility.FromJson <T>(json_textAsset.text);
                }
#else
                var json_textAsset = XCore.GetMainInstance()?.GetService <TinaX.Services.IAssetService>()?.Load <TextAsset>(jsonPath);
                final_asset = JsonUtility.FromJson <T>(json_textAsset.text);
#endif
            }
            else if (loadType == AssetLoadType.SystemIO)
            {
                var json_text = System.IO.File.ReadAllText(jsonPath, Encoding.UTF8);
                final_asset = JsonUtility.FromJson <T>(json_text);
            }
            else
            {
                throw new Exception($"[TinaX] XConfig System can't load asset by \"{loadType.ToString()}\"loadtype.");
            }

            if (cache_flag)
            {
                if (mDict_ConfigCache.ContainsKey(cache_key))
                {
                    mDict_ConfigCache[cache_key] = final_asset;
                }
                else
                {
                    mDict_ConfigCache.Add(cache_key, final_asset);
                }
            }

            return(final_asset);
        }
Esempio n. 10
0
 // loadType, path;objType
 public static string SerializeFile(AssetLoadType loadType, string path, string objType)
 {
     return(string.Format("{0};{1};{2}", (int)loadType, path, objType));
 }
Esempio n. 11
0
 public static string SerializeFile(AssetLoadType loadType, string path, string objType, string assetBundleName, string assetName, string ext)
 {
     return(string.Format("{0};{1};{2};{3};{4};{5}", (int)loadType, path, objType, assetBundleName, assetName, ext));
 }
 internal AssetLoadingParameters(string name, Type type, AssetLoadType loadType)
 {
     Name     = name;
     Type     = type;
     LoadType = loadType;
 }
Esempio n. 13
0
 internal AssetLoadedContext(string assetName, Type assetType, AssetLoadType loadType, AssetBundle bundle, UnityEngine.Object[] assets)
 {
     Parameters = new AssetLoadedParameters(assetName, assetType, loadType);
     Bundle     = bundle;
     Assets     = assets;
 }
Esempio n. 14
0
 internal AsyncAssetLoadingContext(string assetName, Type assetType, AssetLoadType loadType, AssetBundle bundle)
 {
     Parameters = new AssetLoadingParameters(assetName, assetType, loadType);
     Bundle     = bundle;
 }