private void Start()
    {
        string[] directions =
        { "", "E", "ES", "ESW", "EW", "N", "NE", "NES", "NESW", "NEW", "NS", "NSW", "NW", "S", "SW", "W" };
        foreach (var wallName in WallNames)
        {
            foreach (var direction in directions)
            {
                var address      = string.Format("Assets/Sprites/Walls/{0}.png[{0}_{1}]", wallName, direction);
                var SpriteHandle = Addressables.LoadAssetAsync <Sprite>(address);
                SpriteHandle.Completed += WallSprite_Completed;
            }
        }

        _maxWallTiles = directions.Length * WallNames.Count;

        var atlasAddress      = "Assets/Sprites/Terrain/Terrain.spriteatlas";
        var SpriteAtlasHandle = Addressables.LoadAssetAsync <SpriteAtlas>(atlasAddress);

        SpriteAtlasHandle.Completed += TerrainSpriteAtlas_Completed;

        atlasAddress                 = "Assets/Sprites/Objects/Furniture.spriteatlas";
        SpriteAtlasHandle            = Addressables.LoadAssetAsync <SpriteAtlas>(atlasAddress);
        SpriteAtlasHandle.Completed += FurnitureSpriteAtlas_Completed;

        foreach (var adress in spriteAtlasAddress)
        {
            var atlasedSpriteAddress = adress;
            Addressables.LoadAssetAsync <SpriteAtlas>(atlasedSpriteAddress).Completed += SpriteAtlasLoaded;
        }
    }
    public void Initialize(ScenarioObject a_ScenarioObject, GameReferences a_GameReferences)
    {
        m_GameReferences = a_GameReferences;

        gameObject.name = a_ScenarioObject.Template.Name;

        m_SpriteRenderer.sortingOrder = -32767 + a_ScenarioObject.SortOrder;

        uint _ColorIndex = a_ScenarioObject.DwellingOwner;

        // Seems neutral objects can represent multiple different values
        if (_ColorIndex > 8)
        {
            _ColorIndex = 8;
        }

        m_SpriteRenderer.material.SetColor("_PlayerColor", m_PlayerColors.Colors[_ColorIndex]);

        var _Operation = Addressables.LoadAssetAsync <MapObjectVisualData>($"MapObjects/{gameObject.name}.asset");

        // Synchonously, because underground objects are initially disabled, which break their coroutines
        MapObjectVisualData _Data = _Operation.WaitForCompletion();

        if (_Operation.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Failed)
        {
            Debug.Log(gameObject.name);
        }
        else
        {
            m_Renderer.SetSprites(_Operation.Result.Sprites);
            m_ShadowRenderer.SetSprites(_Operation.Result.ShadowSprites);
        }
    }
    public static T LoadAsset <T>(string path)
    {
        var handle = Addressables.LoadAssetAsync <T>(path);

        //实现同步加载的API
        return(handle.WaitForCompletion());
    }
Example #4
0
    public void Add <T>(object key, System.Action <UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle <T> > onComplete = null)
    {
        var h = Addressables.LoadAssetAsync <T>(key);

        h.Completed += onComplete;
        handles.Add(h);
    }
Example #5
0
    public void RegisterButtonClick(GameObject go)
    {
        if (index % 2 == 1)
        {
            AsyncOperationHandle <SpriteAtlas> handle = Addressables.LoadAssetAsync <SpriteAtlas>("QTE");
            // AsyncOperationHandle<Sprite[]> handle = Addressables.LoadAssetAsync<Sprite[]>(atlasName);
            handle.Completed += (op) =>
            {
                if (op.Status == AsyncOperationStatus.Succeeded)
                {
                    atlas = handle.Result;

                    startButton.image.sprite = atlas.GetSprite("ui_button_001");
                    //  if (!_cachedAtlasDict.ContainsKey(atlasName))
                    //     _cachedAtlasDict.Add(atlasName, handle.Result);
                    // image.sprite = _cachedAtlasDict[atlasName].GetSprite(imageName);
                }
            };
        }
        else
        {
            Addressables.Release(atlas);
        }

        index++;
        return;



        // Debug.Log("Try Register! " + nameInput.text);
        // RegisterArgs args = new RegisterArgs();
        // args.account = nameInput.text;
        // NetworkManager.RegisterReq(args, RegisterAck);
    }
