BS 0.2.0 Visual

This commit is contained in:
2025-07-21 15:58:52 +08:00
parent f6750189d0
commit d0e5420f95
142 changed files with 11176 additions and 11 deletions

View File

@@ -0,0 +1,276 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
namespace Convention.WindowsUI
{
public class BaseWindowBar : WindowsComponent
{
// -----------------
private bool use_VerticalLayoutGroup => layoutGroupType == LayoutGroupType.VerticalLayoutGroup && verticalLayoutGroup;
private bool use_HorizontalLayoutGroup => layoutGroupType == LayoutGroupType.HorizontalLayoutGroup && horizontalLayoutGroup;
private bool use_GridLayoutGroup => layoutGroupType == LayoutGroupType.GridLayoutGroup && gridLayoutGroup;
// -----------------
[Setting] public bool IsMaxInTop = true;
[Setting] public bool IsMinInButtm = true;
public bool hasLayoutGroup => layoutGroupType != LayoutGroupType.None;
[Resources, Setting, HopeNotNull] public SO.Windows WindowConfig;
[Resources, SerializeField, HopeNotNull] private RectTransform BarPlane;
[Resources, SerializeField, HopeNotNull] private WindowManager m_WindowManager;
[Resources, HopeNotNull] public WindowUIModule ButtonPrefab;
[Content, OnlyPlayMode]
public void MinimizeWindow()
{
if (m_WindowManager)
{
if (IsMinInButtm)
m_WindowManager.transform.SetAsFirstSibling();
m_WindowManager.WindowPlane.ExitMaximizeWindowMode();
}
}
[Content, OnlyPlayMode]
public void MaximizeWindow()
{
if (m_WindowManager)
{
m_WindowManager.WindowPlane.MaximizeWindow();
if (IsMaxInTop)
m_WindowManager.transform.SetAsLastSibling();
}
}
[Content, OnlyPlayMode]
public void CloseWindow()
{
if (m_WindowManager)
{
m_WindowManager.CloseWindow();
}
}
public enum LayoutGroupType
{
VerticalLayoutGroup,
HorizontalLayoutGroup,
GridLayoutGroup,
None
}
[Setting] public LayoutGroupType layoutGroupType = LayoutGroupType.VerticalLayoutGroup;
[Resources, Setting, SerializeField, Header("Vertical Layout Group Setting")]
[HopeNotNull, WhenAttribute.Is(nameof(layoutGroupType), LayoutGroupType.VerticalLayoutGroup)]
private VerticalLayoutGroup verticalLayoutGroup;
[Resources, Setting, SerializeField, Header("Horizontal Layout Group Setting")]
[HopeNotNull, WhenAttribute.Is(nameof(layoutGroupType), LayoutGroupType.HorizontalLayoutGroup)]
private HorizontalLayoutGroup horizontalLayoutGroup;
[Resources, Setting, SerializeField, Header("Grid Layout Group")]
[HopeNotNull, WhenAttribute.Is(nameof(layoutGroupType), LayoutGroupType.GridLayoutGroup)]
private GridLayoutGroup gridLayoutGroup;
public void Reset()
{
WindowConfig = Resources.Load<SO.Windows>(SO.Windows.GlobalWindowsConfig);
BarPlane = rectTransform;
ResetWindowManager();
ButtonPrefab = WindowConfig.GetWindowsUI<IButton>(nameof(ModernUIButton)) as WindowUIModule;
layoutGroupType = LayoutGroupType.HorizontalLayoutGroup;
ResetLayoutGroups(false);
}
private void ResetLayoutGroups(bool isDestroy)
{
if (verticalLayoutGroup == null)
verticalLayoutGroup = BarPlane.GetComponent<VerticalLayoutGroup>();
if (horizontalLayoutGroup == null)
horizontalLayoutGroup = BarPlane.GetComponent<HorizontalLayoutGroup>();
if (gridLayoutGroup == null)
gridLayoutGroup = BarPlane.GetComponent<GridLayoutGroup>();
if (!isDestroy)
return;
if (verticalLayoutGroup && layoutGroupType != LayoutGroupType.VerticalLayoutGroup)
Destroy(verticalLayoutGroup);
if (horizontalLayoutGroup && layoutGroupType != LayoutGroupType.HorizontalLayoutGroup)
Destroy(horizontalLayoutGroup);
if (gridLayoutGroup && layoutGroupType != LayoutGroupType.GridLayoutGroup)
Destroy(gridLayoutGroup);
}
private void ResetWindowManager()
{
m_WindowManager = null;
for (Transform item = transform; m_WindowManager == null && item != null; item = item.parent)
{
m_WindowManager = item.gameObject.GetComponent<WindowManager>();
}
}
private void Start()
{
if (BarPlane == null)
BarPlane = rectTransform;
if (m_WindowManager == null)
{
ResetWindowManager();
}
ResetLayoutGroups(true);
}
private IButton InstantiateButton()
{
return Instantiate(ButtonPrefab, BarPlane.transform).GetComponents<IButton>()[0];
}
[Serializable]
public class RegisteredButtonWrapper
{
public readonly BaseWindowBar WindowBar;
public IButton button;
public WindowUIModule buttonModule;
public RegisteredButtonWrapper([In] BaseWindowBar parentBar, [In] IButton button)
{
WindowBar = parentBar;
this.button = button;
buttonModule = button as WindowUIModule;
}
public virtual void Disable()
{
if (buttonModule)
{
buttonModule.gameObject.SetActive(false);
if (WindowBar.useGUILayout)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(WindowBar.BarPlane);
}
}
}
public virtual void Enable()
{
if (buttonModule)
{
buttonModule.gameObject.SetActive(true);
if (WindowBar.useGUILayout)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(WindowBar.BarPlane);
}
}
}
public virtual void Release()
{
if (button == null)
{
throw new InvalidOperationException("wrapper was released");
}
if (buttonModule)
{
Disable();
Destroy(buttonModule.gameObject);
if (WindowBar.useGUILayout)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(WindowBar.BarPlane);
}
}
button = null;
}
~RegisteredButtonWrapper()
{
Release();
}
}
[return: ReturnNotNull, ReturnVirtual]
public virtual RegisteredButtonWrapper RegisterButton()
{
return new RegisteredButtonWrapper(this, InstantiateButton());
}
[Serializable]
public class RegisteredPageWrapper : RegisteredButtonWrapper
{
[SerializeField]private int PageIndex = -1;
[SerializeField]private RectTransform plane, root;
public RegisteredPageWrapper(RectTransform plane, RectTransform root, [In] BaseWindowBar parentBar, [In] IButton button) : base(parentBar, button)
{
button.AddListener(() => WindowBar.m_WindowManager.SelectContextPlane(PageIndex));
PageIndex = parentBar.m_WindowManager.AddContextPlane(plane, root);
this.plane = plane;
this.root = root;
}
public RegisteredPageWrapper(RectTransform plane, [In] BaseWindowBar parentBar, [In] IButton button) : base(parentBar, button)
{
button.AddListener(() => WindowBar.m_WindowManager.SelectContextPlane(PageIndex));
PageIndex = parentBar.m_WindowManager.AddContextPlane(plane);
this.plane = plane;
}
public override void Disable()
{
if (PageIndex < 0)
{
return;
}
WindowBar.m_WindowManager.RemoveContextPlane(PageIndex);
PageIndex = -1;
base.Disable();
}
public override void Enable()
{
if (PageIndex < 0)
{
WindowBar.m_WindowManager.AddContextPlane(plane, root);
base.Enable();
}
}
public override void Release()
{
if (Application.isPlaying)
{
if (!plane)
throw new InvalidOperationException("page was released");
else
return;
}
if (root)
{
root.gameObject.SetActive(false);
Destroy(root);
}
else
{
plane.gameObject.SetActive(false);
Destroy(plane);
}
base.Release();
plane = null;
root = null;
}
public virtual void Select()
{
if (PageIndex < 0)
return;
WindowBar.m_WindowManager.SelectContextPlane(PageIndex);
}
}
[return: ReturnNotNull, ReturnVirtual]
public virtual RegisteredPageWrapper RegisterPage([In] RectTransform plane, [In] RectTransform root)
{
return new RegisteredPageWrapper(plane, root, this, InstantiateButton());
}
[return: ReturnNotNull, ReturnVirtual]
public virtual RegisteredPageWrapper RegisterPage([In] RectTransform plane)
{
return new RegisteredPageWrapper(plane, this, InstantiateButton());
}
public virtual IEnumerable<IButton> GetAllButton()
{
List<IButton> result = new();
foreach(IButton button in BarPlane.transform)
{
result.Add(button);
}
return result;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f75b74b63b41ea54ba58bf470d6d74d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,124 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace Convention.WindowsUI
{
public class BaseWindowPlane : WindowsComponent
{
[Resources, SerializeField, OnlyNotNullMode] private RectTransform m_Plane;
[Resources, SerializeField, HopeNotNull, Tooltip("This animational plane should has the same parent transform")]
private RectTransform m_AnimationPlane;
[Setting, OnlyNotNullMode(nameof(m_AnimationPlane)), SerializeField, Header("Animation Setting")]
private bool IsEnableAnimation = true;
[Setting, OnlyNotNullMode(nameof(m_AnimationPlane)), Percentage(0, 1), Range(0, 1), WhenAttribute.Is(nameof(IsEnableAnimation), true)]
public float AnimationSpeed = 0.5f;
public RectTransform Plane => m_Plane;
[Content, OnlyPlayMode, Ignore] public RectTransformInfo BeforeMaximizeWindow = null;
[Content, OnlyPlayMode, Ignore] public float BeforeMaximizeWindowBackgroundColorA = 1f;
private bool IsMaximizeWindowMode = false;
[Content, OnlyPlayMode]
public void MaximizeWindow()
{
if (IsMaximizeWindowMode)
return;
BeforeMaximizeWindow = new(m_Plane);
var prect = m_Plane.transform.parent.GetComponent<RectTransform>();
m_Plane.SetPositionAndRotation(prect.position, prect.rotation);
m_Plane.anchoredPosition = Vector3.zero;
m_Plane.anchorMax = Vector2.one;
m_Plane.anchorMin = Vector2.zero;
m_Plane.sizeDelta = Vector2.zero;
var backgroundPlane = m_AnimationPlane == null ? m_Plane : m_AnimationPlane;
if (backgroundPlane.TryGetComponent<Image>(out var image))
{
BeforeMaximizeWindowBackgroundColorA = image.color.a;
var color = image.color;
color.a = 1;
image.color = color;
}
IsMaximizeWindowMode = true;
}
[Content, OnlyPlayMode]
public void ExitMaximizeWindowMode()
{
if (!IsMaximizeWindowMode)
return;
BeforeMaximizeWindow.Setup(m_Plane);
var backgroundPlane = m_AnimationPlane == null ? m_Plane : m_AnimationPlane;
if (backgroundPlane.TryGetComponent<Image>(out var image))
{
var color = image.color;
color.a = BeforeMaximizeWindowBackgroundColorA;
image.color = color;
}
IsMaximizeWindowMode = false;
}
private void OnEnable()
{
if (m_AnimationPlane != null)
{
new RectTransformInfo(m_Plane).Setup(m_AnimationPlane);
}
}
[Content]
public void SynchronizedAnimationPlane()
{
new RectTransformInfo(m_Plane).Setup(m_AnimationPlane);
}
private void LateUpdate()
{
if (IsEnableAnimation && m_Plane && m_AnimationPlane)
{
RectTransformInfo.UpdateAnimationPlane(m_Plane, m_AnimationPlane, AnimationSpeed, IsMaximizeWindowMode ? 1 : -1, false);
}
}
public virtual void AddChild(RectTransform target, Rect rect, bool isAdjustSizeToContainsChilds = false)
{
RectTransformExtension.SetParentAndResizeWithoutNotifyBaseWindowPlane(m_Plane, target, rect, isAdjustSizeToContainsChilds);
}
public virtual void AddChild(RectTransform target, bool isAdjustSizeToContainsChilds = false)
{
RectTransformExtension.SetParentAndResizeWithoutNotifyBaseWindowPlane(m_Plane, target, isAdjustSizeToContainsChilds);
}
[Content]
public void ForceRebuildLayoutImmediate()
{
LayoutRebuilder.ForceRebuildLayoutImmediate(rectTransform);
}
[Resources, Tooltip("before AdjustSizeToContainsChilds, will compute it first")] public RectTransform AdjustSizeToContainsRect;
[Content]
public void AdjustSizeToContainsChilds()
{
if (AdjustSizeToContainsRect == null)
RectTransformExtension.AdjustSizeToContainsChilds(rectTransform);
else
{
var corners = new Vector3[4];
Vector2 min = new Vector2(float.MaxValue, float.MaxValue);
Vector2 max = new Vector2(float.MinValue, float.MinValue);
AdjustSizeToContainsRect.GetWorldCorners(corners);
foreach (var corner in corners)
{
Vector2 localCorner = rectTransform.InverseTransformPoint(corner);
if (float.IsNaN(localCorner.x) || float.IsNaN(localCorner.y))
break;
min.x = Mathf.Min(min.x, localCorner.x);
min.y = Mathf.Min(min.y, localCorner.y);
max.x = Mathf.Max(max.x, localCorner.x);
max.y = Mathf.Max(max.y, localCorner.y);
}
RectTransformExtension.AdjustSizeToContainsChilds(rectTransform, min, max, null);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 999be728ad5e8324baf45ccaf0f9c3d2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,252 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1102 &-8092253087371084152
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: ExitFocusInspector
m_Speed: -1
m_CycleOffset: 0
m_Transitions: []
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 7400000, guid: 9525128e21aed17438d2688e99e7e20d, type: 2}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1102 &-6082174505553466741
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: ExitFullMainWindow
m_Speed: -1
m_CycleOffset: 0
m_Transitions: []
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 7400000, guid: 3c2a3f60d986c0149bf92b6d3983302e, type: 2}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1102 &-3932555576849271677
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: New State
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 0}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1102 &-2403780335683535720
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: FullMainWindow
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 7400000, guid: 3c2a3f60d986c0149bf92b6d3983302e, type: 2}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!91 &9100000
AnimatorController:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Canvas
serializedVersion: 5
m_AnimatorParameters:
- m_Name: IsFocus
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
m_StateMachine: {fileID: 1296624602851365648}
m_Mask: {fileID: 0}
m_Motions: []
m_Behaviours: []
m_BlendingMode: 0
m_SyncedLayerIndex: -1
m_DefaultWeight: 0
m_IKPass: 0
m_SyncedLayerAffectsTiming: 0
m_Controller: {fileID: 9100000}
--- !u!1107 &1296624602851365648
AnimatorStateMachine:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Base Layer
m_ChildStates:
- serializedVersion: 1
m_State: {fileID: 6070089197181197078}
m_Position: {x: 450, y: -10, z: 0}
- serializedVersion: 1
m_State: {fileID: -3932555576849271677}
m_Position: {x: 10, y: 70, z: 0}
- serializedVersion: 1
m_State: {fileID: 1675010782392993655}
m_Position: {x: 450, y: 50, z: 0}
- serializedVersion: 1
m_State: {fileID: -2403780335683535720}
m_Position: {x: 670, y: -10, z: 0}
- serializedVersion: 1
m_State: {fileID: -6082174505553466741}
m_Position: {x: 670, y: 50, z: 0}
- serializedVersion: 1
m_State: {fileID: 1810835025064308519}
m_Position: {x: 450, y: 110, z: 0}
- serializedVersion: 1
m_State: {fileID: -8092253087371084152}
m_Position: {x: 450, y: 160, z: 0}
m_ChildStateMachines: []
m_AnyStateTransitions: []
m_EntryTransitions: []
m_StateMachineTransitions: {}
m_StateMachineBehaviours: []
m_AnyStatePosition: {x: 50, y: 20, z: 0}
m_EntryPosition: {x: 50, y: 120, z: 0}
m_ExitPosition: {x: 50, y: -20, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: -3932555576849271677}
--- !u!1102 &1675010782392993655
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: ExitFocusMainWindow
m_Speed: -1
m_CycleOffset: 0
m_Transitions: []
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 7400000, guid: ca95e26c36202a54fb6f43ca904d2bcf, type: 2}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1102 &1810835025064308519
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: FocusInspector
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 7400000, guid: 9525128e21aed17438d2688e99e7e20d, type: 2}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1102 &6070089197181197078
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: FocusMainWindow
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 7400000, guid: ca95e26c36202a54fb6f43ca904d2bcf, type: 2}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e407ea59aaf27714e830a008e8f5f2f3
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
namespace Convention.WindowsUI
{
public class ClickBoard : WindowUIModule
{
[Resources] public BehaviourContextManager Context;
[Setting] public UnityEvent<PointerEventData> LeftButtonClick = new();
[Setting] public UnityEvent<PointerEventData> RightButtonClick = new();
private void Start()
{
if (Context == null)
Context = this.GetOrAddComponent<BehaviourContextManager>();
Context.OnPointerClickEvent = BehaviourContextManager.InitializeContextSingleEvent(Context.OnPointerClickEvent, point =>
{
if (point.button == PointerEventData.InputButton.Left)
{
LeftButtonClick.Invoke(point);
}
if (point.button == PointerEventData.InputButton.Right)
{
RightButtonClick.Invoke(point);
}
});
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 23af7c7b9a98a1b4a9614459934e2aec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,49 @@
using System.Collections.Generic;
using Convention.WindowsUI;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace Convention
{
public class CustomMenu : WindowsComponent
{
[Setting, SerializeField] private bool IsDestroy = true;
[Resources, SerializeField, OnlyNotNullMode] private Button ButtonPrefab;
[Resources, SerializeField, OnlyNotNullMode] private RectTransform Plane;
[Content] public List<GameObject> childs = new();
[Content, OnlyPlayMode]
[return: IsInstantiated(true)]
public virtual Button CreateItem()
{
var item = GameObject.Instantiate(ButtonPrefab, Plane).GetComponent<Button>();
item.gameObject.SetActive(true);
childs.Add(item.gameObject);
return item;
}
[return: IsInstantiated(true)]
public virtual Button CreateItem(UnityAction callback, string title)
{
var item = CreateItem();
item.onClick.AddListener(callback);
item.GetComponents<IText>()[0].text = title;
return item;
}
public virtual void ClearAllItem()
{
foreach (var child in childs)
{
GameObject.Destroy(child);
}
childs.Clear();
}
public virtual void ReleaseMenu()
{
if (IsDestroy)
Destroy(this.gameObject);
else
gameObject.SetActive(false);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ca19a363a3f85a042b6055ee363a16f0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,746 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!74 &7400000
AnimationClip:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: FocusInspector
serializedVersion: 7
m_Legacy: 0
m_Compressed: 0
m_UseHighQualityCurve: 1
m_RotationCurves: []
m_CompressedRotationCurves: []
m_EulerCurves: []
m_PositionCurves: []
m_ScaleCurves: []
m_FloatCurves:
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: -500
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_AnchoredPosition.x
path: Hierarchy
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: -500
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_AnchoredPosition.x
path: Tools
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: -400
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: -400
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_SizeDelta.x
path: Assets
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: -200
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: -700
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_AnchoredPosition.x
path: Assets
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 200
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: 700
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_SizeDelta.x
path: Inspector
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: -500
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_AnchoredPosition.x
path: Main
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: -400
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: -400
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_SizeDelta.x
path: Main
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 100
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.083333336
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.25
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_AnchoredPosition.x
path: EditorBar
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: -200
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.083333336
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.25
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_SizeDelta.x
path: EditorBar
classID: 224
script: {fileID: 0}
flags: 0
m_PPtrCurves: []
m_SampleRate: 60
m_WrapMode: 0
m_Bounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}
m_ClipBindingConstant:
genericBindings:
- serializedVersion: 2
path: 2022418957
attribute: 1460864421
script: {fileID: 0}
typeID: 224
customType: 28
isPPtrCurve: 0
isIntCurve: 0
isSerializeReferenceCurve: 0
- serializedVersion: 2
path: 725348723
attribute: 1460864421
script: {fileID: 0}
typeID: 224
customType: 28
isPPtrCurve: 0
isIntCurve: 0
isSerializeReferenceCurve: 0
- serializedVersion: 2
path: 2122152120
attribute: 1460864421
script: {fileID: 0}
typeID: 224
customType: 28
isPPtrCurve: 0
isIntCurve: 0
isSerializeReferenceCurve: 0
- serializedVersion: 2
path: 4029469480
attribute: 1967290853
script: {fileID: 0}
typeID: 224
customType: 28
isPPtrCurve: 0
isIntCurve: 0
isSerializeReferenceCurve: 0
- serializedVersion: 2
path: 521822810
attribute: 1460864421
script: {fileID: 0}
typeID: 224
customType: 28
isPPtrCurve: 0
isIntCurve: 0
isSerializeReferenceCurve: 0
- serializedVersion: 2
path: 3281461653
attribute: 1460864421
script: {fileID: 0}
typeID: 224
customType: 28
isPPtrCurve: 0
isIntCurve: 0
isSerializeReferenceCurve: 0
- serializedVersion: 2
path: 3281461653
attribute: 1967290853
script: {fileID: 0}
typeID: 224
customType: 28
isPPtrCurve: 0
isIntCurve: 0
isSerializeReferenceCurve: 0
- serializedVersion: 2
path: 2122152120
attribute: 1967290853
script: {fileID: 0}
typeID: 224
customType: 28
isPPtrCurve: 0
isIntCurve: 0
isSerializeReferenceCurve: 0
- serializedVersion: 2
path: 521822810
attribute: 1967290853
script: {fileID: 0}
typeID: 224
customType: 28
isPPtrCurve: 0
isIntCurve: 0
isSerializeReferenceCurve: 0
pptrCurveMapping: []
m_AnimationClipSettings:
serializedVersion: 2
m_AdditiveReferencePoseClip: {fileID: 0}
m_AdditiveReferencePoseTime: 0
m_StartTime: 0
m_StopTime: 0.5
m_OrientationOffsetY: 0
m_Level: 0
m_CycleOffset: 0
m_HasAdditiveReferencePose: 0
m_LoopTime: 0
m_LoopBlend: 0
m_LoopBlendOrientation: 0
m_LoopBlendPositionY: 0
m_LoopBlendPositionXZ: 0
m_KeepOriginalOrientation: 0
m_KeepOriginalPositionY: 1
m_KeepOriginalPositionXZ: 0
m_HeightFromFeet: 0
m_Mirror: 0
m_EditorCurves:
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: -500
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_AnchoredPosition.x
path: Hierarchy
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: -500
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_AnchoredPosition.x
path: Tools
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: -400
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: -400
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_SizeDelta.x
path: Assets
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: -200
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: -700
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_AnchoredPosition.x
path: Assets
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 200
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: 700
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_SizeDelta.x
path: Inspector
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: -500
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_AnchoredPosition.x
path: Main
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: -400
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: -400
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_SizeDelta.x
path: Main
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 100
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.083333336
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.25
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_AnchoredPosition.x
path: EditorBar
classID: 224
script: {fileID: 0}
flags: 0
- serializedVersion: 2
curve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: -200
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.083333336
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.25
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
value: 0
inSlope: 0
outSlope: 0
tangentMode: 136
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
attribute: m_SizeDelta.x
path: EditorBar
classID: 224
script: {fileID: 0}
flags: 0
m_EulerEditorCurves: []
m_HasGenericRootTransform: 0
m_HasMotionFloatCurves: 0
m_Events: []

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9525128e21aed17438d2688e99e7e20d
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ca95e26c36202a54fb6f43ca904d2bcf
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3c2a3f60d986c0149bf92b6d3983302e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,490 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Convention
{
public class GradientEffect : BaseMeshEffect
{
[return: ReturnNotNull]
public string SymbolName()
{
return GetType().Name;
}
[SerializeField]
Type _gradientType;
[Setting, SerializeField]
private Blend _blendMode = Blend.Multiply;
[Setting, SerializeField]
private bool _modifyVertices = true;
[Setting, SerializeField, Range(-1, 1)]
private float m_offset = 0f;
[Setting, SerializeField, Range(0.1f, 10)]
private float m_zoom = 1f;
[Setting]
public Gradient m_effectGradient = new Gradient()
{
colorKeys = new GradientColorKey[]
{
new GradientColorKey(Color.white, 1),
new GradientColorKey(Color.white, 1)
}
};
public Blend BlendMode
{
get { return _blendMode; }
set
{
_blendMode = value;
graphic.SetVerticesDirty();
}
}
public Gradient EffectGradient
{
get { return m_effectGradient; }
set
{
m_effectGradient = value;
graphic.SetVerticesDirty();
}
}
public Type GradientType
{
get { return _gradientType; }
set
{
_gradientType = value;
graphic.SetVerticesDirty();
}
}
public bool ModifyVertices
{
get { return _modifyVertices; }
set
{
_modifyVertices = value;
graphic.SetVerticesDirty();
}
}
public float Offset
{
get { return m_offset; }
set
{
m_offset = Mathf.Clamp(value, -1f, 1f);
graphic.SetVerticesDirty();
}
}
public float Zoom
{
get { return m_zoom; }
set
{
m_zoom = Mathf.Clamp(value, 0.1f, 10f);
graphic.SetVerticesDirty();
}
}
public enum Type
{
Horizontal,
Vertical,
Diamond
}
public enum Blend
{
Override,
Add,
Multiply
}
#region Gradient
public override void ModifyMesh(VertexHelper helper)
{
if (!IsActive() || helper.currentVertCount == 0)
return;
List<UIVertex> _vertexList = new List<UIVertex>();
helper.GetUIVertexStream(_vertexList);
int nCount = _vertexList.Count;
switch (GradientType)
{
case Type.Horizontal:
case Type.Vertical:
{
Rect bounds = GetBounds(_vertexList);
float min = bounds.xMin;
float w = bounds.width;
Func<UIVertex, float> GetPosition = v => v.position.x;
if (GradientType == Type.Vertical)
{
min = bounds.yMin;
w = bounds.height;
GetPosition = v => v.position.y;
}
float width = w == 0f ? 0f : 1f / w / Zoom;
float zoomOffset = (1 - (1 / Zoom)) * 0.5f;
float offset = (Offset * (1 - zoomOffset)) - zoomOffset;
if (ModifyVertices)
SplitTrianglesAtGradientStops(_vertexList, bounds, zoomOffset, helper);
UIVertex vertex = new UIVertex();
for (int i = 0; i < helper.currentVertCount; i++)
{
helper.PopulateUIVertex(ref vertex, i);
vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate((GetPosition(vertex) - min) * width - offset));
helper.SetUIVertex(vertex, i);
}
}
break;
case Type.Diamond:
{
Rect bounds = GetBounds(_vertexList);
float height = bounds.height == 0f ? 0f : 1f / bounds.height / Zoom;
float radius = bounds.center.y / 2f;
Vector3 center = (Vector3.right + Vector3.up) * radius + Vector3.forward * _vertexList[0].position.z;
if (ModifyVertices)
{
helper.Clear();
for (int i = 0; i < nCount; i++) helper.AddVert(_vertexList[i]);
UIVertex centralVertex = new UIVertex();
centralVertex.position = center;
centralVertex.normal = _vertexList[0].normal;
centralVertex.uv0 = new Vector2(0.5f, 0.5f);
centralVertex.color = Color.white;
helper.AddVert(centralVertex);
for (int i = 1; i < nCount; i++) helper.AddTriangle(i - 1, i, nCount);
helper.AddTriangle(0, nCount - 1, nCount);
}
UIVertex vertex = new UIVertex();
for (int i = 0; i < helper.currentVertCount; i++)
{
helper.PopulateUIVertex(ref vertex, i);
vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate(
Vector3.Distance(vertex.position, center) * height - Offset));
helper.SetUIVertex(vertex, i);
}
}
break;
}
}
private Rect GetBounds(List<UIVertex> vertices)
{
float left = vertices[0].position.x;
float right = left;
float bottom = vertices[0].position.y;
float top = bottom;
for (int i = vertices.Count - 1; i >= 1; --i)
{
float x = vertices[i].position.x;
float y = vertices[i].position.y;
if (x > right)
right = x;
else if (x < left)
left = x;
if (y > top)
top = y;
else if (y < bottom)
bottom = y;
}
return new Rect(left, bottom, right - left, top - bottom);
}
private void SplitTrianglesAtGradientStops(List<UIVertex> _vertexList, Rect bounds, float zoomOffset, VertexHelper helper)
{
List<float> stops = FindStops(zoomOffset, bounds);
if (stops.Count > 0)
{
helper.Clear();
int nCount = _vertexList.Count;
for (int i = 0; i < nCount; i += 3)
{
float[] positions = GetPositions(_vertexList, i);
List<int> originIndices = new List<int>(3);
List<UIVertex> starts = new List<UIVertex>(3);
List<UIVertex> ends = new List<UIVertex>(2);
for (int s = 0; s < stops.Count; s++)
{
int initialCount = helper.currentVertCount;
bool hadEnds = ends.Count > 0;
bool earlyStart = false;
for (int p = 0; p < 3; p++)
{
if (!originIndices.Contains(p) && positions[p] < stops[s])
{
int p1 = (p + 1) % 3;
var start = _vertexList[p + i];
if (positions[p1] > stops[s])
{
originIndices.Insert(0, p);
starts.Insert(0, start);
earlyStart = true;
}
else
{
originIndices.Add(p);
starts.Add(start);
}
}
}
if (originIndices.Count == 0)
continue;
if (originIndices.Count == 3)
break;
foreach (var start in starts)
helper.AddVert(start);
ends.Clear();
foreach (int index in originIndices)
{
int oppositeIndex = (index + 1) % 3;
if (positions[oppositeIndex] < stops[s])
oppositeIndex = (oppositeIndex + 1) % 3;
ends.Add(CreateSplitVertex(_vertexList[index + i], _vertexList[oppositeIndex + i], stops[s]));
}
if (ends.Count == 1)
{
int oppositeIndex = (originIndices[0] + 2) % 3;
ends.Add(CreateSplitVertex(_vertexList[originIndices[0] + i], _vertexList[oppositeIndex + i], stops[s]));
}
foreach (var end in ends)
helper.AddVert(end);
if (hadEnds)
{
helper.AddTriangle(initialCount - 2, initialCount, initialCount + 1);
helper.AddTriangle(initialCount - 2, initialCount + 1, initialCount - 1);
if (starts.Count > 0)
{
if (earlyStart)
helper.AddTriangle(initialCount - 2, initialCount + 3, initialCount);
else
helper.AddTriangle(initialCount + 1, initialCount + 3, initialCount - 1);
}
}
else
{
int vertexCount = helper.currentVertCount;
helper.AddTriangle(initialCount, vertexCount - 2, vertexCount - 1);
if (starts.Count > 1)
helper.AddTriangle(initialCount, vertexCount - 1, initialCount + 1);
}
starts.Clear();
}
if (ends.Count > 0)
{
if (starts.Count == 0)
{
for (int p = 0; p < 3; p++)
{
if (!originIndices.Contains(p) && positions[p] > stops[stops.Count - 1])
{
int p1 = (p + 1) % 3;
UIVertex end = _vertexList[p + i];
if (positions[p1] > stops[stops.Count - 1])
starts.Insert(0, end);
else
starts.Add(end);
}
}
}
foreach (var start in starts)
helper.AddVert(start);
int vertexCount = helper.currentVertCount;
if (starts.Count > 1)
{
helper.AddTriangle(vertexCount - 4, vertexCount - 2, vertexCount - 1);
helper.AddTriangle(vertexCount - 4, vertexCount - 1, vertexCount - 3);
}
else if (starts.Count > 0)
helper.AddTriangle(vertexCount - 3, vertexCount - 1, vertexCount - 2);
}
else
{
helper.AddVert(_vertexList[i]);
helper.AddVert(_vertexList[i + 1]);
helper.AddVert(_vertexList[i + 2]);
int vertexCount = helper.currentVertCount;
helper.AddTriangle(vertexCount - 3, vertexCount - 2, vertexCount - 1);
}
}
}
}
private float[] GetPositions(List<UIVertex> _vertexList, int index)
{
float[] positions = new float[3];
if (GradientType == Type.Horizontal)
{
positions[0] = _vertexList[index].position.x;
positions[1] = _vertexList[index + 1].position.x;
positions[2] = _vertexList[index + 2].position.x;
}
else
{
positions[0] = _vertexList[index].position.y;
positions[1] = _vertexList[index + 1].position.y;
positions[2] = _vertexList[index + 2].position.y;
}
return positions;
}
private List<float> FindStops(float zoomOffset, Rect bounds)
{
List<float> stops = new List<float>();
var offset = Offset * (1 - zoomOffset);
var startBoundary = zoomOffset - offset;
var endBoundary = (1 - zoomOffset) - offset;
foreach (var color in EffectGradient.colorKeys)
{
if (color.time >= endBoundary)
break;
if (color.time > startBoundary)
stops.Add((color.time - startBoundary) * Zoom);
}
foreach (var alpha in EffectGradient.alphaKeys)
{
if (alpha.time >= endBoundary)
break;
if (alpha.time > startBoundary)
stops.Add((alpha.time - startBoundary) * Zoom);
}
float min = bounds.xMin;
float size = bounds.width;
if (GradientType == Type.Vertical)
{
min = bounds.yMin;
size = bounds.height;
}
stops.Sort();
for (int i = 0; i < stops.Count; i++)
{
stops[i] = (stops[i] * size) + min;
if (i > 0 && Mathf.Abs(stops[i] - stops[i - 1]) < 2)
{
stops.RemoveAt(i);
--i;
}
}
return stops;
}
private UIVertex CreateSplitVertex(UIVertex vertex1, UIVertex vertex2, float stop)
{
if (GradientType == Type.Horizontal)
{
float sx = vertex1.position.x - stop;
float dx = vertex1.position.x - vertex2.position.x;
float dy = vertex1.position.y - vertex2.position.y;
float uvx = vertex1.uv0.x - vertex2.uv0.x;
float uvy = vertex1.uv0.y - vertex2.uv0.y;
float ratio = sx / dx;
float splitY = vertex1.position.y - (dy * ratio);
UIVertex splitVertex = new UIVertex();
splitVertex.position = new Vector3(stop, splitY, vertex1.position.z);
splitVertex.normal = vertex1.normal;
splitVertex.uv0 = new Vector2(vertex1.uv0.x - (uvx * ratio), vertex1.uv0.y - (uvy * ratio));
splitVertex.color = Color.white;
return splitVertex;
}
else
{
float sy = vertex1.position.y - stop;
float dy = vertex1.position.y - vertex2.position.y;
float dx = vertex1.position.x - vertex2.position.x;
float uvx = vertex1.uv0.x - vertex2.uv0.x;
float uvy = vertex1.uv0.y - vertex2.uv0.y;
float ratio = sy / dy;
float splitX = vertex1.position.x - (dx * ratio);
UIVertex splitVertex = new UIVertex();
splitVertex.position = new Vector3(splitX, stop, vertex1.position.z);
splitVertex.normal = vertex1.normal;
splitVertex.uv0 = new Vector2(vertex1.uv0.x - (uvx * ratio), vertex1.uv0.y - (uvy * ratio));
splitVertex.color = Color.white;
return splitVertex;
}
}
private Color BlendColor(Color colorA, Color colorB)
{
switch (BlendMode)
{
default: return colorB;
case Blend.Add: return colorA + colorB;
case Blend.Multiply: return colorA * colorB;
}
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 37787d9486d30424c8dc81d6936fc0d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,67 @@
using TMPro;
using UnityEngine;
using UnityEngine.Events;
namespace Convention.WindowsUI
{
public partial class InputField : WindowUIModule, IInputField
{
[Resources, HopeNotNull] public TMP_InputField Source;
[Resources] public TMP_Text placeholder;
private void Start()
{
if (Source == null)
Source = this.GetComponent<TMP_InputField>();
if (placeholder == null)
placeholder = Source.placeholder.GetComponent<TMP_Text>();
}
private void OnValidate()
{
if (Source == null)
Source = this.GetComponent<TMP_InputField>();
if (placeholder == null)
placeholder = Source.placeholder.GetComponent<TMP_Text>();
}
public virtual string text
{
get { return Source.text; }
set { Source.text = value; }
}
public bool interactable { get => Source.interactable; set => Source.interactable = value; }
public void SetPlaceholderText(string text)
{
placeholder.text = text;
}
public InputField SetTextWithoutNotify(string text)
{
Source.SetTextWithoutNotify(text);
return this;
}
public IActionInvoke<string> AddListener(params UnityAction<string>[] action)
{
foreach (var actionItem in action)
Source.onEndEdit.AddListener(actionItem);
return this;
}
public IActionInvoke<string> RemoveListener(params UnityAction<string>[] action)
{
foreach (var actionItem in action)
Source.onEndEdit.RemoveListener(actionItem);
return this;
}
public IActionInvoke<string> RemoveAllListeners()
{
Source.onEndEdit.RemoveAllListeners();
return this;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 38258cef5bae3434a888b83f4d00a95a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Convention.WindowsUI
{
public class KeyboardStatsBar : WindowUIModule
{
[Serializable]
public class KeyboardStatsData
{
public Key key;
public CanvasGroup iconCanvasGroup;
public float notPress = 0.3f;
public float press = 1f;
}
[Setting] public List<KeyboardStatsData> bindings = new();
private void Update()
{
foreach (var bind in bindings)
{
bind.iconCanvasGroup.alpha = Keyboard.current[bind.key].isPressed ? bind.press : bind.notPress;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e60555c2f1c7dc742b5fa240211acc82
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,366 @@
using System;
using System.Collections;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Convention.WindowsUI.Internal;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace Convention.WindowsUI
{
namespace Internal
{
public class Ripple : MonoBehaviour
{
public bool unscaledTime = false;
public float speed;
public float maxSize;
public Color startColor;
public Color transitionColor;
UnityEngine.UI.Image colorImg;
void Start()
{
transform.localScale = new Vector3(0f, 0f, 0f);
colorImg = GetComponent<UnityEngine.UI.Image>();
colorImg.color = new Color(startColor.r, startColor.g, startColor.b, startColor.a);
colorImg.raycastTarget = false;
}
void Update()
{
if (unscaledTime == false)
{
transform.localScale = Vector3.Lerp(transform.localScale, new Vector3(maxSize, maxSize, maxSize), Time.deltaTime * speed);
colorImg.color = Color.Lerp(colorImg.color, new Color(transitionColor.r, transitionColor.g, transitionColor.b, transitionColor.a), Time.deltaTime * speed);
if (transform.localScale.x >= maxSize * 0.998)
{
if (transform.parent.childCount == 1)
transform.parent.gameObject.SetActive(false);
Destroy(gameObject);
}
}
else
{
transform.localScale = Vector3.Lerp(transform.localScale, new Vector3(maxSize, maxSize, maxSize), Time.unscaledDeltaTime * speed);
colorImg.color = Color.Lerp(colorImg.color, new Color(transitionColor.r, transitionColor.g, transitionColor.b, transitionColor.a), Time.unscaledDeltaTime * speed);
if (transform.localScale.x >= maxSize * 0.998)
{
if (transform.parent.childCount == 1)
transform.parent.gameObject.SetActive(false);
Destroy(gameObject);
}
}
}
}
}
public partial class ModernUIButton : WindowUIModule, IButton, ITitle
{
// ---------------------------------------------------------------- stats
private bool useRipple => animationSolution == AnimationSolution.SCRIPT && m_useRipple;
// ----------------------------------------------------------------
public enum RippleUpdateMode
{
NORMAL,
UNSCALED_TIME
}
public enum AnimationSolution
{
ANIMATOR,
SCRIPT
}
[Content, SerializeField] private string m_title = "";
public string title
{
get => m_title;
set
{
m_title = value;
UpdateUI();
}
}
[Content] public UnityEvent clickEvent = new();
[Content] public UnityEvent hoverEvent = new();
[Resources, OnlyNotNullMode] public TextMeshProUGUI normalText;
[Resources, HopeNotNull] public CanvasGroup normalCanvasGroup;
[Resources, OnlyNotNullMode] public TextMeshProUGUI highlightedText;
[Resources, HopeNotNull] public CanvasGroup highlightedCanvasGroup;
[Resources, Setting, HopeNotNull, Header("Sound Setting")] public AudioSource soundSource;
[Resources, Setting, OnlyNotNullMode(nameof(soundSource))] public bool enableButtonSounds = false;
[Resources, Setting, OnlyNotNullMode(nameof(soundSource))] public bool useHoverSound = true;
[Resources, Setting, OnlyNotNullMode(nameof(soundSource))] public bool useClickSound = true;
[Resources, WhenAttribute.Is(nameof(useHoverSound), true), OnlyNotNullMode(nameof(soundSource))] public AudioClip hoverSound;
[Resources, WhenAttribute.Is(nameof(useClickSound), true), OnlyNotNullMode(nameof(soundSource))] public AudioClip clickSound;
[Resources, Setting, SerializeField, Header("Animation Setting")]
private AnimationSolution animationSolution = AnimationSolution.SCRIPT;
[Resources, WhenAttribute.Is(nameof(animationSolution), AnimationSolution.SCRIPT), OnlyNotNullMode]
public GameObject rippleParent;
[Resources, WhenAttribute.Is(nameof(animationSolution), AnimationSolution.SCRIPT), Setting, SerializeField]
private bool m_useRipple = true;
[WhenAttribute.Is(nameof(useRipple), true), Setting] public bool renderOnTop = false;
[WhenAttribute.Is(nameof(useRipple), true), Setting] public bool centered = false;
[WhenAttribute.Is(nameof(useRipple), true), Setting] public RippleUpdateMode rippleUpdateMode = RippleUpdateMode.UNSCALED_TIME;
[WhenAttribute.Is(nameof(useRipple), true), Setting, Range(0.25f, 15)] public float fadingMultiplier = 8;
[WhenAttribute.Is(nameof(useRipple), true), Setting, Range(0.1f, 5)] public float speed = 1f;
[WhenAttribute.Is(nameof(useRipple), true), Setting, Range(0.5f, 25)] public float maxSize = 4f;
[WhenAttribute.Is(nameof(useRipple), true), Setting] public Color startColor = new Color(1f, 1f, 1f, 1f);
[WhenAttribute.Is(nameof(useRipple), true), Setting] public Color transitionColor = new Color(1f, 1f, 1f, 1f);
[WhenAttribute.Is(nameof(useRipple), true), Resources, HopeNotNull] public Sprite rippleShape;
[WhenAttribute.Is(nameof(useRipple), true), Setting] public bool hoverCreateRipple = false;
[WhenAttribute.Is(nameof(useRipple), true), Setting] public bool exitCreateRipple = false;
//[Header("Others")]
[Content, Ignore] private bool isPointerNotExit;
[Content, Ignore] private float currentNormalValue;
[Content, Ignore] private float currenthighlightedValue;
[Setting, SerializeField] private bool m_interactable = true;
public bool interactable
{
get => m_interactable;
set => m_interactable = value;
}
private void Start()
{
ResetContext();
if (animationSolution == AnimationSolution.SCRIPT)
{
if (normalCanvasGroup == null)
normalCanvasGroup = transform.Find("Normal").GetComponent<CanvasGroup>();
if (highlightedCanvasGroup == null)
highlightedCanvasGroup = transform.Find("Highlighted").GetComponent<CanvasGroup>();
Animator tempAnimator = this.GetComponent<Animator>();
Destroy(tempAnimator);
}
if (rippleParent)
{
if (useRipple)
rippleParent.SetActive(false);
else
Destroy(rippleParent);
}
}
private void OnValidate()
{
UpdateUI();
}
public void ResetContext()
{
var Context = this.GetOrAddComponent<BehaviourContextManager>();
Context.OnPointerDownEvent = BehaviourContextManager.InitializeContextSingleEvent(Context.OnPointerDownEvent, OnPointerDown);
Context.OnPointerEnterEvent = BehaviourContextManager.InitializeContextSingleEvent(Context.OnPointerEnterEvent, OnPointerEnter);
Context.OnPointerExitEvent = BehaviourContextManager.InitializeContextSingleEvent(Context.OnPointerExitEvent, OnPointerExit);
}
public void Reset()
{
ResetContext();
if (normalCanvasGroup == null)
normalCanvasGroup = transform.Find("Normal").GetComponent<CanvasGroup>();
if (highlightedCanvasGroup == null)
highlightedCanvasGroup = transform.Find("Highlighted").GetComponent<CanvasGroup>();
}
void OnEnable()
{
UpdateUI();
normalCanvasGroup.alpha = 1;
highlightedCanvasGroup.alpha = 0;
}
[Setting, Header("Is Auto Rename"), SerializeField] private bool m_IsAutoRename = true;
public void UpdateUI()
{
normalText.text = m_title;
highlightedText.text = m_title;
if (m_IsAutoRename)
{
this.name = $"{this.GetType().Name}<{m_title}>";
}
}
public void CreateRipple(Vector2 pos)
{
if (rippleParent != null)
{
GameObject rippleObj = new GameObject();
rippleObj.AddComponent<UnityEngine.UI.Image>();
rippleObj.GetComponent<UnityEngine.UI.Image>().sprite = rippleShape;
rippleObj.name = "Ripple";
rippleParent.SetActive(true);
rippleObj.transform.SetParent(rippleParent.transform);
if (renderOnTop == true)
rippleParent.transform.SetAsLastSibling();
else
rippleParent.transform.SetAsFirstSibling();
if (centered == true)
rippleObj.transform.localPosition = new Vector2(0f, 0f);
else
rippleObj.transform.position = pos;
rippleObj.AddComponent<Ripple>();
Ripple tempRipple = rippleObj.GetComponent<Ripple>();
tempRipple.speed = speed;
tempRipple.maxSize = maxSize;
tempRipple.startColor = startColor;
tempRipple.transitionColor = transitionColor;
if (rippleUpdateMode == RippleUpdateMode.NORMAL)
tempRipple.unscaledTime = false;
else
tempRipple.unscaledTime = true;
}
}
public void OnPointerCreateRipple(PointerEventData eventData)
{
if (useRipple == true && isPointerNotExit == true)
#if ENABLE_LEGACY_INPUT_MANAGER
CreateRipple(Input.mousePosition);
#elif ENABLE_INPUT_SYSTEM && ENABLE_LEGACY_INPUT_MANAGER
CreateRipple(Input.mousePosition);
#elif ENABLE_INPUT_SYSTEM
CreateRipple(Mouse.current.position.ReadValue());
#endif
else if (useRipple == false)
this.enabled = false;
}
public void OnPointerDown(PointerEventData eventData)
{
if (interactable == false)
return;
if (enableButtonSounds == true && useClickSound == true)
soundSource.PlayOneShot(clickSound);
clickEvent.Invoke();
OnPointerCreateRipple(eventData);
}
private void OnPointerEnter(PointerEventData eventData)
{
if (interactable == false)
return;
if (enableButtonSounds == true && useHoverSound == true)
soundSource.PlayOneShot(hoverSound);
hoverEvent.Invoke();
isPointerNotExit = true;
if (animationSolution == AnimationSolution.SCRIPT)
StartCoroutine(nameof(FadeIn));
if (hoverCreateRipple)
OnPointerCreateRipple(eventData);
}
private void OnPointerExit(PointerEventData eventData)
{
if (interactable == false)
return;
if (exitCreateRipple)
OnPointerCreateRipple(eventData);
isPointerNotExit = false;
if (animationSolution == AnimationSolution.SCRIPT)
StartCoroutine(nameof(FadeOut));
}
IEnumerator FadeIn()
{
StopCoroutine("FadeOut");
currentNormalValue = normalCanvasGroup.alpha;
currenthighlightedValue = highlightedCanvasGroup.alpha;
while (currenthighlightedValue <= 1)
{
currentNormalValue -= Time.deltaTime * fadingMultiplier;
normalCanvasGroup.alpha = currentNormalValue;
currenthighlightedValue += Time.deltaTime * fadingMultiplier;
highlightedCanvasGroup.alpha = currenthighlightedValue;
if (normalCanvasGroup.alpha >= 1)
StopCoroutine("FadeIn");
yield return null;
}
}
IEnumerator FadeOut()
{
StopCoroutine("FadeIn");
currentNormalValue = normalCanvasGroup.alpha;
currenthighlightedValue = highlightedCanvasGroup.alpha;
while (currentNormalValue >= 0)
{
currentNormalValue += Time.deltaTime * fadingMultiplier;
normalCanvasGroup.alpha = currentNormalValue;
currenthighlightedValue -= Time.deltaTime * fadingMultiplier;
highlightedCanvasGroup.alpha = currenthighlightedValue;
if (highlightedCanvasGroup.alpha <= 0)
StopCoroutine("FadeOut");
yield return null;
}
}
public IActionInvoke AddListener(params UnityAction[] action)
{
foreach (var actionItem in action)
clickEvent.AddListener(actionItem);
return this;
}
public IActionInvoke RemoveListener(params UnityAction[] action)
{
foreach (var actionItem in action)
clickEvent.RemoveListener(actionItem);
return this;
}
public IActionInvoke RemoveAllListeners()
{
clickEvent.RemoveAllListeners();
return this;
}
public Color NormalColor
{
get => normalCanvasGroup.GetComponentInChildren<Image>().color;
set
{
normalCanvasGroup.GetComponentInChildren<Image>().color = value;
normalCanvasGroup.GetComponentInChildren<TMP_Text>().color = value;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e3fbc3fc42c6e744d90ac678ccb527bd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,412 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using static Convention.ProjectContextLabelAttribute;
namespace Convention.WindowsUI
{
public class ModernUIDropdown : WindowUIModule, IActionInvoke<string>, ITitle
{
// Resources
[Resources, OnlyNotNullMode] public GameObject triggerObject;
[Resources, OnlyNotNullMode] public Transform itemParent;
[Resources, OnlyNotNullMode] public GameObject itemPrefab;
[Resources, OnlyNotNullMode] public GameObject scrollbar;
private VerticalLayoutGroup itemList;
private Transform currentListParent;
[Resources, WhenAttribute.Is(nameof(isListItem), true)] public Transform listParent;
private Animator dropdownAnimator;
[Resources, OnlyNotNullMode] public TextMeshProUGUI m_Title;
private Button m_RawButton;
// Settings
[Setting] public bool enableTrigger = true;
[Setting] public bool enableScrollbar = true;
[Setting] public bool setHighPriorty = true;
[Setting] public bool outOnPointerExit = false;
[Setting] public bool isListItem = false;
[Setting] public AnimationType animationType = AnimationType.FADING;
[Setting] public UnityEvent<string> OnSelect = new();
[Setting] public bool isMutiSelect = false;
// Items
[Content] public List<Item> dropdownItems = new();
// Other variables
bool isOn;
[Content] public int siblingIndex = 0;
private bool m_interactable = true;
public bool interactable
{
get => m_interactable;
set
{
if (m_interactable != value)
{
m_interactable = value;
RefreshImmediate();
}
}
}
public string title { get => m_Title.text; set => m_Title.text = value; }
public enum AnimationType
{
None,
FADING,
SLIDING,
STYLISH
}
[System.Serializable]
public class Item
{
public string itemName = "Dropdown Item";
[HideInInspector] private Toggle m_ToggleItem;
public Toggle ToggleItem
{
get => m_ToggleItem;
set
{
if (m_ToggleItem != value)
{
m_ToggleItem = value;
if (m_ToggleItem != null)
m_ToggleItem.isOn = lazy_isOn;
lazy_isOn = false;
}
}
}
public UnityEvent<bool> toggleEvents = new();
private bool lazy_isOn = false;
public bool isOn
{
get => ToggleItem == null ? lazy_isOn : ToggleItem.isOn;
set
{
if (ToggleItem == null)
lazy_isOn = value;
else
ToggleItem.SetIsOnWithoutNotify(value);
}
}
}
private void Reset()
{
triggerObject = transform.Find("Trigger").gameObject;
}
[Resources] public RectTransform ResizeBroadcastRect;
public IEnumerator ResizeBroadcast()
{
if (ResizeBroadcastRect == null)
yield break;
for (int i = 0; i < 60; i++)
{
RectTransformExtension.AdjustSizeToContainsChilds(ResizeBroadcastRect);
yield return null;
}
}
private void Start()
{
m_RawButton = GetComponent<Button>();
try
{
dropdownAnimator = this.GetComponent<Animator>();
itemList = itemParent.GetComponent<VerticalLayoutGroup>();
RefreshImmediate();
currentListParent = transform.parent;
}
catch
{
DebugError("Dropdown", "Cannot initalize the object", ContextLabelType.Resources, this);
}
if (enableScrollbar == true)
{
itemList.padding.right = 25;
scrollbar.SetActive(true);
}
else
{
itemList.padding.right = 8;
Destroy(scrollbar);
}
if (setHighPriorty == true)
transform.SetAsLastSibling();
}
[Content, OnlyPlayMode]
public void RefreshImmediate()
{
foreach (Transform child in itemParent)
if (child.gameObject != itemPrefab)
GameObject.Destroy(child.gameObject);
for (int i = 0; i < dropdownItems.Count; ++i)
{
Item current = dropdownItems[i];
GameObject go = Instantiate(itemPrefab, itemParent);
go.SetActive(true);
go.GetComponentInChildren<TMP_Text>().text = current.itemName;
Toggle itemToggle = go.GetComponent<Toggle>();
current.ToggleItem = itemToggle;
itemToggle.isOn = false;
itemToggle.interactable = interactable;
}
foreach (var current in dropdownItems)
{
var itemToggle = current.ToggleItem;
itemToggle.onValueChanged.AddListener(GenerateCallback(current));
}
currentListParent = transform.parent;
UnityAction<bool> GenerateCallback(Item current)
{
void Callback(bool T)
{
if (isMutiSelect)
{
int selectCount = 0;
Item selectedLast = null;
foreach (var item in dropdownItems)
{
if (item.isOn)
{
selectCount++;
selectedLast = item;
}
}
if (selectCount == 0)
this.title = "Empty";
else if (selectCount == 1)
this.title = selectedLast.itemName;
else if (selectCount == dropdownItems.Count)
this.title = "Every";
else
this.title = "Muti";
}
else
{
if (T)
{
foreach (var item in dropdownItems)
{
if (current != item)
item.isOn = false;
}
this.title = current.itemName;
}
else
{
dropdownItems[0].isOn = true;
this.title = dropdownItems[0].itemName;
}
}
current.toggleEvents.Invoke(T);
OnSelect.Invoke(current.itemName);
}
return Callback;
}
}
public void Animate()
{
if (isOn == false && animationType == AnimationType.FADING)
{
dropdownAnimator.Play("Fading In");
isOn = true;
if (isListItem == true)
{
siblingIndex = transform.GetSiblingIndex();
gameObject.transform.SetParent(listParent, true);
}
}
else if (isOn == true && animationType == AnimationType.FADING)
{
dropdownAnimator.Play("Fading Out");
isOn = false;
if (isListItem == true)
{
gameObject.transform.SetParent(currentListParent, true);
gameObject.transform.SetSiblingIndex(siblingIndex);
}
}
else if (isOn == false && animationType == AnimationType.SLIDING)
{
dropdownAnimator.Play("Sliding In");
isOn = true;
if (isListItem == true)
{
siblingIndex = transform.GetSiblingIndex();
gameObject.transform.SetParent(listParent, true);
}
}
else if (isOn == true && animationType == AnimationType.SLIDING)
{
dropdownAnimator.Play("Sliding Out");
isOn = false;
if (isListItem == true)
{
gameObject.transform.SetParent(currentListParent, true);
gameObject.transform.SetSiblingIndex(siblingIndex);
}
}
else if (isOn == false && animationType == AnimationType.STYLISH)
{
dropdownAnimator.Play("Stylish In");
isOn = true;
if (isListItem == true)
{
siblingIndex = transform.GetSiblingIndex();
gameObject.transform.SetParent(listParent, true);
}
}
else if (isOn == true && animationType == AnimationType.STYLISH)
{
dropdownAnimator.Play("Stylish Out");
isOn = false;
if (isListItem == true)
{
gameObject.transform.SetParent(currentListParent, true);
gameObject.transform.SetSiblingIndex(siblingIndex);
}
}
StopCoroutine(nameof(ResizeBroadcast));
StartCoroutine(nameof(ResizeBroadcast));
if (enableTrigger == true && isOn == false)
triggerObject.SetActive(false);
else if (enableTrigger == true && isOn == true)
triggerObject.SetActive(true);
if (outOnPointerExit == true)
triggerObject.SetActive(false);
if (setHighPriorty == true)
transform.SetAsLastSibling();
}
public void OnPointerExit(PointerEventData eventData)
{
if (outOnPointerExit == true)
{
if (isOn == true)
{
Animate();
isOn = false;
}
if (isListItem == true)
gameObject.transform.SetParent(currentListParent, true);
}
}
public void UpdateValues()
{
if (enableScrollbar == true)
{
itemList.padding.right = 25;
scrollbar.SetActive(true);
}
else
{
itemList.padding.right = 8;
scrollbar.SetActive(false);
}
}
public Item CreateOption(string name, params UnityAction<bool>[] actions)
{
Item item = new()
{
itemName = name,
toggleEvents = ConventionUtility.WrapperAction2Event(actions)
};
dropdownItems.Add(item);
return item;
}
public void RemoveOption(params Item[] items)
{
foreach (var item in items)
{
dropdownItems.RemoveAll(T => T == item);
}
RefreshImmediate();
}
[Content, OnlyPlayMode]
public void ClearOptions()
{
dropdownItems.Clear();
RefreshImmediate();
}
public void Select(string option)
{
var target = dropdownItems.FirstOrDefault(T => T.itemName == option);
if (target != default)
{
target.ToggleItem.isOn = true;
title = option;
}
}
public IActionInvoke<string> AddListener(params UnityAction<string>[] action)
{
foreach (var item in action)
{
OnSelect.AddListener(item);
}
return this;
}
public IActionInvoke<string> RemoveListener(params UnityAction<string>[] action)
{
foreach (var item in action)
{
OnSelect.RemoveListener(item);
}
return this;
}
public IActionInvoke<string> RemoveAllListeners()
{
OnSelect.RemoveAllListeners();
return this;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d81168c7a313be441953c8dfd93e8564
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,150 @@
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Convention.WindowsUI
{
public class ModernUIFillBar : WindowUIModule
{
// Content
private float lastPercent;
[Range(0, 1)] public float currentPercent;
public float minValue = 0;
public float maxValue = 100;
public UnityEvent<float> OnValueChange = new();
public UnityEvent<float> OnEndChange = new();
public UnityEvent<float> OnTransValueChange = new();
public UnityEvent<float> OnEndTransChange = new();
public float value => (maxValue - minValue) * currentPercent + minValue;
public float Value => (maxValue - minValue) * currentPercent + minValue;
// Resources
public Image loadingBar;
public TextMeshProUGUI textPercent;
public TextMeshProUGUI textValue;
public bool IsLockByScript = true;
// Settings
public bool IsPercent = true;
public bool IsInt = false;
public float DragChangeSpeed = 0.5f;
public void Start()
{
var Context = this.GetOrAddComponent<BehaviourContextManager>();
Context.OnDragEvent = BehaviourContextManager.InitializeContextSingleEvent(Context.OnDragEvent, OnDrag);
this.currentPercent = loadingBar.fillAmount = this.lastPercent = value;
textPercent.text = (IsPercent ? currentPercent * 100 : currentPercent).ToString("F2") + (IsPercent ? "%" : "");
textValue.text = GetValue().ToString("F2");
}
public void SetValue(float t)
{
SetPerecent((t - minValue) / (maxValue - minValue));
}
public void SetPerecent(float t)
{
if (IsLockByScript) currentPercent = Mathf.Clamp(t, 0, 1);
else loadingBar.fillAmount = t;
}
public void SetPerecent(float t, float a, float b)
{
if (IsLockByScript) currentPercent = Mathf.Clamp(t, 0, 1);
else loadingBar.fillAmount = t;
minValue = a;
maxValue = b;
IsInt = false;
}
public void SetPerecent(float t, int a, int b)
{
if (IsLockByScript) currentPercent = Mathf.Clamp(t, 0, 1);
else loadingBar.fillAmount = t;
minValue = a;
maxValue = b;
IsInt = true;
}
public void OnDrag(PointerEventData data)
{
if (!IsLockByScript) loadingBar.fillAmount += data.delta.x * Time.deltaTime * DragChangeSpeed;
}
private bool IsUpdateAndInvoke = true;
public void LateUpdate()
{
if (IsLockByScript) loadingBar.fillAmount = Mathf.Clamp(currentPercent, 0, 1);
else currentPercent = loadingBar.fillAmount;
if (currentPercent == lastPercent)
{
if (!IsUpdateAndInvoke)
{
IsUpdateAndInvoke = true;
OnEndChange.Invoke(currentPercent);
OnEndTransChange.Invoke(Value);
}
return;
}
IsUpdateAndInvoke = false;
lastPercent = currentPercent;
OnValueChange.Invoke(currentPercent);
OnTransValueChange.Invoke(Value);
textPercent.text = (IsPercent ? currentPercent * 100 : currentPercent).ToString("F2") + (IsPercent ? "%" : "");
textValue.text = GetValue().ToString("F2");
}
public void UpdateWithInvoke()
{
if (IsLockByScript) loadingBar.fillAmount = Mathf.Clamp(currentPercent, 0, 1);
else currentPercent = loadingBar.fillAmount;
if (currentPercent == lastPercent)
{
if (!IsUpdateAndInvoke)
{
IsUpdateAndInvoke = true;
}
return;
}
IsUpdateAndInvoke = false;
lastPercent = currentPercent;
textPercent.text = currentPercent.ToString("F2") + (IsPercent ? "%" : "");
textValue.text = GetValue().ToString("F2");
}
public float GetValue()
{
return IsInt ? (int)value : value;
}
public int GetIntValue()
{
return (int)value;
}
public void Set(float min, float max)
{
currentPercent = 0;
minValue = min;
maxValue = max;
}
public void Set(float percent, float min, float max)
{
currentPercent = percent;
minValue = min;
maxValue = max;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8d016f728204dfb44ab4747507548d8c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
using UnityEngine;
using UnityEngine.UI;
namespace Convention.WindowsUI
{
public class ModernUIImage : WindowUIModule
{
[Resources, SerializeField, HopeNotNull] private RawImage m_RawImage;
[Resources, SerializeField] private GradientEffect m_GradientEffect;
private void Reset()
{
m_RawImage = GetComponent<RawImage>();
}
private void Start()
{
if (m_RawImage == null)
m_RawImage = GetComponent<RawImage>();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 08b5d0477bc06d24586c8b2f5ee9e130
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,37 @@
using UnityEngine.Events;
namespace Convention.WindowsUI
{
public partial class ModernUIInputField : WindowUIModule, ITitle, IInputField
{
[Resources, HopeNotNull] public Text TitleSource;
[Resources, HopeNotNull] public InputField InputFieldSource;
public virtual string text { get => InputFieldSource.text; set => InputFieldSource.text = value; }
public virtual string title { get => TitleSource.title; set => TitleSource.title = value; }
public bool interactable { get => InputFieldSource.Source.interactable; set => InputFieldSource.Source.interactable = value; }
public IActionInvoke<string> AddListener(params UnityAction<string>[] action)
{
return ((IActionInvoke<string>)this.InputFieldSource).AddListener(action);
}
public IActionInvoke<string> RemoveAllListeners()
{
return ((IActionInvoke<string>)this.InputFieldSource).RemoveAllListeners();
}
public IActionInvoke<string> RemoveListener(params UnityAction<string>[] action)
{
return ((IActionInvoke<string>)this.InputFieldSource).RemoveListener(action);
}
private void Reset()
{
TitleSource = GetComponentInChildren<Text>();
InputFieldSource = GetComponentInChildren<InputField>();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c20431df589b2094bb93ed965972a6c5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,126 @@
using System;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
namespace Convention.WindowsUI
{
[Serializable]
public class ModernUIToggle : WindowUIModule, IToggle, ITitle
{
[Content] public UnityEvent m_SwitchOnEvent = new();
[Content] public UnityEvent m_SwitchOffEvent = new();
[Content] public UnityEvent<bool> m_ToggleEvent = new();
[Resources, OnlyNotNullMode] public TextMeshProUGUI normalText;
[Resources, HopeNotNull] public CanvasGroup normalCanvasGroup;
[Resources, OnlyNotNullMode] public TextMeshProUGUI selectedText;
[Resources, HopeNotNull] public CanvasGroup selectedCanvasGroup;
[Resources, Setting, HopeNotNull, Header("Sound Setting")] public AudioSource soundSource;
[Resources, Setting, OnlyNotNullMode(nameof(soundSource))] public bool enableButtonSounds = false;
[Resources, WhenAttribute.Is(nameof(enableButtonSounds), true), OnlyNotNullMode(nameof(soundSource))] public AudioClip m_SwitchOnSound;
[Resources, WhenAttribute.Is(nameof(enableButtonSounds), true), OnlyNotNullMode(nameof(soundSource))] public AudioClip m_SwitchOffSound;
[Content, SerializeField] private string m_title = "";
[Content, SerializeField] private bool m_value = false;
public bool ref_value
{
get => m_value;
set
{
if (m_value != value)
{
m_value = value;
normalCanvasGroup.alpha = m_value ? 0 : 1;
selectedCanvasGroup.alpha = m_value ? 1 : 0;
}
}
}
public string title
{
get => m_title;
set
{
m_title = value;
UpdateUI();
}
}
[Setting, SerializeField] private bool m_interactable = true;
public bool interactable { get => m_interactable; set => m_interactable = value; }
private void Start()
{
ResetContext();
}
private void OnValidate()
{
UpdateUI();
}
public void Reset()
{
ResetContext();
if (normalCanvasGroup == null)
normalCanvasGroup = transform.Find("Normal").GetComponent<CanvasGroup>();
if (selectedCanvasGroup == null)
selectedCanvasGroup = transform.Find("Selected").GetComponent<CanvasGroup>();
interactable = true;
}
void OnEnable()
{
UpdateUI();
}
public void ResetContext()
{
var Context = this.GetOrAddComponent<BehaviourContextManager>();
Context.OnPointerDownEvent = BehaviourContextManager.InitializeContextSingleEvent(Context.OnPointerDownEvent, OnPointerDown);
}
public void UpdateUI()
{
normalText.text = m_title;
selectedText.text = m_title;
normalCanvasGroup.alpha = m_value ? 0 : 1;
selectedCanvasGroup.alpha = m_value ? 1 : 0;
}
public void OnPointerDown(PointerEventData eventData)
{
if (interactable == false)
return;
ref_value = !ref_value;
if (enableButtonSounds == true)
soundSource.PlayOneShot(ref_value ? m_SwitchOnSound : m_SwitchOffSound);
(ref_value ? m_SwitchOnEvent : m_SwitchOffEvent).Invoke();
m_ToggleEvent.Invoke(ref_value);
}
public IActionInvoke<bool> AddListener(params UnityAction<bool>[] action)
{
foreach (var item in action)
{
m_ToggleEvent.AddListener(item);
}
return this;
}
public IActionInvoke<bool> RemoveListener(params UnityAction<bool>[] action)
{
foreach (var item in action)
{
m_ToggleEvent.RemoveListener(item);
}
return this;
}
public IActionInvoke<bool> RemoveAllListeners()
{
m_ToggleEvent.RemoveAllListeners();
return this;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dd9a03449cd6bb444a191c450ed8cf97
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,95 @@
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.Events;
namespace Convention.WindowsUI
{
public interface IWindowUIModule { }
public class WindowUIModule : MonoBehaviour, IWindowUIModule { }
public static partial class UIInterfaceExtension
{
public static void AutoTransform(GameObject @object)
{
if (@object == null) return;
foreach (var text in @object.GetComponentsInChildren<IText>(true))
{
text.Transform();
}
foreach (var title in @object.GetComponentsInChildren<ITitle>(true))
{
title.Transform();
}
foreach (Transform child in @object.transform)
{
AutoTransform(child.gameObject);
}
}
private const string ExpressionPattern = @"\$\$.*?\$\$";
public static void Transform(this IText self)
{
try
{
string result = self.text;
foreach (Match match in Regex.Matches(self.text, ExpressionPattern))
{
result = result.Replace(match.Value, StringExtension.Transform(match.Value[2..^2]));
}
self.text = result;
}
catch (System.Exception) { }
}
public static void Transform(this ITitle self)
{
try
{
string result = self.title;
foreach (Match match in Regex.Matches(self.title, ExpressionPattern))
{
result = result.Replace(match.Value, StringExtension.Transform(match.Value[2..^2]));
}
self.title = result;
}
catch (System.Exception) { }
}
}
public interface IText : IAnyClass
{
string text { get; set; }
}
public interface ITitle : IAnyClass
{
string title { get; set; }
}
public interface IInteractable : IAnyClass
{
bool interactable { get; set; }
}
public interface IActionInvoke : IInteractable
{
IActionInvoke AddListener(params UnityAction[] action);
IActionInvoke RemoveListener(params UnityAction[] action);
IActionInvoke RemoveAllListeners();
}
public interface IActionInvoke<Args> : IInteractable
{
IActionInvoke<Args> AddListener(params UnityAction<Args>[] action);
IActionInvoke<Args> RemoveListener(params UnityAction<Args>[] action);
IActionInvoke<Args> RemoveAllListeners();
}
public interface IButton : IWindowUIModule, IActionInvoke { }
public interface IToggle : IWindowUIModule, IActionInvoke<bool> { }
public interface IInputField : IWindowUIModule, IActionInvoke<string>, IText { }
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 435b5d2ff26047d429796e05ebf8acdf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
using UnityEngine;
namespace Convention.WindowsUI
{
public partial class ScrollView : WindowUIModule
{
[Resources, HopeNotNull] public UnityEngine.UI.ScrollRect scrollRect;
private void Reset()
{
scrollRect = GetComponent<UnityEngine.UI.ScrollRect>();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 04d84e08b7419414ca6823f22f502154
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
using TMPro;
using UnityEngine;
namespace Convention.WindowsUI
{
public partial class Text : WindowUIModule, IText, ITitle
{
[Resources, HopeNotNull] public TextMeshProUGUI source;
public virtual string text
{
get => source.text;
set => source.text = value;
}
public virtual string title
{
get => source.text;
set => source.text = value;
}
private void Start()
{
if (source == null)
source = this.GetComponent<TextMeshProUGUI>();
}
private void Reset()
{
if (source == null)
source = this.GetComponent<TextMeshProUGUI>();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 11e9ceb9d81e8074d82ec570260c56d2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ff1a65153fc10c04ba56684597bfa8d6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fcda8b09e5a240d4ca0e140a4691a7bf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using static Convention.WindowsUI.Variant.PropertiesWindow;
namespace Convention.WindowsUI.Variant
{
public class AssetsItem : WindowUIModule, IText, ITitle, IItemEntry
{
public static int TextStringLimit = 16;
public static AssetsItem FocusItem;
public interface IAssetsItemInvoke
{
void OnAssetsItemInvoke(AssetsItem item);
void OnAssetsItemFocus(AssetsItem item);
}
[Resources, SerializeField, OnlyNotNullMode] private Button m_RawButton;
[Resources, SerializeField, OnlyNotNullMode] private Text m_Text;
[Content, SerializeField] private string m_TextString;
[Content, SerializeField] private List<ItemEntry> m_ChildEntries = new();
[Content, SerializeField] private ItemEntry m_entry;
[Setting] public bool HasChildLayer = true;
public ItemEntry Entry
{
get => m_entry;
set
{
if (this.gameObject.activeInHierarchy && m_entry != null)
{
throw new InvalidOperationException();
}
m_entry = value;
m_entry.ref_value = this;
}
}
public Sprite ButtonSprite
{
get => m_RawButton.GetComponent<Image>().sprite;
set => m_RawButton.GetComponent<Image>().sprite = value;
}
public List<ItemEntry> AddChilds(int count)
{
var entries = Entry.rootWindow.CreateRootItemEntries(false, count);
m_ChildEntries.AddRange(entries);
return entries;
}
public ItemEntry AddChild()
{
var entry = Entry.rootWindow.CreateRootItemEntries(false, 1)[0];
m_ChildEntries.Add(entry);
return entry;
}
public void RemoveChild([In] ItemEntry entry)
{
if (m_ChildEntries.Remove(entry))
entry.Disable(true);
}
public void RemoveAllChilds()
{
foreach (var entry in m_ChildEntries)
{
entry.Disable(true);
}
m_ChildEntries.Clear();
}
public int ChildCount()
{
return m_ChildEntries.Count;
}
public ItemEntry GetChild(int index)
{
return m_ChildEntries[index];
}
public string title
{
get => m_TextString;
set
{
m_TextString = value;
if (value.Length > TextStringLimit)
this.m_Text.title = value[..(TextStringLimit - 3)] + "...";
else
this.m_Text.title = value;
}
}
public string text
{
get => title; set => title = value;
}
private void Start()
{
m_RawButton.onClick.AddListener(() =>
{
Invoke();
});
}
public virtual void Invoke()
{
AssetsWindow.instance.CurrentTargetName = m_TextString;
if (FocusItem != this)
{
FocusItem = this;
if (FocusWindowIndictaor.instance != null)
FocusWindowIndictaor.instance.SetTargetRectTransform(this.transform as RectTransform);
foreach (var component in this.GetComponents<IAssetsItemInvoke>())
{
component.OnAssetsItemFocus(this);
}
}
else
{
FocusItem = null;
if (FocusWindowIndictaor.instance != null)
FocusWindowIndictaor.instance.SetTargetRectTransform(null);
if (HasChildLayer)
Entry.rootWindow.GetComponent<AssetsWindow>().Push(title, m_ChildEntries, true);
foreach (var component in this.GetComponents<IAssetsItemInvoke>())
{
component.OnAssetsItemInvoke(this);
}
}
AssetsWindow.instance.UpdatePathText();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 94ea2554d072ca644a059dec276f3a69
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,95 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
namespace Convention.WindowsUI.Variant
{
[RequireComponent(typeof(PropertiesWindow))]
public class AssetsWindow : MonoSingleton<AssetsWindow>
{
[Content, OnlyPlayMode, SerializeField, Header("Assets Stack")] private Stack<List<PropertiesWindow.ItemEntry>> m_EntriesStack = new();
[Resources, OnlyNotNullMode, SerializeField] private PropertiesWindow m_PropertiesWindow;
[Resources, OnlyNotNullMode, SerializeField, Tooltip("Back Button")] private Button m_BackButton;
[Resources, OnlyNotNullMode, SerializeField, Tooltip("Path Text")] private Text m_PathTitle;
[Content, OnlyPlayMode] public string CurrentTargetName;
[Content, OnlyPlayMode, SerializeField] public List<string> pathContainer = new();
private RegisterWrapper<AssetsWindow> m_RegisterWrapper;
private void OnDestroy()
{
m_RegisterWrapper.Release();
}
public PropertiesWindow MainPropertiesWindow => m_PropertiesWindow;
public void UpdatePathText()
{
m_PathTitle.text = string.Join('/', pathContainer.ToArray()) +
(string.IsNullOrEmpty(CurrentTargetName) ? "" : $":<color=blue>{CurrentTargetName}</color>");
}
protected virtual void Start()
{
m_BackButton.onClick.AddListener(() => Pop(true));
UpdatePathText();
m_RegisterWrapper = new(() => { });
}
protected virtual void Reset()
{
m_PropertiesWindow.m_PerformanceMode = PerformanceIndicator.PerformanceMode.L1;
m_PropertiesWindow = GetComponent<PropertiesWindow>();
}
public void Push([In] string label, [In] List<PropertiesWindow.ItemEntry> entries, bool isRefreshTop)
{
var top = Peek();
if (top != null)
foreach (var entry in top)
{
entry.Disable(false);
}
m_EntriesStack.Push(entries);
foreach (var entry in entries)
{
entry.Enable(false);
}
if (isRefreshTop)
RectTransformExtension.AdjustSizeToContainsChilds(m_PropertiesWindow.TargetWindowContent);
pathContainer.Add(label);
UpdatePathText();
}
[return: ReturnMayNull, When("m_EntriesStack is empty")]
public List<PropertiesWindow.ItemEntry> Peek()
{
if (m_EntriesStack.Count == 0)
return null;
return m_EntriesStack.Peek();
}
[return: ReturnMayNull, When("m_EntriesStack is empty")]
public List<PropertiesWindow.ItemEntry> Pop(bool isRefreshTop)
{
if (m_EntriesStack.Count <= 1)
return null;
var top = m_EntriesStack.Pop();
if (top != null)
foreach (var entry in top)
{
entry.Disable(false);
}
var entries = Peek();
if (entries != null)
foreach (var entry in entries)
{
entry.Enable(false);
}
if (isRefreshTop)
RectTransformExtension.AdjustSizeToContainsChilds(m_PropertiesWindow.TargetWindowContent);
if (pathContainer.Count != 0)
pathContainer.RemoveAt(pathContainer.Count - 1);
UpdatePathText();
return top;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6145859b1511d7e4bb47c6c770695b6f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,75 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Convention.WindowsUI.Variant
{
public class FileSystemAssets : MonoSingleton<FileSystemAssets>
{
public static void InitLoadedRoots(ref List<string> LoadedInRoot)
{
LoadedInRoot = new List<string>();
if (PlatformIndicator.is_platform_windows)
{
LoadedInRoot.Add(Application.persistentDataPath);
LoadedInRoot.Add(Application.streamingAssetsPath);
}
else
{
LoadedInRoot.Add(Application.persistentDataPath);
}
}
[Resources, SerializeField, OnlyNotNullMode] private AssetsWindow m_AssetsWindow;
[Resources, OnlyNotNullMode] public Text CurrentSelectFilename;
[Setting] public long LoadedFileAutoLoadMaxFileSize = 1024 * 50;
[Setting] public List<string> LoadedInRoot = null;
[Setting] public List<string> LoadedFileIconsExtension = new() { "skys", "scenes", "gameobjects" };
[Setting] public string RootName = "Root";
protected override void Awake()
{
base.Awake();
// Starter
FileSystemAssetsItem.LoadedFiles.Clear();
if (LoadedInRoot == null || LoadedInRoot.Count == 0)
InitLoadedRoots(ref LoadedInRoot);
// Update extensions
var extensions = ToolFile.AssetBundleExtension.ToList();
extensions.AddRange(LoadedFileIconsExtension);
ToolFile.AssetBundleExtension = extensions.ToArray();
// Read Config
if (LoadedFileAutoLoadMaxFileSize != 0)
FileSystemAssetsItem.LoadedFileAutoLoadMaxFileSize = LoadedFileAutoLoadMaxFileSize;
}
private void Start()
{
var entries = m_AssetsWindow.MainPropertiesWindow.CreateRootItemEntries(false, LoadedInRoot.Count);
for (int i = 0, e = LoadedInRoot.Count; i != e; i++)
{
entries[i].ref_value.GetComponent<FileSystemAssetsItem>().RebuildFileInfo(LoadedInRoot[i]);
}
m_AssetsWindow.Push(RootName, entries, true);
CurrentSelectFilename.title = "";
}
private void Reset()
{
m_AssetsWindow = GetComponent<AssetsWindow>();
InitLoadedRoots(ref LoadedInRoot);
LoadedFileIconsExtension = new() { "skys", "scenes", "gameobjects" };
}
public void RefreshImmediate()
{
if (FocusWindowIndictaor.instance.Target == m_AssetsWindow.transform as RectTransform)
{
foreach (var entry in m_AssetsWindow.Peek())
{
entry.ref_value.GetComponent<FileSystemAssetsItem>().SetDirty();
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 734fec2b42b743a42be5f7a781c1eb10
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,383 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace Convention.WindowsUI.Variant
{
public class FileSystemAssetsItem : MonoAnyBehaviour, AssetsItem.IAssetsItemInvoke
{
public static Dictionary<string, ToolFile> LoadedFiles = new();
public static long LoadedFileAutoLoadMaxFileSize = 1024 * 50;
[Setting] public ToolFile m_File;
[Setting, InspectorDraw(InspectorDrawType.Text), Ignore] public string ItemPathName;
[Setting] public ScriptableObject m_Icons;
[Content, OnlyPlayMode, SerializeField] private bool m_Dirty = false;
[Content, OnlyNotNullMode, SerializeField, InspectorDraw(InspectorDrawType.Toggle), Ignore]
private bool m_IsLoading = false;
private void OnDestroy()
{
if (m_File.data is AssetBundle)
{
return;
}
m_File.data = null;
}
public void RebuildFileInfo([In] string path)
{
if (LoadedFiles.ContainsKey(path))
m_File = LoadedFiles[path];
else
{
LoadedFiles.Add(path, new ToolFile(path));
m_File = new(path);
}
m_Dirty = true;
ItemPathName = m_File.GetFilename(false);
OnAssetsItemFocusWithFileMode(GetComponent<AssetsItem>(), m_File.GetFilename(true));
}
public void RebuildButNotFileInfo([In] string title)
{
var temp = new ToolFile(title);
ItemPathName = temp.GetFilename(false);
if (title.Contains("."))
UpdateSpriteAndTitle(GetComponent<AssetsItem>(), title, title.Split('.')[^1]);
else
UpdateSpriteAndTitle(GetComponent<AssetsItem>(), title, "ab.data");
}
private void UpdateSprite([In] AssetsItem item, [In] string sprite)
{
item.ButtonSprite = m_Icons.FindItem<Sprite>(sprite);
}
private void UpdateSpriteAndTitle([In] AssetsItem item, [In] string name, [In] string extension)
{
item.title = name;
UpdateSprite(item, extension);
}
/// <summary>
/// Some extensions see <see cref="FileSystemAssets.Awake"/>
/// </summary>
/// <param name="item"></param>
private void OnAssetsItemFocusWithFileMode([In] AssetsItem item, [In] string name)
{
item.title = name;
FileSystemAssets.instance.CurrentSelectFilename.title = m_File.FullPath;
if (m_File.IsExist == false)
return;
else if (m_File.IsDir())
UpdateSprite(item, "folder");
else if (m_File.Extension.Length != 0 && m_Icons.uobjects.ContainsKey(m_File.Extension))
UpdateSprite(item, m_File.Extension);
else if (m_File.Extension.Length != 0 && m_Icons.uobjects.ContainsKey(m_File.Extension[1..]))
UpdateSprite(item, m_File.Extension[1..]);
else if (m_File.IsImage)
UpdateSprite(item, "image");
else if (m_File.IsText)
UpdateSprite(item, "text");
else if (m_File.IsJson)
UpdateSprite(item, "json");
else if (m_File.IsAssetBundle)
UpdateSprite(item, "ab");
else
UpdateSprite(item, "default");
}
// --------------------
private abstract class AssetBundleItem : WindowUIModule, AssetsItem.IAssetsItemInvoke
{
[Resources] public AssetBundle ab;
[Resources] public string targetName;
public abstract void OnAssetsItemFocus(AssetsItem item);
public abstract void OnAssetsItemInvoke(AssetsItem item);
}
private class SkyItem : AssetBundleItem
{
[Resources, SerializeField] private Material SkyBox;
public class SkyItemInstanceWrapper : Singleton<SkyItemInstanceWrapper>
{
public static void InitInstance()
{
if (instance == null)
{
instance = new SkyItemInstanceWrapper();
}
}
[InspectorDraw(InspectorDrawType.Reference), Ignore] public Material SkyBox;
[InspectorDraw(InspectorDrawType.Text), Ignore] public string SkyBoxName;
}
private void OnEnable()
{
SkyItemInstanceWrapper.InitInstance();
}
private void OnDisable()
{
SkyBox = null;
}
public override void OnAssetsItemFocus(AssetsItem item)
{
if (SkyBox == null)
{
SkyBox = ab.LoadAsset<Material>(targetName);
}
}
public override void OnAssetsItemInvoke(AssetsItem item)
{
SkyExtension.Load(SkyBox);
if (!HierarchyWindow.instance.ContainsReference(SkyItemInstanceWrapper.instance))
{
var skyItem = HierarchyWindow.instance.CreateRootItemEntryWithBinders(SkyItemInstanceWrapper.instance)[0].ref_value.GetComponent<HierarchyItem>();
skyItem.title = "Global Skybox";
}
SkyItemInstanceWrapper.instance.SkyBox = SkyBox;
SkyItemInstanceWrapper.instance.SkyBoxName = targetName;
InspectorWindow.instance.ClearWindow();
}
}
private class SceneItem : AssetBundleItem
{
[Resources, SerializeField] private bool isLoad = false;
[Content, SerializeField, Ignore] private Scene m_Scene;
private PropertiesWindow.ItemEntry m_entry;
public override void OnAssetsItemFocus(AssetsItem item)
{
}
public override void OnAssetsItemInvoke(AssetsItem item)
{
if (isLoad = !isLoad)
{
SceneExtension.Load(targetName);
item.GetComponent<Image>().color = Color.green;
// init scene item
m_Scene = SceneExtension.GetScene(targetName);
m_entry = HierarchyWindow.instance.CreateRootItemEntryWithBinders(item)[0];
var hierarchyItem = m_entry.ref_value.GetComponent<HierarchyItem>();
hierarchyItem.title = m_Scene.name;
}
else
{
SceneExtension.Unload(targetName);
item.GetComponent<Image>().color = Color.white;
// unload scene item
m_entry.Release();
}
}
}
private class GameObjectItem : AssetBundleItem, IOnlyFocusThisOnInspector
{
[Content, IsInstantiated(true)] public GameObject target;
[Content, IsInstantiated(true)] public GameObject last;
private Image image;
[InspectorDraw(InspectorDrawType.Button), Content]
public void ReleaseGameObjectToScene()
{
if (target != null)
{
HierarchyWindow.instance.CreateRootItemEntryWithGameObject(target);
target = null;
}
}
[InspectorDraw(InspectorDrawType.Button), Content]
public void DestroyCurrentSelect()
{
if (target != null)
{
if (HierarchyWindow.instance.ContainsReference(target))
{
HierarchyWindow.instance.GetReferenceItem(target).Entry.Release();
HierarchyWindow.instance.RemoveReference(target);
}
GameObject.Destroy(target);
target = null;
}
}
private void OnEnable()
{
image = GetComponent<Image>();
}
private void OnDisable()
{
if (target != null)
{
GameObject.Destroy(target);
}
}
private void FixedUpdate()
{
image.color = target == null ? Color.white : Color.green;
}
public override void OnAssetsItemFocus(AssetsItem item)
{
}
public override void OnAssetsItemInvoke(AssetsItem item)
{
if (target == null)
{
last = target;
target = GameObject.Instantiate(ab.LoadAsset<GameObject>(targetName));
try
{
target.BroadcastMessage($"On{nameof(GameObjectItem)}", this, SendMessageOptions.DontRequireReceiver);
}
catch (InvalidOperationException)
{
target = null;
}
}
else
{
ReleaseGameObjectToScene();
}
}
}
// --------------------
private void OnAssetsItemFocusWithFileLoading([In] AssetsItem item)
{
if (m_File.IsAssetBundle)
{
if (m_File.data == null)
{
StartLoad();
StartCoroutine(this.m_File.LoadAsAssetBundle(LoadAssetBundle));
}
}
else
{
if (m_File.data == null && m_File.FileSize < 1024 * 50)
m_File.Load();
}
void StartLoad()
{
m_IsLoading = true;
item.GetComponent<Image>().color = Color.red;
}
void EndLoad()
{
m_IsLoading = false;
item.GetComponent<Image>().color = Color.white;
}
void LoadAssetBundle()
{
EndLoad();
AssetBundle ab = m_File.data as AssetBundle;
var assets = ab.GetAllAssetNames().ToList();
assets.AddRange(ab.GetAllScenePaths());
var entries = item.AddChilds(assets.Count);
for (int i = 0, e = assets.Count; i < e; i++)
{
entries[i].ref_value.GetComponent<FileSystemAssetsItem>().RebuildButNotFileInfo(assets[i]);
AssetBundleItem abitem = null;
var objectName = new ToolFile(assets[i]).GetFilename(false);
if (objectName.Contains("is sky") || m_File.ExtensionIs("skys"))
{
abitem = entries[i].ref_value.gameObject.AddComponent<SkyItem>();
}
else if (m_File.ExtensionIs("scenes"))
{
abitem = entries[i].ref_value.gameObject.AddComponent<SceneItem>();
UpdateSpriteAndTitle(entries[i].ref_value.gameObject.GetComponent<AssetsItem>(), new ToolFile(assets[i]).GetFilename(true), "scene");
abitem.targetName = assets[i];
}
else if (objectName.Contains("is gameobject") || m_File.ExtensionIs("gameobjects"))
{
abitem = entries[i].ref_value.gameObject.AddComponent<GameObjectItem>();
}
if (abitem != null)
{
if (abitem.ab == null)
abitem.ab = ab;
if (abitem.targetName == null || abitem.targetName.Length == 0)
abitem.targetName = objectName;
}
}
}
}
private void RefreshWithToolFile([In] AssetsItem item)
{
ReleaseAllChilds(item);
if (m_File.IsDir())
{
var files = m_File.DirToolFileIter();
var paths = (from file in files
where !file.ExtensionIs("meta")
where !file.Filename.ToLower().Contains("<ignore file>")
select file).ToList().ConvertAll(x => x.FullPath);
AddChils(item, paths);
}
else
{
OnAssetsItemFocusWithFileLoading(item);
}
ItemPathName = m_File.GetFilename(false);
OnAssetsItemFocusWithFileMode(item, m_File.GetFilename(true));
}
private void ReleaseAllChilds(AssetsItem item)
{
item.RemoveAllChilds();
}
private List<PropertiesWindow.ItemEntry> AddChils([In] AssetsItem item, [In] List<string> paths)
{
var entries = item.AddChilds(paths.Count);
for (int i = 0, e = paths.Count; i < e; i++)
{
entries[i].ref_value.GetComponent<FileSystemAssetsItem>().RebuildFileInfo(paths[i]);
}
return entries;
}
public void OnAssetsItemFocus([In] AssetsItem item)
{
if (m_Dirty)
{
if (m_File != null)
{
RefreshWithToolFile(item);
}
m_Dirty = false;
}
item.HasChildLayer = item.ChildCount() != 0 ||
((m_File != null && m_File.IsExist) && (m_File.IsDir() || m_File.IsAssetBundle));
FileSystemAssets.instance.CurrentSelectFilename.title = ItemPathName;
InspectorWindow.instance.SetTarget(this, null);
}
public void OnAssetsItemInvoke([In] AssetsItem item)
{
//while (m_IsLoading)
{
#if UNITY_EDITOR
// Debug.Log("file loading", this);
#endif
}
}
[Content, OnlyPlayMode]
public void SetDirty()
{
m_Dirty = true;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cc6284120f6af2d4481a45e6627ca545
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 164be0dc96141c54f83118ba1fcc3d6f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
using UnityEngine;
using UnityEngine.UI;
namespace Convention.WindowsUI.Variant
{
public class ConsoleListItem : WindowUIModule,IText,ITitle
{
[Resources, SerializeField, OnlyNotNullMode] private Text MyTitleText;
[Resources, SerializeField, OnlyNotNullMode] private Button RawButton;
public string stackTrace;
public bool IsEnableFocusWindow;
public LogType logType;
public string text { get => ((IText)this.MyTitleText).text; set => ((IText)this.MyTitleText).text = value; }
public string title { get => ((ITitle)this.MyTitleText).title; set => ((ITitle)this.MyTitleText).title = value; }
public void SetupMessage(string message, string stackTrace, string color, LogType logType, string format = "<color={color}>{message}</color>")
{
format = format.Replace("{color}", color);
format = format.Replace("{message}", message);
this.title = format;
this.stackTrace = stackTrace;
this.logType = logType;
}
protected void Start()
{
RawButton.onClick.AddListener(OnFocusConsoleItem);
}
[Content]
public void OnFocusConsoleItem()
{
ConsoleWindow.instance.SetStackTrace(this.title + "\n\n" + this.stackTrace);
if (!IsEnableFocusWindow)
return;
if (FocusWindowIndictaor.instance != null)
FocusWindowIndictaor.instance.SetTargetRectTransform(MyTitleText.transform as RectTransform);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ec27d0c4063956e4fbe412c7e30f2b3c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,153 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Convention.WindowsUI.Variant
{
[RequireComponent(typeof(PropertiesWindow))]
public class ConsoleWindow : MonoSingleton<ConsoleWindow>
{
[Resources, SerializeField, OnlyNotNullMode, Header("Bar Button Setting")] private WindowManager m_WindowManager;
[Resources, SerializeField, OnlyNotNullMode(nameof(m_WindowManager))] private RectTransform m_root;
[Resources, SerializeField, OnlyNotNullMode(nameof(m_WindowManager))] private RectTransform m_plane;
public int ConsoleWindowIndex { get; private set; }
[Header("Property Window - ListView"), Resources, SerializeField, OnlyNotNullMode] private PropertiesWindow m_ListView;
private List<PropertiesWindow.ItemEntry> m_entries = new();
[Resources, SerializeField, OnlyNotNullMode] private ModernUIInputField StackTrace;
[Header("Message Switch"), Resources, SerializeField, OnlyNotNullMode] private ModernUIToggle m_MessageSwitch;
[Resources, SerializeField, OnlyNotNullMode] private ModernUIToggle m_WarningSwitch;
[Resources, SerializeField, OnlyNotNullMode] private ModernUIToggle m_VitalSwitch;
[Resources, SerializeField, OnlyNotNullMode] private Button m_ClearLogs;
[Setting] public string ConsoleButtonName = "Console";
public void ClearLog()
{
foreach (var entry in m_entries)
{
entry.Release();
}
m_entries.Clear();
}
public void Log(string condition, string stackTrace, LogType type = LogType.Log)
{
ConsoleListItem item;
string color;
GenerateLogItem(type, out item, out color);
item.SetupMessage(condition, stackTrace, color, type);
}
private void GenerateLogItem(LogType type, out ConsoleListItem item, out string color)
{
bool isActive = type switch
{
LogType.Log => m_MessageSwitch.ref_value,
LogType.Warning => m_WarningSwitch.ref_value,
_ => m_VitalSwitch.ref_value
};
PropertiesWindow.ItemEntry entry = m_ListView.CreateRootItemEntries(isActive, 1)[0];
m_entries.Add(entry);
item = entry.ref_value.GetComponent<ConsoleListItem>();
color = type switch
{
LogType.Log => "white",
LogType.Warning => "yellow",
_ => "red"
};
}
public void Log(string condition, string stackTrace, LogType type, string format)
{
ConsoleListItem item;
string color;
GenerateLogItem(type, out item, out color);
item.SetupMessage(condition, stackTrace, color, type, format);
}
public void SetStackTrace(string str)
{
StackTrace.text = str;
}
private void Start()
{
Application.logMessageReceived -= Log;
Application.logMessageReceived += Log;
ConsoleWindowIndex = m_WindowManager.AddContextPlane(m_plane, m_root);
var buttonWrapper = m_WindowManager.CreateWindowBarButton(() =>
{
m_WindowManager.SelectContextPlane(ConsoleWindowIndex);
});
(buttonWrapper.button as ITitle).title = ConsoleButtonName;
//StackTrace.interactable = false;
StackTrace.InputFieldSource.Source.readOnly = true;
m_MessageSwitch.ref_value = true;
m_WarningSwitch.ref_value = true;
m_VitalSwitch.ref_value = true;
m_MessageSwitch.AddListener(x =>
{
foreach (var entry in m_entries)
{
var item = entry.ref_value.GetComponent<ConsoleListItem>();
if (item.logType == LogType.Log)
{
item.gameObject.SetActive(x);
}
}
});
m_WarningSwitch.AddListener(x =>
{
foreach (var entry in m_entries)
{
var item = entry.ref_value.GetComponent<ConsoleListItem>();
if (item.logType == LogType.Warning)
{
item.gameObject.SetActive(x);
}
}
});
m_VitalSwitch.AddListener(x =>
{
foreach (var entry in m_entries)
{
var item = entry.ref_value.GetComponent<ConsoleListItem>();
if (item.logType != LogType.Log && item.logType != LogType.Warning)
{
item.gameObject.SetActive(x);
}
}
});
m_ClearLogs.onClick.AddListener(() =>
{
foreach (var entry in m_entries)
{
entry.Release();
}
m_entries.Clear();
});
m_WindowManager.SelectContextPlane(0);
}
[Setting, OnlyPlayMode]
public void TestLog()
{
Debug.Log("Test");
}
[Setting, OnlyPlayMode]
public void TestWarning()
{
Debug.LogWarning("Test");
}
[Setting, OnlyPlayMode]
public void TestError()
{
Debug.LogError("Test");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6845a63f12419f14fa03fa95accccfb0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2e7463b7af27b97469b0411d420abc2c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using System.Collections.Generic;
using System;
using static Convention.WindowsUI.Variant.PropertiesWindow;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;
namespace Convention.WindowsUI.Variant
{
public class ConversationItem : PropertyListItem
{
[Resources, SerializeField] private Image m_Icon;
[Resources, SerializeField] private Text m_Role;
[Resources, SerializeField] private Text m_Text;
[Setting] public float LineHeight = 25;
public void Setup([In] string text, [In] string role, int lineSize)
{
m_Icon.sprite = ConversationWindow.instance.GetRoleIconSprite(role);
m_Role.text = text;
m_Text.text = text;
var rect = this.transform as RectTransform;
rect.sizeDelta = new(rect.sizeDelta.x, LineHeight * lineSize);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ec9571cdaa96bb5468eb62021185574e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,76 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Convention.WindowsUI.Variant
{
public class ConversationWindow : MonoSingleton<ConversationWindow>
{
[Resources, OnlyNotNullMode] public WindowManager m_WindowManager;
[Resources, SerializeField, OnlyNotNullMode] private PropertiesWindow m_PropertiesWindow;
private RegisterWrapper<ConversationWindow> m_RegisterWrapper;
[Resources, Header("HeadLine"), OnlyNotNullMode] public Image HeadIcon;
[Resources, OnlyNotNullMode] public ModernUIInputField HeadText = new();
[Resources] public List<Text> HeadTitles = new();
private List<PropertiesWindow.ItemEntry> m_entries = new();
[Resources, Header("Roles Icon"), SerializeField, HopeNotNull] private ScriptableObject m_RolesIcon;
[Resources, SerializeField, OnlyNotNullMode] private Sprite m_DefaultRoleIcon;
public Sprite GetRoleIconSprite([In] string role)
{
if (m_RolesIcon == null)
return m_DefaultRoleIcon;
if (m_RolesIcon.uobjects.TryGetValue(role, out var roleIcon_) && roleIcon_ is Sprite roleIcon)
return roleIcon;
return m_DefaultRoleIcon;
}
private void Reset()
{
m_WindowManager = GetComponent<WindowManager>();
m_PropertiesWindow = GetComponent<PropertiesWindow>();
}
private void Start()
{
m_RegisterWrapper = new(() =>
{
});
}
private void OnDestroy()
{
m_RegisterWrapper.Release();
}
public void SetHeadText(string text)
{
HeadText.text = text;
}
public void SetHeadTitle(int index, string text)
{
HeadTitles[index].text = text;
}
[Resources, Header("InputField")] private ModernUIInputField m_InputField;
public delegate void MessageListener([In] string message);
public event MessageListener messageListener;
public void SendMessage()
{
messageListener?.Invoke(m_InputField.text);
m_InputField.text = "";
}
public void CreateNewMessageListItem()
{
PropertiesWindow.ItemEntry entry = m_PropertiesWindow.CreateRootItemEntries(1)[0];
m_entries.Add(entry);
var item = entry.ref_value.GetComponent<ConversationItem>();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bbd4a444651c94648b33642126ab25b8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,34 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Convention.WindowsUI.Variant
{
public class FocusWindowIndictaor : MonoSingleton<FocusWindowIndictaor>
{
[Setting, Range(0, 1), Percentage(0, 1)] public float Speed = 0.36f;
[Resources, OnlyNotNullMode] public RectTransform RectBox;
[Resources, OnlyNotNullMode] public RectTransform RopParent;
[Resources] public List<RectTransform> Targets = new();
[Content] public int TargetIndex;
[Content, OnlyPlayMode] public RectTransform Target;
public void SetTargetRectTransform(RectTransform target)
{
Target = target;
}
public void SelectNextTarget()
{
Debug.Log(TargetIndex);
Target = Targets[TargetIndex = (TargetIndex + 1) % Targets.Count];
}
private void LateUpdate()
{
if (Target != null)
RectTransformInfo.UpdateAnimationPlane(Target, RectBox, Speed, 0, true);
else
RectTransformInfo.UpdateAnimationPlane(RopParent, RectBox, Speed, 0, true);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1111f99dcb7341846bbfbb88d064e74f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: be6db8313bbc30c449c607d88e55fb87
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fed528a9d8dfc2d49a3e345c09ed5837
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b9daa10f8493ef343892b18ea5365cf7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;
});
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 958316f304c029041901ecb7fffa1929
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: aed19e8d829e0df48a19fe9c40c6754f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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>();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f2ff2c456623f0b44b8a3151524f8a2c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Convention.WindowsUI.Variant
{
public class InspectorDictionary : InspectorDrawer
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b3247e464de0aa44ead75124e669e841
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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();
}
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b74cf48865e5f12469141133ccca7e21
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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>();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: be24c6df69229ae41a42cfbc76ab1ad4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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 { }
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f0533291b170c1a4399696cd176e4440
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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>();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1e7609e8ffb820b4ea1eadd9b8e37728
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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>();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e7dc85b7bdeffeb4bbc9d7cc6d9a9aaf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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>();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c5f5aa321c5fb034cb333247eafbaa1b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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>();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 427a4f8c9974bd14ea853c4a51a28037
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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>();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: adbc0b509e231964f9116d4769a80da2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2a86b441edb5f434fb07b2f3e6e0837c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 23ba94e03fe829344b1f1b89b1d84423
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using Cinemachine;
using System.Linq;
using UnityEngine.UI;
namespace Convention.WindowsUI.Variant
{
public class SceneGameWindow : WindowsComponent
{
[Resources, SerializeField, OnlyNotNullMode,Header("Bar Button Setting")] private WindowManager m_WindowManager;
[Resources, SerializeField, OnlyNotNullMode(nameof(m_WindowManager))] private GameObject m_root;
[Resources, SerializeField, OnlyNotNullMode(nameof(m_WindowManager)), TextArea(1, 3)] private string m_planePath;
[Resources, SerializeField] private string moduleName = "Game";
[Resources, SerializeField,Header("Camera Base")] private CinemachineVirtualCameraBase SceneCamera;
[Resources, SerializeField] private CinemachineVirtualCameraBase ModuleCamera;
[Resources, SerializeField,HopeNotNull] private CinemachineBrain MainCamera;
[Resources, SerializeField, OnlyNotNullMode] private RawImage TextureRenderer;
[Resources, SerializeField] private GameObject m_GameObjectOnSceneOnly;
public BaseWindowBar.RegisteredPageWrapper GameWindowIndex { get; private set; }
public void CameraSelect(bool isScene)
{
SceneCamera.gameObject.SetActive(isScene);
ModuleCamera.gameObject.SetActive(!isScene);
if (m_GameObjectOnSceneOnly != null)
{
m_GameObjectOnSceneOnly.SetActive(isScene);
}
}
private void Start()
{
if (m_WindowManager == null)
{
m_WindowManager = GetComponent<WindowManager>();
}
if(MainCamera==null)
{
MainCamera = Camera.main.GetComponent<CinemachineBrain>();
}
CameraInitializer.InitializeImmediate(MainCamera.gameObject);
TextureRenderer.texture = MainCamera.GetComponent<Camera>().targetTexture;
if (m_root == null)
{
m_root = m_WindowManager.CurrentContextRectTransform.gameObject;
}
var root = Instantiate(m_root, m_WindowManager.WindowPlane.Plane.transform);
var plane = root.transform;
if (m_planePath != null && m_planePath.Length != 0)
{
var paths = m_planePath.Split('/', '\\');
foreach (var path in paths)
{
var temp= plane.Find(path);
if (temp == null)
throw new NullReferenceException($"{path} cannt find in {plane}");
plane = temp;
}
}
GameWindowIndex = m_WindowManager.CreateSubWindowWithBarButton(plane as RectTransform, root.GetComponent<RectTransform>());
(GameWindowIndex.button as ITitle).title = moduleName;
GameWindowIndex.button.AddListener(() =>
{
CameraSelect(false);
GameWindowIndex.Select();
});
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2e5965b3e248d5743aec2dad26483515
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,484 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace Convention.WindowsUI.Variant
{
public class PropertiesWindow : MonoAnyBehaviour
{
[ArgPackage]
public class ItemEntry : LeftValueReference<WindowUIModule>
{
#region Tools
private static bool IsSetupParentRectTransformAdjustSizeToContainsChilds = false;
private static void SetupParentRectTransform([In] RectTransform child, [In] WindowManager parent)
{
parent.AddContextChild(child, IsSetupParentRectTransformAdjustSizeToContainsChilds);
}
private static void SetupParentRectTransform([In] RectTransform child, [In] RectTransform parent)
{
if (parent.GetComponent<WindowManager>() != null)
SetupParentRectTransform(child, parent.GetComponent<WindowManager>());
else if (parent.GetComponents<BaseWindowPlane>().Length != 0)
parent.GetComponents<BaseWindowPlane>()[0].AddChild(child, IsSetupParentRectTransformAdjustSizeToContainsChilds);
else
RectTransformExtension.SetParentAndResize(parent, child, IsSetupParentRectTransformAdjustSizeToContainsChilds);
}
[return: IsInstantiated(true)]
public static WindowUIModule InstantiateItemObject([In] string prefab, [In] WindowManager windowManager, [In] SO.Windows config)
{
var go = Instantiate(config.GetWindowsUI<WindowUIModule>(prefab).gameObject);
var rgo = go.GetComponent<RectTransform>();
SetupParentRectTransform(rgo, windowManager);
return go.GetComponent<WindowUIModule>();
}
[return: IsInstantiated(true)]
public static WindowUIModule InstantiateItemObject([In] string prefab, [In] RectTransform plane, [In] SO.Windows config)
{
var go = Instantiate(config.GetWindowsUI<WindowUIModule>(prefab).gameObject);
var rgo = go.GetComponent<RectTransform>();
SetupParentRectTransform(rgo, plane);
return go.GetComponent<WindowUIModule>();
}
[return: IsInstantiated(true)]
public static WindowUIModule InstantiateItemObject(
[In, IsInstantiated(false)] WindowUIModule prefab,
[In] WindowManager windowManager)
{
var go = Instantiate(prefab.gameObject);
var rgo = go.GetComponent<RectTransform>();
SetupParentRectTransform(rgo, windowManager);
return go.GetComponent<WindowUIModule>();
}
[return: IsInstantiated(true)]
public static WindowUIModule InstantiateItemObject(
[In, IsInstantiated(false)] WindowUIModule prefab,
[In] RectTransform plane)
{
var go = Instantiate(prefab.gameObject);
var rgo = go.GetComponent<RectTransform>();
SetupParentRectTransform(rgo, plane);
return go.GetComponent<WindowUIModule>();
}
[return: ArgPackage]
public static ItemEntry MakeItemWithInstantiate([In] string prefab, [In] PropertiesWindow parent)
{
return new ItemEntry(parent)
{
ref_value = InstantiateItemObject(prefab, parent.m_WindowManager, parent.m_WindowsConfig)
};
}
[return: ArgPackage]
public static ItemEntry MakeItemWithInstantiate([In] string prefab, [In] ItemEntry parent, [In] SO.Windows config)
{
return new ItemEntry(parent)
{
ref_value = InstantiateItemObject(prefab, parent.ref_value.GetComponent<RectTransform>(), config)
};
}
[return: ArgPackage]
public static ItemEntry MakeItemWithInstantiate(
[In, IsInstantiated(false)] WindowUIModule prefab,
[In] PropertiesWindow parent)
{
return new ItemEntry(parent)
{
ref_value = InstantiateItemObject(prefab, parent.m_WindowManager)
};
}
[return: ArgPackage]
public static ItemEntry MakeItemWithInstantiate(
[In, IsInstantiated(false)] WindowUIModule prefab,
[In] ItemEntry parent)
{
return new ItemEntry(parent)
{
ref_value = InstantiateItemObject(prefab, parent.ref_value.GetComponent<RectTransform>())
};
}
[return: ArgPackage]
public static ItemEntry MakeItem([In] PropertiesWindow parent)
{
return new ItemEntry(parent);
}
[return: ArgPackage]
public static ItemEntry MakeItem([In] ItemEntry parent)
{
return new ItemEntry(parent);
}
public static IActionInvoke MakeItemAsActionInvoke(
[In, Out] ItemEntry entry,
[In] string invokerName, [In] PropertiesWindow parent,
[In][Opt, When("If you sure not need a target")] IAnyClass target,
params UnityAction<IAnyClass>[] actions)
{
entry.ref_value = InstantiateItemObject(invokerName, parent.m_WindowManager, parent.m_WindowsConfig);
var invoker = entry.ref_value as IActionInvoke;
foreach (var action in actions)
{
invoker.AddListener(() => action.Invoke(target));
}
return invoker;
}
public static IButton MakeItemAsActionInvoke(
[In, Out] ItemEntry entry,
[In] string invokerName, [In] ItemEntry parent, [In] SO.Windows config,
[In][Opt, When("If you sure not need a target")] IAnyClass target,
params UnityAction<IAnyClass>[] actions)
{
entry.ref_value = InstantiateItemObject(invokerName, parent.ref_value.GetComponent<RectTransform>(), config);
var invoker = entry.ref_value as IButton;
foreach (var action in actions)
{
invoker.AddListener(() => action.Invoke(target));
}
return invoker;
}
public static IButton MakeItemAsButton(
[In, Out] ItemEntry entry,
[In] string buttonName, [In] PropertiesWindow parent,
[In][Opt, When("If you sure not need a target")] IAnyClass target,
params UnityAction<IAnyClass>[] actions)
{
entry.ref_value = InstantiateItemObject(buttonName, parent.m_WindowManager, parent.m_WindowsConfig);
var button = entry.ref_value as IButton;
foreach (var action in actions)
{
button.AddListener(() => action.Invoke(target));
}
return button;
}
public static IButton MakeItemAsButton(
[In, Out] ItemEntry entry,
[In] string buttonName, [In] ItemEntry parent, [In] SO.Windows config,
[In][Opt, When("If you sure not need a target")] IAnyClass target,
params UnityAction<IAnyClass>[] actions)
{
entry.ref_value = InstantiateItemObject(buttonName, parent.ref_value.GetComponent<RectTransform>(), config);
var button = entry.ref_value as IButton;
foreach (var action in actions)
{
button.AddListener(() => action.Invoke(target));
}
return button;
}
public static IText MakeItemAsText(
[In, Out] ItemEntry entry,
[In] string textName, [In] PropertiesWindow parent,
[In] string textStr)
{
entry.ref_value = InstantiateItemObject(textName, parent.m_WindowManager, parent.m_WindowsConfig);
var text = entry.ref_value as IText;
text.text = textStr;
return text;
}
public static IText MakeItemAsText(
[In, Out] ItemEntry entry,
[In] string textName, [In] ItemEntry parent, [In] SO.Windows config,
[In] string textStr)
{
entry.ref_value = InstantiateItemObject(textName, parent.ref_value.GetComponent<RectTransform>(), config);
var text = entry.ref_value as IText;
text.text = textStr;
return text;
}
public static ITitle MakeItemAsTitle(
[In, Out] ItemEntry entry,
[In] string textName, [In] PropertiesWindow parent,
[In] string textStr)
{
entry.ref_value = InstantiateItemObject(textName, parent.m_WindowManager, parent.m_WindowsConfig);
var text = entry.ref_value as ITitle;
text.title = textStr;
return text;
}
public static ITitle MakeItemAsTitle(
[In, Out] ItemEntry entry,
[In] string textName, [In] ItemEntry parent, [In] SO.Windows config,
[In] string textStr)
{
entry.ref_value = InstantiateItemObject(textName, parent.ref_value.GetComponent<RectTransform>(), config);
var text = entry.ref_value as ITitle;
text.title = textStr;
return text;
}
#endregion
public override WindowUIModule ref_value
{
get => base.ref_value;
set
{
if (base.ref_value != value)
{
if (base.ref_value != null)
{
base.ref_value.gameObject.SetActive(false);
}
base.ref_value = value;
if (parentWindow != null)
{
parentWindow.m_WindowManager.SelectContextPlane(parentWindow.m_TargetWindowContent);
if (value != null)
parentWindow.m_WindowManager.AddContextChild(value.GetComponent<RectTransform>(), true);
}
else if (parentEntry != null)
{
if (value != null)
SetupParentRectTransform(value.GetComponent<RectTransform>(), parentEntry.ref_value.GetComponent<RectTransform>());
}
ForceRebuildLayoutImmediate();
}
}
}
public PropertyListItem GetPropertyListItem()
{
return ref_value.GetComponent<PropertyListItem>();
}
public HierarchyItem GetHierarchyItem()
{
return ref_value.GetComponent<HierarchyItem>();
}
[Resources, SerializeField] private List<ItemEntry> childs = new();
[Content, OnlyPlayMode, Ignore, SerializeField] private PropertiesWindow parentWindow;
[Content, OnlyPlayMode, Ignore, SerializeField] private ItemEntry parentEntry;
[Content] public readonly int layer;
public readonly PropertiesWindow rootWindow;
public List<ItemEntry> GetChilds() => new(childs);
public ItemEntry GetParent() => parentEntry;
public ItemEntry(PropertiesWindow parent) : base(null)
{
childs = new();
this.parentWindow = parent;
this.rootWindow = parent;
parent.m_Entrys.Add(this);
layer = 0;
}
public ItemEntry(ItemEntry parent) : base(null)
{
childs = new();
this.parentEntry = parent;
this.rootWindow = parent.rootWindow;
parent.childs.Add(this);
layer = parent.layer + 1;
}
private void ForceRebuildLayoutImmediate()
{
if (ref_value != null)
{
ConventionUtility.StartCoroutine(Adjuster(ref_value.transform as RectTransform));
}
if (parentWindow)
{
ConventionUtility.StartCoroutine(Adjuster(parentWindow.TargetWindowContent));
}
else
{
ConventionUtility.StartCoroutine(Adjuster2(parentEntry.ref_value.transform as RectTransform, parentEntry));
}
static IEnumerator Adjuster(RectTransform rectTransform)
{
if (rectTransform == null)
yield break;
LayoutRebuilder.ForceRebuildLayoutImmediate(rectTransform);
yield return null;
if (rectTransform == null)
yield break;
RectTransformExtension.AdjustSizeToContainsChilds(rectTransform);
}
static IEnumerator Adjuster2(RectTransform rectTransform, ItemEntry parentEntry)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(rectTransform);
yield return null;
RectTransformExtension.AdjustSizeToContainsChilds(rectTransform);
yield return null;
parentEntry.ForceRebuildLayoutImmediate();
yield break;
}
}
public void DisableChilds(bool isForceRebuildLayoutImmediate)
{
foreach (var item in childs)
{
item.ref_value.gameObject.SetActive(false);
}
if (isForceRebuildLayoutImmediate)
ForceRebuildLayoutImmediate();
}
public void Disable(bool isForceRebuildLayoutImmediate)
{
if (ref_value)
{
ref_value.gameObject.SetActive(false);
}
DisableChilds(false);
if (isForceRebuildLayoutImmediate)
ForceRebuildLayoutImmediate();
}
public void EnableChilds(bool isForceRebuildLayoutImmediate)
{
foreach (var item in childs)
{
item.ref_value.gameObject.SetActive(true);
}
if (isForceRebuildLayoutImmediate)
ForceRebuildLayoutImmediate();
}
public void Enable(bool isForceRebuildLayoutImmediate)
{
EnableChilds(false);
if (ref_value)
{
ref_value.gameObject.SetActive(true);
}
if (isForceRebuildLayoutImmediate)
ForceRebuildLayoutImmediate();
}
public void Release()
{
if ((parentWindow == null && parentEntry == null) || childs == null || rootWindow == null)
{
Debug.LogWarning("Auto Gen is bad supporting");
return;
}
if (ref_value)
{
ref_value.gameObject.SetActive(false);
Destroy(ref_value.gameObject);
}
foreach (var item in childs)
{
item.Release();
}
if (parentWindow != null)
parentWindow.m_Entrys.Remove(this);
else
parentEntry.childs.Remove(this);
ref_value = null;
}
~ItemEntry()
{
Release();
}
}
public interface IItemEntry
{
ItemEntry Entry { get; set; }
}
[Resources, SerializeField, HopeNotNull] private SO.Windows m_WindowsConfig;
[Resources, SerializeField, HopeNotNull] private WindowManager m_WindowManager;
[Setting, SerializeField, OnlyNotNullMode(nameof(m_WindowManager))] private int m_TargetWindowContent = 0;
[Resources, SerializeField, HopeNotNull, WhenAttribute.Is(nameof(m_WindowManager), null)]
private RectTransform m_ContentPlaneWhenNoWindow;
[Content, SerializeField, OnlyPlayMode] private List<ItemEntry> m_Entrys = new();
[Resources, SerializeField, HopeNotNull] public WindowUIModule ItemPrefab;
[Setting, Tooltip("RUNTIME MODE")] public PerformanceIndicator.PerformanceMode m_PerformanceMode = PerformanceIndicator.PerformanceMode.Quality;
public RectTransform TargetWindowContent => m_WindowManager == null ? m_ContentPlaneWhenNoWindow : m_WindowManager[m_TargetWindowContent];
private void Start()
{
if (m_WindowsConfig == null)
m_WindowsConfig = SO.Windows.GlobalInstance;
if (m_WindowManager == null)
m_WindowManager = GetComponent<WindowManager>();
if (m_ContentPlaneWhenNoWindow == null)
m_ContentPlaneWhenNoWindow = transform as RectTransform;
}
private void Reset()
{
m_WindowsConfig = SO.Windows.GlobalInstance;
m_WindowManager = GetComponent<WindowManager>();
foreach (var entry in m_Entrys)
{
entry.Release();
}
m_Entrys = new();
if (m_ContentPlaneWhenNoWindow == null)
m_ContentPlaneWhenNoWindow = transform as RectTransform;
}
private void FixedUpdate()
{
//if ((m_PerformanceMode & PerformanceIndicator.PerformanceMode.L8) != 0)
// RectTransformExtension.AdjustSizeToContainsChilds(TargetWindowContent);
}
public List<ItemEntry> CreateRootItemEntriesFromString(bool isActive, params string[] prefabs)
{
List<ItemEntry> result = new();
foreach (string prefab in prefabs)
{
var current = ItemEntry.MakeItemWithInstantiate(prefab, this);
result.Add(current);
if (current.ref_value.GetComponents<IItemEntry>().Length != 0)
{
current.ref_value.GetComponents<IItemEntry>()[0].Entry = current;
}
current.ref_value.gameObject.SetActive(isActive);
}
if (isActive)
RectTransformExtension.AdjustSizeToContainsChilds(TargetWindowContent);
return result;
}
public List<ItemEntry> CreateRootItemEntriesFromString(params string[] prefabs)
{
return CreateRootItemEntriesFromString(true, prefabs);
}
public List<ItemEntry> CreateRootItemEntries(bool isActive, int count)
{
List<ItemEntry> result = new();
while (count-- > 0)
{
var current = ItemEntry.MakeItemWithInstantiate(ItemPrefab, this);
result.Add(current);
if (current.ref_value.GetComponents<IItemEntry>().Length != 0)
{
current.ref_value.GetComponents<IItemEntry>()[0].Entry = current;
}
current.ref_value.gameObject.SetActive(isActive);
}
if (isActive)
RectTransformExtension.AdjustSizeToContainsChilds(TargetWindowContent);
return result;
}
public List<ItemEntry> CreateRootItemEntries(int count)
{
return CreateRootItemEntries(true, count);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5b96c24611a65c34abcfc36d83ba5e5c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,158 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using static Convention.WindowsUI.Variant.PropertiesWindow;
namespace Convention.WindowsUI.Variant
{
public class PropertyListItem : WindowUIModule, ITitle, IText, IItemEntry, IActionInvoke
{
[Resources, SerializeField, OnlyNotNullMode] private Button m_rawButton;
[Resources, SerializeField, OnlyNotNullMode(nameof(m_rawButton))] private float layerTab = 7.5f;
[Resources, SerializeField, OnlyNotNullMode(nameof(m_rawButton))] private float layerHeight = 15f;
[Resources, SerializeField, OnlyNotNullMode] private RectTransform dropdownImage;
[Resources, SerializeField, OnlyNotNullMode] private Text m_buttonText;
[Resources, SerializeField, OnlyNotNullMode, Header("Self Layer")] private RectTransform m_Layer;
public RectTransform TextRectTransform;
[Content, SerializeField] private ItemEntry m_entry;
[Content, SerializeField] private bool m_folderStats = true;
public ItemEntry Entry
{
get => m_entry;
set
{
if (this.gameObject.activeInHierarchy &&
//因为unity会生成可序列化的成员, 所以需要再检查类内必定存在的成员是否生成
(m_entry != null && m_entry.rootWindow != null))
{
throw new InvalidOperationException();
}
m_entry = value;
m_entry.ref_value = this;
}
}
private void Relayer()
{
m_Layer.sizeDelta = new(m_entry != null ? layerTab * m_entry.layer : 0, layerHeight);
}
protected virtual void Start()
{
m_rawButton.gameObject.AddComponent<RectTransformExtension.AdjustSizeIgnore>();
dropdownImage.gameObject.AddComponent<RectTransformExtension.AdjustSizeIgnore>();
m_buttonText.gameObject.AddComponent<RectTransformExtension.AdjustSizeIgnore>();
m_rawButton.onClick.AddListener(Switch);
TextRectTransform = m_buttonText.GetComponent<RectTransform>();
dropdownImage.eulerAngles = new(0, 0, IsFold ? 90 : 0);
}
protected virtual void OnEnable()
{
Relayer();
}
public bool IsFold
{
get => m_folderStats;
set
{
if (value != m_folderStats)
{
m_folderStats = value;
if (value)
{
FoldChilds();
}
else
{
UnfoldChilds();
}
}
}
}
public virtual string title { get => m_buttonText.title; set => m_buttonText.title = value; }
public virtual string text { get => m_buttonText.text; set => m_buttonText.text = value; }
public virtual bool interactable { get => m_rawButton.interactable; set => m_rawButton.interactable = value; }
public void Switch()
{
IsFold = !IsFold;
}
protected virtual void FoldChilds()
{
dropdownImage.eulerAngles = new(0, 0, 90);
m_entry.DisableChilds(true);
}
protected virtual void UnfoldChilds()
{
m_entry.EnableChilds(true);
dropdownImage.eulerAngles = new(0, 0, 0);
}
public List<ItemEntry> CreateSubPropertyItem([In] PropertiesWindow propertyWindow, int count)
{
List<ItemEntry> result = new();
while (count-- > 0)
{
var item = ItemEntry.MakeItemWithInstantiate(propertyWindow.ItemPrefab, this.Entry);
(item.ref_value as PropertyListItem).Entry = item;
result.Add(item);
}
return result;
}
public List<ItemEntry> CreateSubPropertyItem(int count)
{
return CreateSubPropertyItem(Entry.rootWindow, count);
}
public List<ItemEntry> CreateSubPropertyItem([In] WindowUIModule prefab, int count)
{
List<ItemEntry> result = new();
while (count-- > 0)
{
var item = ItemEntry.MakeItemWithInstantiate(prefab, this.Entry);
(item.ref_value as PropertyListItem).Entry = item;
result.Add(item);
}
return result;
}
[Content]
public void AdjustSizeToContainsChilds()
{
RectTransformExtension.AdjustSizeToContainsChilds(transform as RectTransform);
}
public IActionInvoke AddListener(params UnityAction[] action)
{
foreach (var item in action)
{
m_rawButton.onClick.AddListener(item);
}
return this;
}
public IActionInvoke RemoveListener(params UnityAction[] action)
{
foreach (var item in action)
{
m_rawButton.onClick.RemoveListener(item);
}
return this;
}
public IActionInvoke RemoveAllListeners()
{
m_rawButton.onClick.RemoveAllListeners();
return this;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 98dc4395e9cae5d44a13d910cc6709d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Convention.WindowsUI.Variant
{
public class SharedModule : MonoSingleton<SharedModule>, IWindowUIModule
{
[Resources, OnlyNotNullMode, SerializeField] private ModernUIInputField SingleInputField;
[Resources, OnlyNotNullMode, SerializeField, WhenAttribute.Not(nameof(SingleInputField), null)] private RectTransform SingleInputFieldRelease;
[Resources, OnlyNotNullMode, SerializeField, IsInstantiated(false)] private CustomMenu CustomMenuPrefab;
[Resources, OnlyNotNullMode, SerializeField, WhenAttribute.Not(nameof(CustomMenuPrefab), null)] private RectTransform CustomMenuPlane;
[Resources, OnlyNotNullMode, SerializeField, WhenAttribute.Not(nameof(CustomMenuPrefab), null)] private Button CustomMenuRelease;
[Content,SerializeField,OnlyPlayMode]private List<CustomMenu> customMenus = new List<CustomMenu>();
private Action<string> RenameCallback;
private void Start()
{
SingleInputField.AddListener(x =>
{
SingleInputFieldRelease.gameObject.SetActive(false);
RenameCallback(x);
SingleInputField.gameObject.SetActive(false);
});
this.CustomMenuRelease.onClick.AddListener(() =>
{
ReleaseAllCustomMenu();
});
}
private void ReleaseAllCustomMenu()
{
foreach (var menu in customMenus)
{
menu.ReleaseMenu();
}
CustomMenuRelease.gameObject.SetActive(false);
customMenus.Clear();
}
public void SingleEditString([In]string title, [In]string initText, [In]Action<string> callback)
{
SingleInputFieldRelease.gameObject.SetActive(true);
SingleInputField.gameObject.SetActive(true);
SingleInputField.title = title;
SingleInputField.text = initText;
RenameCallback = callback;
}
public void Rename([In] string initText, [In] Action<string> callback)
{
SingleEditString("Rename", initText, callback);
}
[ArgPackage]
public class CallbackData : AnyClass
{
public string name;
public Action<Vector3> callback;
public CallbackData(string name, Action<Vector3> callback)
{
this.name = name;
this.callback = callback;
}
}
/// <summary>
/// <20>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>root
/// </summary>
[return: ReturnNotNull, IsInstantiated(true)]
public CustomMenu OpenCustomMenu([In] RectTransform root, params CallbackData[] actions)
{
var target = GameObject.Instantiate(CustomMenuPrefab.gameObject, CustomMenuPlane).GetComponent<CustomMenu>();
target.gameObject.SetActive(true);
customMenus.Add(target);
Vector3[] points = new Vector3[4];
root.GetWorldCorners(points);
var rightTop = points[2];
Vector3[] points2 = new Vector3[4];
target.rectTransform.GetWorldCorners(points2);
var leftTop = points2[1];
target.rectTransform.Translate(rightTop - leftTop, Space.World);
foreach (var action in actions)
{
target.CreateItem(() =>
{
action.callback(rightTop);
ReleaseAllCustomMenu();
}, action.name);
}
CustomMenuRelease.gameObject.SetActive(true);
return target;
}
}
}

Some files were not shown because too many files have changed in this diff Show More