static void OnAssetDatabaseStateChange(ResourceManageToolModel m)
    {
        LabelCtrl stateLabel = s_root.FindControl("_StateLabel") as LabelCtrl;

        stateLabel.Name = "_StateLabel";


        switch (m.CurrDBState)
        {
        case ResourceManageToolModel.State.STATE_INIT:
            stateLabel.textColor = Color.red;
            stateLabel.Caption   = "数据库没有更新,无法查看无用资源列表与反向引用!";
            break;

        case ResourceManageToolModel.State.STATE_BUILD:
            stateLabel.textColor = Color.green;
            stateLabel.Caption   = "您使用的是\"" + m.GetAssetDatabaseUpdateTime() + "\"更新的数据库";
            break;

        default:
            break;
        }

        RequestRepaint();
    }
Ejemplo n.º 2
0
    public override void Visit(EditorControl c)
    {
        LabelCtrl label = c as LabelCtrl;

        if (
            (null == label)
            )
        {
            return;
        }

        EditorGUI.BeginDisabledGroup(!label.Enable);

        Color oldColor = labelStyle.normal.textColor;

        labelStyle.normal.textColor = label.textColor;
        //Add by liteng for MoveAtlas At 2014/1/4
        labelStyle.fontSize = label.fontSize;
        labelStyle.margin   = label.margin;

        GUILayout.Label(c.Caption, labelStyle, c.GetOptions());

        labelStyle.normal.textColor = oldColor;

        EditorGUI.EndDisabledGroup();

        c.UpdateLastRect();

        HandleMouseInput(c);
    }
    /*
     * 资源数据库状态标签
     */

    static void UpdateAssetDBStateLabel()
    {
        LabelCtrl dbStateLabel = s_root.FindControl("_StateLabel") as LabelCtrl;

        dbStateLabel.textColor = Color.green;
        dbStateLabel.Caption   = "您使用的是\"" + ResourceManageToolModel.GetInstance().GetAssetDatabaseUpdateTime() + "\"更新的数据库";
    }
Ejemplo n.º 4
0
    void ClearPreview()
    {
        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;
        }

        UniversalEditorUtility.DestoryChildren(spriteView.GetBindingTarget());
        UniversalEditorUtility.DestoryChildren(atlasView.GetBindingTarget());

        spriteInfo.Caption = "";
        atlasInfo.Caption  = "";
    }
Ejemplo n.º 5
0
    private void HandleMouseInput(EditorControl c)
    {
        LabelCtrl currCtrl = c as LabelCtrl;

        if (
            (null == currCtrl) ||
            !currCtrl.IsCurrentCtrlEnable() ||
            currCtrl.IsEventTriggered()
            )
        {
            return;
        }

        CheckInputEvent(c);

        Vector2 localMousePos = CalcLocalPos(c, FrameInputInfo.GetInstance().currPos);

        localMousePos += currCtrl.ScrollPos;

        if (
            FrameInputInfo.GetInstance().leftBtnDoubleClick &&
            currCtrl.LastRect.Contains(localMousePos)
            )
        {
            currCtrl.frameTriggerInfo.isDoubleClick = true;
            currCtrl.ClickObject = null;

            currCtrl.RequestRepaint();
        }
        else if (
            FrameInputInfo.GetInstance().leftBtnClick &&
            currCtrl.LastRect.Contains(localMousePos)
            )
        {
            currCtrl.frameTriggerInfo.isClick = true;
            currCtrl.ClickObject = null;

            currCtrl.RequestRepaint();
        }
        else if (
            FrameInputInfo.GetInstance().leftBtnOnPress &&
            currCtrl.LastRect.Contains(localMousePos)
            )
        {
            currCtrl.frameTriggerInfo.isOnPress = true;
            currCtrl.ClickObject = null;

            currCtrl.RequestRepaint();
        }
        else if (
            FrameInputInfo.GetInstance().leftBtnPress &&
            currCtrl.LastRect.Contains(localMousePos)
            )
        {
            currCtrl.frameTriggerInfo.isPressDown = true;
            currCtrl.ClickObject = null;

            currCtrl.RequestRepaint();
        }
        else if (
            FrameInputInfo.GetInstance().leftBtnPressUp &&
            currCtrl.LastRect.Contains(localMousePos)
            )
        {
            currCtrl.frameTriggerInfo.isPressUp = true;
            currCtrl.ClickObject = null;

            currCtrl.RequestRepaint();
        }
    }
