Skip to content

Commit 148f130

Browse files
committed
Removed unnecessary bloat and features to simplify core mechanics.
Changed Release system to use RefItems and not rely on the actual pools. Removed IPool as it was no longer used. Added IReleasable interface for RefComponents that can Release RefItems. Removed cyclic detection from the PoolGroupAsset and RefPoolerGroup. Removed unused IPoolItem interface.
1 parent 8da5bce commit 148f130

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+508
-906
lines changed

Editor/EditorUtil.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static void CreateGroup(MenuCommand menuCommand)
2323
{
2424
GameObject child = new($"Pool #{i + 1}", typeof(RefPooler));
2525
child.transform.SetParent(root.transform);
26-
rootGroup.AddPool(child.GetComponent<RefPooler>());
26+
rootGroup.Add(child.GetComponent<RefPooler>());
2727
}
2828
EditorCreeate(menuCommand, root);
2929
}

Editor/PoolAsset/UXML_PoolAsset.uxml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<ui:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
22
<ui:TextField label="Display Name" binding-path="displayName" />
33
<uie:ObjectField label="Prefab" type="UnityEngine.GameObject, UnityEngine.CoreModule" binding-path="prefab" />
4-
<ui:Toggle label="Persistent" binding-path="isPersistant" />
54
<ui:Toggle label="Reuse Objects" data-source-path="reuseObjects" />
65
<ui:Label text="Size" style="-unity-text-align: upper-center; -unity-font-style: bold; font-size: 16px; margin-top: 10px;" />
76
<ui:IntegerField label="Init Size" value="0" binding-path="initSize" />
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<ui:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
22
<ui:TextField label="Display Name" binding-path="displayName" />
3-
<ui:EnumField label="Pick Mode" value="Random" type="BP.RefPool.PoolPickMode, BP.RefPool" />
4-
<ui:Toggle label="Persistent" binding-path="isPersistent" />
3+
<ui:EnumField label="Pick Mode" value="Random" type="BP.RefPool.PoolPickMode, BP.RefPool" binding-path="pickMode" />
54
<ui:Label text="Pools" style="margin-top: 10px; font-size: 16px; -unity-font-style: bold; -unity-text-align: upper-center;" />
6-
<ui:ListView binding-path="pools" reorderable="true" show-bound-collection-size="false" show-add-remove-footer="true" reorder-mode="Animated" show-border="true" />
5+
<ui:ListView binding-path="pools" reorderable="true" show-bound-collection-size="false" show-add-remove-footer="true" reorder-mode="Animated" show-border="true" virtualization-method="DynamicHeight" />
76
</ui:UXML>

Editor/RefPooler/RefPoolerEditor.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,17 @@ private void Update()
6060
{
6161
if (!Application.isPlaying) return;
6262

63-
int usedCount = refPooler.UsedCount;
64-
int currentSize = refPooler.CurrentSize;
65-
int maxSize = refPooler.MaxSize;
63+
runtimeStats.MarkDirtyRepaint();
6664

67-
usageProgressBar.value = usedCount / (float)currentSize;
68-
usageProgressBar.title = $"{usedCount}/{currentSize}";
65+
int currentCount = refPooler.Count;
66+
int useCount = refPooler.UsedCount;
67+
int maxCount = refPooler.MaxSize;
6968

70-
// Capacity
71-
capacityProgressBar.value = currentSize / (float)maxSize;
72-
capacityProgressBar.title = $"{currentSize}/{maxSize}";
69+
capacityProgressBar.value = currentCount / (float)maxCount;
70+
capacityProgressBar.title = $"Capacity: {currentCount}/{maxCount}";
71+
72+
usageProgressBar.value = useCount / (float)currentCount;
73+
usageProgressBar.title = $"Usage: {useCount} / {currentCount}";
7374
}
7475

7576
private void UpdateStatsVisibility(bool show)

