Exemple #1
0
    public void Load(System.Action callback)
    {
        if (_userCallback != null)
        {
            return;
        }

        _userCallback      = callback;
        _handle            = _assetRef.LoadAssetAsync <TextAsset>();
        _handle.Completed += Handle_Completed;
    }
    public void Load(System.Action callback)
    {
        if (_isLoadAsset)
        {
            return;
        }

        _isLoadAsset       = true;
        _userCallback      = callback;
        _handle            = ResourceManager.Instance.LoadAssetAsync <TextAsset>(Location);
        _handle.Completed += Handle_Completed;
    }
        /// <summary>
        /// 加载表格
        /// </summary>
        public void Load(string location)
        {
            if (_isLoadAsset)
            {
                return;
            }

            _isLoadAsset       = true;
            Location           = location;
            _handle            = ResourceManager.Instance.LoadAssetAsync <TextAsset>(location);
            _handle.Completed += Handle_Completed;
        }
        /// <summary>
        /// 加载表格
        /// </summary>
        /// <param name="location"></param>
        /// <param name="callback"></param>
        public void Load(string location)
        {
            if (_assetRef != null)
            {
                return;
            }

            Location           = location;
            _assetRef          = new AssetReference(location);
            _handle            = _assetRef.LoadAssetAsync <TextAsset>();
            _handle.Completed += Handle_Completed;
        }
        public GameObjectPool(Transform root, string location, int capacity)
        {
            _root    = root;
            Capacity = capacity;

            // 创建缓存池
            _pool = new Stack <GameObject>(capacity);

            // 加载资源
            _assetRef          = new AssetReference(location);
            _handle            = _assetRef.LoadAssetAsync <GameObject>();
            _handle.Completed += Handle_Completed;
        }
        public GameObjectCollector(Transform root, string location, int capacity)
        {
            _root    = root;
            Capacity = capacity;

            // 创建缓存池
            _collector = new Queue <SpawnGameObject>(capacity);

            // 加载资源
            _assetRef          = new AssetReference(location);
            _handle            = _assetRef.LoadAssetAsync <GameObject>();
            _handle.Completed += Handle_Completed;
        }
Exemple #7
0
        internal void InternalLoad(string location, System.Action <UIWindow> prepareCallback, System.Object userData)
        {
            if (_isLoadAsset)
            {
                return;
            }

            UserData           = userData;
            _isLoadAsset       = true;
            _prepareCallback   = prepareCallback;
            _handle            = ResourceManager.Instance.LoadAssetAsync <GameObject>(location);
            _handle.Completed += Handle_Completed;
        }
Exemple #8
0
        private void Handle_Completed(AssetOperationHandle obj)
        {
            if (_handle.AssetObject == null)
            {
                return;
            }

            // 实例化对象
            Go = _handle.InstantiateSync();
            GameObject.DontDestroyOnLoad(Go);

            // 调用重载函数
            OnAssetLoad(Go);
        }
Exemple #9
0
        public GameObjectCollector(Transform root, string location, int capacity, bool dontDestroy)
        {
            _root       = root;
            Location    = location;
            Capacity    = capacity;
            DontDestroy = dontDestroy;

            // 创建缓存池
            _collector = new Queue <SpawnGameObject>(capacity);

            // 加载资源
            _handle            = ResourceManager.Instance.LoadAssetAsync <GameObject>(location);
            _handle.Completed += Handle_Completed;
        }
    internal void InternalLoad(System.Action <UIWindow> callback)
    {
        if (IsPrepare)
        {
            callback?.Invoke(this);
        }

        if (_assetRef == null)
        {
            _userCallback      = callback;
            _assetRef          = new AssetReference($"UIPanel/{WindowType}");
            _handle            = _assetRef.LoadAssetAsync <GameObject>();
            _handle.Completed += Handle_Completed;
        }
    }