Ejemplo n.º 6
0
    public static void InitControls(EditorRoot root)
    {
        /*将编辑器分为上下两个区域*/
        HSpliterCtrl Upanddown = new HSpliterCtrl();

        root.RootCtrl = Upanddown;
        Upanddown.layoutConstraint = LayoutConstraint.GetSpliterConstraint(30f);

        #region 编辑器事件回调
        /*编辑器初始化事件*/
        root.onEnable += EditorWindowOnEnable;
        /*编辑器关闭事件*/
        root.onDestroy += EditorWindowOnDestroy;
        #endregion

        #region 编辑器的上边
        /*存放上方资源的容器*/
        HBoxCtrl upspliter = new HBoxCtrl();
        Upanddown.Add(upspliter);

        /*扫描资源按钮*/
        Rect       SearchBtnRect = new Rect(0, 0, 160, 20);
        ButtonCtrl SearchBtn     = new ButtonCtrl();
        SearchBtn.onClick  = SearchBtnClickEvent;
        SearchBtn.Size     = SearchBtnRect;
        SearchBtn.Visiable = true;
        SearchBtn.Caption  = "扫描资源";
        SearchBtn.Name     = "_SearchButton";

        /*下拉菜单,过滤器*/
        Rect ComboxFliterRect         = new Rect(0, 0, 120, 20);
        ComboBoxCtrl <int> TypeFliter = new ComboBoxCtrl <int>(0);
        TypeFliter.Size           = ComboxFliterRect;
        TypeFliter.Name           = "_TypeFliter";
        TypeFliter.onValueChange += FilterOnchange;

        for (int i = 0; i <= 3; i++)
        {
            TypeFliter.AddItem(new ComboItem("选项0", 0));
            TypeFliter.AddItem(new ComboItem("选项1", 1));
            TypeFliter.AddItem(new ComboItem("选项2", 2));
            TypeFliter.AddItem(new ComboItem("选项3", 3));
        }

        TypeFliter.CurrValue = 0;

        /*数据库状态显示*/
        LabelCtrl StateLabel = new LabelCtrl();
        StateLabel.Caption = "数据库没有更新,请点击刷新资源数据库";
        StateLabel.Name    = "_StateLabel";

        /*将控件放入上方资源*/
        upspliter.Add(SearchBtn);
        upspliter.Add(TypeFliter);
        upspliter.Add(StateLabel);
        #endregion

        #region 编辑器的下边
        /*将下放资源分为左右两个区域*/
        VSpliterCtrl downspliter = new VSpliterCtrl();
        Upanddown.Add(downspliter);
        downspliter.layoutConstraint = LayoutConstraint.GetSpliterConstraint(300f);
        downspliter.Dragable         = true;

        /*存放左侧资源列表和无引用资源的容器*/
        VBoxCtrl LeftAssetContainer = new VBoxCtrl();
        downspliter.Add(LeftAssetContainer);

        /*左侧两枚选项卡*/
        TabViewCtrl leftTabView = new TabViewCtrl();
        LeftAssetContainer.Add(leftTabView);

        /*资源列表*/
        TreeViewCtrl AssetsTreeView = new TreeViewCtrl();
        AssetsTreeView.Caption = "资源列表";
        AssetsTreeView.Name    = "_AssetList";
        leftTabView.Add(AssetsTreeView);

        /*无用资源列表*/
        ListViewCtrl UseLessAssetsList = new ListViewCtrl();
        UseLessAssetsList.Caption = "无用资源";
        UseLessAssetsList.Name    = "_UseLessAssetsList";
        leftTabView.Add(UseLessAssetsList);

        /*存放正向反向资源依赖关系的容器*/
        VBoxCtrl RightAssetDependceContainer = new VBoxCtrl();
        downspliter.Add(RightAssetDependceContainer);

        /*右侧两枚选项卡*/
        TabViewCtrl rightTabView = new TabViewCtrl();
        RightAssetDependceContainer.Add(rightTabView);

        /*资源正向依赖关系列表*/
        ListViewCtrl DependcyAssetsList = new ListViewCtrl();
        DependcyAssetsList.Caption = "正向依赖关系";
        DependcyAssetsList.Name    = "_DependAssetsList";
        rightTabView.Add(DependcyAssetsList);

        /*资源反向依赖关系列表*/
        ListViewCtrl DedependcyAssetsList = new ListViewCtrl();
        DedependcyAssetsList.Caption = "反向依赖关系";
        DedependcyAssetsList.Name    = "_DedependcyAssetsList";
        rightTabView.Add(DedependcyAssetsList);
        #endregion
    }