Example #6
0
        private async Task <Material> GetMaterialAsync(eTileType tileType)
        {
            switch (tileType)
            {
            case eTileType.Earth:
                return(await Addressables.LoadAssetAsync <Material>("Assets/Addressible/Cubes/Materials/Grass.mat").Task);

            case eTileType.Stone:
                return(await Addressables.LoadAssetAsync <Material>("Assets/Addressible/Cubes/Materials/Grey Stones.mat").Task);

            case eTileType.Ocean:
                return(await Addressables.LoadAssetAsync <Material>("Assets/Addressible/Cubes/Materials/Water Deep Blue.mat").Task);

            case eTileType.Lake:
                return(await Addressables.LoadAssetAsync <Material>("Assets/Addressible/Cubes/Materials/Water Light Blue.mat").Task);

            case eTileType.Tree:
                return(await Addressables.LoadAssetAsync <Material>("Assets/Addressible/Cubes/Materials/Sandy.mat").Task);

            case eTileType.Sand:
                return(await Addressables.LoadAssetAsync <Material>("Assets/Addressible/Cubes/Materials/Sandy Orange.mat").Task);
            }

            return(null);
        }
Example #7
0
        public IEnumerator GetSoundAsync(string key, Action <AudioClip> callback)
        {
            if (!audioDic.ContainsKey(key))
            {
                switch (sourceType)
                {
                case SourceType.Resources:
                    var progress = Resources.LoadAsync <AudioClip>(Path.Combine(soundPath, key).Replace("\\", "/"));
                    yield return(new WaitUntil(() => progress.isDone));

                    audioDic.Add(key, progress.asset as AudioClip);
                    break;

#if ADDRESSABLE_EXISTS
                case SourceType.Addressable:
                    var finalPath = useFormatPath
                            ? string.Format(soundPath, key)
                            : Path.Combine(soundPath, key).Replace("\\", "/");
                    var progress3 = Addressables.LoadAssetAsync <AudioClip>(finalPath);
                    yield return(new WaitUntil(() => progress3.IsDone));

                    audioDic.Add(key, progress3.Result);
                    break;
#endif
                case SourceType.Custom:
                    yield return(provider.GetSound(key, result => { audioDic.Add(key, result); }));

                    break;
                }
            }

            callback(audioDic[key]);
            yield break;
        }
Example #8
0
        void ModifyInteractablePrefabWithVanillaAssets()
        {
            var brokenMtl = Addressables.LoadAssetAsync <Material>("RoR2/Base/Drones/matDroneBrokenGeneric.mat")
                            .WaitForCompletion();

            bulwarkDroneInteractablePrefab.transform.Find("Model Base/BulwarkDrone").GetComponent <MeshRenderer>().material = brokenMtl;
        }
Example #9
0
        protected IEnumerator RunPlayer(string audioName,
                                        float volumeRate,
                                        float delay,
                                        float pitch,
                                        bool isLoop,
                                        Action <AudioSource> callback = null)
        {
            AudioClip current;

            if (!_audioClipDict.ContainsKey(audioName))
            {
                var handle = Addressables.LoadAssetAsync <AudioClip>(audioName);
                yield return(handle);

                current = handle.Result;
                if (_cacheType == AudioCacheType.Used)
                {
                    _audioClipDict[audioName] = current;
                }
            }
            else
            {
                current = _audioClipDict[audioName];
            }
            RunPlayer(current, volumeRate, delay, pitch, isLoop, callback);
        }