Exemple #11
0
 internal void InternalLoad(string location, System.Action <UIWindow> prepareCallback, System.Object userData)
 {
     if (_assetRef == null)
     {
         UserData           = userData;
         _prepareCallback   = prepareCallback;
         _assetRef          = new AssetReference(location);
         _handle            = _assetRef.LoadAssetAsync <GameObject>();
         _handle.Completed += Handle_Completed;
     }
     else
     {
         throw new System.NotImplementedException();
     }
 }
        public GameObjectCollector(Transform root, string location, bool dontDestroy, int initCapacity, int maxCapacity, float destroyTime)
        {
            _root        = root;
            Location     = location;
            DontDestroy  = dontDestroy;
            InitCapacity = initCapacity;
            MaxCapacity  = maxCapacity;
            DestroyTime  = destroyTime;

            // 创建缓存池
            _cache = new Queue <GameObject>(initCapacity);

            // 加载资源
            _handle            = ResourceManager.Instance.LoadAssetAsync <GameObject>(location);
            _handle.Completed += Handle_Completed;
        }
Exemple #13
0
        public void Load(bool isAdditive, bool activeOnLoad, System.Action <SceneInstance> callback)
        {
            if (_userCallback != null)
            {
                return;
            }

            // 场景加载参数
            SceneInstanceParam param = new SceneInstanceParam();

            param.IsAdditive     = isAdditive;
            param.ActivateOnLoad = activeOnLoad;

            _userCallback      = callback;
            _handle            = _assetRef.LoadAssetAsync <SceneInstance>(param);
            _handle.Completed += Handle_Completed;
        }
Exemple #14
0
        public void Load(bool isAdditive, bool activeOnLoad, System.Action <SceneInstance> callback)
        {
            if (_isLoadScene)
            {
                return;
            }

            // 场景加载参数
            SceneInstanceParam param = new SceneInstanceParam();

            param.IsAdditive     = isAdditive;
            param.ActivateOnLoad = activeOnLoad;

            MotionLog.Log($"Begin to load scene : {Location}");
            _isLoadScene       = true;
            _userCallback      = callback;
            _handle            = ResourceManager.Instance.LoadAssetAsync <SceneInstance>(Location, param);
            _handle.Completed += Handle_Completed;
        }
Exemple #15
0
        private void Handle_Completed(AssetOperationHandle obj)
        {
            _cloneObject = _handle.InstantiateObject;

            // 如果加载失败,创建临时对象
            if (_cloneObject == null)
            {
                _cloneObject = new GameObject(Location);
            }

            // 设置克隆对象
            SetRestoreCloneObject(_cloneObject);

            // 创建初始对象
            for (int i = 0; i < Capacity; i++)
            {
                GameObject      cloneObj = GameObject.Instantiate(_cloneObject);
                SpawnGameObject spawn    = new SpawnGameObject(this, cloneObj);
                SetRestoreCloneObject(cloneObj);
                _collector.Enqueue(spawn);
            }

            // 最后返回结果
            for (int i = 0; i < _loadingSpawn.Count; i++)
            {
                GameObject      cloneObj = GameObject.Instantiate(_cloneObject);
                SpawnGameObject spawn    = _loadingSpawn[i];
                spawn.Go = cloneObj;
                if (spawn.IsSpawning)
                {
                    SetSpawnCloneObject(cloneObj);
                    spawn.UserCallback?.Invoke(cloneObj);
                }
                else
                {
                    // 注意:直接回收
                    Restore(spawn);
                }
            }
            _loadingSpawn.Clear();
        }
        private void Handle_Completed(AssetOperationHandle obj)
        {
            // 创建初始对象
            for (int i = 0; i < InitCapacity; i++)
            {
                GameObject cloneObj = InstantiateGameObject();
                SetRestoreCloneObject(cloneObj);
                _cache.Enqueue(cloneObj);
            }

            // 最后返回结果
            for (int i = 0; i < _loadingSpawn.Count; i++)
            {
                GameObject      cloneObj = InstantiateGameObject();
                SpawnGameObject spawn    = _loadingSpawn[i];
                spawn.Go = cloneObj;

                // 注意Spawn对象的当前状态
                if (spawn.SpawnState == SpawnGameObject.ESpawnState.Restore)
                {
                    if (spawn.Go != null)
                    {
                        RestoreGameObject(spawn.Go);
                    }
                }
                else if (spawn.SpawnState == SpawnGameObject.ESpawnState.Discard)
                {
                    if (spawn.Go != null)
                    {
                        DiscardGameObject(spawn.Go);
                    }
                }
                else
                {
                    SetSpawnCloneObject(cloneObj);
                    spawn.UserCallback?.Invoke(spawn);
                }
            }
            _loadingSpawn.Clear();
        }
