예제 #1
0
        public void LoadObject <T>(string address, Action <T> onComplete = null) where T : class
        {
            Address = address;
            var result = Addressables.LoadAsset <T>(address);

            InternalOnComplete <T>(result, onComplete);
        }
예제 #2
0
        private async UniTask Play(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                Debug.unityLogger.LogError(GetType().Name, $"name is null or empty.");
                return;
            }

            AudioClip clip;

            if (!_clips.TryGetValue(name, out clip))
            {
                var operation = Addressables.LoadAsset <AudioClip>(name);
                await operation.ToUniTask();

                clip = operation.Result;
                _clips.Add(name, clip);
            }

            if (clip == null)
            {
                Debug.unityLogger.LogError(GetType().Name, $"{name} is not found.");
                return;
            }

            _playQueue.Enqueue(clip);
        }
        private void SetPuzzle(PuzzleSetMB puzzleSetMB)
        {
            var pieceIdList         = puzzleSetMB.puzzlePieceIdList;
            var puzzlePieceInfoList = new List <PuzzlePieceInfo>();

            pieceIdList.ForEach(id =>
            {
                var puzzlePieceMB = ApplicationContext.MasterLoader.Get <PuzzlePieceMB>(id);

                //いずれアセットバンドル化
                Addressables.LoadAsset <Sprite>(puzzlePieceMB.imagePath)
                .Completed += sprite => { puzzlePieceInfoList.Add(new PuzzlePieceInfo(id, sprite.Result)); };
            });

            //ランダムで最初作って、
            if (pazzlePieceList == null || pazzlePieceList.Count == 0)
            {
                return;
            }
            pazzlePieceList.ForEach(parts =>
            {
                int index          = UnityEngine.Random.Range(0, puzzlePieceInfoList.Count - 1);
                var info           = puzzlePieceInfoList[index];
                parts.image.sprite = info.sprite;
                parts.pieceId      = info.id;
            });
            //組み合わせがない場合は作り直す。(繰り返し
            Check();
        }
        private async UniTask Play(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                Debug.unityLogger.LogError(GetType().Name, $"name is null or empty.");
                return;
            }

            AudioClip clip;

            if (_clips.TryGetValue(name, out clip))
            {
                var operation = Addressables.LoadAsset <AudioClip>(name);
                await operation.ToUniTask();

                clip = operation.Result;
            }

            if (clip == null)
            {
                Debug.unityLogger.LogError(GetType().Name, $"{name} is not found.");
                return;
            }

            var source = _sources.FirstOrDefault(x => !x.isPlaying);

            if (source == null)
            {
                Debug.unityLogger.LogWarning(GetType().Name, $"could not play {name}, because of the number of playback.");
                return;
            }

            source.PlayOneShot(clip);
        }
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            m_Fired++;
            if (m_Fired == 1)
            {
                swapToSingle.LoadAsset().Completed += SingleDone;
            }
            else if (m_Fired == 2)
            {
                Addressables.LoadAsset <IList <Sprite> >(spriteSheetAddress).Completed += SheetDone;
            }
        }

        if (sheetEntry != null)
        {
            spriteSheetTest.sprite = sheetEntry;
            sheetEntry             = null;
        }

        if (singleEntry != null)
        {
            singleSpriteTest.sprite = singleEntry;
            singleEntry             = null;
        }
    }
예제 #6
0
 public void InstantiateComponentAsync <T> (string key, Action <RequestResult> callBack, Transform parent = null) where T : UnityEngine.Object
 {
     if (m_allPrefab.ContainsKey(key))
     {
         var obj    = GameObject.Instantiate(m_allPrefab[key], parent);
         var result = GetResult(key, obj.GetComponent <T> ());
         callBack?.Invoke(result);
         return;
     }
     Addressables.LoadAsset <GameObject> (key).Completed += operation => {
         var result = GetResult(key, operation);
         if (result.status == RequestStatus.FAIL)
         {
             callBack?.Invoke(result);
             return;
         }
         if (!m_allPrefab.ContainsKey(key))
         {
             m_allPrefab.Add(key, operation.Result);
         }
         var obj = Object.Instantiate(operation.Result, parent);
         result.result = obj.GetComponent <T> ();
         callBack?.Invoke(result);
     };
 }