Example #10
0
        private IEnumerator Init()
        {
            AsyncOperationHandle <Sprite> horize   = Addressables.LoadAssetAsync <Sprite>("sprite_h");
            AsyncOperationHandle <Sprite> vertical = Addressables.LoadAssetAsync <Sprite>("sprite_v");
            AsyncOperationHandle <Sprite> lu       = Addressables.LoadAssetAsync <Sprite>("sprite_lu");
            AsyncOperationHandle <Sprite> ld       = Addressables.LoadAssetAsync <Sprite>("sprite_ld");
            AsyncOperationHandle <Sprite> ru       = Addressables.LoadAssetAsync <Sprite>("sprite_ru");
            AsyncOperationHandle <Sprite> rd       = Addressables.LoadAssetAsync <Sprite>("sprite_rd");
            AsyncOperationHandle <Sprite> tr       = Addressables.LoadAssetAsync <Sprite>("sprite_tr");

            yield return(horize);

            yield return(vertical);

            yield return(lu);

            yield return(ld);

            yield return(ru);

            yield return(rd);

            yield return(tr);

            // 设置图片
            sprite_h  = horize.Result;
            sprite_v  = vertical.Result;
            sprite_lu = lu.Result;
            sprite_ld = ld.Result;
            sprite_ru = ru.Result;
            sprite_rd = rd.Result;
            sprite_tr = tr.Result;
        }
Example #11
0
        public static OperationHandle Load <T>(AssetReference assetRef, System.Action <T> onComplete) where T : UnityEngine.Object
        {
            AsyncOperationHandle <T> ao = Addressables.LoadAssetAsync <T>(assetRef);

            ao.Completed += (x) => { onComplete?.Invoke(x.Result); };
            return(new OperationHandle(ao));
        }
Example #12
0
    public void OnButtonClick()
    {
        button.interactable = false;
        m_ClickCount++;
        switch (m_ClickCount)
        {
        case 1:
            singleSpriteReference.LoadAssetAsync <Sprite>().Completed += SingleDone;
            break;

        case 2:
            spriteSheetReference.LoadAssetAsync <IList <Sprite> >().Completed += SheetDone;
            break;

        case 3:
            spriteAtlasReference.LoadAssetAsync().Completed += AtlasDone;
            break;

        case 4:
            spriteSubAssetReference.LoadAssetAsync <Sprite>().Completed += SheetSubDone;
            break;

        case 5:
            atlasSubAssetReference.LoadAssetAsync <Sprite>().Completed += AtlasSubDone;
            break;

        case 6:
            Addressables.LoadAssetAsync <Sprite>("sheet[sprite_sheet_4]").Completed += SheetNameSubDone;
            break;

        case 7:
            Addressables.LoadAssetAsync <Sprite>("Atlas[u7]").Completed += AtlasNameSubDone;
            break;
        }
    }
        public IEnumerator LoadAllSpriteAtlas(List <string> spriteAltas)
        {
            Debug.Log("LoadAllSpriteAtlas");
            if (spriteAltas == null || spriteAltas.Count <= 0)
            {
                yield break;
            }

            foreach (var sa in spriteAltas)
            {
                var fileName = Path.GetFileNameWithoutExtension(sa);
                if (!m_spriteAtlasHandle.ContainsKey(fileName))
                {
                    var handle = Addressables.LoadAssetAsync <SpriteAtlas>(sa);
                    handle.Completed += OnSpriteAtlasLoaded;
                    m_spriteAtlasHandle.Add(sa, handle);
                    m_requestedCount++;
                }
            }

            yield return(new WaitUntil(() =>
            {
                while (m_requestedCount > 0)
                {
                    return false;
                }
                return true;
            }));
        }
