예제 #1
0
    protected void GetSpriteByName(Dictionary <string, Sprite> dicIcon, SpriteAtlas spriteAtlas, string resName, string name, Action <SpriteAtlas> callBackForSpriteAtlas, Action <Sprite> callBackForSprite)
    {
        if (name == null)
        {
            return;
        }
        //从字典获取sprite
        if (dicIcon.TryGetValue(name, out Sprite value))
        {
            callBackForSprite?.Invoke(value);
            return;
        }
        //如果字典没有 尝试从atlas获取sprite
        if (spriteAtlas != null)
        {
            Sprite itemSprite = GetSpriteByName(name, spriteAtlas);
            if (itemSprite != null)
            {
                dicIcon.Add(name, itemSprite);
            }
            callBackForSprite?.Invoke(itemSprite);
            return;
        }
        Action <AsyncOperationHandle <SpriteAtlas> > loadCallBack = (data) =>
        {
            if (data.Result != null)
            {
                SpriteAtlas spriteAtlas = data.Result;
                callBackForSpriteAtlas?.Invoke(spriteAtlas);
            }
        };

        LoadAddressablesUtil.LoadAssetAsync(resName, loadCallBack);
    }
예제 #2
0
    protected void GetModelForAddressables <T>(Dictionary <long, T> listModel, long id, string keyName, Action <T> callBack) where T : UnityEngine.Object
    {
        if (keyName == null)
        {
            callBack?.Invoke(null);
            return;
        }

        if (listModel.TryGetValue(id, out T value))
        {
            callBack?.Invoke(value);
            return;
        }

        LoadAddressablesUtil.LoadAssetAsync <T>(keyName, data =>
        {
            if (data.Result != null)
            {
                if (listModel.TryGetValue(id, out T result))
                {
                    callBack?.Invoke(result);
                }
                else
                {
                    listModel.Add(id, data.Result);
                    callBack?.Invoke(data.Result);
                }
            }
        });
    }
예제 #3
0
    public void LoadClipDataByAddressbles(int type, string name, System.Action <AudioClip> completeAction)
    {
        AudioBeanDictionary dicData = new AudioBeanDictionary();

        switch (type)
        {
        case 1:
            dicData = listMusicData;
            break;

        case 2:
            dicData = listSoundData;
            break;

        case 3:
            dicData = listEnvironmentData;
            break;
        }
        if (dicData.TryGetValue(name, out AudioClip audioClip))
        {
            completeAction?.Invoke(audioClip);
            return;
        }
        LoadAddressablesUtil.LoadAssetAsync <AudioClip>(name, (data) =>
        {
            if (data.Result != null)
            {
                dicData.Add(name, data.Result);
            }
            completeAction?.Invoke(data.Result);
        });
    }
예제 #4
0
    /// <summary>
    /// 获取方块网格数据
    /// </summary>
    public MeshDataCustom GetBlockMeshData()
    {
        BlockTypeEnum blockType = GetBlockType();
        TextAsset     textAsset = LoadAddressablesUtil.LoadAssetSync <TextAsset>($"Assets/Prefabs/BlockMeshData/Block{blockType.GetEnumName()}.txt");

        return(JsonUtil.FromJson <MeshDataCustom>(textAsset.text));
    }
예제 #5
0
    private T CreateElement <T>(string name, string key)
    {
        GameObject objModel = LoadAddressablesUtil.LoadAssetSync <GameObject>(key);
        GameObject objRain  = Instantiate(gameObject, objModel);

        objRain.name = name;
        return(objRain.GetComponent <T>());
    }
예제 #6
0
 /// <summary>
 /// 获取生命条模型
 /// </summary>
 /// <returns></returns>
 public GameObject GetCreatureLifeProgressModel()
 {
     if (modelForLifeProgress == null)
     {
         modelForLifeProgress = LoadAddressablesUtil.LoadAssetSync <GameObject>(pathCreatureLifeProgress);
     }
     return(modelForLifeProgress);
 }
예제 #7
0
    /// <summary>
    /// 获取方块的模型
    /// </summary>
    /// <param name="modelName"></param>
    /// <returns></returns>
    public GameObject GetBlockModel(ushort blockId, string modelName)
    {
        GameObject objModel = arrayBlockModel[blockId];

        if (objModel == null)
        {
            objModel = LoadAddressablesUtil.LoadAssetSync <GameObject>($"{pathForBlockModel}/{modelName}.prefab");
            arrayBlockModel[blockId] = objModel;
        }
        return(objModel);
    }
예제 #8
0
 protected void GetModelForAddressables <T>(List <string> listKeyName, Action <IList <T> > callBack) where T : UnityEngine.Object
 {
     if (listKeyName == null)
     {
         callBack?.Invoke(null);
         return;
     }
     LoadAddressablesUtil.LoadAssetsAsync <T>(listKeyName, listData =>
     {
         callBack?.Invoke(listData.Result);
     });
 }
예제 #9
0
    public void RequestAtlas(string tag, System.Action <SpriteAtlas> callback)
    {
        Action <AsyncOperationHandle <SpriteAtlas> > loadCallBack = (data) =>
        {
            if (data.Result != null)
            {
                SpriteAtlas spriteAtlas = data.Result;
                if (spriteAtlas != null)
                {
                    callback?.Invoke(spriteAtlas);
                }
            }
        };

        LoadAddressablesUtil.LoadAssetAsync(manager.PathSpriteAtlasForUI, loadCallBack);
        LoadAddressablesUtil.LoadAssetAsync(manager.PathSpriteAtlasForItems, loadCallBack);
    }
예제 #10
0
    public void Start()
    {
        //开关角色控制
        //GameControlHandler.Instance.SetPlayerControlEnabled(true);
        //GameHandler.Instance.manager.SetGameState(GameStateEnum.Gaming);
        MeshFilter meshFilter = GetComponent <MeshFilter>();

        TextAsset      textAsset      = LoadAddressablesUtil.LoadAssetSync <TextAsset>($"Assets/Prefabs/BlockMeshData/BlockCraftingTableSimple.txt");
        MeshDataCustom meshDataCustom = JsonUtil.FromJson <MeshDataCustom>(textAsset.text);
        Mesh           mesh           = meshFilter.mesh;

        mesh.vertices  = meshDataCustom.mainMeshData.vertices;
        mesh.uv        = meshDataCustom.mainMeshData.uv;
        mesh.triangles = meshDataCustom.mainMeshData.triangles;
        mesh.RecalculateNormals();
        mesh.RecalculateTangents();
        mesh.RecalculateBounds();


        meshFilter.mesh = mesh;
    }
예제 #11
0
    /// <summary>
    /// 加载资源
    /// </summary>
    public void LoadResources(Action callBack)
    {
        //加载所有方块材质球
        LoadAddressablesUtil.LoadAssetsAsync <Material>(pathForBlockMats, (data) =>
        {
            IList <Material> listMat = data.Result;
            arrayBlockMat            = new Material[listMat.Count];
            for (int i = 0; i < listMat.Count; i++)
            {
                //按照名字中的下标 确认每个材质球的顺序
                Material itemMat        = listMat[i];
                string[] nameList       = itemMat.name.SplitForArrayStr('_');
                int indexMat            = int.Parse(nameList[1]);
                arrayBlockMat[indexMat] = itemMat;
            }

            //加载方块破碎模型
            LoadAddressablesUtil.LoadAssetAsync <GameObject>(pathForBlockCptBreak, (obj) =>
            {
                blockBreakModel = obj.Result;
                callBack?.Invoke();
            });
        });
    }