Exemplo n.º 1
0
        //----------------------------------------------------------------------------
        public sAssetInfo ParseResourseList(ref XmlElement element, EAssetType type = EAssetType.eGameObject)
        {
            sAssetInfo info = sAssetInfo.zero;

            info.strID     = element.GetAttribute("id");
            info.assetName = element.GetAttribute("name");
            if (!string.IsNullOrEmpty(info.assetName))
            {
                info.strName = ParseName(info.assetName);
            }
            info.strFile     = element.GetAttribute("file").ToLower();
            info.strRealFile = element.GetAttribute("file").ToLower();

            if (string.IsNullOrEmpty(info.strName))
            {
                info.strName = ParseName(info.strFile);
            }

            if (string.IsNullOrEmpty(info.assetName))
            {
                info.assetName = info.strName;
            }
            info.bundleName = ParseName(info.strFile);
            info.bPreLoad   = InitToBool(element.GetAttribute("preload"));
            info.eAssetType = type;
            if (element.HasAttribute("EnvirUse"))
            {
                info.ParseEnvir(element.GetAttribute("EnvirUse"));
            }
            else
            {
                info.ParseEnvir("");
            }
            return(info);
        }
Exemplo n.º 2
0
        /// </summary>
        /// 加载资源
        /// </summary>
        /// <param name="resName">资源的相对路径名称</param>
        /// <param name="assetType">资源类型</param>
        /// <param name="callback">完成回调</param>
        /// <returns>返回该资源唯一的加载器</returns>
        public static AssetFileLoader LoadAssetFile(string resName, EAssetType assetType, OnAssetFileLoad callback)
        {
            if (AssetLoadMode == EAssetLoadMode.EditorMode)
            {
                string loadPath = resName;
                return(GetFileLoader(assetType, loadPath, callback, null));
            }
            else if (AssetLoadMode == EAssetLoadMode.ResourceMode)
            {
                string loadPath = resName;
                return(GetFileLoader(assetType, loadPath, callback, null));
            }
            else if (AssetLoadMode == EAssetLoadMode.BundleMode)
            {
                if (BundleMethod == null)
                {
                    throw new Exception("AssetSystem.BundleMethod is null.");
                }

                string manifestPath = AssetPathHelper.ConvertResourcePathToManifestPath(resName);
                string loadPath     = BundleMethod.GetAssetBundleLoadPath(manifestPath);
                return(GetFileLoader(assetType, loadPath, callback, manifestPath));
            }
            else
            {
                throw new NotImplementedException($"{AssetLoadMode}");
            }
        }
Exemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="assetType"></param>
 /// <returns></returns>
 public static Type GetAssetType(EAssetType assetType)
 {
     if (assetType == EAssetType.EAT_Texture)
     {
         return(typeof(Texture));
     }
     else if (assetType == EAssetType.EAT_Sprite)
     {
         return(typeof(Sprite));
     }
     else if (assetType == EAssetType.EAT_UI || assetType == EAssetType.EAT_GameObject)
     {
         return(typeof(GameObject));
     }
     else if (assetType == EAssetType.EAT_AudioClip)
     {
         return(typeof(AudioClip));
     }
     else if (assetType == EAssetType.EAT_TextAsset)
     {
         return(typeof(TextAsset));
     }
     else if (assetType == EAssetType.EAT_SpriteAsset)
     {
         return(typeof(SpriteAsset));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 4
0
        private void StartLoadTaskAsset()
        {
            if (this.m_queueTasks.Count > 0)
            {
                this.ProgressValue = (float)(this.m_iLoadedAssetsNum + 1) / this.m_iAllAssetsNum;
                var task = this.m_queueTasks.Dequeue();
                //Debug.Log(task.Path);
                this.m_eCurAssetType = task.AssetType;
                switch (this.m_eCurAssetType)
                {
                case EAssetType.GameObject:
                    this.LoadGameObjectAsyn(task.Path, (task as ResourceLoadTask <GameObject>).Callback, true);
                    break;

                case EAssetType.Asset:
                    var assetTask = task as ResourceLoadTask <Object>;
                    this.LoadAsssetAsync(task.Path, assetTask.Callback, true);
                    break;

                case EAssetType.Scene:
                    var sceneTask = task as SceneResourceTask <SceneInstance>;
                    this.InnerLoadSceneAsync(sceneTask.Path, sceneTask.Callback, sceneTask.LoadSceneMode, true);
                    break;
                }
            }
        }
Exemplo n.º 5
0
        //----------------------------------------------------------------------------
        public void AddAssetList(string strAssetID, Object obj, EAssetType type = EAssetType.eGameObject)
        {
            if (m_dictAsset.ContainsKey(strAssetID))
            {
                return;
            }
            if (obj == null)
            {
                Debug.LogError("load assetid: " + strAssetID + " no bundle");
                return;
            }

            if (obj.GetType() == typeof(AssetBundle))
            {
                Debug.LogError("load assetid: " + strAssetID + "only bundle");
                return;
            }

            AssetCube cube;

            cube.objAsset  = obj;
            cube.typeAsset = type;
            m_dictAsset.Add(strAssetID, cube);
            ProcessToBeDeletList(strAssetID);
        }
Exemplo n.º 6
0
 public AssetFileLoader(EAssetType assetType, string loadPath)
 {
     RefCount  = 0;
     AssetType = assetType;
     LoadPath  = loadPath;
     LoadState = EAssetFileLoadState.None;
 }
Exemplo n.º 7
0
 public AssetObjectLoader(AssetBundle bundle, string assetName, EAssetType assetType)
 {
     _cacheBundle = bundle;
     AssetName    = assetName;
     AssetType    = assetType;
     LoadState    = EAssetObjectLoadState.None;
 }
Exemplo n.º 8
0
    // After buying an item
    public void PurchaseAsset(int idx, EAssetType type)
    {
        Debug.Log("happened");
        switch (type)
        {
        case EAssetType.ROCKET:
            PlayerUnlocks.Add(idx);
            break;

        case EAssetType.BACKGROUND:
            BackgroundUnlocks.Add(idx);
            break;

        case EAssetType.MUSIC:
            MusicUnlocks.Add(idx);
            break;

        case EAssetType.OBSTACLE:
            ObstacleUnlocks.Add(idx);
            break;
        }

        CloudSaving.instance.SaveGame();
        // SaveManager.instance.SaveToCloud();
    }
Exemplo n.º 9
0
 public Asset(string name, EAssetType type, AssetContext context, object content = null)
 {
     Name    = name ?? throw new ArgumentNullException(nameof(name));
     Type    = type;
     Context = context ?? throw new ArgumentNullException(nameof(context));
     // Content = content;
 }
Exemplo n.º 10
0
        //----------------------------------------------------------------------------
        public sAssetInfo InsertResourseList(ref XmlElement element, EAssetType type = EAssetType.eGameObject)
        {
            sAssetInfo info = ParseResourseList(ref element, type);

            AddElement(ref m_dicResourseList, info.strID, info);
            return(info);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Стандартный конструктор
        /// </summary>
        /// <param name="parAssetType">Основной тип ассета</param>
        /// <param name="parFilePath">Путь к файлу ассета</param>
        public AssetMetadata(/*string nameId,*/ EAssetType parAssetType, string parFilePath)
        {
            //NameId = nameId;

            AssetType = parAssetType;
            FilePath  = parFilePath;
        }
Exemplo n.º 12
0
    static int IntToEnum(IntPtr L)
    {
        int        arg0 = (int)LuaDLL.lua_tonumber(L, 1);
        EAssetType o    = (EAssetType)arg0;

        ToLua.Push(L, o);
        return(1);
    }
Exemplo n.º 13
0
        public void OnLoadSucc(int[] para, UnityObject unityObj)
        {
            var assetInfo = unityObj.Address;
            var obj       = unityObj.AsObject;

            if (null == obj)
            {
                _logger.ErrorFormat("Asset {0}:{1} Load Fialed ", assetInfo.BundleName, assetInfo.AssetName);
                return;
            }

            if (para == null || para.Length != 2)
            {
                return;
            }
            try
            {
                EAssetType atype = (EAssetType)para[0];
                switch (atype)
                {
                case EAssetType.BYTES:
                {
                    //TerrainData
                    var asset = obj as TextAsset;
                    if (null == asset.bytes)
                    {
                        _logger.ErrorFormat("TerrainConfig is NULL");
                        return;
                    }
                    int             subId  = para[1];
                    TerrainImporter import = new TerrainImporter();
                    TerrainItem     item   = new TerrainItem();
                    import.ImportBytesConfig(asset.bytes, item);
                    _terrains[subId] = item;
                    LoadAssets(item);
                    break;
                }

                case EAssetType.MATERIAL:
                {
                    //Material
                    var asset = obj as Material;
                    if (null == asset)
                    {
                        return;
                    }
                    int materialId = para[1];
                    _dictMaterials.Add(materialId, asset);
                    break;
                }
                }
            }
            catch (Exception e)
            {
                _logger.ErrorFormat(e.Message);
            }
        }
Exemplo n.º 14
0
        public AssetType Create(int createdBy, AssetType assetType)
        {
            EAssetType eAssetType = EAssetType(assetType);

            eAssetType.CreatedDate = DateTime.Now;
            eAssetType.CreatedBy   = createdBy;
            eAssetType             = _iDAssetType.Create(eAssetType);
            return(AssetType(eAssetType));
        }
Exemplo n.º 15
0
    /// <summary>
    /// 取消资源加载监听
    /// </summary>
    /// <param name="_type">资源类型</param>
    /// <param name="_path">资源路径</param>
    /// <param name="call">要取消的回调函数</param>
    public void RemoveAsyncCallback(EAssetType assetType, string _path, DAssetsCallback call)
    {
        string      _name   = GetRelativePath(_path, assetType);
        AssetEntity _entity = null;

        if (m_kAssets.TryGetValue(_name, out _entity))
        {
            _entity.RemoveListener(call);
        }
    }
Exemplo n.º 16
0
        //---------------------------------------------------------------------------

        public Asset(string name, string path, EAssetType assetType)
        {
            Save();
            Name             = name;
            Path             = path;
            IncludeInDebug   = false;
            IncludeInRelease = false;
            UpdateThumbnail();
            AssetType = EAssetType.All | assetType;
        }
Exemplo n.º 17
0
        //---------------------------------------------------------------------------

        public void Add(string name, string sourcePath, string targetPath, EAssetType assetType)
        {
            if (AddFile(sourcePath, targetPath))
            {
                string absolutePath = Path.Combine(RootPath, targetPath);
                if (File.Exists(absolutePath))
                {
                    Assets.Add(new Asset(name, targetPath, assetType));
                }
            }
        }
Exemplo n.º 18
0
        public void OnGoLoadSucc(object source, UnityObjectWrapper <GameObject> obj)
        {
            if (null == obj)
            {
                _logger.ErrorFormat("Load GameObject Asset Fialed: obj is null.");
                return;
            }
            if (null == obj.Value)
            {
                _logger.ErrorFormat("Asset {0}:{1} Load GameObject Fialed ", obj.Address.BundleName, obj.Address.AssetName);
                return;
            }

            int[] para = (int[])source;
            if (para == null || para.Length != 2)
            {
                return;
            }

            try
            {
                EAssetType atype = (EAssetType)para[0];
                switch (atype)
                {
                case EAssetType.AUDIO:
                {
                    //Sound
                    int soundId = para[1];
                    if (!_dictSounds.ContainsKey(soundId))
                    {
                        AudioSource audio = obj.Value.GetComponent <AudioSource>();
                        if (null != audio)
                        {
                            _dictSounds.Add(soundId, audio.clip);
                        }
                    }
                    break;
                }

                case EAssetType.EFFECT:
                {
                    //Effect
                    int effectId = para[1];
                    _effectPool.AddEffectPrefab(effectId, obj.Value);
                    break;
                }
                }
                _manager.AddRecycleRequest(obj);
            }
            catch (Exception e)
            {
                _logger.ErrorFormat(e.Message);
            }
        }
Exemplo n.º 19
0
    /// <summary>
    /// 获得加密后的Bundle名称
    /// </summary>
    /// <param name="resName"></param>
    /// <param name="assetType"></param>
    /// <returns></returns>
    public string GetBundleEncrypeName(string resName, EAssetType assetType)
    {
        string finalName = GetBundleName(resName, assetType);

        if (string.IsNullOrEmpty(finalName))
        {
            return(null);
        }

        return(GetBundleEncrypeName(finalName));
    }
Exemplo n.º 20
0
        public void AddAssetTask(string objPath, AssetLoadFinishedEventHandler <Object> callback)
        {
            var task = new ResourceLoadTask <Object>();

            task.Path      = objPath;
            task.Callback  = callback;
            task.AssetType = EAssetType.Asset;
            this.m_queueTasks.Enqueue(task);
            this.m_iAllAssetsNum++;
            this.m_eCurAssetType = EAssetType.None;
        }
Exemplo n.º 21
0
        /// <summary>
        /// 通过guid 得到 AssetItem 实例
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        private static AssetItem GetAssetItemFromGUID(EAssetType type, string guid)
        {
            AssetItem assetItem = null;
            string    assetPath = AssetDatabase.GUIDToAssetPath(guid);
            Object    assetObj  = AssetDatabase.LoadAssetAtPath <Object>(assetPath);

            if (null != assetObj && assetObj.GetType() != typeof(DefaultAsset) && assetObj.GetType() != typeof(MonoScript))
            {
                assetItem = new AssetItem(type, guid, assetPath.Replace(PROJECT_PATH, ""));
            }
            return(assetItem);
        }
Exemplo n.º 22
0
        public void AddSceneTask(string objPath, LoadSceneMode mode, AssetLoadFinishedEventHandler <SceneInstance> callback)
        {
            var task = new SceneResourceTask <SceneInstance>();

            task.Path          = objPath;
            task.Callback      = callback;
            task.AssetType     = EAssetType.Scene;
            task.LoadSceneMode = mode;
            this.m_queueTasks.Enqueue(task);
            this.m_iAllAssetsNum++;
            this.m_eCurAssetType = EAssetType.None;
        }
Exemplo n.º 23
0
        public override void LoadMainAsset(EAssetType mainAssetType, OnAssetObjectLoad callback)
        {
            // Check error
            if (LoadState != EAssetFileLoadState.LoadAssetFileOK)
            {
                LogSystem.Log(ELogType.Error, $"Can not load asset object, {nameof(AssetResourceLoader)} is not ok : {LoadPath}");
                callback?.Invoke(null, false);
                return;
            }

            callback?.Invoke(_mainAsset, LoadState == EAssetFileLoadState.LoadAssetFileOK);
        }
Exemplo n.º 24
0
        /// <summary>
        /// 从缓存列表里获取加载器,如果不存在创建一个新的加载器并添加到列表
        /// </summary>
        public static AssetFileLoader GetFileLoader(EAssetType assetType, string loadPath, OnAssetFileLoad callback, string manifestPath)
        {
            // 如果已经提交相同请求
            AssetFileLoader loader = TryGetFileLoaderInternal(loadPath);

            if (loader != null)
            {
                loader.Reference();                 //引用计数
                if (loader.IsDone())
                {
                    if (callback != null)
                    {
                        callback.Invoke(loader);
                    }
                }
                else
                {
                    if (callback != null)
                    {
                        loader.LoadCallback += callback;
                    }
                }
                return(loader);
            }

            // 创建加载器
            AssetFileLoader newLoader = null;

            if (AssetLoadMode == EAssetLoadMode.EditorMode)
            {
                newLoader = new AssetDatabaseLoader(assetType, loadPath);
            }
            else if (AssetLoadMode == EAssetLoadMode.ResourceMode)
            {
                newLoader = new AssetResourceLoader(assetType, loadPath);
            }
            else if (AssetLoadMode == EAssetLoadMode.BundleMode)
            {
                newLoader = new AssetBundleLoader(assetType, loadPath, manifestPath);
            }
            else
            {
                throw new NotImplementedException($"{AssetLoadMode}");
            }

            // 新增下载需求
            _fileLoaders.Add(newLoader);
            newLoader.LoadCallback = callback;
            newLoader.Reference();          //引用计数
            newLoader.Update();             //立刻轮询
            return(newLoader);
        }
Exemplo n.º 25
0
    /// <summary>
    /// 相对于ResourcesAB的路径
    /// </summary>
    /// <param name="_path">相对于ResourcesAB的路径</param>
    /// <param name="_type">资源类型</param>
    /// <returns></returns>
    public string GetRelativePath(string _path, EAssetType assetType)
    {
#if UNITY_EDITOR && !TEST_AB
        switch (assetType)
        {
        case EAssetType.LUA:
            return(string.Format("Lua/{0}", _path));

        case EAssetType.ENTITY:
            return(string.Format("Entity/{0}.prefab", _path));

        case EAssetType.TEXTURE:
            return(string.Format("Texture/{0}.jpg", _path));

        case EAssetType.SCENE:
            return(string.Format("Scene/{0}.prefab", _path));

        case EAssetType.UI:
            return(string.Format("UI/{0}.prefab", _path));

        case EAssetType.ATLAS:
            return(string.Format("Atlas/{0}.prefab", _path));

        default:
            return(_path);
        }
#else
        switch (assetType)
        {
        case EAssetType.LUA:
            return(string.Format("Lua/{0}", _path));

        case EAssetType.ENTITY:
            return(string.Format("Entity/{0}", _path));

        case EAssetType.TEXTURE:
            return(string.Format("Texture/{0}", _path));

        case EAssetType.SCENE:
            return(string.Format("Scene/{0}", _path));

        case EAssetType.UI:
            return(string.Format("UI/{0}", _path));

        case EAssetType.ATLAS:
            return(string.Format("Atlas/{0}", _path));

        default:
            return(_path);
        }
#endif
    }
Exemplo n.º 26
0
        private string GetExtension(EAssetType type)
        {
            switch (type)
            {
            case EAssetType.Text:
                return(".txt");

            case EAssetType.Texture:
                return(".png");
            }

            return("");
        }
Exemplo n.º 27
0
        //---------------------------------------------------------------------------

        private void GenerateEnum(StreamWriter writer, EAssetType type)
        {
            writer.Write(string.Format("    public enum E{0}Assets\n    {{\n", type.ToString()));
            foreach (Asset asset in Assets)
            {
                if (asset.AssetType.HasFlag(type))
                {
                    writer.Write(string.Format("        {0},\n", asset.Name));
                }
            }
            writer.Write("    }\n");
            writer.Write("\n    //---------------------------------------------------------------------------\n\n");
        }
Exemplo n.º 28
0
    public void Preview(EAssetType type, int idx)
    {
        switch (type)
        {
        case EAssetType.BACKGROUND:
            background.Preview(idx);
            break;

        case EAssetType.MUSIC:
            audio.PreviewMusic(idx);
            break;
        }
    }
Exemplo n.º 29
0
    /// <summary>
    /// load asset in editor.
    /// </summary>
    /// <param name="szFile"></param>
    /// <param name="inType"></param>
    /// <returns></returns>
    public static UnityEngine.Object LoadAsset_Editor(string szFile, EAssetType inType)
    {
#if UNITY_EDITOR
        Type tmp = GetAssetType(inType);
        if (tmp == null)
        {
            return(null);
        }
        return(UnityEditor.AssetDatabase.LoadAssetAtPath(szFile, tmp));
#else
        return(null);
#endif
    }
Exemplo n.º 30
0
        public void OnGoLoadSucc(int[] para, UnityObject unityObj)
        {
            var obj = unityObj.AsGameObject;

            if (null == obj)
            {
                _logger.ErrorFormat("Asset {0}:{1} Load GameObject Fialed ", unityObj.Address.BundleName, unityObj.Address.AssetName);
                return;
            }

            if (para == null || para.Length != 2)
            {
                return;
            }

            try
            {
                EAssetType atype = (EAssetType)para[0];
                switch (atype)
                {
                case EAssetType.AUDIO:
                {
                    //Sound
                    int soundId = para[1];
                    if (!_dictSounds.ContainsKey(soundId))
                    {
                        AudioSource audio = obj.GetComponent <AudioSource>();
                        if (null != audio)
                        {
                            _dictSounds.Add(soundId, audio.clip);
                        }
                    }
                    break;
                }

                case EAssetType.EFFECT:
                {
                    //Effect
                    int effectId = para[1];
                    _effectPool.AddEffectPrefab(effectId, obj);
                    break;
                }
                }

                _assetManager.Recycle(unityObj);
            }
            catch (Exception e)
            {
                _logger.ErrorFormat(e.Message);
            }
        }