Example #14
0
 internal static void RegisterBuffs()
 {
     Buffs.TemplArmorBuff             = Buffs.AddNewBuff("TemplArmorBuff", Addressables.LoadAssetAsync <BuffDef>("RoR2/Base/RoboBallBoss/bdEngiShield.asset").WaitForCompletion().iconSprite, new Color(0.54f, 0.21f, 0.12f), false, false);
     Buffs.TemplarstationaryArmorBuff = Buffs.AddNewBuff("TemplarstationaryArmorBuff", Addressables.LoadAssetAsync <BuffDef>("RoR2/Base/RoboBallBoss/bdEngiShield.asset").WaitForCompletion().iconSprite, new Color(0.74f, 0.41f, 0.32f), false, false);
     Buffs.TemplarigniteDebuff        = Buffs.AddNewBuff("TemplarScorchedDebuff", Addressables.LoadAssetAsync <BuffDef>("RoR2/Base/ArmorReductionOnHit/bdPulverized.asset").WaitForCompletion().iconSprite, new Color(0.3f, 0.3f, 0.3f), false, true);
     Buffs.TemplarOverdriveBuff       = Buffs.AddNewBuff("TemplarOverdriveBuff", Addressables.LoadAssetAsync <BuffDef>("RoR2/Base/WarCryOnMultiKill/bdWarCryBuff.asset").WaitForCompletion().iconSprite, new Color(0.84f, 0.51f, 0.42f), false, false);
 }
        public override void SetupAttributes()
        {
            base.SetupAttributes();

            var captainSD = LegacyResourcesAPI.Load <SkillDef>("SkillDefs/CaptainBody/CaptainSkillUsedUp");

            disabledSkillDef = SkillUtil.CloneSkillDef(captainSD);
            disabledSkillDef.skillNameToken               = "TKSAT_DISABLED_SKILL_NAME";
            disabledSkillDef.skillDescriptionToken        = "TKSAT_DISABLED_SKILL_DESCRIPTION";
            disabledSkillDef.dontAllowPastMaxStocks       = false;
            disabledSkillDef.beginSkillCooldownOnSkillEnd = true;

            ContentAddition.AddSkillDef(disabledSkillDef);

            tauntDebuff            = ScriptableObject.CreateInstance <BuffDef>();
            tauntDebuff.buffColor  = Color.white;
            tauntDebuff.canStack   = false;
            tauntDebuff.isDebuff   = true;
            tauntDebuff.name       = "TKSATTaunt";
            tauntDebuff.iconSprite = Addressables.LoadAssetAsync <Sprite>("RoR2/Base/Common/MiscIcons/texAttackIcon.png")
                                     .WaitForCompletion();
            ContentAddition.AddBuffDef(tauntDebuff);

            R2API.Networking.NetworkingAPI.RegisterMessageType <ServerTimedSkillDisable.MsgApply>();
            R2API.Networking.NetworkingAPI.RegisterMessageType <ServerTimedSkillDisable.MsgRemove>();
        }
Example #16
0
    public void SpawnObjects()
    {
        if (_spawnedObjects.Count > 0)
        {
            DeSpawnObjects();
        }
        if (!ObjectToSpawn.RuntimeKeyIsValid())
        {
            return;
        }

        // load object
        _loadOperationHandle            = Addressables.LoadAssetAsync <GameObject>(ObjectToSpawn);
        _loadOperationHandle.Completed += (operation) =>
        {
            Vector3 spawnPos;
            // then instantiate
            for (int i = 0; i < _spawnColumns * _spawnRows; i++)
            {
                spawnPos = transform.position + i % _spawnColumns * transform.right * _columnOffset + i / _spawnColumns * transform.forward * _rowOffset;
                ObjectToSpawn.InstantiateAsync(spawnPos, Quaternion.identity, transform).Completed += (asyncOpHandle) =>
                {
                    _spawnedObjects.Add(asyncOpHandle.Result);
                };
            }
        };
    }
        IEnumerator LoadAndAssociateResultWithKey(IList <string> keys)
        {
            if (operationDictionary == null)
            {
                operationDictionary = new Dictionary <string, AsyncOperationHandle <GameObject> >();
            }

            AsyncOperationHandle <IList <IResourceLocation> > locations
                = Addressables.LoadResourceLocationsAsync(keys,
                                                          Addressables.MergeMode.Union, typeof(GameObject));

            yield return(locations);

            var loadOps = new List <AsyncOperationHandle>(locations.Result.Count);

            foreach (IResourceLocation location in locations.Result)
            {
                AsyncOperationHandle <GameObject> handle =
                    Addressables.LoadAssetAsync <GameObject>(location);
                handle.Completed += obj => operationDictionary.Add(location.PrimaryKey, obj);
                loadOps.Add(handle);
            }

            yield return(Addressables.ResourceManager.CreateGenericGroupOperation(loadOps, true));

            Ready.Invoke();
        }
Example #18
0
        protected override void OnCreate()
        {
            Entities.ForEach(
                (ref PlayerInputData playerData) =>
            {
                playerData.cameraMovement = Vector2.zero;
                playerData.playerMovement = Vector2.zero;
                playerData.exitPressed    = false;
            }).Run();

            Entities.ForEach((ref AnalogInputData analogData) =>
            {
                analogData.direction    = AnalogType.NONE;
                analogData.holdingUp    = false;
                analogData.holdingDown  = false;
                analogData.holdingLeft  = false;
                analogData.holdingRight = false;
            }).Run();

            Entities.ForEach((ref ToolsInputData toolsData) =>
            {
                toolsData.grabMode   = false;
                toolsData.selectMode = false;
            }).Run();

            // Cargo la configuración de controles
            Addressables.LoadAssetAsync <InputSettings>("Assets/Settings/InputSettings.asset").Completed +=
                handle => input = handle.Result;
        }
