float GetButtonLeft(int nIndex, float fx) { float fTexH = 15.0f; SelectSpriteInfo sp = m_SelectSprite[nIndex]; int nValueType = 0; if (sp.m_bSelect) { nValueType = 2; if (sp.m_sprite != null) { nValueType = 1; } } if (nValueType == 2) { return(fx); } else if (nValueType == 1) { return(fx - 15.0f); } else { if (sp.m_bDelete) { return(fx - 60.0f); } else { return(fx); } } return(fx); }
static int CompareSpritesByID_Down(SelectSpriteInfo a, SelectSpriteInfo b) { if (a.m_nIndex != b.m_nIndex) { return(a.m_nIndex > b.m_nIndex ? -1 : 1); } return(0); }
void RefreshSelectObject() { m_bInit = true; List <UISpriteInfo> aSprite = CAtlasMng.instance.GetAllSprite(); m_SelectSprite.Clear(); List <SelectSpriteInfo> aSelect = GetSelectedInfo(); Dictionary <string, int> SelectFlags = new Dictionary <string, int>(); m_nSelectCount = aSelect.Count; for (int i = 0; i < m_nSelectCount; ++i) { SelectFlags[aSelect[i].m_szSpriteName] = 1; m_SelectSprite.Add(aSelect[i]); aSelect[i].m_bSelect = true; aSelect[i].m_bDelete = false; if (m_pSelectSprite != null && m_pSelectSprite.m_szSpriteName == aSelect[i].m_szSpriteName) { m_pSelectSprite = null; } } int nSpriteCount = aSprite.Count; for (int i = 0; i < nSpriteCount; ++i) { if (SelectFlags.ContainsKey(aSprite[i].name)) { continue; } if (!IsNeedShow(aSprite[i].name)) { continue; } SelectSpriteInfo node = new SelectSpriteInfo(); node.m_sprite = aSprite[i]; node.m_szAtlasName = aSprite[i].m_szAtlasName; node.m_szSpriteName = aSprite[i].name; m_SelectSprite.Add(node); } nSpriteCount = m_SelectSprite.Count; for (int i = 0; i < nSpriteCount; ++i) { m_SelectSprite[i].m_nIndex = i; if (m_szSelectSpriteName == m_SelectSprite[i].m_szSpriteName) { m_SelectSprite[i].m_bCurSelect = true; if (m_pSelectSprite != null && m_pSelectSprite.m_szSpriteName == m_szSelectSpriteName) { m_SelectSprite[i].m_szAtlasName = m_pSelectSprite.m_szAtlasName; m_SelectSprite[i].m_nNextAssetsType = m_pSelectSprite.m_nNextAssetsType; m_SelectSprite[i].m_szAssetsName = m_pSelectSprite.m_szAssetsName; } } } }
// 渲染按纽操作 void RenderSpriteButton(int nIndex, float fx, float fy, ref bool delete) { float fTexH = 15.0f; SelectSpriteInfo sp = m_SelectSprite[nIndex]; int nValueType = 0; if (sp.m_bSelect) { nValueType = 2; if (sp.m_sprite != null) { nValueType = 1; } } if (nValueType == 2) { GUI.color = Color.green; GUI.Label(new Rect(fx, fy, 30.0f, fTexH), "Add"); GUI.color = Color.white; } else if (nValueType == 1) { GUI.color = Color.cyan; GUI.Label(new Rect(fx - 15.0f, fy, 45.0f, fTexH), "Update"); GUI.color = Color.white; } else { if (sp.m_bDelete) { GUI.backgroundColor = Color.red; if (GUI.Button(new Rect(fx - 60.0f, fy, 60.0f, fTexH), "Delete")) { sp.m_bDelete = true; delete = true; } GUI.backgroundColor = Color.green; if (GUI.Button(new Rect(fx, fy, 30, fTexH), "X")) { sp.m_bDelete = false; delete = false; } GUI.backgroundColor = Color.white; } else { // If we have not yet selected a sprite for deletion, show a small "X" button if (GUI.Button(new Rect(fx, fy, 30, fTexH), "X")) { sp.m_bDelete = !sp.m_bDelete; } } } }
static int CompareSpritesBySelect(SelectSpriteInfo a, SelectSpriteInfo b) { if (a.m_bSelect != b.m_bSelect) { return(a.m_bSelect ? -1 : 1); } if (a.m_bDelete != b.m_bDelete) { return(a.m_bDelete ? -1 : 1); } if (a.m_bCurSelect != b.m_bCurSelect) { return(a.m_bCurSelect ? -1 : 1); } return(0); }
// 功能:选择一个精灵对象 public void OnSelectSprite(string szNewSelectSpriteName) { if (m_curSelectSprite == null) { if (m_curObj == null) { GameObject obj = new GameObject(); m_curObj = obj; m_curObj.SetActive(false); } m_curSelectSprite = m_curObj.AddComponent <MyUISpritePreView>(); } if (m_curSelectSprite.spritename != szNewSelectSpriteName) { m_szSelectSpriteName = szNewSelectSpriteName; m_pSelectSprite = null; m_curSelectSprite.spritename = szNewSelectSpriteName; } Selection.activeObject = m_curSelectSprite; }
List <SelectSpriteInfo> GetSelectedInfo() { List <SelectSpriteInfo> aSelect = new List <SelectSpriteInfo>(); List <Texture> aTexList = AtlasMng_Editor.GetSelectedTextures(); foreach (Texture o in aTexList) { string szName = AtlasMng_Editor.GetAssetPathByTexture(o); if (!string.IsNullOrEmpty(szName)) { if (szName.IndexOf("Assets/Atlas/") == 0) { continue; } SelectSpriteInfo info = new SelectSpriteInfo(); info.m_szAssetsName = szName; info.m_szSpriteName = AtlasMng_Editor.GetSpriteNameByAssetsName(szName); info.m_szAtlasName = CAtlasMng.instance.GetAtlasNameBySpriteName(info.m_szSpriteName); if (string.IsNullOrEmpty(info.m_szAtlasName)) { info.m_szAtlasName = NGUISettings.atlasName.Trim(); if (string.IsNullOrEmpty(info.m_szAtlasName)) { info.m_szAtlasName = "default"; } } UITexAtlas atlas = CAtlasMng.instance.GetAltas(info.m_szSpriteName); if (atlas != null) { continue; } info.m_sprite = CAtlasMng.instance.GetSprite(info.m_szSpriteName); info.m_selectTex = o; aSelect.Add(info); } } return(aSelect); }
Color GetSpriteButtonColor(int nIndex) { SelectSpriteInfo sp = m_SelectSprite[nIndex]; int nValueType = 0; if (sp.m_bSelect) { nValueType = 2; if (sp.m_sprite != null) { nValueType = 1; } } if (nValueType == 2) { return(Color.green); } else if (nValueType == 1) { return(Color.cyan); } else { if (sp.m_bDelete) { return(Color.red); } else { if (sp.m_bCurSelect) { return(Color.yellow); } return(Color.white); } } return(Color.white); }
void ExportSelectID(string szPathName) { if (m_SelectSprite == null) { return; } CSerialize ar = new CSerialize(SerializeType.write, szPathName); ar.PushTextString("ID\tName"); for (int i = 0; i < m_SelectSprite.Count; ++i) { SelectSpriteInfo spInfo = m_SelectSprite[i]; if (spInfo == null) { continue; } UISpriteInfo sp = spInfo.m_sprite; ar.PushTextString(string.Format("\r\n{0}\t{1}", sp.m_nNameID, sp.name)); } ar.Close(); szPathName = szPathName.Replace('/', '\\'); System.Diagnostics.Process.Start("explorer.exe", szPathName); }
void OnSpriteOperator(bool delete, bool update, SelectSpriteInfo select) { int nSpriteCount = m_SelectSprite.Count; if (delete) { // 有要删除对象 List <string> nameList = new List <string>(); for (int i = 0; i < nSpriteCount; ++i) { if (m_SelectSprite[i].m_bDelete) { nameList.Add(m_SelectSprite[i].m_szSpriteName); } } AtlasMng_Editor.instance.m_lpImportPackTextureFunc = ImportPackTextureFunc; CAtlasMng.instance.DeleteSprite(nameList); RefrshUIObject(nameList); RefreshSelectObject(); } else if (update) { // 有要更新的对象 List <SUpdateTexInfo> spriteNameList = new List <SUpdateTexInfo>(); List <string> nameList = new List <string>(); for (int i = 0; i < nSpriteCount; ++i) { if (m_SelectSprite[i].m_bSelect) { SelectSpriteInfo sp = m_SelectSprite[i]; SUpdateTexInfo node = new SUpdateTexInfo(); node.m_szAssetsName = sp.m_szAssetsName; node.m_szAtlasName = sp.m_szAtlasName; node.m_szSpriteName = sp.m_szSpriteName; spriteNameList.Add(node); nameList.Add(sp.m_szSpriteName); } } bool bTrimAlpha = NGUISettings.atlasTrimming; AtlasMng_Editor.instance.m_lpImportPackTextureFunc = ImportPackTextureFunc; AtlasMng_Editor.instance.AddOrUpdateSelectSprite(spriteNameList, bTrimAlpha, NGUISettings.atlasPMA, NGUISettings.canLOD); RefrshUIObject(nameList); RefreshSelectObject(); } if (select != null) { for (int i = 0; i < nSpriteCount; ++i) { if (select.m_nIndex != m_SelectSprite[i].m_nIndex) { m_SelectSprite[i].m_bCurSelect = false; } } if (select.m_sprite != null) { // 创建一个对象 OnSelectSprite(select.m_sprite.name); } else { Selection.activeObject = select.m_selectTex; } } }
void RenderAllSpriteInfo(ref int nX, ref int nY) { float fx = (float)nX; float fy = (float)nY; float fLineGap = 3.0f; float fBtH = 20.0f; float fBtW = 100.0f; float fTexH = 15.0f; bool bUpdate = false; // 得到当前选中的对象 Color backColor = GUI.backgroundColor; float fButtonX = fx; if (m_nSelectCount > 0) { GUI.backgroundColor = Color.green; if (GUI.Button(new Rect(fButtonX, fy, 100, fBtH), "添加或更新")) { bUpdate = true; } GUI.backgroundColor = Color.white; } else { GUI.Button(new Rect(fButtonX, fy, 100, fBtH), "请先选中图片"); } fButtonX += 100; if (GUI.Button(new Rect(fButtonX, fy, 80, fBtH), "ID排序")) { SortByID(); } fButtonX += 80; if (GUI.Button(new Rect(fButtonX, fy, 80, fBtH), "Name排序")) { SortBySpriteName(); } fButtonX += 80; if (GUI.Button(new Rect(fButtonX, fy, 80, fBtH), "材质名排序")) { SortByAtlasName(); } fButtonX += 80; if (GUI.Button(new Rect(fButtonX, fy, 80, fBtH), "选择排序")) { SortBySelect(); } fButtonX += 80; GUI.Label(new Rect(fButtonX, fy - fBtH - fLineGap, 200, fBtH), "我要搜索(材质名&精灵名)"); string szNewLockSearchName = GUI.TextField(new Rect(fButtonX, fy, 200, fBtH), m_szLockSearchName, 25); if (szNewLockSearchName != m_szLockSearchName) { m_szLockSearchName = szNewLockSearchName; RefresyByLockName(); } fButtonX += 210; UITexAtlas atlas = CAtlasMng.instance.GetAltas(NGUISettings.atlasName); bool bOldLOD = NGUISettings.canLOD; if (atlas != null) { bOldLOD = atlas.IsCanLOD(); } bool bIsCanLOD = GUI.Toggle(new Rect(fButtonX, fy, 100, fBtH), bOldLOD, "图集允许LOD"); if (bIsCanLOD != bOldLOD) { NGUISettings.canLOD = bIsCanLOD; if (atlas != null) { atlas.SetLODFlag(bIsCanLOD); CAtlasMng.instance.SaveAltasCfg(); } } fy += fBtH + fLineGap; // m_szLockSearchName // 开始渲染当前材质的对象了 Rect rc = position; int nScreenW = Screen.width; float fListH = rc.height - fy; float fWindowW = rc.width; int nSelect = -1; bool bDelete = false; SelectSpriteInfo select = null; int nSpriteCount = m_SelectSprite.Count; if (nSpriteCount > 0) { float fSize = fListH; float topValue = 0.0f; float bottomValue = nSpriteCount * (fTexH + fLineGap) + fTexH; Rect rcView = new Rect(fx, fy, fWindowW, fListH); Rect rcRange = new Rect(fx, fy, fWindowW + fx, bottomValue - m_fScrollPos + fTexH); m_vScrollPos = GUI.BeginScrollView(rcView, m_vScrollPos, rcRange, false, false); //m_fScrollPos = GUI.VerticalScrollbar(new Rect(fWindowW - 30, fy, 30, fListH), m_fScrollPos, fSize, topValue, bottomValue); m_fScrollPos = m_vScrollPos.y; int nStartShow = (int)(m_fScrollPos) / (int)(fTexH + fLineGap); float fSpriteWidth = fWindowW * 0.75f; if (nStartShow < 0) { nStartShow = 0; } float x = fx; float y = fy; float fTempY = fy + m_fScrollPos; for (int i = nStartShow; i < nSpriteCount; ++i) { SelectSpriteInfo sp = m_SelectSprite[i]; y = fTempY - m_fScrollPos; float fRight = GetButtonLeft(i, fWindowW - 70); GUI.backgroundColor = GetSpriteButtonColor(i); if (GUI.Button(new Rect(x, y, fRight, fTexH), GUIContent.none)) { m_szSelectSpriteName = sp.m_szSpriteName; sp.m_bCurSelect = true;// !sp.m_bCurSelect; nSelect = i; select = sp; m_pSelectSprite = sp; if (!string.IsNullOrEmpty(sp.m_szAssetsName)) { sp.m_nNextAssetsType++; if (sp.m_nNextAssetsType > 1) { sp.m_nNextAssetsType = 0; } // 输入名字 -- 文件名字,两个做转换 if (sp.m_nNextAssetsType == 0) { sp.m_szAtlasName = NGUISettings.atlasName.Clone() as string; if (string.IsNullOrEmpty(sp.m_szAtlasName)) { sp.m_szAtlasName = sp.m_szSpriteName; NGUISettings.atlasName = sp.m_szAtlasName.Clone() as string; } } else { sp.m_szAtlasName = sp.m_szSpriteName; } } } GUI.backgroundColor = Color.white; //GUI.Label(new Rect(x, y, 30, fTexH), sp.m_nIndex.ToString()); int nSpriteID = sp.m_sprite != null ? sp.m_sprite.m_nNameID : 0; GUI.Label(new Rect(x, y, 30, fTexH), nSpriteID.ToString()); GUI.Label(new Rect(x + 30, y, fSpriteWidth, fTexH), sp.m_szSpriteName); GUI.Label(new Rect(x + fWindowW * 0.5f - 20, y, fWindowW * 0.25f + 40, fTexH), sp.m_szAtlasName); RenderSpriteButton(i, fWindowW - 70, y, ref bDelete); fTempY += fTexH + fLineGap; } GUI.EndScrollView(); } else { } // 处理消息逻辑 if (bDelete || bUpdate || select != null) { if (select != null) { UITexAtlas selectAtlas = CAtlasMng.instance.GetAltasBySpriteName(m_szSelectSpriteName); if (selectAtlas != null) { NGUISettings.atlasPadding = selectAtlas.pixelSize; NGUISettings.atlasTrimming = false; NGUISettings.atlasPMA = selectAtlas.premultipliedAlpha; NGUISettings.atlasName = selectAtlas.m_szAtlasName.Clone() as string; } } OnSpriteOperator(bDelete, bUpdate, select); } }
static int CompareSpritesBySelect_Down(SelectSpriteInfo a, SelectSpriteInfo b) { return(CompareSpritesBySelect(b, a)); }
static int CompareSpritesByAtlsName_Down(SelectSpriteInfo a, SelectSpriteInfo b) { return(b.m_szAtlasName.CompareTo(a.m_szAtlasName)); }
static int CompareSpritesBySpriteName(SelectSpriteInfo a, SelectSpriteInfo b) { return(a.m_szSpriteName.CompareTo(b.m_szSpriteName)); }