2021-04-23 21:50:58 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityExplorer.Core;
|
|
|
|
|
using UnityExplorer.Core.Config;
|
|
|
|
|
using UnityExplorer.UI.Models;
|
2021-05-09 20:18:33 +10:00
|
|
|
|
using UnityExplorer.UI.ObjectExplorer;
|
2021-04-23 21:50:58 +10:00
|
|
|
|
using UnityExplorer.UI.Utility;
|
|
|
|
|
using UnityExplorer.UI.Widgets;
|
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.UI.Panels
|
|
|
|
|
{
|
2021-05-09 20:18:33 +10:00
|
|
|
|
public class ObjectExplorerPanel : UIPanel
|
2021-04-23 21:50:58 +10:00
|
|
|
|
{
|
|
|
|
|
public override string Name => "Object Explorer";
|
|
|
|
|
public override UIManager.Panels PanelType => UIManager.Panels.ObjectExplorer;
|
2021-05-05 21:27:09 +10:00
|
|
|
|
public override int MinWidth => 350;
|
|
|
|
|
public override int MinHeight => 200;
|
2021-04-23 21:50:58 +10:00
|
|
|
|
|
|
|
|
|
public SceneExplorer SceneExplorer;
|
|
|
|
|
public ObjectSearch ObjectSearch;
|
|
|
|
|
|
2021-04-30 21:34:50 +10:00
|
|
|
|
public override bool ShowByDefault => true;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
public override bool ShouldSaveActiveState => true;
|
|
|
|
|
|
2021-04-29 21:01:08 +10:00
|
|
|
|
public int SelectedTab = 0;
|
2021-04-23 21:50:58 +10:00
|
|
|
|
private readonly List<UIModel> tabPages = new List<UIModel>();
|
2021-04-26 19:56:21 +10:00
|
|
|
|
private readonly List<ButtonRef> tabButtons = new List<ButtonRef>();
|
2021-04-23 21:50:58 +10:00
|
|
|
|
|
|
|
|
|
public void SetTab(int tabIndex)
|
|
|
|
|
{
|
|
|
|
|
if (SelectedTab != -1)
|
|
|
|
|
DisableTab(SelectedTab);
|
|
|
|
|
|
|
|
|
|
var content = tabPages[tabIndex];
|
|
|
|
|
content.SetActive(true);
|
|
|
|
|
|
|
|
|
|
var button = tabButtons[tabIndex];
|
2021-05-11 19:18:27 +10:00
|
|
|
|
RuntimeProvider.Instance.SetColorBlock(button.Component, UIManager.enabledButtonColor, UIManager.enabledButtonColor * 1.2f);
|
2021-04-23 21:50:58 +10:00
|
|
|
|
|
|
|
|
|
SelectedTab = tabIndex;
|
|
|
|
|
SaveToConfigManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisableTab(int tabIndex)
|
|
|
|
|
{
|
|
|
|
|
tabPages[tabIndex].SetActive(false);
|
2021-05-11 19:18:27 +10:00
|
|
|
|
RuntimeProvider.Instance.SetColorBlock(tabButtons[tabIndex].Component, UIManager.disabledButtonColor, UIManager.disabledButtonColor * 1.2f);
|
2021-04-23 21:50:58 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update()
|
|
|
|
|
{
|
2021-04-24 05:23:29 +10:00
|
|
|
|
if (SelectedTab == 0)
|
|
|
|
|
SceneExplorer.Update();
|
2021-05-05 21:27:09 +10:00
|
|
|
|
else
|
|
|
|
|
ObjectSearch.Update();
|
2021-04-23 21:50:58 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-13 23:03:30 +10:00
|
|
|
|
public override string GetSaveDataFromConfigManager() => ConfigManager.ObjectExplorerData.Value;
|
2021-05-05 21:27:09 +10:00
|
|
|
|
|
2021-04-29 21:01:08 +10:00
|
|
|
|
public override void DoSaveToConfigElement()
|
2021-04-23 21:50:58 +10:00
|
|
|
|
{
|
2021-04-29 21:01:08 +10:00
|
|
|
|
ConfigManager.ObjectExplorerData.Value = this.ToSaveData();
|
2021-04-23 21:50:58 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToSaveData()
|
|
|
|
|
{
|
|
|
|
|
string ret = base.ToSaveData();
|
|
|
|
|
ret += "|" + SelectedTab;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ApplySaveData(string data)
|
|
|
|
|
{
|
|
|
|
|
base.ApplySaveData(data);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int tab = int.Parse(data.Split('|').Last());
|
|
|
|
|
SelectedTab = tab;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
SelectedTab = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-29 21:01:08 +10:00
|
|
|
|
SelectedTab = Math.Max(0, SelectedTab);
|
|
|
|
|
SelectedTab = Math.Min(1, SelectedTab);
|
|
|
|
|
|
2021-04-23 21:50:58 +10:00
|
|
|
|
SetTab(SelectedTab);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-05 21:27:09 +10:00
|
|
|
|
protected internal override void DoSetDefaultPosAndAnchors()
|
2021-04-23 21:50:58 +10:00
|
|
|
|
{
|
|
|
|
|
mainPanelRect.localPosition = Vector2.zero;
|
2021-05-03 21:02:01 +10:00
|
|
|
|
mainPanelRect.pivot = new Vector2(0f, 1f);
|
2021-05-05 21:27:09 +10:00
|
|
|
|
mainPanelRect.anchorMin = new Vector2(0.125f, 0.175f);
|
|
|
|
|
mainPanelRect.anchorMax = new Vector2(0.325f, 0.925f);
|
|
|
|
|
//mainPanelRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 350);
|
2021-04-23 21:50:58 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ConstructPanelContent()
|
|
|
|
|
{
|
|
|
|
|
// Tab bar
|
|
|
|
|
var tabGroup = UIFactory.CreateHorizontalGroup(content, "TabBar", true, true, true, true, 2, new Vector4(2, 2, 2, 2));
|
|
|
|
|
UIFactory.SetLayoutElement(tabGroup, minHeight: 25, flexibleHeight: 0);
|
|
|
|
|
|
|
|
|
|
// Scene Explorer
|
|
|
|
|
SceneExplorer = new SceneExplorer(this);
|
|
|
|
|
SceneExplorer.ConstructUI(content);
|
|
|
|
|
tabPages.Add(SceneExplorer);
|
|
|
|
|
|
|
|
|
|
// Object search
|
|
|
|
|
ObjectSearch = new ObjectSearch(this);
|
|
|
|
|
ObjectSearch.ConstructUI(content);
|
|
|
|
|
tabPages.Add(ObjectSearch);
|
|
|
|
|
|
|
|
|
|
// set up tabs
|
|
|
|
|
AddTabButton(tabGroup, "Scene Explorer");
|
|
|
|
|
AddTabButton(tabGroup, "Object Search");
|
|
|
|
|
|
|
|
|
|
// default active state: Active
|
|
|
|
|
UIManager.SetPanelActive(PanelType, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddTabButton(GameObject tabGroup, string label)
|
|
|
|
|
{
|
|
|
|
|
var button = UIFactory.CreateButton(tabGroup, $"Button_{label}", label);
|
|
|
|
|
|
|
|
|
|
int idx = tabButtons.Count;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
//button.onClick.AddListener(() => { SetTab(idx); });
|
|
|
|
|
button.OnClick += () => { SetTab(idx); };
|
2021-04-23 21:50:58 +10:00
|
|
|
|
|
|
|
|
|
tabButtons.Add(button);
|
|
|
|
|
|
|
|
|
|
DisableTab(tabButtons.Count - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|