Example #19
0
    public IEnumerator LoadAsset <T>(Action <T> callback)
    {
        lastLoadTime = DateTime.Now.Ticks;

        if (!handle.IsValid())
        {
            handle = Addressables.LoadAssetAsync <T>(m_assetPath);
            yield return(handle);
        }
        if (!handle.IsDone)
        {
            yield return(handle);
        }
        if (handle.Status == AsyncOperationStatus.Succeeded)
        {
            if (callback != null)
            {
                loadCount++;
                callback((T)handle.Result);
            }
        }
        else
        {
            YDebuger.LogError("load asset fail " + m_assetPath + " handle state:" + handle.Status);
            if (callback != null)
            {
                callback(default(T));
            }
        }
    }
Example #20
0
        async UniTask <AsyncOperationHandle <T> > IAssetLoader.Load <T>(object key)
        {
            await Exist(key);

            while (true)
            {
                var operation = Addressables.LoadAssetAsync <T>(key);
                await operation.Task;
                if (operation.OperationException != null)
                {
                    var errorResult = await errorRequester.Request(ErrorMessage.Create(ErrorStatus.Fatal, operation.OperationException));

                    if (errorResult == ErrorResult.Retry)
                    {
                        continue;
                    }
                    else if (errorResult == ErrorResult.Error)
                    {
                        throw operation.OperationException;
                    }
                }

                return(operation);
            }
        }
Example #21
0
        public IEnumerator GetDialogueAsync(string key, Action <string> callback)
        {
            switch (sourceType)
            {
            case SourceType.Resources:
                var progress = Resources.LoadAsync <TextAsset>(Path.Combine(dialoguePath, key).Replace("\\", "/"));
                yield return(new WaitUntil(() => progress.isDone));

                var ta = progress.asset as TextAsset;
                callback(ta.text);
                break;

#if ADDRESSABLE_EXISTS
            case SourceType.Addressable:
                var finalPath = useFormatPath
                        ? string.Format(dialoguePath, key)
                        : Path.Combine(dialoguePath, key).Replace("\\", "/");
                var progress3 = Addressables.LoadAssetAsync <TextAsset>(finalPath);
                yield return(new WaitUntil(() => progress3.IsDone));

                callback(progress3.Result.text);
                Addressables.Release(progress3);
                break;
#endif
            case SourceType.Custom:
                yield return(provider.GetDialogue(key, result => { callback(result); }));

                break;
            }
        }
        internal AssetReferenceTracker(string _key, AssetReferenceTrackerCallbackDelegate <TObject> _callback)
        {
            handle = Addressables.LoadAssetAsync <TObject>(_key);

            loadingTrackers.Add(handle, new Pair(this, _callback));
            handle.Completed += OnCompleted;
        }
 void Start()
 {
     // Create operation
     opHandle = Addressables.LoadAssetAsync <GameObject>(address);
     // Add event handler
     opHandle.Completed += Operation_Completed;
 }
Example #24
0
        public async UniTask <TObject> LoadAsync <TObject>(string componentId) where TObject : Object
        {
            var handler  = Addressables.LoadAssetAsync <TObject>(componentId);
            var instance = await HandleAddressableCreation(handler);

            return(instance);
        }
        protected override async void OnCreate()
        {
            var configLoader = Addressables.LoadAssetAsync <SimulationConfig>("SimulationConfig");
            await configLoader.Task;

            _decayRate = configLoader.Result.PheromoneDecayRate;
        }