예제 #7
0
        protected override void OnUpdate()
        {
            for (int i = 0; i < _moveStateEntry.Length; ++i)
            {
                Entity e = _moveStateEntry.entities[i];
                EntityManager.AddComponent(e, typeof(PlayerMoveStateTag));
                EntityManager.RemoveComponent(e, typeof(PlayerMoveStateEntryTag));
            }

            for (int i = 0; i < _moveState.Length; ++i)
            {
                EntityManager manager = EntityManager;
                Entity        e       = _moveState.entities[i];
                float         angle   = Vector3.SignedAngle(new Vector3(1, 1, 0), math.normalize(_moveState.velocity[i].Value), new Vector3(0, 0, 1));

                //an angle
                angle = angle < 0 ? 360 + angle : angle;

                int index = Mathf.Clamp(Mathf.FloorToInt(angle / 90), 0, 3);

                Addressables.LoadAsset <SpriteAnimations>("playerAnimation").Completed += op2 =>
                {
                    manager.SetSharedComponentData(e, op2.Result.GetAnimation(WalkingAnimName[index]));
                };
            }
        }
        /// <summary>
        /// Loads an object of type T into memory.
        /// </summary>
        /// <typeparam name="T">Type of object to load.</typeparam>
        /// <param name="path">Path of the object to load in the Addressables system.</param>
        /// <returns>Returns an object of type T.</returns>
        public async Task <T> Load <T>(string path) where T : class
        {
            T anyObj = null;

            anyObj = await Addressables.LoadAsset <T>(path);

            return(anyObj);
        }
예제 #9
0
 // Addressable Assets System
 public static UniTask <T> LoadAddressables <T>(object key) where T : class
 {
     return(new UniTask <T>(() =>
     {
         var completionSource = new UniTaskCompletionSource <T>();
         Addressables.LoadAsset <T>(key).Completed += x => completionSource.TrySetResult(x.Result);
         return completionSource.Task;
     }));
 }
예제 #10
0
 void Start()
 {
     Addressables.LoadAsset <GameObject>(Ref).Completed += (handle) => {
         if (handle.Status == AsyncOperationStatus.Succeeded)
         {
             this.Obj = Instantiate(handle.Result, transform.position, Quaternion.identity);
         }
     };
 }
예제 #11
0
	// Use this for initialization
	void Start () {
        Addressables.LoadAsset<GameObject>("Point").Completed += op =>
        {
            Debug.Log(op.Result);
            _pointPrefab = op.Result;

            Main();
        };
	}
예제 #12
0
    public static IEnumerator LoadAssets()
    {
        var loadAssetRoutine = Addressables.LoadAsset <Material>(PLAYER_CLONE_MATERIAL_ADDRESS);

        yield return(loadAssetRoutine);

        Debug.Assert(loadAssetRoutine.Status == AsyncOperationStatus.Succeeded, "Failed to load player clone material");
        playerCloneMaterial = loadAssetRoutine.Result;
    }
 /// <summary>
 /// Force the table to load all assets(if they are not already loading or loaded.
 /// </summary>
 public virtual void LoadAllAssets()
 {
     foreach (var item in AssetMap.Values)
     {
         if (item.AsyncOperation == null && item.GuidHash.isValid)
         {
             item.AsyncOperation = Addressables.LoadAsset <TObject>(item.GuidHash);
         }
     }
 }
예제 #14
0
 public void LoadAddressableAsset(string address, OnAssetLoadedAction <UObject> callback)
 {
     Addressables.LoadAsset <UObject>(address).Completed += (opr) =>
     {
         if (callback != null)
         {
             callback(opr.Result);
         }
     };
 }
    /// <summary>
    /// Use the Addressables system if in real play, use `AssetDatabase` if in edit mode.
    /// </summary>
    /// <param name="key">Addressable key</param>
    /// <param name="pathForEditor">This starts with "Assets/..." and you need the file extension as well.</param>
    public static async UniTask <T> LoadAssetX <T>(string key, string pathForEditor)
        where T : UnityEngine.Object
    {
#if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            return(AssetDatabase.LoadAssetAtPath <T>(pathForEditor));
        }
#endif
        return(await Addressables.LoadAsset <T>(key));
    }
예제 #16
0
    public PlayerCloneState(Player src)
    {
        Rotation = src.Controller.Rotation;
        Origin   = src.Controller.Origin;
        //MEGA HACK GARBAGE
        clonedMesh = src.Controller.transform.Find("Object").Find("character").GetComponent <MeshFilter>(); //EWWW

        if (playerCloneMaterial == null)
        {
            playerCloneMaterial = Addressables.LoadAsset <Material>(PLAYER_CLONE_MATERIAL_ADDRESS).Result;
        }
    }