Ejemplo n.º 7
0
    public static void InitControls(EditorRoot editorRoot)
    {//初始化窗口
        if (editorRoot == null)
        {
            //提示程序错误Message
            EditorUtility.DisplayDialog("运行错误",
                                        "窗口初始化失败",
                                        "确认");
            return;
        }

        s_root = editorRoot;
        //s_root.position = new Rect(100f, 100f, 1280, 768f);

        {
            s_root.onEnable  = OnEnable;
            s_root.onDisable = OnDisable;
        }

        #region 创建布置窗口元素

        #region 第一级分割
        Rect btnRect   = new Rect(0, 0, 80, 20);
        Rect labelRect = new Rect(0, 0, 80, 5);
        Rect hboxRect  = new Rect(0, 0, 300, 5);

        HSpliterCtrl hs1 = new HSpliterCtrl();
        hs1.layoutConstraint = LayoutConstraint.GetSpliterConstraint(30f);
        HSpliterCtrl hs2 = new HSpliterCtrl();
        hs2.layoutConstraint = LayoutConstraint.GetSpliterConstraint(30f, true);

        HBoxCtrl hb1 = new HBoxCtrl();      //布置上方菜单条
        HBoxCtrl hb2 = new HBoxCtrl();      //布置主窗口
        HBoxCtrl hb3 = new HBoxCtrl();      //布置下方状态栏
        #endregion

        #region 第二级分割
        VSpliterCtrl vs2_1 = new VSpliterCtrl();
        vs2_1.layoutConstraint = LayoutConstraint.GetSpliterConstraint(300f);
        vs2_1.Dragable         = true;
        VSpliterCtrl vs2_2 = new VSpliterCtrl();
        vs2_2.layoutConstraint = LayoutConstraint.GetSpliterConstraint(300f, true);
        vs2_2.Dragable         = true;

        VBoxCtrl vb2_1 = new VBoxCtrl();               //布置工程目录/小图列表
        VBoxCtrl vb2_2 = new VBoxCtrl();               //布置预览窗口
        VBoxCtrl vb2_3 = new VBoxCtrl();               //布置Inspector窗口
        #endregion

        #region 第三级分割
        HSpliterCtrl hs2_1_1 = new HSpliterCtrl();
        hs2_1_1.layoutConstraint = LayoutConstraint.GetSpliterConstraint(260f, true);

        VBoxCtrl vb2_1_1 = new VBoxCtrl();                    //布置小图列表
        VBoxCtrl vb2_1_2 = new VBoxCtrl();                    //布置工程目录
        #endregion

        #region  第四级分割
        HSpliterCtrl hs2_1_2_1 = new HSpliterCtrl();
        hs2_1_2_1.layoutConstraint = LayoutConstraint.GetSpliterConstraint(240, true);

        VBoxCtrl vb2_1_2_1 = new VBoxCtrl();                    //布置小图列表
        VBoxCtrl vb2_1_2_2 = new VBoxCtrl();                    //布置工程目录
        #endregion
        #endregion

        #region 布置窗口(由高至低布置)

        #region 第四级分割

        #region Project View
        HBoxCtrl projectBtnBox = new HBoxCtrl();
        projectBtnBox.Size = hboxRect;

        LabelCtrl procLabel = new LabelCtrl();
        procLabel.Size    = labelRect;
        procLabel.Caption = "Project View";

        ButtonCtrl newProjBtn = new ButtonCtrl();
        newProjBtn.Caption = "新建工程";
        newProjBtn.Name    = "_NewProjBtn";
        newProjBtn.Size    = btnRect;
        newProjBtn.onClick = OnNewProjBtn;

        ButtonCtrl openProjBtn = new ButtonCtrl();
        openProjBtn.Caption = "打开工程";
        openProjBtn.Name    = "_OpenProjBtn";
        openProjBtn.Size    = btnRect;
        openProjBtn.onClick = OnOpenProjBtn;

        ButtonCtrl saveProjBtn = new ButtonCtrl();
        saveProjBtn.Caption = "保存工程";
        saveProjBtn.Name    = "_SaveProjBtn";
        saveProjBtn.Size    = btnRect;
        saveProjBtn.onClick = OnSaveProjBtn;
        projectBtnBox.Add(newProjBtn);
        projectBtnBox.Add(saveProjBtn);
        projectBtnBox.Add(openProjBtn);

        // vb2_1_2_1.Add(procLabel);
        vb2_1_2_1.Add(projectBtnBox);
        #endregion

        m_projTreeView                = new ListViewCtrl(); //工程目录
        m_projTreeView.Caption        = "Project";
        m_projTreeView.Name           = "Project";
        m_projTreeView.onItemSelected = OnSelectProjectListItem;
        m_projTreeView.IsTextureView  = false;


        vb2_1_2_2.Add(m_projTreeView);

        hs2_1_2_1.Add(vb2_1_2_1);
        hs2_1_2_1.Add(vb2_1_2_2);
        #endregion

        #region 第三级分割
        m_spriteListView = new ListViewCtrl();        //小图列表
        m_spriteListView.IsTextureView = false;
        m_spriteListView.Caption       = "小图";
        m_spriteListView.Name          = "spriteTreeView";

        m_spriteListView.onItemSelected     = OnSelectListItem;
        m_spriteListView.onItemCtrlSelected = OnSelectListItem;
        m_spriteListView.onItemSelectedR    = OnSelectListItemR;
        m_spriteListView.onItemSelectedRU   = OnSelectListItemRU;
        vb2_1_1.Add(m_spriteListView);
        vb2_1_2.Add(hs2_1_2_1);

        hs2_1_1.Add(vb2_1_1);
        hs2_1_1.Add(vb2_1_2);
        #endregion

        #region 第二级分割
        m_preview          = new MainViewCtrl();     //预览窗口
        m_preview.Name     = "_Preview";
        m_preview.bkColor  = Color.grey;
        m_preview.Is2DView = true;

        m_inspector             = new InspectorViewCtrl(); //属性窗口
        m_inspector.Name        = "_Inspector";
        m_inspector.onInspector = null;

        vb2_1.Add(hs2_1_1);
        vb2_2.Add(m_preview);
        vb2_3.Add(m_inspector);

        vs2_1.Add(vb2_1);
        vs2_1.Add(vs2_2);

        vs2_2.Add(m_preview);
        vs2_2.Add(vb2_3);
        #endregion

        #region 第一级分割
        #region  方菜单条
        ButtonCtrl addImageBtn = new ButtonCtrl();
        addImageBtn.Caption = "添加小图";
        addImageBtn.Name    = "_AddImageBtn";
        addImageBtn.Size    = btnRect;
        addImageBtn.onClick = OnAddImageBtn;

        ButtonCtrl previewBtn = new ButtonCtrl();
        previewBtn.Caption = "生成预览";
        previewBtn.Name    = "_PreviewBtn";
        previewBtn.Size    = btnRect;
        previewBtn.onClick = OnPreviewBtn;

        ButtonCtrl makeAtlasBtn = new ButtonCtrl();
        makeAtlasBtn.Caption = "生成图集";
        makeAtlasBtn.Name    = "_MakeAtlasBtn";
        makeAtlasBtn.Size    = btnRect;
        makeAtlasBtn.onClick = OnMakeAtlasBtn;

        ButtonCtrl configImageBaseBtn = new ButtonCtrl();
        configImageBaseBtn.Caption = "配置图库路径";
        configImageBaseBtn.Name    = "_ConfigImageBaseBtn";
        configImageBaseBtn.Size    = btnRect;
        configImageBaseBtn.onClick = OnConfigImageBaseBtn;

        ButtonCtrl helpBtn = new ButtonCtrl();
        helpBtn.Caption  = "帮助";
        helpBtn.Size     = btnRect;
        helpBtn.onClick += OnHelp;

        hb1.Add(addImageBtn);
        hb1.Add(previewBtn);
        hb1.Add(makeAtlasBtn);
        hb1.Add(configImageBaseBtn);
        hb1.Add(helpBtn);
        #endregion

        hb2.Add(vs2_1);

        hs1.Add(hb1);
        hs1.Add(hs2);

        hs2.Add(hb2);
        hs2.Add(hb3);
        #endregion

        #endregion

        //设置窗口根控件
        s_root.RootCtrl = hs1;

        //注册UIAtlasEditorModel回调函数
        UIAtlasEditorModel.GetInstance().onNewProject          = OnNewProject;
        UIAtlasEditorModel.GetInstance().onSpriteImageLoad     = OnSpriteImageLoad;
        UIAtlasEditorModel.GetInstance().onClearCurrentProject = OnClearCurrentProject;

        UIAtlasEditorModel.GetInstance().onAddSpriteImageCommand    = OnAddSpriteImageCommand;
        UIAtlasEditorModel.GetInstance().onDeleteSpriteImageCommand = OnDeleteSpriteImageCommand;
        UIAtlasEditorModel.GetInstance().onMakeAtlasCommand         = OnMakeAtlasCommand;
        UIAtlasEditorModel.GetInstance().onSpriteZoomChangedCommand = OnSpriteImageZoomChangedCommand;

        //注册编辑器窗口OnGui回调函数
        s_root.onGUI        = OnEditorGUI;
        m_Counter           = new GameObject();
        m_Counter.name      = "AtlasCmdCounter";
        m_Counter.hideFlags = HideFlags.HideAndDontSave;
        m_Counter.AddComponent <UIAtlasCommandCounter>();
        m_CommandCounter = m_Counter.GetComponent <UIAtlasCommandCounter>();
    }
    //这个方法就是利用EditorManager回调回来的一个EditorRoot实例;
    //构建了一个树形结构;
    public static void InitControls(EditorRoot editorRoot)
    {
        //将之前实例化的那个EditorWindow赋值给s_root
        s_root = editorRoot;

        //s_root.position = new Rect(100f, 100f, 1024, 768f);

        {//对编辑器全局消息响应;
            EditorApplication.projectWindowItemOnGUI += OnProjectWindowItem;
            EditorApplication.projectWindowChanged   += OnProjectWindowChanged;
        }

        {//协程回调
            s_root.onCoroutineMessage      = OnCoroutineMessage;
            s_root.onCoroutineTaskFinished = OnCoroutineTaskFinished;
            s_root.onDestroy = OnDestroy;
            s_root.onEnable  = OnEnable;
        }

        {//注册数据库变化回调
            ResourceManageToolModel.GetInstance().onResourceDBUpdate      = OnAssetDatabaseUpdate;
            ResourceManageToolModel.GetInstance().onResrouceDBStateChange = OnAssetDatabaseStateChange;
        }

        HSpliterCtrl hspliter = new HSpliterCtrl();

        s_root.RootCtrl           = hspliter;
        hspliter.layoutConstraint = LayoutConstraint.GetSpliterConstraint(30f);

        //用来放置上方菜单
        HBoxCtrl     hb0      = new HBoxCtrl();
        VSpliterCtrl vspliter = new VSpliterCtrl();

        vspliter.layoutConstraint = LayoutConstraint.GetSpliterConstraint(300f);
        vspliter.Dragable         = true;

        hspliter.Add(hb0);
        hspliter.Add(vspliter);

        //用来存放 资源列表、无引用资源列表
        VBoxCtrl vb0 = new VBoxCtrl();
        //用来存放 资源依赖项、反向引用
        VBoxCtrl vb1 = new VBoxCtrl();

        vspliter.Add(vb0);
        vspliter.Add(vb1);

        //左侧TabView
        TabViewCtrl leftTabView = new TabViewCtrl();
        //右侧TabView
        TabViewCtrl rightTabView = new TabViewCtrl();

        vb0.Add(leftTabView);
        vb1.Add(rightTabView);

        //资源列表
        TreeViewCtrl resTreeList = new TreeViewCtrl();

        resTreeList.Caption        = "资源列表";
        resTreeList.Name           = "_ResTreeList";
        resTreeList.onItemSelected = OnResourcesTreeViewSelectChanged;

        //无引用资源列表
        ListViewCtrl unUsedList = new ListViewCtrl();

        unUsedList.Caption        = "无引用资源";
        unUsedList.Name           = "_UnUsedResList";
        unUsedList.onItemSelected = OnUnUsedResourcesListViewSelectChanged;

        leftTabView.Add(resTreeList);
        leftTabView.Add(unUsedList);

        //资源依赖项
        TreeViewCtrl resRefTreeView = new TreeViewCtrl();

        resRefTreeView.Caption = "资源依赖项";
        resRefTreeView.Name    = "_ResRefTreeView";


        //反向引用
        TreeViewCtrl resReverseRefTreeView = new TreeViewCtrl();

        resReverseRefTreeView.Caption = "反向引用";
        resReverseRefTreeView.Name    = "_ResReverseRefTreeView";

        rightTabView.Add(resRefTreeView);
        rightTabView.Add(resReverseRefTreeView);


        Rect       btnRect   = new Rect(0, 0, 120, 20);
        ButtonCtrl searchBtn = new ButtonCtrl();

        searchBtn.Name     = "_SearchAllResources";
        searchBtn.Caption  = "扫描资源!";
        searchBtn.Size     = btnRect;
        searchBtn.onClick += OnSearchAllAssets;
        searchBtn.BtnColor = Color.green;
        searchBtn.Visiable = true;

        Rect comboBoxRect = new Rect(0, 0, 100, 20);
        ComboBoxCtrl <int> assetTypeCombo = new ComboBoxCtrl <int>(0);

        assetTypeCombo.Size          = comboBoxRect;
        assetTypeCombo.Name          = "_AssetTypeCombo";
        assetTypeCombo.onValueChange = OnFilterComboSelectChanged;

        List <IAssetFilter> assetFilters = ResourceManageToolModel.GetInstance().AssetFilterList;

        foreach (var filter in assetFilters)
        {
            AssetTypeFilter f = filter as AssetTypeFilter;
            assetTypeCombo.AddItem(new ComboItem(f.DisplayTypeName, f.TypeIndex));
        }

        assetTypeCombo.CurrValue = 0;

        TextBoxCtrl searchTextBox = new TextBoxCtrl();

        searchTextBox.Size          = comboBoxRect;
        searchTextBox.Icon          = UnityInternalIconCache.GetInstance().GetCacheIcon("d_ViewToolZoom");
        searchTextBox.Name          = "_SearchBox";
        searchTextBox.Caption       = "搜索";
        searchTextBox.Visiable      = true;
        searchTextBox.onValueChange = OnSearchTextBoxChange;

        ButtonCtrl helpBtn = new ButtonCtrl();

        helpBtn.Name     = "_HelpButton";
        helpBtn.Caption  = "帮助文档";
        helpBtn.onClick  = OnHelp;
        helpBtn.Size     = btnRect;
        helpBtn.Visiable = true;

        LabelCtrl stateLabel = new LabelCtrl();

        stateLabel.Name             = "_StateLabel";
        stateLabel.textColor        = Color.red;
        stateLabel.Caption          = "数据库没有更新,无法查看无用资源列表与反向引用!";
        stateLabel.layoutConstraint = LayoutConstraint.GetExtensibleViewConstraint();

        hb0.Add(searchBtn);
        hb0.Add(assetTypeCombo);
        hb0.Add(searchTextBox);
        hb0.Add(helpBtn);
        hb0.Add(stateLabel);
    }
