Skip to content

Commit 40b0f9a

Browse files
committed
Updated README. Added warnings to PoolAsset and RefPooler if prefab is not assigned. Added several sample scenes to showcase Refpool features.
1 parent 5574428 commit 40b0f9a

Some content is hidden

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

56 files changed

+7996
-94
lines changed

Editor/EditorUtil.cs renamed to Editor/EditorItems.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44
namespace BP.RefPool.Editor
55
{
6-
public static class EditorUtil
6+
internal static class EditorItems
77
{
8-
98
[MenuItem("GameObject/RefPool/Pool", false, 10)]
109
public static void CreatePool(MenuCommand menuCommand)
1110
{
1211
GameObject go = new("Pool");
1312
go.AddComponent<RefPooler>();
14-
EditorCreeate(menuCommand, go);
13+
EditorCreate(menuCommand, go);
1514
}
1615

1716
[MenuItem("GameObject/RefPool/Group", false, 10)]
@@ -25,18 +24,18 @@ public static void CreateGroup(MenuCommand menuCommand)
2524
child.transform.SetParent(root.transform);
2625
rootGroup.Add(child.GetComponent<RefPooler>());
2726
}
28-
EditorCreeate(menuCommand, root);
27+
EditorCreate(menuCommand, root);
2928
}
3029

3130

3231
[MenuItem("GameObject/RefPool/Spawner", false, 10)]
3332
public static void CreateSpawner(MenuCommand menuCommand)
3433
{
3534
GameObject root = new("Spawner", typeof(RefSpawner));
36-
EditorCreeate(menuCommand, root);
35+
EditorCreate(menuCommand, root);
3736
}
3837

