BS 0.2.0 Visual
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using static Convention.WindowsUI.Variant.PropertiesWindow;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Convention.WindowsUI.Variant
|
||||
{
|
||||
public interface IHierarchyItemTitle
|
||||
{
|
||||
string HierarchyItemTitle { get; }
|
||||
}
|
||||
|
||||
public class HierarchyItem : PropertyListItem
|
||||
{
|
||||
[Content, HopeNotNull] public object m_target;
|
||||
public object target
|
||||
{
|
||||
get => m_target;
|
||||
set
|
||||
{
|
||||
m_target = value;
|
||||
}
|
||||
}
|
||||
[Content] public bool IsEnableFocusWindow = true;
|
||||
[Content] public bool IsUpdateWhenTargetIsString = true;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (target is IHierarchyItemTitle ht)
|
||||
{
|
||||
this.title = ht.HierarchyItemTitle;
|
||||
}
|
||||
else if (IsUpdateWhenTargetIsString && target is string str)
|
||||
{
|
||||
this.title = str;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
AddListener(OnFocusHierarchyItem);
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (InspectorWindow.instance.GetTarget() == target)
|
||||
{
|
||||
InspectorWindow.instance.ClearWindow();
|
||||
}
|
||||
}
|
||||
|
||||
public List<ItemEntry> CreateSubPropertyItemWithBinders(params object[] binders)
|
||||
{
|
||||
List<ItemEntry> entries = CreateSubPropertyItem(Entry.rootWindow, binders.Length);
|
||||
for (int i = 0, e = binders.Length; i != e; i++)
|
||||
{
|
||||
var item = entries[i].ref_value.GetComponent<HierarchyItem>();
|
||||
item.target = binders[i];
|
||||
HierarchyWindow.instance.AddReference(binders[i], item);
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
[Content]
|
||||
public void OnFocusHierarchyItem()
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
throw new InvalidOperationException("target is null");
|
||||
}
|
||||
InspectorWindow.instance.SetTarget(target, this);
|
||||
if (!IsEnableFocusWindow)
|
||||
return;
|
||||
if (FocusWindowIndictaor.instance != null)
|
||||
FocusWindowIndictaor.instance.SetTargetRectTransform(TextRectTransform);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fed528a9d8dfc2d49a3e345c09ed5837
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Convention
|
||||
{
|
||||
public interface ILoadedInHierarchy { }
|
||||
public interface IOnlyLoadedInHierarchy { }
|
||||
public class HierarchyLoadedIn : MonoAnyBehaviour
|
||||
{
|
||||
private void Update()
|
||||
{
|
||||
if (!RegisterBaseWrapperExtension.Registers.ContainsKey(typeof(WindowsUI.Variant.HierarchyWindow)))
|
||||
return;
|
||||
var onlys = GetComponents<IOnlyLoadedInHierarchy>();
|
||||
try
|
||||
{
|
||||
if (onlys != null && onlys.Length != 0)
|
||||
{
|
||||
WindowsUI.Variant.HierarchyWindow.instance.CreateRootItemEntryWithBinders(onlys[0])[0]
|
||||
.ref_value
|
||||
.GetComponent<WindowsUI.Variant.HierarchyItem>()
|
||||
.title = $"{name}";
|
||||
}
|
||||
else
|
||||
{
|
||||
var components = GetComponents<ILoadedInHierarchy>();
|
||||
if (components.Length > 1)
|
||||
{
|
||||
var goItem = WindowsUI.Variant.HierarchyWindow.instance.CreateRootItemEntryWithGameObject(gameObject);
|
||||
goItem.ref_value.GetComponent<WindowsUI.Variant.HierarchyItem>().title = $"{name}";
|
||||
foreach (var item in components)
|
||||
{
|
||||
goItem.ref_value.GetComponent<WindowsUI.Variant.HierarchyItem>().CreateSubPropertyItemWithBinders(item)[0]
|
||||
.ref_value
|
||||
.GetComponent<WindowsUI.Variant.HierarchyItem>()
|
||||
.title = $"{name}-{item.GetType()}";
|
||||
}
|
||||
}
|
||||
else if(components.Length==1)
|
||||
{
|
||||
WindowsUI.Variant.HierarchyWindow.instance.CreateRootItemEntryWithBinders(components[0])[0]
|
||||
.ref_value
|
||||
.GetComponent<WindowsUI.Variant.HierarchyItem>()
|
||||
.title = $"{name}";
|
||||
}
|
||||
else
|
||||
{
|
||||
var goItem = WindowsUI.Variant.HierarchyWindow.instance.CreateRootItemEntryWithGameObject(gameObject);
|
||||
goItem.ref_value.GetComponent<WindowsUI.Variant.HierarchyItem>().title = $"{name}";
|
||||
foreach (var item in GetComponents<Component>())
|
||||
{
|
||||
goItem.ref_value.GetComponent<WindowsUI.Variant.HierarchyItem>().CreateSubPropertyItemWithBinders(item)[0]
|
||||
.ref_value
|
||||
.GetComponent<WindowsUI.Variant.HierarchyItem>()
|
||||
.title = $"{name}-{item.GetType()}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
finally
|
||||
{
|
||||
GameObject.DestroyImmediate(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9daa10f8493ef343892b18ea5365cf7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,135 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using static Convention.WindowsUI.Variant.PropertiesWindow;
|
||||
|
||||
namespace Convention.WindowsUI.Variant
|
||||
{
|
||||
[RequireComponent(typeof(PropertiesWindow))]
|
||||
public class HierarchyWindow : MonoSingleton<HierarchyWindow>
|
||||
{
|
||||
[Resources] public WindowManager windowManager;
|
||||
[Resources, SerializeField] private PropertiesWindow m_PropertiesWindow;
|
||||
private RegisterWrapper<HierarchyWindow> m_RegisterWrapper;
|
||||
|
||||
private Dictionary<int, object> AllReferenceLinker = new();
|
||||
private Dictionary<object, int> AllReferenceLinker_R = new();
|
||||
private Dictionary<object, HierarchyItem> AllReferenceItemLinker = new();
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>Ӧ<EFBFBD><D3A6>tab
|
||||
/// </summary>
|
||||
/// <param name="reference"></param>
|
||||
/// <param name="item"></param>
|
||||
public void AddReference([In] object reference, [In] HierarchyItem item)
|
||||
{
|
||||
int code = reference.GetHashCode();
|
||||
this.AllReferenceLinker[code] = reference;
|
||||
this.AllReferenceLinker_R[reference] = code;
|
||||
this.AllReferenceItemLinker[reference] = item;
|
||||
}
|
||||
public void RemoveReference([In] object reference)
|
||||
{
|
||||
int code = this.AllReferenceLinker_R[reference];
|
||||
this.AllReferenceLinker_R.Remove(reference);
|
||||
this.AllReferenceLinker.Remove(code);
|
||||
this.AllReferenceItemLinker.Remove(reference);
|
||||
}
|
||||
public object GetReference(int code) => this.AllReferenceLinker[code];
|
||||
public int GetReferenceCode([In] object reference) => this.AllReferenceLinker_R[reference];
|
||||
public HierarchyItem GetReferenceItem([In] object reference) => this.AllReferenceItemLinker[reference];
|
||||
public bool ContainsReference(int code) => this.AllReferenceLinker.ContainsKey(code);
|
||||
public bool ContainsReference(object reference) => this.AllReferenceLinker_R.ContainsKey(reference);
|
||||
|
||||
public void SetHierarchyItemParent([In] HierarchyItem childItemTab, [In] HierarchyItem parentItemTab)
|
||||
{
|
||||
//object target = childItemTab.target;
|
||||
//childItemTab.Entry.Release();
|
||||
//parentItemTab.CreateSubPropertyItemWithBinders(target);
|
||||
childItemTab.transform.SetParent(parentItemTab.transform);
|
||||
}
|
||||
public void SetHierarchyItemParent([In] HierarchyItem childItemTab, [In] HierarchyWindow rootWindow)
|
||||
{
|
||||
//object target = childItemTab.target;
|
||||
//childItemTab.Entry.Release();
|
||||
//rootWindow.CreateRootItemEntryWithBinders(target);
|
||||
childItemTab.transform.SetParent(rootWindow.m_PropertiesWindow.TargetWindowContent);
|
||||
}
|
||||
|
||||
|
||||
public List<ItemEntry> CreateRootItemEntryWithBinders(params object[] binders)
|
||||
{
|
||||
List<ItemEntry> entries = m_PropertiesWindow.CreateRootItemEntries(binders.Length);
|
||||
for (int i = 0, e = binders.Length; i != e; i++)
|
||||
{
|
||||
var item = entries[i].ref_value.GetComponent<HierarchyItem>();
|
||||
item.target = binders[i];
|
||||
AddReference(binders[i], item);
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
public ItemEntry CreateRootItemEntryWithGameObjectAndSetParent([In] GameObject binder, [In] HierarchyItem parentItemTab)
|
||||
{
|
||||
var result = parentItemTab.CreateSubPropertyItemWithBinders(binder)[0];
|
||||
var root = result.ref_value.GetComponent<HierarchyItem>();
|
||||
root.title = binder.name;
|
||||
root.target = binder;
|
||||
AddReference(binder, root);
|
||||
foreach (Transform child in binder.transform)
|
||||
{
|
||||
CreateRootItemEntryWithGameObjectAndSetParent(child.gameObject, root);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public ItemEntry CreateRootItemEntryWithGameObject([In] GameObject binder)
|
||||
{
|
||||
var result = m_PropertiesWindow.CreateRootItemEntries(1)[0];
|
||||
var root = result.ref_value.GetComponent<HierarchyItem>();
|
||||
root.title = binder.name;
|
||||
root.target = binder;
|
||||
AddReference(binder, root);
|
||||
foreach (Transform child in binder.transform)
|
||||
{
|
||||
CreateRootItemEntryWithGameObjectAndSetParent(child.gameObject, root);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
m_RegisterWrapper = new(() => { });
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
windowManager = GetComponent<WindowManager>();
|
||||
m_PropertiesWindow = GetComponent<PropertiesWindow>();
|
||||
AllReferenceLinker = new();
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
m_RegisterWrapper.Release();
|
||||
}
|
||||
|
||||
public void RenameTabWhenItFocus()
|
||||
{
|
||||
Transform focus = FocusWindowIndictaor.instance.Target;
|
||||
var item = focus.GetComponent<HierarchyItem>();
|
||||
while (item == null && focus != null)
|
||||
{
|
||||
focus = focus.parent;
|
||||
if (focus == null)
|
||||
return;
|
||||
item = focus.GetComponent<HierarchyItem>();
|
||||
}
|
||||
if (item != null)
|
||||
{
|
||||
SharedModule.instance.Rename(item.text, x =>
|
||||
{
|
||||
item.text = x;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 958316f304c029041901ecb7fffa1929
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user