Exemple #17
0
    IEnumerator Start()
    {
        GameObject uiRoot = GameObject.Find("UIRoot");

        // 加载窗口
        GameLog.Log("加载游戏窗口");
        _gameWindowHandle = ResourceManager.Instance.LoadAssetAsync <GameObject>("UIPanel/GameWindow");
        yield return(_gameWindowHandle);

        _window = _gameWindowHandle.InstantiateObject;
        _window.transform.SetParent(uiRoot.transform, false);

        // 退出按钮
        var exitBtn = _window.transform.BFSearch("Exit").GetComponent <Button>();

        exitBtn.onClick.AddListener(OnClickExit);

        // 加载模型
        {
            GameLog.Log("加载模型");
            if (Demo.Instance.PlayLevel == 1)
            {
                _monsterHandle            = ResourceManager.Instance.LoadAssetAsync <GameObject>("Entity/Level1/footman_Blue");
                _monsterHandle.Completed += MonsterHandle_Completed;
            }
            else if (Demo.Instance.PlayLevel == 2)
            {
                _monsterHandle            = ResourceManager.Instance.LoadAssetAsync <GameObject>("Entity/Level2/footman_Green");
                _monsterHandle.Completed += MonsterHandle_Completed;
            }
            else if (Demo.Instance.PlayLevel == 3)
            {
                _monsterHandle            = ResourceManager.Instance.LoadAssetAsync <GameObject>("Entity/Level3/footman_Red");
                _monsterHandle.Completed += MonsterHandle_Completed;
            }
        }

        // 加载头像
        this.StartCoroutine(LoadPhotoAsync());
    }
    IEnumerator Start()
    {
        GameObject uiRoot = GameObject.Find("UIRoot");

        GameLog.Log("加载大厅窗口");
        _lobbyWindowHandle = ResourceManager.Instance.LoadAssetAsync <GameObject>("UIPanel/LobbyWindow");
        yield return(_lobbyWindowHandle);

        GameObject window = _lobbyWindowHandle.InstantiateObject;

        window.transform.SetParent(uiRoot.transform, false);

        // 关卡按钮
        var level1Btn = window.transform.BFSearch("Level1Button").GetComponent <Button>();

        level1Btn.onClick.AddListener(OnClickLevel1);
        var level2Btn = window.transform.BFSearch("Level2Button").GetComponent <Button>();

        level2Btn.onClick.AddListener(OnClickLevel2);
        var level3Btn = window.transform.BFSearch("Level3Button").GetComponent <Button>();

        level3Btn.onClick.AddListener(OnClickLevel3);

        // 下载按钮
        PatchDownloader downloader = PatchManager.Instance.CreateDLCDownloader("level3", 1, 1);

        _downloadBtn  = window.transform.BFSearch("DownloadBtn").GetComponent <Button>();
        _downloadTips = window.transform.BFSearch("DownloadTips").GetComponent <Text>();
        if (downloader.TotalDownloadBytes == 0)
        {
            _downloadBtn.gameObject.SetActive(false);
        }
        else
        {
            _downloadBtn.onClick.AddListener(OnClickDownload);
        }

        // 加载原生文件
        this.StartCoroutine(LoadRawFile());
    }
Exemple #19
0
    private IEnumerator LoadPhotoAsync()
    {
        GameLog.Log("加载头像");
        if (Demo.Instance.PlayLevel == 1)
        {
            _photoHandle = ResourceManager.Instance.LoadAssetAsync <Sprite>("UITexture/Photos/eggs");
        }
        else if (Demo.Instance.PlayLevel == 2)
        {
            _photoHandle = ResourceManager.Instance.LoadAssetAsync <Sprite>("UITexture/Photos/apple");
        }
        else if (Demo.Instance.PlayLevel == 3)
        {
            _photoHandle = ResourceManager.Instance.LoadAssetAsync <Sprite>("UITexture/Photos/magic_fish");
        }

        yield return(_photoHandle);

        Image img = _window.transform.BFSearch("Photo").GetComponent <Image>();

        img.sprite = _photoHandle.AssetObject as Sprite;
    }
