private Dictionary <string, Rect> GetSpriteInfoInAtlas(string spriteName, GameObject atlasObj) { Dictionary <string, Rect> newInfo = new Dictionary <string, Rect>(); if ( string.IsNullOrEmpty(spriteName) || (null == atlasObj) ) { return(null); } Dictionary <string, Rect> tempInfo = UtilityForNGUI.GetSpriteInfo(atlasObj); if (null == tempInfo) { return(null); } Rect spriteRect; if (tempInfo.TryGetValue(spriteName, out spriteRect)) { newInfo.Add(spriteName, spriteRect); } return(newInfo); }
private Dictionary <string, Rect> VagueGetSpriteInfoInAtlas(string spriteName, GameObject atlasObj) { Dictionary <string, Rect> newInfo = new Dictionary <string, Rect>(); if ( string.IsNullOrEmpty(spriteName) || (null == atlasObj) ) { return(null); } Dictionary <string, Rect> tempInfo = UtilityForNGUI.GetSpriteInfo(atlasObj); if (null == tempInfo) { return(null); } foreach (KeyValuePair <string, Rect> item in tempInfo) { if (item.Key.Contains(spriteName)) { newInfo.Add(item.Key, item.Value); } } return(newInfo); }
public SEARCHSPRITE_ERROR_TYPE SetUISprite(GameObject go, string spriteName, string atlasPath) { SEARCHSPRITE_ERROR_TYPE errorType = SEARCHSPRITE_ERROR_TYPE.SEARCHSPRITE_NONE_ERROR; errorType = CheckUtilityForNGUIError(UtilityForNGUI.SetUISprite(go, spriteName, atlasPath)); return(errorType); }
public List <AtlasInfoForSearchSprite> VagueSearchAtlasWithSpecifySprite(string spriteName) { List <AtlasInfoForSearchSprite> atlasInfoTbl = new List <AtlasInfoForSearchSprite>(); if (string.IsNullOrEmpty(spriteName)) { return(null); } string[] paths = AssetDatabase.GetAllAssetPaths(); for (int index = 0; index < paths.Length; index++) { GameObject atlasObj = null; if (UtilityForNGUI.IsAtlasPrefab(paths[index], out atlasObj)) { if (null == atlasObj) { continue; } AtlasInfoForSearchSprite newInfo = new AtlasInfoForSearchSprite(); newInfo.AtlasPath = paths[index]; newInfo.AtlasTexture = UtilityForNGUI.GetAtlasTexture(atlasObj); //newInfo.SpriteInfo = UtilityForNGUI.GetSpriteInfo(atlasObj); newInfo.SpriteInfo = VagueGetSpriteInfoInAtlas(spriteName, atlasObj); if ( (newInfo.SpriteInfo != null) && (newInfo.SpriteInfo.Count != 0) ) { atlasInfoTbl.Add(newInfo); } //if (IsSpriteInAtlas(spriteName, newInfo)) //{ // atlasInfoTbl.Add(newInfo); //} } } return(atlasInfoTbl); }
void OnSelectListItem(EditorControl c, int index) { if ( (m_SearchResultInfo == null) || (m_SearchResultInfo.SearchSpriteInfo == null) ) { return; } ListViewCtrl searchList = c as ListViewCtrl; if (null == searchList) { return; } MainViewCtrl spriteView = _GetControl <MainViewCtrl>(m_SpriteViewName); if (null == spriteView) { return; } MainViewCtrl atlasView = _GetControl <MainViewCtrl>(m_AtlasViewName); if (null == atlasView) { return; } LabelCtrl spriteInfo = _GetControl <LabelCtrl>(m_SpriteInfoLabel); if (null == spriteInfo) { return; } LabelCtrl atlasInfo = _GetControl <LabelCtrl>(m_AtlasInfoLabel); if (null == atlasInfo) { return; } SearchSpriteInfo info = m_SearchResultInfo.SearchSpriteInfo[index]; Texture atlasTex = info.AtlasTexture; //获取Sprite在Atlas中的位置 Rect spriteUVRect = info.SpriteRect; //m_SearchResultInfo.GetSpirteUVRect(index); Rect spriteUVRectReal = UtilityForNGUI.ConvertToTexCoords(spriteUVRect, atlasTex.width, atlasTex.height); float aspect = (float)atlasTex.width / (float)atlasTex.height; float w1 = 10.0f; float h1 = w1 / aspect; float aspect2 = (float)spriteUVRect.width / (float)spriteUVRect.height; float w2 = 3.0f; float h2 = w2 / aspect2; //创建预览Object GameObject spritePreviewObj = _GenTexturePreviewObject(w2, h2, atlasTex, spriteUVRectReal); GameObject atlasPreviewObj = _GenTexturePreviewObject(w1, h1, atlasTex, new Rect(0, 0, 1, 1)); //将预览Object绑定至MainView的主相机之下 UniversalEditorUtility.DestoryChildren(spriteView.GetBindingTarget()); spritePreviewObj.transform.parent = spriteView.GetBindingTarget().transform; spritePreviewObj.transform.localPosition = Vector3.zero; UniversalEditorUtility.DestoryChildren(atlasView.GetBindingTarget()); atlasPreviewObj.transform.parent = atlasView.GetBindingTarget().transform; atlasPreviewObj.transform.localPosition = Vector3.zero; //更新预览信息 string atlasName = Path.GetFileNameWithoutExtension(info.AtlasPath); spriteInfo.Caption = "Sprite: " + info.SpriteName + " , " + spriteUVRect.width + " * " + spriteUVRect.height; atlasInfo.Caption = "Atlas: " + atlasName + " , " + info.AtlasTexture.width + " * " + info.AtlasTexture.height; //spriteView.mainViewUVRect = spriteUVRect; RequestRepaint(); }