예제 #17
0
    void Start()
    {
        Addressables.LoadAsset <GameObject>("Gnome").Completed += (handle) => {
            if (handle.Status == AsyncOperationStatus.Succeeded)
            {
                this.gnomePrefab = handle.Result;
                Reset();
            }
        };

        //Reset();
    }
예제 #18
0
        static IEnumerator <JSonEnemyAttackData[]> ReadEnemyAttackDataServiceRequest()
        {
            var json = Addressables.LoadAsset <TextAsset>("EnemyAttackData");

            while (json.IsDone == false)
            {
                yield return(null);
            }

            var enemiestoSpawn = JsonHelper.getJsonArray <JSonEnemyAttackData>(json.Result.text);

            yield return(enemiestoSpawn);
        }
예제 #19
0
 public void InstantiateConfigAsync(string key, Action <RequestResult> callBack, Transform parent = null)
 {
     Addressables.LoadAsset <ScriptableObject> (key).Completed += operation => {
         var result = GetResult(key, operation);
         if (result.status == RequestStatus.FAIL)
         {
             callBack?.Invoke(result);
             return;
         }
         result.result = Object.Instantiate(operation.Result, parent);
         callBack?.Invoke(result);
     };
 }
예제 #20
0
 public void InstantiateAsync <T> (string key, Action <RequestResult> callBack, Transform parent = null) where T : UnityEngine.Object
 {
     Addressables.LoadAsset <T> (key).Completed += operation => {
         var result = GetResult(key, operation);
         if (result.status == RequestStatus.FAIL)
         {
             callBack?.Invoke(result);
             return;
         }
         result.result = Object.Instantiate(operation.Result, parent);
         callBack?.Invoke(result);
     };
 }
    // Use this for initialization
    IEnumerator Start()
    {
        var aop = Addressables.LoadAsset <Texture2D>(m_ref);

        yield return(aop);

        var tex = aop.Result;

        if (tex != null)
        {
            var render = m_obj.GetComponent <Renderer>();
            render.material.SetTexture("_MainTex", tex);
        }
    }
예제 #22
0
        /// <summary>
        /// Returns the named table.
        /// This function is asynchronous and may not have an immediate result.
        /// Check IsDone to see if the data is available, if it is false then use the Completed event or yield on the operation.
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public virtual IAsyncOperation <StringTableBase> GetTable(string tableName)
        {
            IAsyncOperation <StringTableBase> asyncOp;

            if (m_Tables.TryGetValue(tableName, out asyncOp))
            {
                return(asyncOp);
            }

            var tableAddress = $"{LocalizationSettings.SelectedLocale.Identifier.Code} - {tableName}";

            asyncOp             = Addressables.LoadAsset <StringTableBase>(tableAddress);
            m_Tables[tableName] = asyncOp;
            return(asyncOp);
        }
예제 #23
0
        async UniTask <GameObject> ITransitionFactory.Create(string name)
        {
            ObjectPool pool;

            if (!_objectPools.TryGetValue(name, out pool))
            {
                var operation = Addressables.LoadAsset <GameObject>(name);
                await operation.ToUniTask();

                pool = new ObjectPool(_container, operation.Result);
                _objectPools.Add(name, pool);
            }

            return(pool.Spawn());
        }
    // Use this for initialization
    IEnumerator Start()
    {
        m_tex = null;

        var aop = Addressables.LoadAsset <Texture2D>("Assets/AddressableAssets/try3/m_lower_a.bmp");

        aop.Completed += op => { m_tex = aop.Result; };
        yield return(aop);

        if (m_tex != null)
        {
            var render = m_obj.GetComponent <Renderer>();
            render.material.SetTexture("_MainTex", m_tex);
        }
    }