39-
private static void EditorCreeate(MenuCommand menuCommand, params GameObject[] gameobjects)
38+
private static void EditorCreate(MenuCommand menuCommand, params GameObject[] gameobjects)
4039
{
4140
foreach (var go in gameobjects)
4241
{
File renamed without changes.

Editor/EditorUtils.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using UnityEditor;
2+
using UnityEditor.UIElements;
3+
using UnityEngine.UIElements;
4+
5+
namespace BP.RefPool.Editor
6+
{
7+
public static class EditorUtils
8+
{
9+
public static void TrackVisibilityBasedOnProperty(
10+
this VisualElement element,
11+
SerializedProperty property,
12+
System.Func<SerializedProperty, bool> condition
13+
)
14+
{
15+
element.style.display = condition(property) ? DisplayStyle.Flex : DisplayStyle.None;
16+
element.TrackPropertyValue(property, val =>
17+
element.style.display = condition(val) ? DisplayStyle.Flex : DisplayStyle.None
18+
);
19+
}
20+
21+
public static void PropertyAction(
22+
this VisualElement element,
23+
SerializedProperty property,
24+
System.Action<SerializedProperty> action
25+
)
26+
{
27+
action(property);
28+
element.TrackPropertyValue(property, action);
29+
}
30+
}
31+
}

Editor/EditorUtils.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.

Editor/PoolAsset/PoolAssetEditor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ public override VisualElement CreateInspectorGUI()
1313
{
1414
var root = new VisualElement();
1515
treeAsset.CloneTree(root);
16+
17+
var helpBox = root.Q<HelpBox>("help-box");
18+
var prefabProp = serializedObject.FindProperty("prefab");
19+
20+
helpBox.TrackVisibilityBasedOnProperty(prefabProp, (prop) => prop.boxedValue == null);
1621
return root;
1722
}
1823
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
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="Reuse Objects" data-source-path="reuseObjects" />
4+
<ui:Toggle label="Reuse Objects" data-source-path="reuseObjects" binding-path="reuseObjects" />
55
<ui:Label text="Size" style="-unity-text-align: upper-center; -unity-font-style: bold; font-size: 16px; margin-top: 10px;" />
66
<ui:IntegerField label="Init Size" value="0" binding-path="initSize" />
77
<ui:IntegerField label="Max Size" value="0" binding-path="maxSize" />
8+
<ui:HelpBox text="Prefab is not assigned" message-type="Warning" name="help-box" />
89
</ui:UXML>
Lines changed: 0 additions & 1 deletion
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:TextField label="Display Name" binding-path="displayName" />
33
<ui:EnumField label="Pick Mode" value="Random" type="BP.RefPool.PoolPickMode, BP.RefPool" binding-path="pickMode" />
4-
<ui:Label text="Pools" style="margin-top: 10px; font-size: 16px; -unity-font-style: bold; -unity-text-align: upper-center;" />
54
<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" />
65
</ui:UXML>

Editor/RefItem/UXML_RefItem.uxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
<ui:GroupBox>
33
<ui:Label text="&lt;b&gt;RefItem&lt;/b&gt; acts as handle for pooled items.&lt;br&gt;&lt;b&gt;&lt;i&gt;&lt;color=red&gt;Removal during runtime can result in unexpected behaviour." style="white-space: normal; -unity-text-align: upper-center;" />
44
</ui:GroupBox>
5-
<uie:PropertyField binding-path="onReset" label="On Reset" />
5+
<uie:PropertyField binding-path="onUse" label="OnUse" />
66
</ui:UXML>

Editor/RefPooler/RefPoolerEditor.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using UnityEditor;
2-
using UnityEditor.UIElements;
32
using UnityEngine;
43
using UnityEngine.UIElements;
54

@@ -25,18 +24,21 @@ public override VisualElement CreateInspectorGUI()
2524
treeAsset.CloneTree(root);
2625

2726
var initSizeSlider = root.Q<SliderInt>("init-size");
27+
var helpBox = root.Q<HelpBox>("help-box");
28+
runtimeStats = root.Q("runtime-stats");
29+
usageProgressBar = runtimeStats.Q<ProgressBar>("usage-progress");
30+
capacityProgressBar = runtimeStats.Q<ProgressBar>("capacity-progress");
31+
2832
var maxSizeProp = serializedObject.FindProperty("maxSize");
2933
var initSizeProp = serializedObject.FindProperty("initSize");
34+
var prefabProp = serializedObject.FindProperty("prefab");
3035

31-
initSizeSlider.highValue = maxSizeProp.intValue;
32-
initSizeSlider.TrackPropertyValue(maxSizeProp, (prop) =>
36+
initSizeSlider.PropertyAction(initSizeProp, (prop) =>
3337
{
34-
initSizeSlider.highValue = maxSizeProp.intValue;
38+
initSizeSlider.highValue = prop.intValue;
3539
});
3640

37-
runtimeStats = root.Q("runtime-stats");
38-
usageProgressBar = runtimeStats.Q<ProgressBar>("usage-progress");
39-
capacityProgressBar = runtimeStats.Q<ProgressBar>("capacity-progress");
41+
helpBox.TrackVisibilityBasedOnProperty(prefabProp, (prop) => prop.boxedValue == null);
4042

4143
UpdateStatsVisibility(Application.isPlaying);
4244
EditorApplication.playModeStateChanged -= PlayModeChanged;

Editor/RefPooler/UXML_RefPooler.uxml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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:VisualElement name="runtime-stats" style="flex-grow: 1;">
7+
<ui:VisualElement name="runtime-stats" style="flex-grow: 0;">
88
<ui:GroupBox>
99
<ui:Label text="Runtime Stats" style="-unity-font-style: bold;" />
1010
<ui:VisualElement style="flex-grow: 0; flex-direction: row;">
@@ -17,4 +17,5 @@
1717
</ui:VisualElement>
1818
</ui:GroupBox>
1919
</ui:VisualElement>
20+
<ui:HelpBox message-type="Warning" text="Prefab is not assigned" name="help-box" />
2021
</ui:UXML>

0 commit comments

Comments
 (0)