Beispiel #1
0
 protected Sprite GetSpriteByName(IconBeanDictionary dicIcon, ref SpriteAtlas spriteAtlas, string atlasName, string assetBundlePath, string name)
 {
     if (name == null)
     {
         return(null);
     }
     //从字典获取sprite
     if (dicIcon.TryGetValue(name, out Sprite value))
     {
         return(value);
     }
     //如果字典没有 尝试从atlas获取sprite
     if (spriteAtlas != null)
     {
         Sprite itemSprite = GetSpriteByName(name, spriteAtlas);
         if (itemSprite != null)
         {
             dicIcon.Add(name, itemSprite);
         }
         return(itemSprite);
     }
     //如果没有atlas 先加载atlas
     spriteAtlas = LoadAssetUtil.SyncLoadAsset <SpriteAtlas>(assetBundlePath, atlasName);
     //加载成功后在读取一次
     if (spriteAtlas != null)
     {
         return(GetSpriteByName(dicIcon, ref spriteAtlas, atlasName, assetBundlePath, name));
     }
     return(null);
 }
Beispiel #2
0
    protected Sprite GetSpriteDataByName(int type, string name)
    {
        if (name == null)
        {
            return(null);
        }

        IconBeanDictionary dicData    = null;
        SpriteAtlas        spriteData = null;
        string             atlasName  = "";

        switch (type)
        {
        case 1:
            atlasName  = "AtlasForMask";
            dicData    = listIconMask;
            spriteData = maskAtlas;
            break;

        case 2:
            atlasName  = "AtlasForHat";
            dicData    = listIconHat;
            spriteData = hatAtlas;
            break;

        case 3:
            atlasName  = "AtlasForClothes";
            dicData    = listIconClothes;
            spriteData = clothesAtlas;
            break;

        case 4:
            atlasName  = "AtlasForShoes";
            dicData    = listIconShoes;
            spriteData = shoesAtlas;
            break;
        }
        Sprite itemSprite = GetSpriteByName(dicData, ref spriteData, atlasName, ProjectConfigInfo.ASSETBUNDLE_SPRITEATLAS, name, "Assets/Texture/SpriteAtlas/" + atlasName + ".spriteatlas");

        switch (type)
        {
        case 1:
            maskAtlas = spriteData;
            break;

        case 2:
            hatAtlas = spriteData;
            break;

        case 3:
            clothesAtlas = spriteData;
            break;

        case 4:
            shoesAtlas = spriteData;
            break;
        }
        return(itemSprite);
    }
    protected Sprite GetSpriteDataByName(int type, string name)
    {
        if (name == null)
        {
            return(null);
        }
        IconBeanDictionary dicData    = null;
        SpriteAtlas        spriteData = null;
        string             atlasName  = "";

        switch (type)
        {
        case 1:
            atlasName  = "AtlasForTrunk";
            dicData    = listIconBodyTrunk;
            spriteData = trunkAtlas;
            break;

        case 2:
            atlasName  = "AtlasForHair";
            dicData    = listIconBodyHair;
            spriteData = hairAtlas;
            break;

        case 3:
            atlasName  = "AtlasForEye";
            dicData    = listIconBodyEye;
            spriteData = eyeAtlas;
            break;

        case 4:
            atlasName  = "AtlasForMouth";
            dicData    = listIconBodyMouth;
            spriteData = mouthAtlas;
            break;
        }
        Sprite spData = GetSpriteByName(dicData, ref spriteData, atlasName, ProjectConfigInfo.ASSETBUNDLE_SPRITEATLAS, name, "Assets/Texture/SpriteAtlas/" + atlasName + ".spriteatlas");

        switch (type)
        {
        case 1:
            trunkAtlas = spriteData;
            break;

        case 2:
            hairAtlas = spriteData;
            break;

        case 3:
            eyeAtlas = spriteData;
            break;

        case 4:
            mouthAtlas = spriteData;
            break;
        }
        return(spData);
    }