Example #26
0
    public void Initialize(ScenarioObject a_ScenarioObject, GameReferences a_GameReferences)
    {
        m_GameReferences = a_GameReferences;

        gameObject.name = a_ScenarioObject.Template.Name;

        m_SpriteRenderer.sortingOrder = -32767 + a_ScenarioObject.SortOrder;

        if (a_ScenarioObject.Template.IsLowPrioritySortOrder)
        {
            m_SpriteRenderer.sortingLayerName = "MapLowPriorityObjects";
        }

        var _Operation = Addressables.LoadAssetAsync <MapObjectVisualData>($"MapObjects/{gameObject.name}.asset");

        // Synchonously, because underground objects are initially disabled, which break their coroutines
        MapObjectVisualData _Data = _Operation.WaitForCompletion();

        if (_Operation.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Failed)
        {
            Debug.Log(gameObject.name);
        }
        else
        {
            Renderer.SetSprites(_Operation.Result.Sprites);
            ShadowRenderer.SetSprites(_Operation.Result.ShadowSprites);
        }
    }
Example #27
0
    private static void LoadGameObjectAsync <T>(string key, Action <UnityEngine.Object> cb)
    {
        AsyncOperationHandle handler = new AsyncOperationHandle();

        if (mLoadedCbDict.ContainsKey(key) == false)
        {
            mLoadedCbDict[key] = new List <Action <UnityEngine.Object> >();
        }

        mLoadedCbDict[key].Insert(0, cb);

        handler            = Addressables.LoadAssetAsync <T>(key);
        handler.Completed += (AsyncOperationHandle loadedHandler) =>
        {
            if (loadedHandler.Status == AsyncOperationStatus.Succeeded)
            {
                mAssetCacheDict[key] = loadedHandler;
                if (mLoadedCbDict.ContainsKey(key) == false)
                {
                    Debug.LogError("资源加载完成,但回调已经清空" + key);
                    Addressables.Release(handler);
                    return;
                }

                int count = mLoadedCbDict[key].Count;
                for (int i = count - 1; i >= 0; i--)
                {
                    mLoadedCbDict[key][i](loadedHandler.Result as UnityEngine.Object);
                }

                mLoadedCbDict[key].Clear();
            }
        };
    }
Example #28
0
    protected override void OnCreate()
    {
        enemyArchetype = EntityManager.CreateArchetype(
            typeof(LocalToWorld),
            typeof(Translation),
            typeof(Rotation),
            typeof(Velocity),
            typeof(Faction),
            typeof(Health),
            typeof(Cooldown),
            typeof(ColliderComponent),
            typeof(Speed),
            typeof(RenderBounds),
            typeof(RenderMesh),
            typeof(Enemy));
        Addressables.LoadAssetAsync <EnemySettings>("EnemyPrefabs").Completed          += OnEnemyPrefabListLoadComplete;
        Addressables.LoadAssetAsync <EnemyWaveSettings>("EnemyWaveSettings").Completed += OnEnemyWaveSettingsLoadComplete;

        var query = new EntityQueryDesc
        {
            All = new ComponentType[] { typeof(EnemySettingsComponent) }
        };

        enemySettingsEntityQuery = GetEntityQuery(query);

        var enemyQuery = new EntityQueryDesc
        {
            All = new ComponentType[] { typeof(Enemy) }
        };

        enemyEntityQuery = GetEntityQuery(enemyQuery);
    }
 /// <summary>
 /// Load the specified addressable resource
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="name"></param>
 /// <param name="resourceLoadedCallback"></param>
 public async Task <T> LoadResourceAsync <T>(string name)
 {
     //If we already loaded the resource
     if (resources.ContainsKey(name + typeof(T).ToString()))
     {
         //Use it directly
         return((T)resources[name]);
     }
     else
     {
         //Load it
         if (typeof(T) == typeof(SceneInstance))
         {
             //If it is scene, load it to switch current scene
             handles.Add(Addressables.LoadSceneAsync(name));
             T result = default(T);
             return(result);
         }
         else
         {
             var handle = Addressables.LoadAssetAsync <T>(name);
             handles.Add(handle);
             await handle;
             var   resource = handle.Result;
             resources[name + typeof(T).ToString()] = resource;
             return(resource);
         }
     }
 }
Example #30
0
    // Start is called before the first frame update
    async void Start()
    {
        var dll = await Addressables.LoadAssetAsync <TextAsset>(Consts.Paths.HOT_DLL_NAME).Task;

        hotMgr.Init(dll);
        Init(transform);
    }