Ejemplo n.º 9
0
    public static void InitControls(EditorRoot editorRoot)
    {
        SearchSpriteEditor searchSpriteEditor = editorRoot as SearchSpriteEditor;

        if (editorRoot == null)
        {
            //提示程序错误Message
            EditorUtility.DisplayDialog("运行错误",
                                        "窗口初始化失败",
                                        "确认");
            return;
        }

        m_EditorRoot = searchSpriteEditor;

        m_EditorRoot.position = new Rect(100f, 100f, m_RootWidth, 768f);


        #region 创建窗口布局元素
        Rect searchTextRect = new Rect(0, 0, 300, 20);

        #region 第一级分割
        HSpliterCtrl hs1 = new HSpliterCtrl();
        hs1.layoutConstraint = LayoutConstraint.GetSpliterConstraint(30f);

        HSpliterCtrl hs2 = new HSpliterCtrl();
        hs2.MinOffset        = 100f;
        hs2.layoutConstraint = LayoutConstraint.GetSpliterConstraint(30f, true);
        hs2.Dragable         = true;

        HBoxCtrl hb1 = new HBoxCtrl();      //搜索栏 HB
        HBoxCtrl hb2 = new HBoxCtrl();      //预览区 HB
        VBoxCtrl vb3 = new VBoxCtrl();      //结果List HB
        #endregion

        #region 第二级分割
        VSpliterCtrl vs2_1 = new VSpliterCtrl();
        vs2_1.layoutConstraint = LayoutConstraint.GetSpliterConstraint(m_RootWidth / 2);
        vs2_1.Dragable         = true;

        VBoxCtrl vb2_1 = new VBoxCtrl();
        VBoxCtrl vb2_2 = new VBoxCtrl();
        #endregion

        #region 第三级分割
        HSpliterCtrl hs2_1_1 = new HSpliterCtrl();
        hs2_1_1.layoutConstraint = LayoutConstraint.GetSpliterConstraint(10f, true);

        HSpliterCtrl hs2_2_1 = new HSpliterCtrl();
        hs2_2_1.layoutConstraint = LayoutConstraint.GetSpliterConstraint(10f, true);

        HBoxCtrl hb2_1_1 = new HBoxCtrl();
        HBoxCtrl hb2_1_2 = new HBoxCtrl();

        HBoxCtrl hb2_2_1 = new HBoxCtrl();
        HBoxCtrl hb2_2_2 = new HBoxCtrl();
        #endregion
        #endregion

        #region 布置窗口
        TextBoxCtrl searchTextBox = new TextBoxCtrl();
        searchTextBox.Size    = searchTextRect;
        searchTextBox.Icon    = UnityInternalIconCache.GetInstance().GetCacheIcon("d_ViewToolZoom");
        searchTextBox.Name    = m_SearchTextBoxName;
        searchTextBox.Caption = "搜索";

        ButtonCtrl vagueSearchBtn = new ButtonCtrl();
        vagueSearchBtn.Name    = m_VagueSearchBtnName;
        vagueSearchBtn.Caption = "模糊搜索";
        vagueSearchBtn.onClick = searchSpriteEditor.OnSearchBtn;

        ButtonCtrl searchBtn = new ButtonCtrl();
        searchBtn.Name    = m_SearchBtnName;
        searchBtn.Caption = "精确搜索";
        searchBtn.onClick = searchSpriteEditor.OnSearchBtn;

        ButtonCtrl setBtn = new ButtonCtrl();
        setBtn.Name    = m_SetBtnName;
        setBtn.Caption = "设置";
        setBtn.onClick = searchSpriteEditor.OnSetBtn;

        ButtonCtrl helpBtn = new ButtonCtrl();
        helpBtn.Name    = m_HelpBtnName;
        helpBtn.Caption = "帮助";
        helpBtn.onClick = searchSpriteEditor.OnHelpBtnClick;

        hb1.Add(searchTextBox);
        hb1.Add(vagueSearchBtn);
        hb1.Add(searchBtn);
        hb1.Add(setBtn);
        hb1.Add(helpBtn);

        MainViewCtrl spriteView = new MainViewCtrl();
        spriteView.Name     = m_SpriteViewName;
        spriteView.bkColor  = Color.gray;
        spriteView.Is2DView = true;

        LabelCtrl spriteInfoLabel = new LabelCtrl();
        spriteInfoLabel.Name    = m_SpriteInfoLabel;
        spriteInfoLabel.Caption = "";

        MainViewCtrl atlasView = new MainViewCtrl();
        atlasView.Name     = m_AtlasViewName;
        atlasView.bkColor  = Color.gray;
        atlasView.Is2DView = true;

        LabelCtrl atlasInfoLabel = new LabelCtrl();
        atlasInfoLabel.Name    = m_AtlasInfoLabel;
        atlasInfoLabel.Caption = "";

        hb2_1_1.Add(spriteView);
        hb2_1_2.Add(spriteInfoLabel);

        hb2_2_1.Add(atlasView);
        hb2_2_2.Add(atlasInfoLabel);

        hs2_1_1.Add(hb2_1_1);
        hs2_1_1.Add(hb2_1_2);

        hs2_2_1.Add(hb2_2_1);
        hs2_2_1.Add(hb2_2_2);

        vb2_1.Add(hs2_1_1);
        vb2_2.Add(hs2_2_1);

        vs2_1.Add(vb2_1);
        vs2_1.Add(vb2_2);

        hb2.Add(vs2_1);

        ListViewCtrl searchResultList = new ListViewCtrl();
        searchResultList.Name            = m_SearchResultListName;
        searchResultList.onItemSelected  = searchSpriteEditor.OnSelectListItem;
        searchResultList.onItemSelectedR = searchSpriteEditor.OnSelectListItem;

        SpaceCtrl spaceCtrl = new SpaceCtrl();
        spaceCtrl.CurrValue = 30f;

        vb3.Add(searchResultList);
        vb3.Add(spaceCtrl);

        hs1.Add(hb1);
        hs1.Add(hs2);

        hs2.Add(hb2);
        hs2.Add(vb3);

        m_EditorRoot.RootCtrl = hs1;
        #endregion

        m_EditorRoot.onGUI = searchSpriteEditor.OnEditorGUI;
    }
Ejemplo n.º 10
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();
    }