BS 0.2.0 Visual
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Convention.WindowsUI.Variant
|
||||
{
|
||||
public class InspectorButton : InspectorDrawer
|
||||
{
|
||||
[Resources] public Button RawButton;
|
||||
[Resources] public ModernUIButton ModernButton;
|
||||
|
||||
private void OnCallback()
|
||||
{
|
||||
targetItem.InvokeAction();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (RawButton)
|
||||
{
|
||||
RawButton.onClick.AddListener(OnCallback);
|
||||
if (ModernButton)
|
||||
{
|
||||
ModernButton.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
else if (ModernButton)
|
||||
{
|
||||
ModernButton.AddListener(OnCallback);
|
||||
if (targetItem.targetMemberInfo != null)
|
||||
ModernButton.title = targetItem.targetMemberInfo.Name;
|
||||
else
|
||||
ModernButton.title = "Invoke";
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (RawButton)
|
||||
RawButton.interactable = targetItem.AbleChangeType;
|
||||
if (ModernButton)
|
||||
ModernButton.interactable = targetItem.AbleChangeType;
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
RawButton = GetComponent<Button>();
|
||||
ModernButton = GetComponent<ModernUIButton>();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2ff2c456623f0b44b8a3151524f8a2c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,10 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Convention.WindowsUI.Variant
|
||||
{
|
||||
public class InspectorDictionary : InspectorDrawer
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3247e464de0aa44ead75124e669e841
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Convention.WindowsUI.Variant
|
||||
{
|
||||
public class InspectorEnum : InspectorDrawer
|
||||
{
|
||||
[Resources] public ModernUIDropdown m_Dropdown;
|
||||
|
||||
private Type enumType;
|
||||
private bool isFlags;
|
||||
private string[] enumNames;
|
||||
|
||||
private bool GetIsFlags()
|
||||
{
|
||||
if (enumType.IsEnum)
|
||||
return enumType.GetCustomAttributes(typeof(FlagsAttribute), true).Length != 0;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
private string[] GetEnumNames()
|
||||
{
|
||||
if (enumType.IsEnum)
|
||||
return Enum.GetNames(enumType);
|
||||
else
|
||||
{
|
||||
var curValue = InspectorWindow.instance.GetTarget();
|
||||
var curType = curValue.GetType();
|
||||
var enumGeneratorField = curType.GetField(targetItem.targetDrawer.enumGenerater);
|
||||
if (enumGeneratorField != null)
|
||||
return (enumGeneratorField.GetValue(curValue) as IEnumerable<string>).ToArray();
|
||||
else
|
||||
{
|
||||
return (curType.GetMethod(targetItem.targetDrawer.enumGenerater).Invoke(curValue, new object[] { }) as IEnumerable<string>).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_Dropdown.ClearOptions();
|
||||
enumType = targetItem.GetValue().GetType();
|
||||
isFlags = GetIsFlags();
|
||||
enumNames = GetEnumNames();
|
||||
if (enumType.IsEnum)
|
||||
{
|
||||
int currentValue = (int)targetItem.GetValue();
|
||||
foreach (var name in enumNames)
|
||||
{
|
||||
var item = m_Dropdown.CreateOption(name, T =>
|
||||
{
|
||||
if (Enum.TryParse(enumType, name, out var result))
|
||||
{
|
||||
if (isFlags)
|
||||
{
|
||||
targetItem.SetValue((int)targetItem.GetValue() | (int)result);
|
||||
}
|
||||
else if (T)
|
||||
{
|
||||
targetItem.SetValue(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (isFlags)
|
||||
{
|
||||
item.isOn = ((int)Enum.Parse(enumType, name) & currentValue) != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.isOn = (int)Enum.Parse(enumType, name) == currentValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string currentValue = (string)targetItem.GetValue();
|
||||
foreach (var name in enumNames)
|
||||
{
|
||||
var item = m_Dropdown.CreateOption(name, T => targetItem.SetValue(name));
|
||||
item.isOn = name == currentValue;
|
||||
}
|
||||
}
|
||||
m_Dropdown.interactable = targetItem.AbleChangeType;
|
||||
m_Dropdown.RefreshImmediate();
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
m_Dropdown = GetComponent<ModernUIDropdown>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(targetItem.UpdateType)
|
||||
{
|
||||
foreach (var item in m_Dropdown.dropdownItems)
|
||||
{
|
||||
if (isFlags)
|
||||
{
|
||||
item.isOn = ((int)Enum.Parse(enumType, item.itemName) & (int)targetItem.GetValue()) != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (enumType.IsEnum)
|
||||
item.isOn = (int)Enum.Parse(enumType, item.itemName) == (int)targetItem.GetValue();
|
||||
else
|
||||
item.isOn = item.itemName == (string)targetItem.GetValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b74cf48865e5f12469141133ccca7e21
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,78 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
|
||||
namespace Convention.WindowsUI.Variant
|
||||
{
|
||||
public class InspectorImage : InspectorDrawer
|
||||
{
|
||||
[Resources] public RawImage ImageArea;
|
||||
[Resources] public Button RawButton;
|
||||
|
||||
public void SetImage([In]Texture texture)
|
||||
{
|
||||
if (targetItem.GetValueType() == texture.GetType())
|
||||
targetItem.SetValue(texture);
|
||||
else if (targetItem.GetValueType() == typeof(Sprite))
|
||||
{
|
||||
targetItem.SetValue(texture.CopyTexture().ToSprite());
|
||||
}
|
||||
else if(targetItem.GetType() == typeof(Texture2D))
|
||||
{
|
||||
targetItem.SetValue(texture.CopyTexture());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException("Unsupport Image Convert");
|
||||
}
|
||||
ImageArea.texture = texture;
|
||||
}
|
||||
|
||||
private void OnCallback()
|
||||
{
|
||||
string filter = "";
|
||||
foreach (var ext in ToolFile.ImageFileExtension)
|
||||
filter += "*." + ext + ";";
|
||||
string path = PluginExtenion.SelectFile("image or texture|" + filter);
|
||||
if (path == null || path.Length == 0)
|
||||
return;
|
||||
var file = new ToolFile(path);
|
||||
if (file.IsExist == false)
|
||||
return;
|
||||
Texture2D texture = file.LoadAsImage();
|
||||
SetImage(texture);
|
||||
if (targetItem.target is IInspectorUpdater updater)
|
||||
{
|
||||
updater.OnInspectorUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
RawButton.onClick.AddListener(OnCallback);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
RawButton.interactable = targetItem.AbleChangeType;
|
||||
if (targetItem.GetValueType().IsSubclassOf(typeof(Texture)))
|
||||
ImageArea.texture = (Texture)targetItem.GetValue();
|
||||
else if (targetItem.GetValueType() == typeof(Sprite))
|
||||
ImageArea.texture = ((Sprite)targetItem.GetValue()).texture;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (targetItem.UpdateType && targetItem.GetValueType().IsSubclassOf(typeof(Texture)))
|
||||
{
|
||||
ImageArea.texture = (Texture)targetItem.GetValue();
|
||||
}
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
ImageArea = GetComponent<RawImage>();
|
||||
RawButton = GetComponent<Button>();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be24c6df69229ae41a42cfbc76ab1ad4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,408 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using static Convention.WindowsUI.Variant.PropertiesWindow;
|
||||
|
||||
namespace Convention.WindowsUI.Variant
|
||||
{
|
||||
/// <summary>
|
||||
/// enum&1==1<><31>Ϊ<EFBFBD><CEAA>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public enum InspectorDrawType
|
||||
{
|
||||
// Auto
|
||||
Auto = -1,
|
||||
// String
|
||||
Text = 0,
|
||||
// Bool
|
||||
Toggle = 1 << 1,
|
||||
// Sripte
|
||||
Image = 1 << 2,
|
||||
// Transform
|
||||
Transform = 1 << 3,
|
||||
// Container
|
||||
List = 1 << 4 + 1, Dictionary = 1 << 5 + 1, Array = 1 << 6 + 1,
|
||||
// Object
|
||||
Reference = 1 << 7, Structure = 1 << 8,
|
||||
// Method
|
||||
Button = 1 << 9,
|
||||
// Enum
|
||||
Enum = 1 << 10
|
||||
}
|
||||
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
|
||||
public class InspectorDrawAttribute : Attribute
|
||||
{
|
||||
public readonly InspectorDrawType drawType;
|
||||
public readonly bool isUpdateAble = true;
|
||||
public readonly bool isChangeAble = true;
|
||||
public readonly string name = null;
|
||||
// Get Real Inspector Name: Field
|
||||
public readonly string nameGenerater = null;
|
||||
// Get Real Enum Names: Method
|
||||
public readonly string enumGenerater = null;
|
||||
|
||||
public InspectorDrawAttribute()
|
||||
{
|
||||
this.drawType = InspectorDrawType.Auto;
|
||||
}
|
||||
public InspectorDrawAttribute(InspectorDrawType drawType = InspectorDrawType.Auto, bool isUpdateAble = true,
|
||||
bool isChangeAble = true, string name = null, string nameGenerater = null, string enumGenerater = null)
|
||||
{
|
||||
this.drawType = drawType;
|
||||
this.isUpdateAble = isUpdateAble;
|
||||
this.isChangeAble = isChangeAble;
|
||||
this.name = name;
|
||||
this.nameGenerater = nameGenerater;
|
||||
this.enumGenerater = enumGenerater;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IInspectorUpdater
|
||||
{
|
||||
void OnInspectorUpdate();
|
||||
}
|
||||
|
||||
public abstract class InspectorDrawer : WindowUIModule
|
||||
{
|
||||
[Resources, SerializeField] private InspectorItem m_targetItem;
|
||||
public InspectorItem targetItem { get => m_targetItem; private set => m_targetItem = value; }
|
||||
public virtual void OnInspectorItemInit(InspectorItem item)
|
||||
{
|
||||
targetItem = item;
|
||||
}
|
||||
}
|
||||
|
||||
public class InspectorItem : PropertyListItem,ITitle
|
||||
{
|
||||
[Resources, OnlyNotNullMode, SerializeField] private Text Title;
|
||||
[Resources, OnlyNotNullMode, SerializeField, Header("Inspector Components")]
|
||||
private InspectorDrawer m_TransformModule;
|
||||
[Resources, OnlyNotNullMode, SerializeField]
|
||||
private InspectorDrawer m_TextModule, m_ToggleModule, m_ImageModule, m_ReferenceModule,
|
||||
m_ButtonModule, m_StructureModule, m_DictionaryItemModule, m_EnumItemModule;
|
||||
private Dictionary<InspectorDrawType, InspectorDrawer> m_AllUIModules = new();
|
||||
private List<ItemEntry> m_DynamicSubEntries = new();
|
||||
|
||||
[Content, OnlyPlayMode] public object target;
|
||||
public MemberInfo targetMemberInfo { get; private set; }
|
||||
public ValueWrapper targetValueWrapper { get; private set; }
|
||||
public Action targetFunctionCall { get; private set; }
|
||||
[Setting, SerializeField] private InspectorDrawType targetDrawType;
|
||||
[Setting, SerializeField] private bool targetAbleChangeMode = true;
|
||||
[Setting, SerializeField] private bool targetUpdateMode = true;
|
||||
[Setting, SerializeField] public InspectorDrawAttribute targetDrawer { get; private set; }
|
||||
|
||||
public InspectorDrawer CurrentModule => m_AllUIModules[targetDrawType];
|
||||
public InspectorDrawType DrawType
|
||||
{
|
||||
get => targetDrawType;
|
||||
set => targetDrawType = value;
|
||||
}
|
||||
|
||||
private void EnableDrawType()
|
||||
{
|
||||
if ((1 & (int)targetDrawType) == 0)
|
||||
m_AllUIModules[targetDrawType].gameObject.SetActive(true);
|
||||
else if (targetDrawType == InspectorDrawType.List)
|
||||
{
|
||||
Type listType = (targetMemberInfo != null)
|
||||
? ConventionUtility.SeekValue(target, targetMemberInfo).GetType().GetGenericArguments()[0]
|
||||
: targetValueWrapper.GetValue().GetType().GetGenericArguments()[0];
|
||||
m_DynamicSubEntries = CreateSubPropertyItem(2);
|
||||
m_DynamicSubEntries[0].ref_value.GetComponent<InspectorItem>().SetTarget(null, () =>
|
||||
{
|
||||
(GetValue() as IList).Add(ConventionUtility.GetDefault(listType));
|
||||
});
|
||||
m_DynamicSubEntries[1].ref_value.GetComponent<InspectorItem>().SetTarget(null, () =>
|
||||
{
|
||||
var list = (IList)GetValue();
|
||||
int length = list.Count;
|
||||
if (length != 0)
|
||||
(GetValue() as IList).RemoveAt(length - 1);
|
||||
});
|
||||
CreateSequenceItems(2);
|
||||
}
|
||||
else if (targetDrawType == InspectorDrawType.Dictionary)
|
||||
{
|
||||
|
||||
}
|
||||
else if (targetDrawType == InspectorDrawType.Array)
|
||||
{
|
||||
m_DynamicSubEntries = new();
|
||||
CreateSequenceItems();
|
||||
}
|
||||
else
|
||||
throw new InvalidOperationException($"Unknown {nameof(InspectorDrawType)}: {targetDrawType}");
|
||||
|
||||
void CreateSequenceItems(int offset = 0)
|
||||
{
|
||||
var array = (IList)GetValue();
|
||||
Type arrayType = (targetMemberInfo != null)
|
||||
? ConventionUtility.SeekValue(target, targetMemberInfo).GetType().GetGenericArguments()[0]
|
||||
: targetValueWrapper.GetValue().GetType().GetGenericArguments()[0];
|
||||
int length = array.Count;// (int)ConventionUtility.SeekValue(array, nameof(Array.Length), BindingFlags.Default);
|
||||
m_DynamicSubEntries.AddRange(CreateSubPropertyItem(length));
|
||||
int index = 0;
|
||||
foreach (var item in array)
|
||||
{
|
||||
m_DynamicSubEntries[index + offset].ref_value.GetComponent<PropertyListItem>().title = index.ToString();
|
||||
m_DynamicSubEntries[index + offset].ref_value.GetComponent<InspectorItem>().SetTarget(null, new ValueWrapper(
|
||||
() => array[index],
|
||||
(x) => array[index] = x,
|
||||
arrayType
|
||||
));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DisableDrawType()
|
||||
{
|
||||
if ((1 & (int)targetDrawType) == 0)
|
||||
m_AllUIModules[targetDrawType].gameObject.SetActive(false);
|
||||
else
|
||||
{
|
||||
foreach (var item in m_DynamicSubEntries)
|
||||
{
|
||||
item.Release();
|
||||
}
|
||||
m_DynamicSubEntries.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public bool AbleChangeType
|
||||
{
|
||||
get => targetAbleChangeMode;
|
||||
set => targetAbleChangeMode = value;
|
||||
}
|
||||
public bool UpdateType
|
||||
{
|
||||
get => targetUpdateMode;
|
||||
set => targetUpdateMode = value;
|
||||
}
|
||||
|
||||
public static string BroadcastName => $"On{nameof(InspectorItem)}Init";
|
||||
|
||||
private void InitModules()
|
||||
{
|
||||
m_AllUIModules[InspectorDrawType.Text] = m_TextModule;
|
||||
m_AllUIModules[InspectorDrawType.Toggle] = m_ToggleModule;
|
||||
m_AllUIModules[InspectorDrawType.Image] = m_ImageModule;
|
||||
m_AllUIModules[InspectorDrawType.Transform] = m_TransformModule;
|
||||
m_AllUIModules[InspectorDrawType.Reference] = m_ReferenceModule;
|
||||
m_AllUIModules[InspectorDrawType.Structure] = m_StructureModule;
|
||||
m_AllUIModules[InspectorDrawType.Button] = m_ButtonModule;
|
||||
m_AllUIModules[InspectorDrawType.Enum] = m_EnumItemModule;
|
||||
MakeInspectorItemInit();
|
||||
}
|
||||
private void MakeInspectorItemInit()
|
||||
{
|
||||
foreach (var module in m_AllUIModules)
|
||||
{
|
||||
module.Value.OnInspectorItemInit(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTarget([In] object target, MemberInfo member)
|
||||
{
|
||||
this.target = target;
|
||||
this.targetMemberInfo = member;
|
||||
this.targetValueWrapper = null;
|
||||
this.targetFunctionCall = null;
|
||||
InitModules();
|
||||
RebulidImmediate();
|
||||
}
|
||||
public void SetTarget([In] object target,ValueWrapper wrapper)
|
||||
{
|
||||
this.target = target;
|
||||
this.targetMemberInfo = null;
|
||||
this.targetValueWrapper = wrapper;
|
||||
this.targetFunctionCall = null;
|
||||
InitModules();
|
||||
RebulidImmediate();
|
||||
}
|
||||
public void SetTarget([In] object target,Action action)
|
||||
{
|
||||
this.target = target;
|
||||
this.targetMemberInfo = null;
|
||||
this.targetValueWrapper = null;
|
||||
this.targetFunctionCall = action;
|
||||
InitModules();
|
||||
RebulidImmediate();
|
||||
}
|
||||
|
||||
public void SetValue([In] object value)
|
||||
{
|
||||
if (targetMemberInfo != null)
|
||||
ConventionUtility.PushValue(target, value, targetMemberInfo);
|
||||
else if (targetValueWrapper != null)
|
||||
targetValueWrapper.SetValue(value);
|
||||
else
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
public object GetValue()
|
||||
{
|
||||
if (targetMemberInfo != null)
|
||||
return ConventionUtility.SeekValue(target, targetMemberInfo);
|
||||
else if (targetValueWrapper != null)
|
||||
return targetValueWrapper.GetValue();
|
||||
else
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
public Type GetValueType()
|
||||
{
|
||||
if (targetMemberInfo != null)
|
||||
return ConventionUtility.GetMemberValueType(targetMemberInfo);
|
||||
else if (targetValueWrapper != null)
|
||||
return targetValueWrapper.type;
|
||||
else
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
public void InvokeAction()
|
||||
{
|
||||
if (targetFunctionCall != null)
|
||||
targetFunctionCall.Invoke();
|
||||
else
|
||||
ConventionUtility.InvokeMember(targetMemberInfo, target);
|
||||
}
|
||||
|
||||
[Content, OnlyPlayMode]
|
||||
public void RebulidImmediate()
|
||||
{
|
||||
if (targetMemberInfo != null)
|
||||
{
|
||||
RebuildWithMemberInfo();
|
||||
}
|
||||
else if (targetValueWrapper != null)
|
||||
{
|
||||
RebuildWithWrapper();
|
||||
}
|
||||
else if (targetFunctionCall != null)
|
||||
{
|
||||
RebuildWithFunctionCall();
|
||||
}
|
||||
|
||||
void RebuildWithMemberInfo()
|
||||
{
|
||||
InspectorDrawAttribute drawAttr = null;
|
||||
ArgPackageAttribute argAttr = null;
|
||||
Type type = null;
|
||||
// Reset AbleChangeType
|
||||
this.targetDrawer = drawAttr = targetMemberInfo.GetCustomAttribute<InspectorDrawAttribute>(true);
|
||||
argAttr = targetMemberInfo.GetCustomAttribute<ArgPackageAttribute>(true);
|
||||
type = ConventionUtility.GetMemberValueType(targetMemberInfo);
|
||||
AbleChangeType = targetMemberInfo.GetCustomAttributes(typeof(IgnoreAttribute), true).Length == 0;
|
||||
// Reset DrawType
|
||||
DisableDrawType();
|
||||
if (drawAttr != null)
|
||||
{
|
||||
AbleChangeType &= drawAttr.isChangeAble;
|
||||
UpdateType = drawAttr.isUpdateAble;
|
||||
if (drawAttr.nameGenerater != null)
|
||||
{
|
||||
title = (string)ConventionUtility.SeekValue(target, drawAttr.nameGenerater, typeof(string),
|
||||
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.GetField);
|
||||
}
|
||||
else
|
||||
{
|
||||
title = drawAttr.name;
|
||||
}
|
||||
}
|
||||
if (drawAttr != null && drawAttr.drawType != InspectorDrawType.Auto)
|
||||
{
|
||||
DrawType = drawAttr.drawType;
|
||||
}
|
||||
else if (type != null)
|
||||
{
|
||||
if (ConventionUtility.IsEnum(type))
|
||||
DrawType = InspectorDrawType.Enum;
|
||||
if (ConventionUtility.IsBool(type))
|
||||
DrawType = InspectorDrawType.Toggle;
|
||||
else if (ConventionUtility.IsString(type) || ConventionUtility.IsNumber(type))
|
||||
DrawType = InspectorDrawType.Text;
|
||||
else if (ConventionUtility.IsArray(type))
|
||||
DrawType = InspectorDrawType.Array;
|
||||
else if (ConventionUtility.IsImage(type))
|
||||
DrawType = InspectorDrawType.Image;
|
||||
else if (type.GetInterface(nameof(IEnumerable)) != null && type.GetGenericArguments().Length == 1)
|
||||
DrawType = InspectorDrawType.List;
|
||||
else if (type.GetInterface(nameof(IEnumerable)) != null && type.GetGenericArguments().Length == 2)
|
||||
DrawType = InspectorDrawType.Dictionary;
|
||||
else if (type == typeof(Transform))
|
||||
DrawType = InspectorDrawType.Transform;
|
||||
else if (type.IsClass)
|
||||
DrawType = InspectorDrawType.Reference;
|
||||
else
|
||||
DrawType = InspectorDrawType.Structure;
|
||||
}
|
||||
else if (targetMemberInfo is MethodInfo method)
|
||||
{
|
||||
DrawType = InspectorDrawType.Button;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException("Reach this location by unknown Impl");
|
||||
}
|
||||
EnableDrawType();
|
||||
RectTransformExtension.AdjustSizeToContainsChilds(transform as RectTransform);
|
||||
RectTransformExtension.AdjustSizeToContainsChilds(this.Entry.rootWindow.TargetWindowContent);
|
||||
}
|
||||
|
||||
void RebuildWithWrapper()
|
||||
{
|
||||
Type type = targetValueWrapper.type;
|
||||
AbleChangeType = targetValueWrapper.IsChangeAble;
|
||||
// Reset DrawType
|
||||
if (ConventionUtility.IsBool(type))
|
||||
DrawType = InspectorDrawType.Toggle;
|
||||
else if (ConventionUtility.IsString(type) || ConventionUtility.IsNumber(type))
|
||||
DrawType = InspectorDrawType.Text;
|
||||
else if (ConventionUtility.IsArray(type))
|
||||
DrawType = InspectorDrawType.Array;
|
||||
else if (type.GetInterface(nameof(IEnumerable)) != null && type.GetGenericArguments().Length == 1)
|
||||
DrawType = InspectorDrawType.List;
|
||||
else if (type.GetInterface(nameof(IEnumerable)) != null && type.GetGenericArguments().Length == 2)
|
||||
DrawType = InspectorDrawType.Dictionary;
|
||||
else if (type == typeof(Transform))
|
||||
DrawType = InspectorDrawType.Transform;
|
||||
else if (type.IsSubclassOf(typeof(Texture)))
|
||||
DrawType = InspectorDrawType.Image;
|
||||
else if (type.IsClass)
|
||||
DrawType = InspectorDrawType.Reference;
|
||||
else
|
||||
DrawType = InspectorDrawType.Structure;
|
||||
RectTransformExtension.AdjustSizeToContainsChilds(transform as RectTransform);
|
||||
RectTransformExtension.AdjustSizeToContainsChilds(this.Entry.rootWindow.TargetWindowContent);
|
||||
}
|
||||
|
||||
void RebuildWithFunctionCall()
|
||||
{
|
||||
DrawType = InspectorDrawType.Button;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void FoldChilds()
|
||||
{
|
||||
base.FoldChilds();
|
||||
CurrentModule.gameObject.SetActive(false);
|
||||
}
|
||||
protected override void UnfoldChilds()
|
||||
{
|
||||
base.UnfoldChilds();
|
||||
CurrentModule.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>, <20><><EFBFBD><EFBFBD>GameObject<63><74>SetTarget<65><74>Inspector<6F><72>ʱֻչʾ<D5B9><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չʾComponentsҲ<73><D2B2><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><To GameObject><3E><>ת<EFBFBD><D7AA>GameObject<63><74>Components<74>б<EFBFBD>,
|
||||
/// <20><><see cref="InspectorWindow.BuildWindow"/>
|
||||
/// </summary>
|
||||
public interface IOnlyFocusThisOnInspector : IAnyClass { }
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0533291b170c1a4399696cd176e4440
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,70 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Convention.WindowsUI.Variant
|
||||
{
|
||||
public class InspectorReference : InspectorDrawer
|
||||
{
|
||||
[Resources] public ModernUIInputField TextArea;
|
||||
[Resources] public Button RawButton;
|
||||
public IAnyClass lastReference;
|
||||
[Content] public bool isEditing = false;
|
||||
|
||||
private void OnCallback(string str)
|
||||
{
|
||||
if (str == null || str.Length == 0)
|
||||
{
|
||||
targetItem.SetValue(null);
|
||||
if (targetItem.target is IInspectorUpdater updater)
|
||||
{
|
||||
updater.OnInspectorUpdate();
|
||||
}
|
||||
}
|
||||
else if (int.TryParse(str, out var code) && HierarchyWindow.instance.ContainsReference(code))
|
||||
{
|
||||
targetItem.SetValue(HierarchyWindow.instance.GetReference(code));
|
||||
if (targetItem.target is IInspectorUpdater updater)
|
||||
{
|
||||
updater.OnInspectorUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
RawButton.onClick.AddListener(() => InspectorWindow.instance.SetTarget(targetItem.GetValue(), null));
|
||||
TextArea.AddListener(OnCallback);
|
||||
TextArea.InputFieldSource.Source.onEndEdit.AddListener(x => isEditing = false);
|
||||
TextArea.InputFieldSource.Source.onSelect.AddListener(x => isEditing = true);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
TextArea.interactable = targetItem.AbleChangeType;
|
||||
TextArea.text = targetItem.GetValue().GetHashCode().ToString();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (targetItem.UpdateType && !isEditing)
|
||||
{
|
||||
object value = targetItem.GetValue();
|
||||
if (value != null)
|
||||
{
|
||||
TextArea.text = value.GetHashCode().ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
TextArea.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
TextArea = GetComponent<ModernUIInputField>();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e7609e8ffb820b4ea1eadd9b8e37728
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Convention.WindowsUI.Variant
|
||||
{
|
||||
public class InspectorStructure : InspectorDrawer
|
||||
{
|
||||
[Resources] public Button RawButton;
|
||||
[Resources] public ModernUIButton ModernButton;
|
||||
|
||||
private void OnCallback()
|
||||
{
|
||||
InspectorWindow.instance.SetTarget(targetItem.GetValue(), null);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (RawButton)
|
||||
{
|
||||
RawButton.onClick.AddListener(OnCallback);
|
||||
if (ModernButton)
|
||||
{
|
||||
ModernButton.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
else if (ModernButton)
|
||||
{
|
||||
ModernButton.AddListener(OnCallback);
|
||||
if (targetItem.targetMemberInfo != null)
|
||||
ModernButton.title = targetItem.targetMemberInfo.Name;
|
||||
else
|
||||
ModernButton.title = "Structure";
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (RawButton)
|
||||
RawButton.interactable = targetItem.AbleChangeType;
|
||||
if (ModernButton)
|
||||
ModernButton.interactable = targetItem.AbleChangeType;
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
RawButton = GetComponent<Button>();
|
||||
ModernButton = GetComponent<ModernUIButton>();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7dc85b7bdeffeb4bbc9d7cc6d9a9aaf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Convention.WindowsUI.Variant
|
||||
{
|
||||
public class InspectorText : InspectorDrawer
|
||||
{
|
||||
[Resources] public ModernUIInputField TextArea;
|
||||
[Content] public bool isEditing = false;
|
||||
|
||||
private void OnCallback(string str)
|
||||
{
|
||||
Type[] paramaters = new Type[] { typeof(string), targetItem.GetValueType().MakeByRefType() };
|
||||
var parser = targetItem.GetValueType().GetMethod(nameof(float.Parse), paramaters);
|
||||
if (parser != null)
|
||||
{
|
||||
object out_value = ConventionUtility.GetDefault(targetItem.GetValueType());
|
||||
if ((bool)parser.Invoke(null, new object[] { str, out_value }))
|
||||
{
|
||||
targetItem.SetValue(out_value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
targetItem.SetValue(str);
|
||||
}
|
||||
if (targetItem.target is IInspectorUpdater updater)
|
||||
{
|
||||
updater.OnInspectorUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
TextArea.AddListener(OnCallback);
|
||||
TextArea.InputFieldSource.Source.onEndEdit.AddListener(x => isEditing = false);
|
||||
TextArea.InputFieldSource.Source.onSelect.AddListener(x => isEditing = true);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
TextArea.InputFieldSource.Source.readOnly = !targetItem.AbleChangeType;
|
||||
if (targetItem.AbleChangeType)
|
||||
{
|
||||
try
|
||||
{
|
||||
TextArea.interactable = targetItem.GetValueType().GetMethod(nameof(float.Parse)) != null || ConventionUtility.IsString(targetItem.GetValueType());
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
var value = targetItem.GetValue();
|
||||
TextArea.text = value == null ? "" : value.ToString();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (targetItem.UpdateType && !isEditing)
|
||||
{
|
||||
TextArea.text = targetItem.GetValue().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
TextArea = GetComponent<ModernUIInputField>();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c5f5aa321c5fb034cb333247eafbaa1b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,44 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Convention.WindowsUI.Variant
|
||||
{
|
||||
public class InspectorToggle : InspectorDrawer
|
||||
{
|
||||
[Resources] public ModernUIToggle Toggle;
|
||||
|
||||
private void OnCallback(bool value)
|
||||
{
|
||||
targetItem.SetValue(value);
|
||||
if (targetItem.target is IInspectorUpdater updater)
|
||||
{
|
||||
updater.OnInspectorUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Toggle.AddListener(OnCallback);
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (targetItem.UpdateType)
|
||||
{
|
||||
Toggle.ref_value = (bool)targetItem.GetValue();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
Toggle.interactable = targetItem.AbleChangeType;
|
||||
Toggle.ref_value = (bool)targetItem.GetValue();
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
Toggle = GetComponent<ModernUIToggle>();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 427a4f8c9974bd14ea853c4a51a28037
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,184 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Convention.WindowsUI.Variant
|
||||
{
|
||||
public class InspectorTransform : InspectorDrawer
|
||||
{
|
||||
[Resources] public ModernUIInputField LocalPosition;
|
||||
[Resources] public ModernUIInputField Position;
|
||||
[Resources] public ModernUIInputField Rotation;
|
||||
[Resources] public ModernUIInputField Scale;
|
||||
[Resources] public ModernUIInputField ThisID;
|
||||
[Resources] public ModernUIInputField ParentID;
|
||||
[Content] public bool isEditing = false;
|
||||
[Content] public string lastValue;
|
||||
|
||||
private static bool Parse(string str, out Vector3 result)
|
||||
{
|
||||
var strs = str.Split(',');
|
||||
result = new();
|
||||
if (strs.Length != 3)
|
||||
return false;
|
||||
if (float.TryParse(strs[0], out float x) == false)
|
||||
return false;
|
||||
if (float.TryParse(strs[1], out float y) == false)
|
||||
return false;
|
||||
if (float.TryParse(strs[2], out float z) == false)
|
||||
return false;
|
||||
result.x = x;
|
||||
result.y = y;
|
||||
result.z = z;
|
||||
return true;
|
||||
}
|
||||
private static string ConvertString(Vector3 vec)
|
||||
{
|
||||
return $"{vec.x:F4},{vec.y:F4},{vec.z:F4}";
|
||||
}
|
||||
|
||||
private UnityAction<string> GenerateCallback(Action<Vector3> action)
|
||||
{
|
||||
void OnCallback(string str)
|
||||
{
|
||||
if(Parse(str,out var result))
|
||||
{
|
||||
action(result);
|
||||
if (targetItem.target is IInspectorUpdater updater)
|
||||
{
|
||||
updater.OnInspectorUpdate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Parse(lastValue, out var lastVec))
|
||||
action(lastVec);
|
||||
else
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
return OnCallback;
|
||||
}
|
||||
|
||||
private void GenerateCallback_Transform(string str)
|
||||
{
|
||||
if (int.TryParse(str, out var code))
|
||||
{
|
||||
var TargetTransform = (Transform)targetItem.GetValue();
|
||||
if (code == 0)
|
||||
{
|
||||
TargetTransform.parent = null;
|
||||
if (targetItem.target is IInspectorUpdater updater)
|
||||
{
|
||||
updater.OnInspectorUpdate();
|
||||
}
|
||||
}
|
||||
else if (HierarchyWindow.instance.ContainsReference(code))
|
||||
{
|
||||
var reference = HierarchyWindow.instance.GetReference(code);
|
||||
if (reference is Component component)
|
||||
{
|
||||
TargetTransform.parent = component.transform;
|
||||
if (targetItem.target is IInspectorUpdater updater)
|
||||
{
|
||||
updater.OnInspectorUpdate();
|
||||
}
|
||||
}
|
||||
else if(reference is GameObject go)
|
||||
{
|
||||
TargetTransform.parent = go.transform;
|
||||
if (targetItem.target is IInspectorUpdater updater)
|
||||
{
|
||||
updater.OnInspectorUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
var TargetTransform = (Transform)targetItem.GetValue();
|
||||
LocalPosition.AddListener(GenerateCallback(x => TargetTransform.localPosition = x));
|
||||
LocalPosition.InputFieldSource.Source.onEndEdit.AddListener(x => isEditing = false);
|
||||
LocalPosition.InputFieldSource.Source.onSelect.AddListener(x => isEditing = true);
|
||||
LocalPosition.InputFieldSource.Source.onSelect.AddListener(x => lastValue = ConvertString(TargetTransform.localPosition));
|
||||
|
||||
Position.AddListener(GenerateCallback(x => TargetTransform.position = x));
|
||||
Position.InputFieldSource.Source.onEndEdit.AddListener(x => isEditing = false);
|
||||
Position.InputFieldSource.Source.onSelect.AddListener(x => isEditing = true);
|
||||
Position.InputFieldSource.Source.onSelect.AddListener(x => lastValue = ConvertString(TargetTransform.position));
|
||||
|
||||
Rotation.AddListener(GenerateCallback(x => TargetTransform.eulerAngles = x));
|
||||
Rotation.InputFieldSource.Source.onEndEdit.AddListener(x => isEditing = false);
|
||||
Rotation.InputFieldSource.Source.onSelect.AddListener(x => isEditing = true);
|
||||
Rotation.InputFieldSource.Source.onSelect.AddListener(x => lastValue = ConvertString(TargetTransform.eulerAngles));
|
||||
|
||||
Scale.AddListener(GenerateCallback(x => TargetTransform.localScale = x));
|
||||
Scale.InputFieldSource.Source.onEndEdit.AddListener(x => isEditing = false);
|
||||
Scale.InputFieldSource.Source.onSelect.AddListener(x => isEditing = true);
|
||||
Scale.InputFieldSource.Source.onSelect.AddListener(x => lastValue = ConvertString(TargetTransform.localScale));
|
||||
|
||||
ThisID.InputFieldSource.Source.onEndEdit.AddListener(x => isEditing = false);
|
||||
ThisID.InputFieldSource.Source.onSelect.AddListener(x => isEditing = true);
|
||||
ThisID.InputFieldSource.Source.onSelect.AddListener(x => lastValue = ThisID.text);
|
||||
|
||||
ParentID.AddListener(GenerateCallback_Transform);
|
||||
ParentID.InputFieldSource.Source.onEndEdit.AddListener(x => isEditing = false);
|
||||
ParentID.InputFieldSource.Source.onSelect.AddListener(x => isEditing = true);
|
||||
ParentID.InputFieldSource.Source.onSelect.AddListener(x => lastValue = ParentID.text);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
LocalPosition.interactable = targetItem.AbleChangeType;
|
||||
var TargetTransform = ((Transform)targetItem.GetValue());
|
||||
this.LocalPosition.text = ConvertString(TargetTransform.localPosition);
|
||||
Position.interactable = targetItem.AbleChangeType;
|
||||
this.Position.text = ConvertString(TargetTransform.position);
|
||||
Rotation.interactable = targetItem.AbleChangeType;
|
||||
this.Rotation.text = ConvertString(TargetTransform.eulerAngles);
|
||||
Scale.interactable = targetItem.AbleChangeType;
|
||||
this.Scale.text = ConvertString(TargetTransform.localScale);
|
||||
ThisID.text = targetItem.target.GetHashCode().ToString();
|
||||
if (TargetTransform.parent == null)
|
||||
ParentID.text = "0";
|
||||
else
|
||||
ParentID.text = TargetTransform.parent.GetHashCode().ToString();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (targetItem.UpdateType && !isEditing)
|
||||
{
|
||||
var TargetTransform = ((Transform)targetItem.GetValue());
|
||||
this.LocalPosition.text = ConvertString(TargetTransform.localPosition);
|
||||
this.Position.text = ConvertString(TargetTransform.position);
|
||||
this.Rotation.text = ConvertString(TargetTransform.eulerAngles);
|
||||
this.Scale.text = ConvertString(TargetTransform.localScale);
|
||||
this.ThisID.text = targetItem.target.GetHashCode().ToString();
|
||||
if (TargetTransform.parent == null)
|
||||
ParentID.text = "0";
|
||||
else
|
||||
ParentID.text = TargetTransform.parent.GetHashCode().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
LocalPosition = transform.Find(nameof(LocalPosition)).GetComponent<ModernUIInputField>();
|
||||
Position = transform.Find(nameof(Position)).GetComponent<ModernUIInputField>();
|
||||
Rotation = transform.Find(nameof(Rotation)).GetComponent<ModernUIInputField>();
|
||||
Scale = transform.Find(nameof(Scale)).GetComponent<ModernUIInputField>();
|
||||
ThisID = transform.Find(nameof(ThisID)).GetComponent<ModernUIInputField>();
|
||||
ParentID = transform.Find(nameof(ParentID)).GetComponent<ModernUIInputField>();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: adbc0b509e231964f9116d4769a80da2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,354 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Convention.WindowsUI.Variant
|
||||
{
|
||||
public class InspectorWindow : WindowsComponent, ISingleton<InspectorWindow>
|
||||
{
|
||||
public static InspectorWindow instance { get; private set; }
|
||||
private RegisterWrapper<InspectorWindow> m_RegisterWrapper;
|
||||
private object target;
|
||||
|
||||
[Setting] public bool IsWorkWithHierarchyWindow = true;
|
||||
[Setting] public bool IsWorkWithTypeIndictaor = true;
|
||||
[Resources, SerializeField, OnlyNotNullMode, WhenAttribute.Is(nameof(IsWorkWithHierarchyWindow), true)] private ModernUIInputField m_ParentHashCodeField;
|
||||
private int m_lastParentHashCode = 0;
|
||||
[Resources, SerializeField, OnlyNotNullMode, WhenAttribute.Is(nameof(IsWorkWithHierarchyWindow), true)] private ModernUIInputField m_ThisHashCodeField;
|
||||
[Resources, SerializeField, HopeNotNull] private WindowManager m_WindowManager;
|
||||
[Resources, SerializeField, HopeNotNull] private PropertiesWindow m_PropertiesWindow;
|
||||
[Content, SerializeField] private List<PropertiesWindow.ItemEntry> m_currentEntries = new();
|
||||
|
||||
[Resources, SerializeField, OnlyNotNullMode, WhenAttribute.Is(nameof(IsWorkWithTypeIndictaor), true)] private Text m_TypeText;
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
if (m_WindowManager == null)
|
||||
m_WindowManager = GetComponent<WindowManager>();
|
||||
if (m_PropertiesWindow == null)
|
||||
m_PropertiesWindow = GetComponent<PropertiesWindow>();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
m_RegisterWrapper.Release();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (m_WindowManager == null)
|
||||
m_WindowManager = GetComponent<WindowManager>();
|
||||
if (m_PropertiesWindow == null)
|
||||
m_PropertiesWindow = GetComponent<PropertiesWindow>();
|
||||
|
||||
m_RegisterWrapper = new(() => { });
|
||||
instance = this;
|
||||
|
||||
if (IsWorkWithHierarchyWindow == true)
|
||||
{
|
||||
m_ParentHashCodeField.gameObject.SetActive(false);
|
||||
m_ParentHashCodeField.AddListener(x =>
|
||||
{
|
||||
if (int.TryParse(x, out var code))
|
||||
{
|
||||
m_lastParentHashCode = code;
|
||||
if (code == 0)
|
||||
{
|
||||
HierarchyWindow.instance.SetHierarchyItemParent(
|
||||
HierarchyWindow.instance.GetReferenceItem(target),
|
||||
HierarchyWindow.instance
|
||||
);
|
||||
}
|
||||
else if (HierarchyWindow.instance.ContainsReference(code))
|
||||
{
|
||||
HierarchyWindow.instance.SetHierarchyItemParent(
|
||||
HierarchyWindow.instance.GetReferenceItem(target),
|
||||
HierarchyWindow.instance.GetReferenceItem(HierarchyWindow.instance.GetReference(code))
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ParentHashCodeField.text = m_lastParentHashCode.ToString();
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (m_ParentHashCodeField != null)
|
||||
m_ParentHashCodeField.gameObject.SetActive(false);
|
||||
if (IsWorkWithHierarchyWindow == true)
|
||||
m_ThisHashCodeField.gameObject.SetActive(false);
|
||||
else if (m_ThisHashCodeField != null)
|
||||
m_ThisHashCodeField.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (IsWorkWithHierarchyWindow && target != null)
|
||||
m_ThisHashCodeField.text = target.GetHashCode().ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>Ӧ<EFBFBD><D3A6>tab
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <returns><3E>Ƿ<EFBFBD><C7B7>봫<EFBFBD><EBB4AB><EFBFBD><EFBFBD>target<65><74>ͬ</returns>
|
||||
[return: When("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>target<65>뱻<EFBFBD><EBB1BB><EFBFBD><EFBFBD>Ϊtarget<65><74>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>ͬ")]
|
||||
public bool SetTarget([In] object target, [In, Opt] HierarchyItem item)
|
||||
{
|
||||
if (item != null && IsWorkWithHierarchyWindow)
|
||||
{
|
||||
throw new InvalidOperationException($"This {nameof(InspectorWindow)} is set {nameof(IsWorkWithHierarchyWindow)}={IsWorkWithHierarchyWindow}, but Argument" +
|
||||
$"{nameof(item)}={item} not null");
|
||||
}
|
||||
bool result = true;
|
||||
if (target is GameObject go)
|
||||
{
|
||||
var only = ConventionUtility.SeekComponent<IOnlyFocusThisOnInspector>(go);
|
||||
if (only != null)
|
||||
{
|
||||
result = true;
|
||||
target = only;
|
||||
}
|
||||
}
|
||||
if (this.target == target)
|
||||
return true;
|
||||
this.target = target;
|
||||
if (IsWorkWithHierarchyWindow)
|
||||
{
|
||||
if (item)
|
||||
{
|
||||
m_ThisHashCodeField.text = target.GetHashCode().ToString();
|
||||
m_lastParentHashCode = item.Entry.GetParent() == null ? 0 : item.Entry.GetParent().ref_value.GetComponent<HierarchyItem>().target.GetHashCode();
|
||||
}
|
||||
m_ParentHashCodeField.gameObject.SetActive(item != null);
|
||||
m_ThisHashCodeField.gameObject.SetActive(item != null);
|
||||
}
|
||||
RefreshImmediateWithoutFocusCheck();
|
||||
return result;
|
||||
}
|
||||
public object GetTarget()
|
||||
{
|
||||
return this.target;
|
||||
}
|
||||
public void RefreshImmediateWithoutFocusCheck()
|
||||
{
|
||||
ClearWindow();
|
||||
if (target != null)
|
||||
BuildWindow();
|
||||
}
|
||||
public void RefreshImmediate()
|
||||
{
|
||||
if (FocusWindowIndictaor.instance.Target == this.rectTransform)
|
||||
{
|
||||
RefreshImmediateWithoutFocusCheck();
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearWindow()
|
||||
{
|
||||
if (IsWorkWithTypeIndictaor)
|
||||
m_TypeText.text = "Not Selected";
|
||||
foreach (var entry in m_currentEntries)
|
||||
{
|
||||
entry.Release();
|
||||
}
|
||||
m_currentEntries.Clear();
|
||||
}
|
||||
private static readonly Type[] IgnoreCutOffType = new Type[] {
|
||||
typeof(MonoAnyBehaviour),
|
||||
typeof(GameObject),
|
||||
typeof(MonoBehaviour),
|
||||
typeof(UnityEngine.Object),
|
||||
typeof(Component)
|
||||
};
|
||||
private void BuildWindow()
|
||||
{
|
||||
if (IsWorkWithTypeIndictaor)
|
||||
m_TypeText.text = target.GetType().Name;
|
||||
var allmembers = ConventionUtility.GetMemberInfos(target.GetType(), IgnoreCutOffType, true, true);
|
||||
var members =
|
||||
(from member in allmembers
|
||||
where member.GetCustomAttributes(typeof(InspectorDrawAttribute), true).Length != 0
|
||||
where (member is MethodInfo info && info.GetParameters().Length == 0) || member is not MethodInfo
|
||||
select member).ToList();
|
||||
int offset = m_currentEntries.Count;
|
||||
// Component or GameObject
|
||||
if (target is Component component)
|
||||
{
|
||||
offset = GenerateComponentTransformModule(offset, component.transform);
|
||||
}
|
||||
else if (target is GameObject go)
|
||||
{
|
||||
offset = GenerateComponentTransformModule(offset, go.transform);
|
||||
offset = GenerateGameObjectComponentModules(offset, go);
|
||||
}
|
||||
// Main
|
||||
if (members.Count == 0)
|
||||
{
|
||||
allmembers = ConventionUtility.GetMemberInfos(target.GetType(), IgnoreCutOffType, false, true);
|
||||
members = (from member in allmembers
|
||||
where (
|
||||
member is MethodInfo info &&
|
||||
info.GetParameters().Length == 0 &&
|
||||
!info.Name.StartsWith("get_") &&
|
||||
!info.Name.StartsWith("set_")
|
||||
) || member is not MethodInfo
|
||||
select member).ToList();
|
||||
}
|
||||
m_currentEntries.AddRange(m_PropertiesWindow.CreateRootItemEntries(members.Count));
|
||||
for (int i = 0, e = members.Count; i < e; i++)
|
||||
{
|
||||
m_currentEntries[i + offset].ref_value.GetComponent<PropertyListItem>().title = members[i].Name;
|
||||
m_currentEntries[i + offset].ref_value.GetComponent<InspectorItem>().SetTarget(target, members[i]);
|
||||
}
|
||||
offset += members.Count;
|
||||
// End To GameObject
|
||||
if (target is MonoBehaviour mono)
|
||||
{
|
||||
offset = GenerateEnableToggleModule(offset, mono);
|
||||
}
|
||||
if (target is Component component_1)
|
||||
{
|
||||
offset = GenerateRemoveComponentButtonModule(offset, component_1);
|
||||
offset = GenerateToGameObjectButtonModule(offset, component_1);
|
||||
}
|
||||
|
||||
int GenerateGameObjectComponentModules(int offset, GameObject go)
|
||||
{
|
||||
int componentsCount = go.GetComponentCount();
|
||||
for (int i = 0; i < componentsCount; i++)
|
||||
{
|
||||
var x_component = go.GetComponentAtIndex(i);
|
||||
var current = m_PropertiesWindow.CreateRootItemEntries(1)[0];
|
||||
m_currentEntries.Add(current);
|
||||
current.ref_value.GetComponent<PropertyListItem>().title = x_component.GetType().Name;
|
||||
current.ref_value.GetComponent<InspectorItem>().SetTarget(
|
||||
target, () => InspectorWindow.instance.SetTarget(x_component, null));
|
||||
}
|
||||
offset += componentsCount;
|
||||
{
|
||||
var DestroyGameObjectButton = m_PropertiesWindow.CreateRootItemEntries(1)[0];
|
||||
DestroyGameObjectButton.ref_value.GetComponent<PropertyListItem>().title = "Destroy GameObject";
|
||||
DestroyGameObjectButton.ref_value.GetComponent<InspectorItem>().SetTarget(target, () =>
|
||||
{
|
||||
HierarchyWindow.instance.GetReferenceItem(go).Entry.Release();
|
||||
HierarchyWindow.instance.RemoveReference(go);
|
||||
GameObject.Destroy(go);
|
||||
InspectorWindow.instance.ClearWindow();
|
||||
});
|
||||
m_currentEntries.Add(DestroyGameObjectButton);
|
||||
offset++;
|
||||
}
|
||||
{
|
||||
var DestroyGameObjectButton = m_PropertiesWindow.CreateRootItemEntries(1)[0];
|
||||
DestroyGameObjectButton.ref_value.GetComponent<PropertyListItem>().title = "GameObject Active";
|
||||
DestroyGameObjectButton.ref_value.GetComponent<InspectorItem>().SetTarget(target, new ValueWrapper(
|
||||
() => go.activeSelf,
|
||||
(x) => go.SetActive((bool)x),
|
||||
typeof(bool)
|
||||
));
|
||||
m_currentEntries.Add(DestroyGameObjectButton);
|
||||
offset++;
|
||||
}
|
||||
{
|
||||
var addComponentField = m_PropertiesWindow.CreateRootItemEntries(1)[0];
|
||||
addComponentField.ref_value.GetComponent<PropertyListItem>().title = "Add Component";
|
||||
var item = addComponentField.ref_value.GetComponent<InspectorItem>();
|
||||
item.SetTarget(target, new ValueWrapper(
|
||||
() => "",
|
||||
(x) =>
|
||||
{
|
||||
string typeName = (string)x;
|
||||
var components = ConventionUtility.SeekType(t => t.IsSubclassOf(typeof(Component)) && t.FullName.Contains(typeName));
|
||||
int c = 0;
|
||||
foreach (var x_component in components)
|
||||
{
|
||||
if (x_component.GetType().Name == typeName || x_component.GetType().Name == typeName)
|
||||
{
|
||||
c++;
|
||||
}
|
||||
}
|
||||
if (c == 1)
|
||||
{
|
||||
components = (
|
||||
from y_component in components
|
||||
where y_component.GetType().Name == typeName || y_component.GetType().FullName == typeName
|
||||
select y_component).ToList();
|
||||
}
|
||||
if (components.Count != 1)
|
||||
return;
|
||||
var component = components[0];
|
||||
InspectorWindow.instance.SetTarget(go.AddComponent(component), null);
|
||||
},
|
||||
typeof(string)
|
||||
));
|
||||
m_currentEntries.Add(addComponentField);
|
||||
offset++;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
int GenerateComponentTransformModule(int offset, Transform transform)
|
||||
{
|
||||
var transformItem = m_PropertiesWindow.CreateRootItemEntries(1)[0];
|
||||
transformItem.ref_value.GetComponent<PropertyListItem>().title = "Transform";
|
||||
transformItem.ref_value.GetComponent<InspectorItem>().SetTarget(target, new ValueWrapper(
|
||||
() => transform,
|
||||
(x) => throw new InvalidOperationException("Transform cannt be set"),
|
||||
typeof(Transform)
|
||||
));
|
||||
m_currentEntries.Add(transformItem);
|
||||
offset++;
|
||||
return offset;
|
||||
}
|
||||
|
||||
int GenerateToGameObjectButtonModule(int offset, Component component)
|
||||
{
|
||||
var toGameObjectButton = m_PropertiesWindow.CreateRootItemEntries(1)[0];
|
||||
toGameObjectButton.ref_value.GetComponent<PropertyListItem>().title = "To GameObject";
|
||||
toGameObjectButton.ref_value.GetComponent<InspectorItem>().SetTarget(target, () => SetTarget(component.gameObject, null));
|
||||
m_currentEntries.Add(toGameObjectButton);
|
||||
offset++;
|
||||
return offset;
|
||||
}
|
||||
|
||||
int GenerateRemoveComponentButtonModule(int offset, Component component)
|
||||
{
|
||||
var toGameObjectButton = m_PropertiesWindow.CreateRootItemEntries(1)[0];
|
||||
toGameObjectButton.ref_value.GetComponent<PropertyListItem>().title = "Remove Component";
|
||||
toGameObjectButton.ref_value.GetComponent<InspectorItem>().SetTarget(target, () =>
|
||||
{
|
||||
HierarchyItem item = null;
|
||||
if (HierarchyWindow.instance.ContainsReference(component.gameObject))
|
||||
item = HierarchyWindow.instance.GetReferenceItem(component.gameObject);
|
||||
if (HierarchyWindow.instance.ContainsReference(component))
|
||||
HierarchyWindow.instance.GetReferenceItem(component).Entry.Release();
|
||||
var xtemp = component.gameObject;
|
||||
Component.Destroy(component);
|
||||
InspectorWindow.instance.SetTarget(xtemp, item);
|
||||
});
|
||||
m_currentEntries.Add(toGameObjectButton);
|
||||
offset++;
|
||||
return offset;
|
||||
}
|
||||
|
||||
int GenerateEnableToggleModule(int offset, MonoBehaviour mono)
|
||||
{
|
||||
var toGameObjectButton = m_PropertiesWindow.CreateRootItemEntries(1)[0];
|
||||
toGameObjectButton.ref_value.GetComponent<PropertyListItem>().title = "Is Enable";
|
||||
toGameObjectButton.ref_value.GetComponent<InspectorItem>().SetTarget(target, new ValueWrapper(
|
||||
() => mono.enabled,
|
||||
(x) => mono.enabled = (bool)x,
|
||||
typeof(bool)
|
||||
));
|
||||
m_currentEntries.Add(toGameObjectButton);
|
||||
offset++;
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a86b441edb5f434fb07b2f3e6e0837c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user