public static void AddEffectSprite(string spriteName, string path) { Action <UnityEngine.Object> callback = (asset) => { if (asset != null) { GameObject go = asset as GameObject; SpriteAsset sa = go.GetComponent <SpriteAsset>(); Sprite sprite = sa.GetSpriteByName(spriteName); if (sprite == null) { Debug.LogWarning("The sprite asset " + spriteName + " not in Atlas"); } else { if (!effectsMap.ContainsKey(spriteName)) { effectsMap.Add(spriteName, sprite); } } } else { Debug.LogWarning("Failed to load Font " + spriteName); } }; //AssetUtility.ResourceManager.AsyncLoadResourceAndCleanUp(path, false, false, callback); }
public static void AddEffectSpriteObj(string spriteName, GameObject resObj) { if (effectsMap.ContainsKey(spriteName)) { return; } if (resObj == null) { return; } SpriteAsset sa = resObj.GetComponent <SpriteAsset>(); if (sa == null) { return; } Sprite sprite = sa.GetSpriteByName(spriteName); if (sprite == null) { Debug.LogWarning("The sprite asset " + spriteName + " not in Atlas"); } else { effectsMap.Add(spriteName, sprite); } }
static int GetSpriteByName(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); SpriteAsset obj = (SpriteAsset)ToLua.CheckObject <SpriteAsset>(L, 1); string arg0 = ToLua.CheckString(L, 2); UnityEngine.Sprite o = obj.GetSpriteByName(arg0); ToLua.PushSealed(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// 设置一个Image组件的Sprite为某个图集中的图片 /// </summary> /// <param name="atlasID"></param>图集的资源ID /// <param name="image"></param>要设置的Image组件 /// <param name="spriteName"></param>图集中对应的Sprite的名称 /// <param name="keepNativeSize"></param>是否保持原始尺寸 public static void SetImageSpriteFromAtlas(int atlasID, Image image, string spriteName, bool keepNativeSize) { if (null == image) { Debug.LogWarning("需要指定一个image"); return; } if (string.IsNullOrEmpty(spriteName)) { Debug.LogWarning("需要指定一个SpriteName"); return; } if (image.overrideSprite && image.overrideSprite.name == spriteName) { return; } GameObject atlasObj = ResourceMgr.GetInstance().GetResourceById <GameObject>(atlasID); if (null != atlasObj) { SpriteAsset spriteAsset = atlasObj.GetComponent <SpriteAsset>(); if (null != spriteAsset) { Sprite sprite = spriteAsset.GetSpriteByName(spriteName); if (null != sprite) { image.overrideSprite = sprite; if (keepNativeSize) { image.SetNativeSize(); } } } } }