Exemple #20
0
        private void Handle_Completed(AssetOperationHandle obj)
        {
            try
            {
                TextAsset txt = _handle.AssetObject as TextAsset;
                if (txt != null)
                {
                    // 解析数据
                    ParseDataInternal(txt.bytes);
                }
            }
            catch (Exception ex)
            {
                MotionLog.Error($"Failed to parse config {Location}. Error : {ex.ToString()}");
            }

            // 注意:为了节省内存这里立即释放了资源
            _handle.Release();

            IsPrepare = true;
            _userCallback?.Invoke(this);
        }
Exemple #21
0
    IEnumerator Start()
    {
        GameObject uiRoot = GameObject.Find("UIRoot");

        GameLog.Log("加载登录窗口");
        _loginWindowHandle = ResourceManager.Instance.LoadAssetAsync <GameObject>("UIPanel/LoginWindow");
        yield return(_loginWindowHandle);

        GameObject window = _loginWindowHandle.InstantiateObject;

        window.transform.SetParent(uiRoot.transform, false);

        // 显示版本信息
        var gameVersionTxt = window.transform.BFSearch("GameVersion").GetComponent <Text>();
        var resVersionTxt  = window.transform.BFSearch("ResVersion").GetComponent <Text>();

        gameVersionTxt.text = $"Game Version : {PatchUpdater.Instance.GameVersion}";
        resVersionTxt.text  = $"Resource Version : {PatchManager.Instance.GetResourceVersion()}";

        // 登录按钮
        var loginBtn = window.transform.BFSearch("LoginButton").GetComponent <Button>();

        loginBtn.onClick.AddListener(OnClickLogin);
    }
Exemple #22
0
 // 资源回调
 private void Handle_Completed(AssetOperationHandle obj)
 {
     _userCallback?.Invoke(_handle.AssetObject as SceneInstance);
 }
Exemple #23
0
 // 资源回调
 private void Handle_Completed(AssetOperationHandle obj)
 {
     _userCallback?.Invoke(_handle.AssetScene);
 }
Exemple #24
0
 // 资源回调
 private void Handle_Completed(AssetOperationHandle obj)
 {
     Clip = _handle.AssetObject as AudioClip;
     _userCallback?.Invoke(Clip);
 }
    private IEnumerator LoadAssets()
    {
        // 加载UI面板
        GameLog.Log("Load UIRoot.");
        var rootHandle = ResourceManager.Instance.LoadAssetAsync <GameObject>("UIPanel/UIRoot");

        yield return(rootHandle);

        GameObject uiRoot = rootHandle.InstantiateObject;         // 实例化对象

        // 加载窗口
        GameLog.Log("Load LoginWindow");
        GameObject window;
        {
            var handle = ResourceManager.Instance.LoadAssetAsync <GameObject>("UIPanel/LoginWindow");
            yield return(handle);

            window = handle.InstantiateObject;             // 实例化对象
            window.transform.SetParent(uiRoot.transform, false);

            var versionTxt = window.transform.BFSearch("Version").GetComponent <Text>();
            if (MotionEngine.Contains(typeof(PatchManager)))
            {
                versionTxt.text = PatchManager.Instance.GetRequestedGameVersion().ToString();
            }
            else
            {
                versionTxt.text = "NO Server";
            }
        }

        // 加载资源包
        {
            GameLog.Log("Load texture package");
            _handle1 = ResourceManager.Instance.LoadAssetAsync <Texture>("UITexture/Foods/eggs");
            yield return(_handle1);

            Texture tex1 = _handle1.AssetObject as Texture;

            _handle2 = ResourceManager.Instance.LoadAssetAsync <Texture>("UITexture/Foods/apple");
            yield return(_handle2);

            Texture tex2 = _handle2.AssetObject as Texture;

            // 设置纹理1
            RawImage img1 = window.transform.BFSearch("FoodImg1").GetComponent <RawImage>();
            img1.texture = tex1;
            img1.SetNativeSize();

            // 设置纹理2
            RawImage img2 = window.transform.BFSearch("FoodImg2").GetComponent <RawImage>();
            img2.texture = tex2;
            img2.SetNativeSize();
        }

        // 加载模型
        {
            GameLog.Log("Load Monster");
            var handle = ResourceManager.Instance.LoadAssetAsync <GameObject>("Entity/Monster/Boss");
            yield return(handle);

            var sphere = handle.InstantiateObject;             // 实例化对象
            sphere.transform.position   = new Vector3(5f, 0, 0);
            sphere.transform.localScale = sphere.transform.localScale * 2f;
        }
    }