Esempio n. 1
0
    void FixSearchResultAndList(string searchName, List <AtlasInfoForSearchSprite> atlasInfoTbl)
    {
        if (null == atlasInfoTbl)
        {
            return;
        }

        ListViewCtrl searchList = _GetControl <ListViewCtrl>(m_SearchResultListName);

        if (null == searchList)
        {
            return;
        }

        searchList.ClearItems();

        m_SearchResultInfo                  = new SearchResultInfo();
        m_SearchResultInfo.SearchName       = searchName;
        m_SearchResultInfo.SearchSpriteInfo = new List <SearchSpriteInfo>();

        for (int index = 0; index < atlasInfoTbl.Count; index++)
        {
            foreach (var item in atlasInfoTbl[index].SpriteInfo)
            {
                SearchSpriteInfo newInfo = new SearchSpriteInfo();
                newInfo.AtlasPath    = atlasInfoTbl[index].AtlasPath;
                newInfo.AtlasTexture = atlasInfoTbl[index].AtlasTexture;
                newInfo.SpriteName   = item.Key;
                newInfo.SpriteRect   = item.Value;

                m_SearchResultInfo.SearchSpriteInfo.Add(newInfo);

                ListCtrlItem newItem = new ListCtrlItem();
                newItem.name          = item.Key + "  " + newInfo.AtlasPath;
                newItem.color         = Color.white;
                newItem.onSelectColor = Color.blue;
                searchList.AddItem(newItem);
            }
        }
    }
Esempio n. 2
0
    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();
    }