Beispiel #4
0
 /// <summary>
 /// 根据指定文件添加字典
 /// </summary>
 /// <param name="filePath"></param>
 /// <param name="map"></param>
 public static void AddIconBeanDictionaryByFile(string filePath, IconBeanDictionary map)
 {
     Object[] objs = AssetDatabase.LoadAllAssetsAtPath(filePath);
     objs.ToList().ForEach(obj =>
     {
         if (obj as Sprite != null)
         {
             map.Add(obj.name, obj as Sprite);
         }
     });
 }
Beispiel #5
0
    /// <summary>
    ///  图标字典转List
    /// </summary>
    /// <param name="map"></param>
    /// <returns></returns>
    public static List <IconBean> IconBeanDictionaryToList(IconBeanDictionary map)
    {
        List <IconBean> listData = new List <IconBean>();

        foreach (string key in map.Keys)
        {
            IconBean iconBean = new IconBean
            {
                key   = key,
                value = map[key]
            };
            listData.Add(iconBean);
        }
        return(listData);
    }
Beispiel #6
0
 /// <summary>
 /// 通过名字获取Icon
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public virtual Sprite GetSpriteByName(string name, IconBeanDictionary map)
 {
     if (name == null)
     {
         return(null);
     }
     if (map.TryGetValue(name, out Sprite spIcon))
     {
         return(spIcon);
     }
     else
     {
         return(null);
     }
 }
Beispiel #7
0
 /// <summary>
 /// 根据文件夹下所有文件添加字典
 /// </summary>
 /// <param name="folderPath"></param>
 /// <param name="mapFood"></param>
 public static void AddIconBeanDictionaryByFolder(string folderPath, IconBeanDictionary map)
 {
     FileInfo[] files = FileUtil.GetFilesByPath(folderPath);
     foreach (FileInfo item in files)
     {
         Object[] objs = AssetDatabase.LoadAllAssetsAtPath(folderPath + item.Name);
         objs.ToList().ForEach(obj =>
         {
             if (obj as Sprite != null)
             {
                 map.Add(obj.name, obj as Sprite);
             }
         });
     }
 }
Beispiel #8
0
    protected Sprite GetSpriteByName(IconBeanDictionary dicIcon, ref SpriteAtlas spriteAtlas, string atlasName, string assetBundlePath, string name, string remarkResourcesPath)
    {
        if (name == null)
        {
            return(null);
        }
        //从字典获取sprite
        if (dicIcon.TryGetValue(name, out Sprite value))
        {
            return(value);
        }
        //如果字典没有 尝试从atlas获取sprite
        if (spriteAtlas != null)
        {
            Sprite itemSprite = GetSpriteByName(name, spriteAtlas);
            if (itemSprite != null)
            {
                dicIcon.Add(name, itemSprite);
            }
            return(itemSprite);
        }
#if UNITY_EDITOR
        //编辑器模式下直接加载资源
        if (!remarkResourcesPath.IsNull())
        {
            spriteAtlas = LoadAssetUtil.LoadAssetAtPathForEditor <SpriteAtlas>(remarkResourcesPath);
        }
        else
        {
            //如果没有atlas 先加载atlas
            spriteAtlas = LoadAssetUtil.SyncLoadAsset <SpriteAtlas>(assetBundlePath, atlasName);
            //spriteAtlas = LoadResourcesUtil.SyncLoadData<SpriteAtlas>(assetBundlePath+ atlasName);
        }
#else
        //如果没有atlas 先加载atlas
        spriteAtlas = LoadAssetUtil.SyncLoadAsset <SpriteAtlas>(assetBundlePath, atlasName);
        //spriteAtlas = LoadResourcesUtil.SyncLoadData<SpriteAtlas>(assetBundlePath + atlasName);
#endif

        //加载成功后在读取一次
        if (spriteAtlas != null)
        {
            return(GetSpriteByName(dicIcon, ref spriteAtlas, atlasName, assetBundlePath, name, remarkResourcesPath));
        }
        return(null);
    }
Beispiel #9
0
 protected Sprite GetSpriteByName(IconBeanDictionary dicIcon, ref SpriteAtlas spriteAtlas, string atlasName, string assetBundlePath, string name)
 {
     return(GetSpriteByName(dicIcon, ref spriteAtlas, atlasName, assetBundlePath, name, null));
 }