예제 #25
0
        public async Task <GameObject> GetWindowPrefab <T>() where T : UiViewModel
        {
            try
            {
                var AssetName = ConvertGenericName(typeof(T).Name.ToString());
                var window    = await Addressables.LoadAsset <GameObject>(AssetName) as GameObject;

                return(window);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                return(null);
            }
        }
        private async UniTask Play(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                Debug.unityLogger.LogError(GetType().Name, $"name is null or empty");
                return;
            }

            var afterSource = _sources.FirstOrDefault(x => !x.enabled);

            if (afterSource == null)
            {
                Debug.unityLogger.LogWarning(GetType().Name, $"could not play {name}, because of the number of playback.");
                return;
            }

            AudioClip clip;

            if (!_clips.TryGetValue(name, out clip))
            {
                var operation = Addressables.LoadAsset <AudioClip>(name);
                await operation.ToUniTask();

                clip = operation.Result;
                _clips.Add(name, clip);
            }

            if (clip == null)
            {
                Debug.unityLogger.LogError(GetType().Name, $"{name} is not found.");
                return;
            }

            var beforeSource = _sources.FirstOrDefault(x => x.enabled);

            afterSource.enabled = true;
            afterSource.PlayWithFadeIn(clip, 1.0f, _settings.FadeInDuration);

            if (beforeSource == null)
            {
                return;
            }
            await beforeSource.FadeOutAsCoroutine(_settings.FadeOutDuration).ToUniTask();

            beforeSource.Stop();
            beforeSource.enabled = false;
        }
예제 #27
0
    public IEnumerator TestAddressableAsyncLoad()
    {
        yield return(ValidateTestDependency());

        PreInstall();
        AsyncOperationHandle <GameObject> handle = default;

        Container.BindAsync <GameObject>().FromMethod(async() =>
        {
            try
            {
                var locationsHandle = Addressables.LoadResourceLocationsAsync("TestAddressablePrefab");
                await locationsHandle.Task;
                Assert.Greater(locationsHandle.Result.Count, 0, "Key required for test is not configured. Check Readme.txt in addressable test folder");

                IResourceLocation location = locationsHandle.Result[0];
                handle = Addressables.LoadAsset <GameObject>(location);
                await handle.Task;
                return(handle.Result);
            }
            catch (InvalidKeyException)
            {
            }
            return(null);
        }).AsCached();
        PostInstall();

        yield return(null);

        AsyncInject <GameObject> asycFoo = Container.Resolve <AsyncInject <GameObject> >();

        int frameCounter = 0;

        while (!asycFoo.HasResult && !asycFoo.IsFaulted)
        {
            frameCounter++;
            if (frameCounter > 10000)
            {
                Addressables.Release(handle);
                Assert.Fail();
            }
            yield return(null);
        }

        Addressables.Release(handle);
        Assert.Pass();
    }
        /// <summary>
        /// Returns the loading operation for the asset.
        /// Check isDone to see if the asset is available for immediate use, if not you can yield on the operation or add a callback subscriber.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public IAsyncOperation <TObject> GetAssetAsync(string key)
        {
            AssetTableItemData id;

            if (m_ItemsMap.TryGetValue(key, out id) && id.GuidHash.isValid)
            {
                if (id.AsyncOperation == null)
                {
                    var operation = Addressables.LoadAsset <TObject>(id.GuidHash);
                    operation.Retain();
                    id.AsyncOperation = operation;
                }

                return((IAsyncOperation <TObject>)id.AsyncOperation);
            }
            return(null);
        }
예제 #29
0
        /// <summary>
        /// Returns the loading operation for the selected table. If isDone is true then the table can be used immediately
        /// otherwise yield on the operation or use the callback to wait for it to be completed.
        /// </summary>
        public virtual IAsyncOperation <LocalizedAssetTable> GetTable <TObject>(string tableName) where TObject : Object
        {
            var tables = GetTablesDict(typeof(TObject));
            IAsyncOperation <LocalizedAssetTable> operation;

            if (tables.TryGetValue(tableName, out operation))
            {
                return(operation);
            }

            var tableAddress = string.Format("{0} - {1}", LocalizationSettings.SelectedLocale.Identifier.Code, tableName);
            var asyncOp      = Addressables.LoadAsset <LocalizedAssetTable>(tableAddress);

            asyncOp.Retain();
            tables[tableName] = asyncOp;
            return(asyncOp);
        }
예제 #30
0
        public IEnumerator <GameObject> Build(string prefabName)
        {
            if (_prefabs.TryGetValue(prefabName, out var go) == false)
            {
                var load = Addressables.LoadAsset <GameObject>(prefabName);

                while (load.IsDone == false)
                {
                    yield return(null);
                }

                go = load.Result;

                _prefabs.Add(prefabName, go);
            }

            yield return(GameObject.Instantiate(go));
        }