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 }
//构建控件 public static void InitControls(EditorRoot editorRoot) { s_root = editorRoot; editorRoot.RootCtrl = new HSpliterCtrl(); (editorRoot.RootCtrl as SpliterCtrl).Dragable = false; editorRoot.RootCtrl.layoutConstraint = LayoutConstraint.GetSpliterConstraint(30); HBoxCtrl menuArea = new HBoxCtrl(); editorRoot.RootCtrl.Add(menuArea); _BuildMenuButtons(menuArea); HSpliterCtrl h1 = new HSpliterCtrl(); h1.layoutConstraint = LayoutConstraint.GetSpliterConstraint(30); editorRoot.RootCtrl.Add(h1); HBoxCtrl playCtrlArea = new HBoxCtrl(); h1.Add(playCtrlArea); //播放控件 PlayCtrl playCtrl = new PlayCtrl(); playCtrl.Name = s_playCtrlName; playCtrl.onValueChange = OnPlayCtrlValueChange; playCtrl.onStop = OnPlayCtrlStop; playCtrlArea.Add(playCtrl); VSpliterCtrl v1 = new VSpliterCtrl(); v1.layoutConstraint = LayoutConstraint.GetSpliterConstraint(200); v1.Dragable = false; VBoxCtrl speListArea = new VBoxCtrl(); v1.Add(speListArea); h1.Add(v1); //特效动画子项列表 ListViewCtrl speListView = new ListViewCtrl(); speListView.Name = s_speListCtrlName; speListView.onAcceptDragObjs = OnSpeListAcceptDragObjs; speListView.onDropObjs = OnSpeListDropObjs; speListView.onItemSelected = OnSpeListItemSelect; speListView.onDoubleClick = OnSpeListItemDoubleClick; speListView.onScroll = OnSpeListScroll; //speListView.onItemSelectedR = OnSpeListItemRightBtnUp; speListView.onItemSelectedRU = OnSpeListItemRightBtnUp; speListArea.Add(speListView); VSpliterCtrl v2 = new VSpliterCtrl(); v2.layoutConstraint = LayoutConstraint.GetSpliterConstraint(400, true); v2.Dragable = true; v1.Add(v2); VBoxCtrl timeLineViewArea = new VBoxCtrl(); v2.Add(timeLineViewArea); //时间线控件 TimeLineViewCtrl timeLineView = new TimeLineViewCtrl(); timeLineView.Name = s_speTimeLineCtrlName; timeLineView.onItemSelected = OnTimeLineItemSelect; timeLineViewArea.Add(timeLineView); VBoxCtrl tabViewArea = new VBoxCtrl(); v2.Add(tabViewArea); TabViewCtrl tabView = new TabViewCtrl(); tabView.Name = s_tabViewCtrlName; tabViewArea.Add(tabView); tabView.onItemSelected = OnTabViewSelect; _BuildPropertyTabView(tabView); {//注册窗体回调 editorRoot.onEnable = OnEditorEnable; editorRoot.onDisable = OnEditorDisable; editorRoot.onUpdate = OnEditorUpdate; editorRoot.onDestroy = OnEditorDestroy; editorRoot.onGUI = OnEditorGUI; editorRoot.onMessage = OnEditorMessage; } }
//这个方法就是利用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); }