Editor/RefPooler/UXML_RefPooler.uxml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<ui:IntegerField label="Max Size" value="0" binding-path="maxSize" />
55
<ui:SliderInt label="Init Size" value="42" high-value="10" fill="false" show-input-field="true" binding-path="initSize" name="init-size" />
66
<ui:Toggle label="Reuse Objects" binding-path="reuseObjects" />
7-
<ui:Toggle label="Persistent" binding-path="isPersistent" />
87
<ui:VisualElement name="runtime-stats" style="flex-grow: 1;">
98
<ui:GroupBox>
109
<ui:Label text="Runtime Stats" style="-unity-font-style: bold;" />
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<ui:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
22
<ui:EnumField label="Pick Mode" value="Random" type="BP.RefPool.PoolPickMode, BP.RefPool" include-obsolete-values="false" binding-path="pickMode" />
3-
<ui:Toggle label="Persistant" binding-path="isPersistant" />
43
<ui:Label text="Pools" style="margin-top: 10px; font-size: 16px; -unity-font-style: bold; -unity-text-align: upper-center;" />
5-
<ui:ListView show-add-remove-footer="true" show-foldout-header="false" reorderable="true" reorder-mode="Animated" show-border="true" allow-add="true" binding-path="pools" show-bound-collection-size="false" binding-source-selection-mode="AutoAssign" />
4+
<ui:ListView show-add-remove-footer="true" show-foldout-header="false" reorderable="true" reorder-mode="Animated" show-border="true" allow-add="true" binding-path="pools" show-bound-collection-size="false" binding-source-selection-mode="AutoAssign" virtualization-method="DynamicHeight" />
65
</ui:UXML>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace BP.RefPool.Editor
5+
{
6+
[CustomPropertyDrawer(typeof(RefResource), true)]
7+
public class RefResourcePropertyDrawer : PropertyDrawer
8+
{
9+
private const float ButtonWidth = 20f;
10+
private const float VerticalSpacing = 2f;
11+
private const float IndentSpacing = 15f;
12+
private const float BoxPadding = 4f;
13+
14+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
15+
{
16+
EditorGUI.BeginProperty(position, label, property);
17+
var fieldRect = new Rect(position.x, position.y, position.width - ButtonWidth, EditorGUIUtility.singleLineHeight);
18+
var buttonRect = new Rect(position.x + position.width - ButtonWidth, position.y, ButtonWidth, EditorGUIUtility.singleLineHeight);
19+
EditorGUI.PropertyField(fieldRect, property, label, false);
20+
21+
GUIStyle iconStyle = new(GUI.skin.button)
22+
{
23+
padding = new RectOffset(2, 2, 2, 2),
24+
margin = new RectOffset(0, 0, 0, 0),
25+
alignment = TextAnchor.MiddleCenter
26+
};
27+
28+
GUI.enabled = property.boxedValue != null;
29+
var buttonIcon = EditorGUIUtility.IconContent(property.isExpanded ? "d_SceneViewVisibility@2x" : "d_scenevis_visible_hover@2x");
30+
if (GUI.Button(buttonRect, buttonIcon, iconStyle))
31+
property.isExpanded = !property.isExpanded;
32+
GUI.enabled = true;
33+
34+
if (property.isExpanded && property.boxedValue is Object target)
35+
{
36+
var serialized = new SerializedObject(target);
37+
var iterator = serialized.GetIterator();
38+
39+
Rect boxRect = new(
40+
position.x,
41+
fieldRect.yMax + VerticalSpacing,
42+
position.width,
43+
GetBoxHeight(serialized)
44+
);
45+
EditorGUI.HelpBox(boxRect, "", MessageType.None);
46+
47+
float y = boxRect.y + BoxPadding;
48+
iterator.NextVisible(true);
49+
while (iterator.NextVisible(false))
50+
{
51+
float h = EditorGUI.GetPropertyHeight(iterator, true);
52+
var r = new Rect(position.x + IndentSpacing, y, position.width - IndentSpacing, h);
53+
54+
EditorGUI.BeginDisabledGroup(true);
55+
EditorGUI.PropertyField(r, iterator, true);
56+
EditorGUI.EndDisabledGroup();
57+
58+
y += h + EditorGUIUtility.standardVerticalSpacing;
59+
}
60+
}
61+
62+
EditorGUI.EndProperty();
63+
}
64+
65+
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
66+
{
67+
float height = EditorGUIUtility.singleLineHeight;
68+
69+
if (property.isExpanded && property.boxedValue is Object target)
70+
{
71+
SerializedObject serialized = new(target);
72+
float boxHeight = GetBoxHeight(serialized);
73+
height += VerticalSpacing + boxHeight;
74+
}
75+
76+
return height;
77+
}
78+
79+
private float GetBoxHeight(SerializedObject serialized)
80+
{
81+
float height = 0f;
82+
SerializedProperty iterator = serialized.GetIterator();
83+
iterator.NextVisible(true);
84+
85+
while (iterator.NextVisible(false))
86+
{
87+
height += EditorGUI.GetPropertyHeight(iterator, true) + EditorGUIUtility.standardVerticalSpacing;
88+
}
89+
90+
return height + BoxPadding * 2;
91+
}
92+
}
93+
}

Editor/RefResourcePropertyDrawer.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using UnityEditor;
2+
using UnityEditor.UIElements;
3+
using UnityEngine;
4+
using UnityEngine.UIElements;
5+
6+
namespace BP.RefPool.Editor
7+
{
8+
[CustomEditor(typeof(RefSpawner))]
9+
public class RefSpawnerEditor : UnityEditor.Editor
10+
{
11+
[SerializeField] private VisualTreeAsset treeAsset;
12+
13+
public override VisualElement CreateInspectorGUI()
14+
{
15+
var root = new VisualElement();
16+
treeAsset.CloneTree(root);
17+
18+
var spawnOptions = root.Q<VisualElement>("spawn-options");
19+
var autoSpawnProp = serializedObject.FindProperty("autoSpawn");
20+
21+
UpdateSpawnSettingsVisibility();
22+
spawnOptions.TrackPropertyValue(autoSpawnProp, (prop) => UpdateSpawnSettingsVisibility());
23+
24+
void UpdateSpawnSettingsVisibility()
25+
{
26+
spawnOptions.style.display = autoSpawnProp.boolValue ? DisplayStyle.Flex : DisplayStyle.None;
27+
}
28+
29+
return root;
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)