public static void Add(UIResMgr uiRes, string modName) { if (m_resMgrs.ContainsKey(modName)) { Debug.LogError("重复加载了UIResMgr 模块 : " + modName); return; } m_resMgrs.Add(modName, uiRes); }
static int CalcSpriteDict(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); UIResMgr obj = (UIResMgr)ToLua.CheckObject(L, 1, typeof(UIResMgr)); obj.CalcSpriteDict(); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int Pack(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); UIResMgr obj = (UIResMgr)ToLua.CheckObject(L, 1, typeof(UIResMgr)); System.Collections.Generic.List <UnityEngine.Sprite> arg0 = (System.Collections.Generic.List <UnityEngine.Sprite>)ToLua.CheckObject(L, 2, typeof(System.Collections.Generic.List <UnityEngine.Sprite>)); obj.Pack(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int Get(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); string arg0 = ToLua.CheckString(L, 1); UIResMgr o = UIResTool.Get(arg0); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int Add(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); UIResMgr arg0 = (UIResMgr)ToLua.CheckUnityObject(L, 1, typeof(UIResMgr)); string arg1 = ToLua.CheckString(L, 2); UIResTool.Add(arg0, arg1); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
void LoadPrefabAsync(string modName, string abName, string assetName, LuaFunction func = null, LuaTable tab = null) { ResManager.LoadPrefab(abName, assetName, delegate(UnityEngine.Object[] objs) { if (objs.Length == 0) { return; } GameObject prefab = objs[0] as GameObject; if (prefab == null) { return; } GameObject go = Instantiate(prefab) as GameObject; go.name = assetName; if (assetName == "UIResMgr") { UIResMgr uiResMgr = go.GetComponent <UIResMgr>(); if (uiResMgr == null) { Debug.LogError("abName : " + abName + " assetName : " + assetName + " 没有UIResMgr脚本"); return; } UIResTool.Add(uiResMgr, modName); return; } RectTransform rt = go.GetComponent <RectTransform>(); if (rt != null && m_canvasRoot != null) { rt.SetParent(m_canvasRoot, false); rt.anchorMin = Vector2.zero; rt.anchorMax = Vector2.one; rt.localScale = Vector3.one; rt.anchoredPosition3D = Vector3.zero; rt.sizeDelta = Vector2.zero; m_panels[assetName] = go; //AddSoundFX(panel);//添加UI音效 if (func != null) { func.Call(tab, go); } } }); }
static int GetSprite(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); UIResMgr obj = (UIResMgr)ToLua.CheckObject(L, 1, typeof(UIResMgr)); string arg0 = ToLua.CheckString(L, 2); UnityEngine.Sprite o = obj.GetSprite(arg0); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int get_m_audios(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); UIResMgr obj = (UIResMgr)o; System.Collections.Generic.List <UnityEngine.AudioClip> ret = obj.m_audios; ToLua.PushObject(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index m_audios on a nil value" : e.Message)); } }
static int get_SpriteDict(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); UIResMgr obj = (UIResMgr)o; System.Collections.Generic.Dictionary <string, UnityEngine.Sprite> ret = obj.SpriteDict; ToLua.PushObject(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index SpriteDict on a nil value" : e.Message)); } }
static int set_m_audios(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); UIResMgr obj = (UIResMgr)o; System.Collections.Generic.List <UnityEngine.AudioClip> arg0 = (System.Collections.Generic.List <UnityEngine.AudioClip>)ToLua.CheckObject(L, 2, typeof(System.Collections.Generic.List <UnityEngine.AudioClip>)); obj.m_audios = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index m_audios on a nil value" : e.Message)); } }
static int get_CommonRes(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); UIResMgr obj = (UIResMgr)o; UnityEngine.GameObject ret = obj.CommonRes; ToLua.Push(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index CommonRes on a nil value" : e.Message)); } }
static int set_CommonRes(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); UIResMgr obj = (UIResMgr)o; UnityEngine.GameObject arg0 = (UnityEngine.GameObject)ToLua.CheckUnityObject(L, 2, typeof(UnityEngine.GameObject)); obj.CommonRes = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index CommonRes on a nil value" : e.Message)); } }
public static UIResMgr Get(string modName) { if (!Application.isPlaying) { GameObject prefab = Resources.Load <GameObject>("Prefab/" + modName + "/UIResMgr"); UIResMgr resMgr = prefab.GetComponent <UIResMgr>(); return(resMgr); } else { if (m_resMgrs.ContainsKey(modName)) { return(m_resMgrs[modName]); } Debuger.LogError("未获取到 " + modName + " 模块的资源管理文件"); } return(null); }
IEnumerator LoadPrefab(string modName, string assetName, LuaFunction func = null, LuaTable tab = null) { GameObject prefab = Resources.Load("Prefab/" + modName + "/" + assetName) as GameObject; while (prefab == null) { Debug.Log("加载资源-------" + assetName); yield return(1); } GameObject go = Instantiate(prefab) as GameObject; go.name = assetName; RectTransform rt = go.GetComponent <RectTransform>(); if (rt != null && m_canvasRoot != null) { rt.SetParent(m_canvasRoot); rt.anchorMin = Vector2.zero; rt.anchorMax = Vector2.one; rt.localScale = Vector3.one; rt.anchoredPosition3D = Vector3.zero; rt.sizeDelta = Vector2.zero; m_panels[assetName] = go; //AddSoundFX(panel);//添加UI音效 if (func != null) { func.Call(tab, go); } } if (assetName == "UIResMgr") { UIResMgr uiResMgr = go.GetComponent <UIResMgr>(); if (uiResMgr == null) { Debug.LogError("modName : " + modName + " assetName : " + assetName + " 没有UIResMgr脚本"); yield break; } UIResTool.Add(uiResMgr, modName); } yield break; }
public static void Pack(List<Sprite> sprites) { #if UNITY_EDITOR UIResMgr uiResMgr = instance; HashSet<Sprite> set = new HashSet<Sprite>(); int removeCount = 0; foreach (var sprite in uiResMgr.m_sprites) { if (sprite == null) { ++removeCount; continue; } set.Add(sprite); } Debuger.Log(string.Format("有{0}个已经被删除的sprite", removeCount)); int addCount = 0; foreach(var sprite in sprites ){ if (set.Add(sprite)) ++addCount; } Debuger.Log(string.Format("增加了{0}个sprite", addCount)); uiResMgr.m_sprites.Clear(); foreach (Sprite sprite in set) { uiResMgr.m_sprites.Add(sprite); } UIResMgr.instance.CalcSpriteDict(); UnityEditor.EditorUtility.SetDirty(uiResMgr); UnityEditor.AssetDatabase.Refresh(); UnityEditor.AssetDatabase.SaveAssets(); #endif }
public static Sprite GetSprite(string spriteName) { if (m_commonRes == null) { m_commonRes = Get("Common"); } //现在common里取 Sprite sprite = m_commonRes.GetSprite(spriteName); if (sprite == null) { //没有就在当前模块的图集里取 UIResMgr uiRes = Get(GameManager.GetCurMod()); sprite = uiRes.GetSprite(spriteName); } if (sprite == null) { Debug.LogError("没有找到图片--" + spriteName); } return(sprite); }
void Set() { int i = 0; foreach (TextureImporter tex in m_texs) { CheckRename(tex, m_prefix); if (string.IsNullOrEmpty(m_atlasName)) { tex.textureType = TextureImporterType.Sprite; } else { tex.textureType = TextureImporterType.Default; } tex.npotScale = TextureImporterNPOTScale.None; tex.lightmap = false; tex.normalmap = false; tex.spriteImportMode = SpriteImportMode.Single; tex.spritePackingTag = m_atlasName; tex.borderMipmap = false; tex.linearTexture = false; tex.alphaIsTransparency = true; tex.grayscaleToAlpha = false; tex.isReadable = false; tex.mipmapEnabled = false; tex.generateMipsInLinearSpace = false; tex.wrapMode = TextureWrapMode.Clamp; tex.filterMode = FilterMode.Bilinear; tex.anisoLevel = 1; //if (string.IsNullOrEmpty(m_atlasName) && IsNpot(tex)) //{//单张图而且不是2的n次方的话,自动压缩 // SetFormat(tex, "Standalone", TextureImporterFormat.AutomaticCompressed); // SetFormat(tex, "Android", TextureImporterFormat.AutomaticCompressed); // SetFormat(tex, "iPhone", TextureImporterFormat.AutomaticCompressed); //} //else //{ //SetFormat(tex, "", TextureImporterFormat.ARGB32); //tex.textureFormat = TextureImporterFormat.ARGB32; //SetFormat(tex, "Standalone", TextureImporterFormat.ARGB32); tex.ClearPlatformTextureSettings("Standalone"); SetFormat(tex, "Android", TextureImporterFormat.ETC2_RGBA8); SetFormat(tex, "iPhone", TextureImporterFormat.PVRTC_RGBA4); EditorUtil.SetDirty(tex); //} ++i; EditorUtility.DisplayProgressBar("Loading", string.Format("正在修改格式和重命名,{0}/{1}", i, m_texs.Count), ((float)i / m_texs.Count) * 0.9f); } //根据格式重新导入下资源 foreach (TextureImporter t in m_texs) { AssetDatabase.WriteImportSettingsIfDirty(t.assetPath); } try { AssetDatabase.StartAssetEditing(); i = 0; foreach (TextureImporter t in m_texs) { EditorUtility.DisplayProgressBar("Loading", string.Format("正在重新导出资源:第{0}个,共{1}个", i, m_texs.Count), 0.1f + (0.9f * i) / m_texs.Count); AssetDatabase.WriteImportSettingsIfDirty(t.assetPath); ++i; } } finally { AssetDatabase.StopAssetEditing(); EditorUtility.ClearProgressBar(); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); //检查是不是要重新打包 EditorUtility.DisplayProgressBar("Loading", string.Format("检查打包中"), 0.9f); EditorUtility.ClearProgressBar(); UnityEditor.Sprites.Packer.kDefaultPolicy = "DefaultPackerPolicy";//TightPackerPolicy DefaultPackerPolicy #if UNITY_ANDROID UnityEditor.Sprites.Packer.RebuildAtlasCacheIfNeeded(BuildTarget.Android, true); #endif #if UNITY_IPHONE UnityEditor.Sprites.Packer.RebuildAtlasCacheIfNeeded(BuildTarget.iOS, true); #endif #if UNITY_STANDALONE_WIN UnityEditor.Sprites.Packer.RebuildAtlasCacheIfNeeded(BuildTarget.StandaloneWindows, true); #endif //打包进UI资源管理器中 List <string> path = new List <string>(); foreach (TextureImporter tex in m_texs) { //Debuger.Log("资源路径"+tex.assetPath); path.Add(tex.assetPath); } UIResMgr.PackByPath(path); }
void Set() { int i = 0; foreach (TextureImporter tex in m_texs) { CheckRename(tex, m_atlasName); //if (string.IsNullOrEmpty(m_atlasName)) // tex.textureType = TextureImporterType.Sprite; //else // tex.textureType = TextureImporterType.Default; tex.textureType = TextureImporterType.Sprite; tex.npotScale = TextureImporterNPOTScale.None; tex.spriteImportMode = SpriteImportMode.Single; tex.spritePackingTag = m_atlasName; tex.borderMipmap = false; tex.sRGBTexture = true; tex.alphaIsTransparency = true; tex.isReadable = false; tex.mipmapEnabled = false; tex.wrapMode = TextureWrapMode.Clamp; tex.filterMode = FilterMode.Bilinear; tex.anisoLevel = 1; //if (string.IsNullOrEmpty(m_atlasName) && IsNpot(tex)) //{//单张图而且不是2的n次方的话,自动压缩 // SetFormat(tex, "Standalone", TextureImporterFormat.AutomaticCompressed); // SetFormat(tex, "Android", TextureImporterFormat.AutomaticCompressed); // SetFormat(tex, "iPhone", TextureImporterFormat.AutomaticCompressed); //} //else //{ //SetFormat(tex, "", TextureImporterFormat.ARGB32); //tex.textureFormat = TextureImporterFormat.ARGB32; //SetFormat(tex, "Standalone", TextureImporterFormat.ARGB32); tex.ClearPlatformTextureSettings("Standalone"); //SetFormat(tex, "Android", TextureImporterFormat.ETC2_RGBA8); //SetFormat(tex, "iPhone", TextureImporterFormat.PVRTC_RGBA4); EditorUtil.SetDirty(tex); //} ++i; EditorUtility.DisplayProgressBar("Loading", string.Format("正在修改格式和重命名,{0}/{1}", i, m_texs.Count), ((float)i / m_texs.Count) * 0.9f); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); //检查是不是要重新打包 EditorUtility.DisplayProgressBar("Loading", string.Format("检查打包中"), 0.9f); EditorUtility.ClearProgressBar(); UnityEditor.Sprites.Packer.kDefaultPolicy = "DefaultPackerPolicy";//TightPackerPolicy DefaultPackerPolicy #if UNITY_ANDROID UnityEditor.Sprites.Packer.RebuildAtlasCacheIfNeeded(BuildTarget.Android, true); #endif #if UNITY_IPHONE UnityEditor.Sprites.Packer.RebuildAtlasCacheIfNeeded(BuildTarget.iOS, true); #endif #if UNITY_STANDALONE_WIN UnityEditor.Sprites.Packer.RebuildAtlasCacheIfNeeded(BuildTarget.StandaloneWindows, true); #endif //打包进UI资源管理器中 List <string> path = new List <string>(); foreach (TextureImporter tex in m_texs) { //Debuger.Log("资源路径"+tex.assetPath); path.Add(tex.assetPath); } string modName = ""; string pathStr = path[0]; string[] pList = pathStr.Split('/'); for (int n = 0; n < pList.Length; n++) { if (pList[n] == "Atlas") { modName = pList[n + 1]; } } UIResMgr uiRes = UIResTool.Get(modName); if (Application.isPlaying) { Debug.LogError("运行中不能设置图片"); return; } uiRes.PackByPath(path); }