Exemplo n.º 1
0
    public async Task Download(string assetName, string label)
    {
        IList <IResourceLocation> Locations = new List <IResourceLocation>();
        //each shop item is a listing
        StringBuilder sb = new StringBuilder("Assets/Shop/").Append(assetName);

        if ("Track" == label)
        {
            sb.Append(".bytes");
        }
        string strPath = sb.ToString();
        await AddressableLocationLoader.GetLocations(label, Locations);

        IResourceLocation loc = Locations.SingleOrDefault(l => l.PrimaryKey.Equals(assetName));
        //StartCoroutine(LoadAsset(loc));
        AsyncOperationHandle <UnityEngine.Object> h = Addressables.LoadAssetAsync <UnityEngine.Object>(strPath);

        h.Completed += handle =>
        {
            if (h.Status == AsyncOperationStatus.Succeeded)
            {
                SaveAddressable(h.Result, assetName, label);
            }
            if (h.Status == AsyncOperationStatus.Failed)
            {
                MarkAddressableForDownload(h.Result, assetName, label);
            }
            Debug.Log(assetName);
        };
    }
    private async Task InitAndWaitUntilLocationLoaded()
    {
        await AddressableLocationLoader.GetAll(_label, AssetLocations);

        foreach (var location in AssetLocations)
        {
        }
    }
Exemplo n.º 3
0
    private async Task InitAndWaitUntilLocLoaded()
    {
        await AddressableLocationLoader.GetAll(_label, AssetLocations);

        foreach (var location in AssetLocations)
        {
            //ASSET LOCATION FULLY LOADED
            Debug.Log(location.PrimaryKey);
        }
    }
    private async Task InitAndWaitUntilLocLoaded(string label)
    {
        await AddressableLocationLoader.GetAll(label, AssetLocations);

        foreach (var location in AssetLocations)
        {
            // Asset location fully loaded.
            Debug.Log("LoadedAddressableLocations.InitAndWaitUntilLocLoaded(): " + location.PrimaryKey);
        }
    }
Exemplo n.º 5
0
        private async Task InitAndWaitUntilLoaded(string label)
        {
            await AddressableLocationLoader.GetAll(label, locations);

            foreach (var location in locations)
            {
                await LoadingGameObject(location.PrimaryKey);

                Debug.Log(location.PrimaryKey + " is loaded");
            }

            Debug.Log("All Object is loaded");
        }
Exemplo n.º 6
0
    //ShopItems are id, name, type, category, cost, licence, image, Addressable
    public async Task <List <ShopItem> > ListShopItemsAsync()
    {
        Sprite _icon = null;
        //get the location of the ShopIcons AssetBundle;
        Task  GetLocsTask = AddressableLocationLoader.GetLocations("ShopIcon", _spriteLocs);
        await GetLocsTask;
        //Get the ShopItems json file
        AsyncOperationHandle <TextAsset> MyH = Addressables.LoadAssetAsync <TextAsset>("ShopItems");
        await MyH.Task;
        string jsn = MyH.Result.text;
        List <ShopItemSerial> _shopItems = JsonHelper.FromJson <ShopItemSerial>(jsn).ToList();
        List <ShopItem>       List       = new List <ShopItem>();

        //await hs.Task;
        foreach (var i in _shopItems)
        {
            ShopItemType _type = (ShopItemType)Enum.Parse(typeof(ShopItemType), i.ShopItemType);
            if (i.Addressable && i.ShopItemType != "Track")
            {
                AsyncOperationHandle <Sprite> _iconHandle = Addressables.LoadAssetAsync <Sprite>("Assets/Shop/Icons/CarType" + i.Name + ".png");
                await _iconHandle.Task;
                _icon = _iconHandle.Result;
                Addressables.Release(_iconHandle);
            }
            else
            {
                if (_type == ShopItemType.Scenery || _type == ShopItemType.Road || _type == ShopItemType.Fence)
                {
                    _icon = Resources.Load <Sprite>("Sprites/ToolIcons/ToolType" + i.Name);
                }
                else if (_type == ShopItemType.Camera)
                {
                    _icon = Resources.Load <Sprite>("Sprites/ToolIcons/CamType" + i.Name);
                }
                else if (_type == ShopItemType.Car)
                {
                    _icon = Resources.Load <Sprite>("Sprites/ToolIcons/CarType" + i.Name);
                }
            }

            /*
             * else
             * {
             *  if (type == ShopItemType.Scenery || type == ShopItemType.Road || type == ShopItemType.Fence)
             *      Image = Resources.Load<Sprite>("Sprites/ToolIcons/ToolType" + name);
             *  else if (type == ShopItemType.Camera)
             *      Image = Resources.Load<Sprite>("Sprites/ToolIcons/CamType" + name);
             *  else if (type == ShopItemType.Car)
             *  {
             *      if (name == "Banglia")
             *          Image = ShopItemReader.GetIcon(name).Result;
             *      else
             *          Image = Resources.Load<Sprite>("Sprites/ToolIcons/CarType" + name);
             *  }
             * }
             */
            List.Add(new ShopItem(i.Id, _type, i.Name, i.Category, i.Licence, i.Cost, i.Addressable, _icon));
        }
        Addressables.Release(MyH);
        return(List);
    }