com.amanotes.prefabpool 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md.meta +7 -0
- package/Runtime/MaterialPool.cs.meta +11 -0
- package/Runtime/PoolEntryDrawer.cs.meta +11 -0
- package/Runtime/PrefabPool.asmdef +3 -0
- package/Runtime/PrefabPool.asmdef.meta +7 -0
- package/Runtime/PrefabPool.cs +10 -0
- package/Runtime/PrefabPool.cs.meta +11 -0
- package/Runtime.meta +8 -0
- package/package.json +1 -1
- package/package.json.meta +7 -0
- package/Runtime/Amanotes.PrefabPool.asmdef +0 -14
- package/Runtime/MeshRendererExtensions.cs +0 -80
- /package/{Editor → Runtime}/PoolEntryDrawer.cs +0 -0
package/README.md.meta
ADDED
package/Runtime/PrefabPool.cs
CHANGED
|
@@ -166,6 +166,16 @@ namespace Amanotes.Core
|
|
|
166
166
|
|
|
167
167
|
public static class PrefabPoolExtensions
|
|
168
168
|
{
|
|
169
|
+
internal static T GetComponentWithInterface<T>(this GameObject go)
|
|
170
|
+
{
|
|
171
|
+
var components = go.GetComponents<MonoBehaviour>();
|
|
172
|
+
for (var i = 0; i < components.Length; i++)
|
|
173
|
+
{
|
|
174
|
+
if (components[i] is T t) return t;
|
|
175
|
+
}
|
|
176
|
+
return default(T);
|
|
177
|
+
}
|
|
178
|
+
|
|
169
179
|
public static void DestroyLast<T>(this List<T> list) where T : Component
|
|
170
180
|
{
|
|
171
181
|
if (list.Count == 0) return;
|
package/Runtime.meta
ADDED
package/package.json
CHANGED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "Amanotes.PrefabPool",
|
|
3
|
-
"rootNamespace": "Amanotes.Core",
|
|
4
|
-
"references": [],
|
|
5
|
-
"includePlatforms": [],
|
|
6
|
-
"excludePlatforms": [],
|
|
7
|
-
"allowUnsafeCode": false,
|
|
8
|
-
"overrideReferences": false,
|
|
9
|
-
"precompiledReferences": [],
|
|
10
|
-
"autoReferenced": true,
|
|
11
|
-
"defineConstraints": [],
|
|
12
|
-
"versionDefines": [],
|
|
13
|
-
"noEngineReferences": false
|
|
14
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
using System.Collections.Generic;
|
|
2
|
-
using UnityEditor;
|
|
3
|
-
using UnityEngine;
|
|
4
|
-
|
|
5
|
-
namespace Amanotes.Core
|
|
6
|
-
{
|
|
7
|
-
public static class MeshRendererExtensions
|
|
8
|
-
{
|
|
9
|
-
public static void SetAlpha(this List<SpriteRenderer> sprites, float value)
|
|
10
|
-
{
|
|
11
|
-
for (var i = 0; i < sprites.Count; i++)
|
|
12
|
-
{
|
|
13
|
-
var sprt = sprites[i];
|
|
14
|
-
if (sprt == null) continue;
|
|
15
|
-
|
|
16
|
-
var c = sprt.color;
|
|
17
|
-
c.a = value;
|
|
18
|
-
sprt.color = c;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
public static void SetColor(this List<MeshRenderer> renderers, Color c, bool keepAlpha = true)
|
|
24
|
-
{
|
|
25
|
-
for (var i = 0; i < renderers.Count; i++)
|
|
26
|
-
{
|
|
27
|
-
renderers[i].SetColor(c, keepAlpha);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public static void SetColor(this List<SpriteRenderer> sprites, Color c, bool keepAlpha = true)
|
|
32
|
-
{
|
|
33
|
-
for (var i = 0; i < sprites.Count; i++)
|
|
34
|
-
{
|
|
35
|
-
sprites[i].SetColor(c, keepAlpha);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public static void SetColor(this MeshRenderer renderer, Color c, bool keepAlpha = true)
|
|
40
|
-
{
|
|
41
|
-
if (renderer == null) return;
|
|
42
|
-
var m = renderer.sharedMaterial;
|
|
43
|
-
if (m == null) return;
|
|
44
|
-
|
|
45
|
-
if (keepAlpha) c.a = m.color.a;
|
|
46
|
-
renderer.sharedMaterial.color = c;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public static void SetColor(this SpriteRenderer sprt, Color c, bool keepAlpha = true)
|
|
50
|
-
{
|
|
51
|
-
if (sprt == null) return;
|
|
52
|
-
if (keepAlpha) c.a = sprt.color.a;
|
|
53
|
-
sprt.color = c;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public static void SetAlpha(this SpriteRenderer sprt, float alpha)
|
|
57
|
-
{
|
|
58
|
-
if (sprt == null) return;
|
|
59
|
-
var c = sprt.color;
|
|
60
|
-
c.a = sprt.color.a;
|
|
61
|
-
sprt.color = c;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public static void CloneAndSetAlpha(this MeshRenderer renderer, float alpha)
|
|
65
|
-
{
|
|
66
|
-
// Prevent accidentally changes to prefab's material
|
|
67
|
-
#if UNITY_EDITOR
|
|
68
|
-
if (PrefabUtility.IsPartOfPrefabAsset(renderer)) return;
|
|
69
|
-
if (!Application.isPlaying) return;
|
|
70
|
-
#endif
|
|
71
|
-
if (renderer == null) return;
|
|
72
|
-
|
|
73
|
-
var oMat = renderer.sharedMaterial;
|
|
74
|
-
var cMat = MaterialPool.Take(oMat, renderer.GetInstanceID());
|
|
75
|
-
renderer.sharedMaterial = cMat;
|
|
76
|
-
|
|
77
|
-
cMat.SetAlpha(alpha);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
File without changes
|