布局功能增加黑白名单功能。
This commit is contained in:
@@ -10,23 +10,47 @@ namespace XericUIEditor.OverrideLayout
|
||||
public class XericHorizontalOrVerticalLayoutGroupEditor : HorizontalOrVerticalLayoutGroupEditor
|
||||
{
|
||||
SerializedProperty ignoreInvisible;
|
||||
SerializedProperty enableListScreening;
|
||||
SerializedProperty blackListMode;
|
||||
SerializedProperty whiteList_list;
|
||||
SerializedProperty blackList_list;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
ignoreInvisible = serializedObject.FindProperty("layoutIgnoreInactive");
|
||||
enableListScreening = serializedObject.FindProperty("enableListScreening");
|
||||
blackListMode = serializedObject.FindProperty("blackListMode");
|
||||
whiteList_list = serializedObject.FindProperty("m_whiteList_list");
|
||||
blackList_list = serializedObject.FindProperty("m_blackList_list");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
|
||||
|
||||
serializedObject.Update();
|
||||
|
||||
EditorGUILayout.PropertyField(ignoreInvisible, true);
|
||||
|
||||
EditorGUILayout.PropertyField(enableListScreening);
|
||||
if (enableListScreening.boolValue)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(blackListMode,
|
||||
EditorGUIUtility.TrTextContent(blackListMode.boolValue ? "Black List Mode" : "White List Mode"));
|
||||
if (blackListMode.boolValue)
|
||||
EditorGUILayout.PropertyField(blackList_list, EditorGUIUtility.TrTextContent("Black List"));
|
||||
else
|
||||
EditorGUILayout.PropertyField(whiteList_list, EditorGUIUtility.TrTextContent("White List"));
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(ignoreInvisible, true);
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using XericLibrary.Runtime.MacroLibrary;
|
||||
|
||||
namespace XericUI.OverrideLayout
|
||||
{
|
||||
[AddComponentMenu("Xeric UI Vessel/Layout/Xeric Horizontal Layout Group")]
|
||||
[AddComponentMenu("Xeric UI Vessel/Layout/Xeric Horizontal Layout Group", 10)]
|
||||
/// <summary>
|
||||
/// Layout child layout elements below each other.
|
||||
/// </summary>
|
||||
@@ -26,8 +26,7 @@ namespace XericUI.OverrideLayout
|
||||
for (int i = 0; i < rectTransform.childCount; i++)
|
||||
{
|
||||
var rect = rectTransform.GetChild(i) as RectTransform;
|
||||
if (rect == null ||
|
||||
(layoutIgnoreInactive && !rect.gameObject.activeInHierarchy))
|
||||
if (rect == null || CanSkipLayout(rect))
|
||||
continue;
|
||||
|
||||
rect.GetComponents(typeof(ILayoutIgnorer), toIgnoreList);
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
using Sirenix.OdinInspector;
|
||||
using System.Collections.Generic;
|
||||
using Sirenix.OdinInspector;
|
||||
using Sirenix.Utilities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Pool;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XericUI.OverrideLayout
|
||||
@@ -10,11 +14,113 @@ namespace XericUI.OverrideLayout
|
||||
/// </summary>
|
||||
public bool layoutIgnoreInactive = false;
|
||||
|
||||
|
||||
#region 黑白名单
|
||||
|
||||
/*
|
||||
* 黑名单对象无法参与布局
|
||||
* 仅白名单对象允许参与布局
|
||||
*/
|
||||
|
||||
public bool enableListScreening = true;
|
||||
public bool blackListMode = false;
|
||||
|
||||
private HashSet<RectTransform> m_whiteList_HashSet;
|
||||
private HashSet<RectTransform> m_blackList_HashSet;
|
||||
|
||||
[SerializeField] private List<RectTransform> m_whiteList_list;
|
||||
[SerializeField] private List<RectTransform> m_blackList_list;
|
||||
|
||||
private bool m_whiteListDirty = true;
|
||||
private bool m_blackListDirty = true;
|
||||
|
||||
public List<RectTransform> WhiteList
|
||||
{
|
||||
get => m_whiteList_list ??= ListPool<RectTransform>.Get();
|
||||
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
return;
|
||||
m_whiteListDirty = true;
|
||||
if (m_whiteList_list != value)
|
||||
{
|
||||
if (m_whiteList_list != null)
|
||||
ListPool<RectTransform>.Release(m_whiteList_list);
|
||||
m_whiteList_list = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<RectTransform> BlackList
|
||||
{
|
||||
get => m_blackList_list ??= ListPool<RectTransform>.Get();
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
return;
|
||||
m_blackListDirty = true;
|
||||
if (m_blackList_list != value)
|
||||
{
|
||||
if (m_blackList_list != null)
|
||||
ListPool<RectTransform>.Release(m_blackList_list);
|
||||
m_blackList_list = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
protected override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
enableListScreening = true;
|
||||
blackListMode = false;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
}
|
||||
#endif
|
||||
|
||||
#region 黑白名单
|
||||
|
||||
protected bool CanSkipLayout(RectTransform target)
|
||||
{
|
||||
if (!enableListScreening)
|
||||
return layoutIgnoreInactive && !target.gameObject.activeInHierarchy;
|
||||
return blackListMode ? BlackListContains(target) : !WhiteListContains(target);
|
||||
}
|
||||
|
||||
protected bool WhiteListContains(RectTransform target)
|
||||
=> TackListContains(target, ref m_whiteListDirty, ref m_whiteList_list, ref m_whiteList_HashSet);
|
||||
|
||||
protected bool BlackListContains(RectTransform target)
|
||||
=> TackListContains(target, ref m_blackListDirty, ref m_blackList_list, ref m_blackList_HashSet);
|
||||
|
||||
private bool TackListContains(RectTransform target, ref bool islistDirty, ref List<RectTransform> list,
|
||||
ref HashSet<RectTransform> hashlist)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
return list.Contains(target);
|
||||
#endif
|
||||
|
||||
if (!islistDirty && list.Count == hashlist.Count)
|
||||
return hashlist.Contains(target);
|
||||
|
||||
islistDirty = false;
|
||||
var hashset = HashSetPool<RectTransform>.Get();
|
||||
hashset.AddRange(list);
|
||||
if (hashlist != null)
|
||||
HashSetPool<RectTransform>.Release(hashlist);
|
||||
hashlist = hashset;
|
||||
return hashlist.Contains(target);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ using Sirenix.OdinInspector;
|
||||
|
||||
namespace XericUI.OverrideLayout
|
||||
{
|
||||
[AddComponentMenu("Xeric UI Vessel/UI/Xeric Scroll Rect")]
|
||||
[AddComponentMenu("Xeric UI Vessel/UI/Xeric Scroll Rect", 50)]
|
||||
[SelectionBase]
|
||||
[ExecuteAlways]
|
||||
[DisallowMultipleComponent]
|
||||
|
||||
@@ -7,7 +7,7 @@ using XericLibrary.Runtime.MacroLibrary;
|
||||
|
||||
namespace XericUI.OverrideLayout
|
||||
{
|
||||
[AddComponentMenu("Xeric UI Vessel/Layout/Xeric Vertical Layout Group")]
|
||||
[AddComponentMenu("Xeric UI Vessel/Layout/Xeric Vertical Layout Group", 10)]
|
||||
/// <summary>
|
||||
/// Layout child layout elements below each other.
|
||||
/// </summary>
|
||||
@@ -23,8 +23,7 @@ namespace XericUI.OverrideLayout
|
||||
for (int i = 0; i < rectTransform.childCount; i++)
|
||||
{
|
||||
var rect = rectTransform.GetChild(i) as RectTransform;
|
||||
if (rect == null ||
|
||||
(layoutIgnoreInactive && !rect.gameObject.activeInHierarchy))
|
||||
if (rect == null || CanSkipLayout(rect))
|
||||
continue;
|
||||
|
||||
rect.GetComponents(typeof(ILayoutIgnorer), toIgnoreList);
|
||||
|
||||
Reference in New Issue
Block a user