You've already forked ParticleEffectForUGUI
mirror of
https://github.com/mob-sakai/ParticleEffectForUGUI.git
synced 2026-05-15 12:40:08 +00:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b3cec69ac | ||
|
|
a4dd8c5776 | ||
|
|
dd94bba43c | ||
|
|
2e813c5313 | ||
|
|
1b61904018 | ||
|
|
672cb0abbb | ||
|
|
54da6b3bbf | ||
|
|
c00f5c8806 | ||
|
|
dddbeff155 | ||
|
|
20b9085ca1 | ||
|
|
8c1bef4373 | ||
|
|
a96b6915ef | ||
|
|
025efcbc5d | ||
|
|
162ee53180 | ||
|
|
4dfcb9075e | ||
|
|
7916056868 | ||
|
|
b87a0a02af | ||
|
|
3052cab41b | ||
|
|
a439248e1a | ||
|
|
686fff8690 | ||
|
|
3638df524f | ||
|
|
592d871da2 | ||
|
|
4d0cfd3510 | ||
|
|
4c5251a5ba | ||
|
|
cbb37b0b3a | ||
|
|
3c54f6dc8d | ||
|
|
d3532b9708 | ||
|
|
2ac8a1175b | ||
|
|
9a37e64b20 | ||
|
|
bc0c2e4e63 | ||
|
|
929c0d686b |
1
.coffee.internal.sed
Normal file
1
.coffee.internal.sed
Normal file
@@ -0,0 +1 @@
|
|||||||
|
s/Coffee.Internal/Coffee.UIParticleInternal/g
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
"release-4.x",
|
"release-4.x",
|
||||||
{
|
{
|
||||||
"name": "release-preview",
|
"name": "release-preview",
|
||||||
"prerelease": true
|
"prerelease": "preview"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
|||||||
70
CHANGELOG.md
70
CHANGELOG.md
@@ -1,3 +1,73 @@
|
|||||||
|
## [4.10.2](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v4.10.1...v4.10.2) (2024-11-01)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* trail incorrect offset ([afe00a1](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/afe00a1dde80eb1c0a7bb668b75f4c3733d3fa43)), closes [#335](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/335)
|
||||||
|
|
||||||
|
## [4.10.1](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v4.10.0...v4.10.1) (2024-09-29)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* mainTex will be ignored ([2ee69d0](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/2ee69d04245fabce185f67dc9bd68c870e556564))
|
||||||
|
|
||||||
|
# [4.10.0](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v4.9.1...v4.10.0) (2024-09-29)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* component icon is not set ([5ff6ec8](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/5ff6ec815a174de5d3f16d424f1204c60912a8d8))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add project settings ([1ce4e31](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/1ce4e31a9681bf1a201d2723c8d97e07ecc16592))
|
||||||
|
|
||||||
|
## [4.9.1](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v4.9.0...v4.9.1) (2024-08-07)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* ParticleSystem trails gain offset on parent canvas change ([2a1cd50](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/2a1cd502b452b5b56edf8bcfe91adf99d1bb5147)), closes [#323](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/323)
|
||||||
|
|
||||||
|
# [4.9.0](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v4.8.1...v4.9.0) (2024-07-18)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* ParticleAttractor supports multiple ParticleSystems ([3834780](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/3834780fdb43443fe6e1ef89df54d26a24d62a91))
|
||||||
|
|
||||||
|
## [4.8.1](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v4.8.0...v4.8.1) (2024-06-27)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* remove debug code ([669deb4](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/669deb41d4ac589d9db93b29bc8e95383e7f28a5))
|
||||||
|
|
||||||
|
# [4.8.0](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v4.7.2...v4.8.0) (2024-06-27)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* generated baking-camera object remains in the prefab or scene (again) ([de35cba](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/de35cba34c6312c1405ed522e9927c620c78e72d))
|
||||||
|
* SetParticleSystemInstance/Prefab APIs destroy generated objects ([ae3f3a8](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/ae3f3a8e62cc733420354d237ab765ac777127c8))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add 'custom view' option. ([a703c29](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/a703c2921ca08c2280d0c8fde01e4c0b33b5c69e))
|
||||||
|
* remove overlay window (editor) ([8358170](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/835817049f4fcf00dd2bf98dbada14f041ad3544))
|
||||||
|
* restore `Transform.localScale` when setting `autoScalingMode` to something other than `Transform` (again) ([88a970d](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/88a970d93a2b69cf011d86bd1807569e90538e0e))
|
||||||
|
* the rendering order list in inspector is now more compact ([be90172](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/be901724e064befacf617f4940b0331e1d31e1ca))
|
||||||
|
|
||||||
|
## [4.7.2](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v4.7.1...v4.7.2) (2024-06-21)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* generated baking-camera object remains in the prefab or scene ([0bb8438](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/0bb843830197d8c1252232928becc211c0ada08d))
|
||||||
|
|
||||||
## [4.7.1](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v4.7.0...v4.7.1) (2024-06-20)
|
## [4.7.1](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v4.7.0...v4.7.1) (2024-06-20)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,35 +31,35 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.Aggregate(s_Sb, (a, b) => s_Sb.AppendFormat("{0}, ", b));
|
result.Aggregate(s_Sb, (a, b) =>
|
||||||
|
{
|
||||||
|
s_Sb.Append(b);
|
||||||
|
return s_Sb.Append(", ");
|
||||||
|
});
|
||||||
s_Sb.Length -= 2;
|
s_Sb.Length -= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return s_Sb.ToString();
|
return s_Sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Draw(SerializedProperty sp, Material[] mats)
|
public static void Draw(SerializedProperty sp, List<Material> mats)
|
||||||
{
|
{
|
||||||
bool isClicked;
|
var pos = EditorGUILayout.GetControlRect(true);
|
||||||
using (new EditorGUILayout.HorizontalScope(GUILayout.ExpandWidth(false)))
|
var label = new GUIContent(sp.displayName, sp.tooltip);
|
||||||
{
|
var rect = EditorGUI.PrefixLabel(pos, label);
|
||||||
var pos = EditorGUILayout.GetControlRect(true);
|
var text = sp.hasMultipleDifferentValues
|
||||||
var label = new GUIContent(sp.displayName, sp.tooltip);
|
? "-"
|
||||||
var rect = EditorGUI.PrefixLabel(pos, label);
|
: CollectActiveNames(sp, s_ActiveNames);
|
||||||
var text = sp.hasMultipleDifferentValues
|
|
||||||
? "-"
|
|
||||||
: CollectActiveNames(sp, s_ActiveNames);
|
|
||||||
isClicked = GUI.Button(rect, text, EditorStyles.popup);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isClicked) return;
|
if (!GUI.Button(rect, text, EditorStyles.popup)) return;
|
||||||
|
|
||||||
var gm = new GenericMenu();
|
var gm = new GenericMenu();
|
||||||
gm.AddItem(s_ContentNothing, s_ActiveNames.Count == 0, () =>
|
gm.AddItem(s_ContentNothing, s_ActiveNames.Count == 0, x =>
|
||||||
{
|
{
|
||||||
sp.ClearArray();
|
var current = (SerializedProperty)x;
|
||||||
sp.serializedObject.ApplyModifiedProperties();
|
current.ClearArray();
|
||||||
});
|
current.serializedObject.ApplyModifiedProperties();
|
||||||
|
}, sp);
|
||||||
|
|
||||||
if (!sp.hasMultipleDifferentValues)
|
if (!sp.hasMultipleDifferentValues)
|
||||||
{
|
{
|
||||||
@@ -73,7 +73,7 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
s_Names.Clear();
|
s_Names.Clear();
|
||||||
for (var j = 0; j < mats.Length; j++)
|
for (var j = 0; j < mats.Count; j++)
|
||||||
{
|
{
|
||||||
var mat = mats[j];
|
var mat = mats[j];
|
||||||
if (!mat || !mat.shader) continue;
|
if (!mat || !mat.shader) continue;
|
||||||
@@ -82,8 +82,7 @@ namespace Coffee.UIExtensions
|
|||||||
{
|
{
|
||||||
var name = ShaderUtil.GetPropertyName(mat.shader, i);
|
var name = ShaderUtil.GetPropertyName(mat.shader, i);
|
||||||
var type = (AnimatableProperty.ShaderPropertyType)ShaderUtil.GetPropertyType(mat.shader, i);
|
var type = (AnimatableProperty.ShaderPropertyType)ShaderUtil.GetPropertyType(mat.shader, i);
|
||||||
if (s_Names.Contains(name)) continue;
|
if (!s_Names.Add(name)) continue;
|
||||||
s_Names.Add(name);
|
|
||||||
|
|
||||||
AddMenu(gm, sp, new ShaderProperty(name, type), true);
|
AddMenu(gm, sp, new ShaderProperty(name, type), true);
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ using UnityEditor;
|
|||||||
using UnityEditor.UI;
|
using UnityEditor.UI;
|
||||||
using UnityEditorInternal;
|
using UnityEditorInternal;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Profiling;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using Coffee.UIParticleExtensions;
|
using Coffee.UIParticleInternal;
|
||||||
#if UNITY_2021_2_OR_NEWER
|
#if UNITY_2021_2_OR_NEWER
|
||||||
using UnityEditor.Overlays;
|
using UnityEditor.Overlays;
|
||||||
#else
|
#else
|
||||||
@@ -16,6 +17,7 @@ using Object = UnityEngine.Object;
|
|||||||
#endif
|
#endif
|
||||||
#if UNITY_2021_2_OR_NEWER
|
#if UNITY_2021_2_OR_NEWER
|
||||||
using UnityEditor.SceneManagement;
|
using UnityEditor.SceneManagement;
|
||||||
|
|
||||||
#elif UNITY_2018_3_OR_NEWER
|
#elif UNITY_2018_3_OR_NEWER
|
||||||
using UnityEditor.Experimental.SceneManagement;
|
using UnityEditor.Experimental.SceneManagement;
|
||||||
#endif
|
#endif
|
||||||
@@ -26,41 +28,24 @@ namespace Coffee.UIExtensions
|
|||||||
[CanEditMultipleObjects]
|
[CanEditMultipleObjects]
|
||||||
internal class UIParticleEditor : GraphicEditor
|
internal class UIParticleEditor : GraphicEditor
|
||||||
{
|
{
|
||||||
#if UNITY_2021_2_OR_NEWER
|
|
||||||
#if UNITY_2022_1_OR_NEWER
|
|
||||||
[Overlay(typeof(SceneView), "Scene View/UI Particles", "UI Particles", true,
|
|
||||||
defaultDockPosition = DockPosition.Bottom,
|
|
||||||
defaultDockZone = DockZone.Floating,
|
|
||||||
defaultLayout = Layout.Panel)]
|
|
||||||
#else
|
|
||||||
[Overlay(typeof(SceneView), "Scene View/UI Particles", "UI Particles", true)]
|
|
||||||
#endif
|
|
||||||
private class UIParticleOverlay : IMGUIOverlay, ITransientOverlay
|
|
||||||
{
|
|
||||||
public bool visible => s_SerializedObject != null;
|
|
||||||
|
|
||||||
public override void OnGUI()
|
|
||||||
{
|
|
||||||
if (visible)
|
|
||||||
{
|
|
||||||
WindowFunction();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//################################
|
//################################
|
||||||
// Constant or Static Members.
|
// Constant or Static Members.
|
||||||
//################################
|
//################################
|
||||||
|
private static readonly GUIContent[] s_ContentMaterials = new[]
|
||||||
|
{
|
||||||
|
new GUIContent("Material"),
|
||||||
|
new GUIContent("Trail Material")
|
||||||
|
};
|
||||||
|
|
||||||
private static readonly GUIContent s_ContentRenderingOrder = new GUIContent("Rendering Order");
|
private static readonly GUIContent s_ContentRenderingOrder = new GUIContent("Rendering Order");
|
||||||
private static readonly GUIContent s_ContentRefresh = new GUIContent("Refresh");
|
private static readonly GUIContent s_ContentRefresh = new GUIContent("Refresh");
|
||||||
private static readonly GUIContent s_ContentFix = new GUIContent("Fix");
|
private static readonly GUIContent s_ContentFix = new GUIContent("Fix");
|
||||||
private static readonly GUIContent s_ContentMaterial = new GUIContent("Material");
|
|
||||||
private static readonly GUIContent s_ContentTrailMaterial = new GUIContent("Trail Material");
|
|
||||||
private static readonly GUIContent s_Content3D = new GUIContent("3D");
|
private static readonly GUIContent s_Content3D = new GUIContent("3D");
|
||||||
private static readonly GUIContent s_ContentRandom = new GUIContent("Random");
|
private static readonly GUIContent s_ContentRandom = new GUIContent("Random");
|
||||||
private static readonly GUIContent s_ContentScale = new GUIContent("Scale");
|
private static readonly GUIContent s_ContentScale = new GUIContent("Scale");
|
||||||
private static SerializedObject s_SerializedObject;
|
private static readonly GUIContent s_ContentPrimary = new GUIContent("Primary");
|
||||||
|
private static readonly Regex s_RegexBuiltInGuid = new Regex(@"^0{16}.0{15}$", RegexOptions.Compiled);
|
||||||
|
private static readonly List<Material> s_TempMaterials = new List<Material>();
|
||||||
private static bool s_XYZMode;
|
private static bool s_XYZMode;
|
||||||
|
|
||||||
private SerializedProperty _maskable;
|
private SerializedProperty _maskable;
|
||||||
@@ -71,6 +56,8 @@ namespace Coffee.UIExtensions
|
|||||||
private SerializedProperty _groupMaxId;
|
private SerializedProperty _groupMaxId;
|
||||||
private SerializedProperty _positionMode;
|
private SerializedProperty _positionMode;
|
||||||
private SerializedProperty _autoScalingMode;
|
private SerializedProperty _autoScalingMode;
|
||||||
|
private SerializedProperty _useCustomView;
|
||||||
|
private SerializedProperty _customViewSize;
|
||||||
private ReorderableList _ro;
|
private ReorderableList _ro;
|
||||||
private bool _showMax;
|
private bool _showMax;
|
||||||
|
|
||||||
@@ -88,56 +75,6 @@ namespace Coffee.UIExtensions
|
|||||||
"_ColorMask"
|
"_ColorMask"
|
||||||
};
|
};
|
||||||
|
|
||||||
[InitializeOnLoadMethod]
|
|
||||||
private static void Init()
|
|
||||||
{
|
|
||||||
#if !UNITY_2021_2_OR_NEWER
|
|
||||||
var miSceneViewOverlayWindow = Type.GetType("UnityEditor.SceneViewOverlay, UnityEditor")
|
|
||||||
?.GetMethods(BindingFlags.Public | BindingFlags.Static)
|
|
||||||
.First(x => x.Name == "Window" && 5 <= x.GetParameters().Length);
|
|
||||||
var windowFunction = (Action<Object, SceneView>)WindowFunction;
|
|
||||||
var windowFunctionType = Type.GetType("UnityEditor.SceneViewOverlay+WindowFunction, UnityEditor");
|
|
||||||
var windowFunctionDelegate = Delegate.CreateDelegate(windowFunctionType, windowFunction.Method);
|
|
||||||
var windowTitle = new GUIContent(ObjectNames.NicifyVariableName(nameof(UIParticle)));
|
|
||||||
#if UNITY_2019_2_OR_NEWER
|
|
||||||
//public static void Window(GUIContent title, WindowFunction sceneViewFunc, int order, Object target, WindowDisplayOption option, EditorWindow window = null)
|
|
||||||
var sceneViewArgs = new object[] { windowTitle, windowFunctionDelegate, 599, null, 2, null };
|
|
||||||
#else
|
|
||||||
//public static void Window(GUIContent title, WindowFunction sceneViewFunc, int order, Object target, WindowDisplayOption option)
|
|
||||||
var sceneViewArgs = new object[] { windowTitle, windowFunctionDelegate, 599, null, 2 };
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if UNITY_2019_1_OR_NEWER
|
|
||||||
SceneView.duringSceneGui += _ =>
|
|
||||||
#else
|
|
||||||
SceneView.onSceneGUIDelegate += _ =>
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
if (s_SerializedObject != null)
|
|
||||||
{
|
|
||||||
miSceneViewOverlayWindow.Invoke(null, sceneViewArgs);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SerializedObject CreateSerializeObject()
|
|
||||||
{
|
|
||||||
var uiParticles = Selection.gameObjects.Select(x => x.GetComponent<ParticleSystem>())
|
|
||||||
.Where(x => x)
|
|
||||||
.Select(x => x.GetComponentInParent<UIParticle>(true))
|
|
||||||
.Where(x => x && x.canvas)
|
|
||||||
.Concat(Selection.gameObjects.Select(x => x.GetComponent<UIParticle>())
|
|
||||||
.Where(x => x && x.canvas))
|
|
||||||
.Distinct()
|
|
||||||
.OfType<Object>()
|
|
||||||
.ToArray();
|
|
||||||
return 0 < uiParticles.Length ? new SerializedObject(uiParticles) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
s_SerializedObject = CreateSerializeObject();
|
|
||||||
Selection.selectionChanged += () => s_SerializedObject = CreateSerializeObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
//################################
|
//################################
|
||||||
// Public/Protected Members.
|
// Public/Protected Members.
|
||||||
//################################
|
//################################
|
||||||
@@ -156,31 +93,43 @@ namespace Coffee.UIExtensions
|
|||||||
_groupMaxId = serializedObject.FindProperty("m_GroupMaxId");
|
_groupMaxId = serializedObject.FindProperty("m_GroupMaxId");
|
||||||
_positionMode = serializedObject.FindProperty("m_PositionMode");
|
_positionMode = serializedObject.FindProperty("m_PositionMode");
|
||||||
_autoScalingMode = serializedObject.FindProperty("m_AutoScalingMode");
|
_autoScalingMode = serializedObject.FindProperty("m_AutoScalingMode");
|
||||||
|
_useCustomView = serializedObject.FindProperty("m_UseCustomView");
|
||||||
|
_customViewSize = serializedObject.FindProperty("m_CustomViewSize");
|
||||||
|
|
||||||
var sp = serializedObject.FindProperty("m_Particles");
|
var sp = serializedObject.FindProperty("m_Particles");
|
||||||
_ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true)
|
_ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true)
|
||||||
{
|
{
|
||||||
elementHeight = EditorGUIUtility.singleLineHeight * 3 + 4,
|
elementHeightCallback = index =>
|
||||||
elementHeightCallback = _ => 3 * (EditorGUIUtility.singleLineHeight + 2),
|
{
|
||||||
|
var ps = sp.GetArrayElementAtIndex(index).objectReferenceValue as ParticleSystem;
|
||||||
|
var materialCount = 0;
|
||||||
|
if (ps && ps.TryGetComponent<ParticleSystemRenderer>(out var psr))
|
||||||
|
{
|
||||||
|
materialCount = psr.sharedMaterials.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (materialCount + 1) * (EditorGUIUtility.singleLineHeight + 2);
|
||||||
|
},
|
||||||
drawElementCallback = (rect, index, _, __) =>
|
drawElementCallback = (rect, index, _, __) =>
|
||||||
{
|
{
|
||||||
EditorGUI.BeginDisabledGroup(sp.hasMultipleDifferentValues);
|
rect.y += 2;
|
||||||
rect.y += 1;
|
|
||||||
rect.height = EditorGUIUtility.singleLineHeight;
|
rect.height = EditorGUIUtility.singleLineHeight;
|
||||||
var p = sp.GetArrayElementAtIndex(index);
|
var p = sp.GetArrayElementAtIndex(index);
|
||||||
EditorGUI.ObjectField(rect, p, GUIContent.none);
|
EditorGUI.ObjectField(rect, p, GUIContent.none);
|
||||||
|
var ps = p.objectReferenceValue as ParticleSystem;
|
||||||
|
if (!ps || !ps.TryGetComponent<ParticleSystemRenderer>(out var psr)) return;
|
||||||
|
|
||||||
rect.x += 15;
|
rect.x += 15;
|
||||||
rect.width -= 15;
|
rect.width -= 15;
|
||||||
var ps = p.objectReferenceValue as ParticleSystem;
|
var materials = new SerializedObject(psr).FindProperty("m_Materials");
|
||||||
var materials = ps
|
var count = Mathf.Min(materials.arraySize, 2);
|
||||||
? new SerializedObject(ps.GetComponent<ParticleSystemRenderer>()).FindProperty("m_Materials")
|
for (var i = 0; i < count; i++)
|
||||||
: null;
|
{
|
||||||
rect.y += rect.height + 1;
|
rect.y += rect.height + 2;
|
||||||
MaterialField(rect, s_ContentMaterial, materials, 0);
|
EditorGUI.PropertyField(rect, materials.GetArrayElementAtIndex(i), s_ContentMaterials[i]);
|
||||||
rect.y += rect.height + 1;
|
}
|
||||||
MaterialField(rect, s_ContentTrailMaterial, materials, 1);
|
|
||||||
EditorGUI.EndDisabledGroup();
|
if (materials.serializedObject.hasModifiedProperties)
|
||||||
if (materials != null && materials.serializedObject.hasModifiedProperties)
|
|
||||||
{
|
{
|
||||||
materials.serializedObject.ApplyModifiedProperties();
|
materials.serializedObject.ApplyModifiedProperties();
|
||||||
}
|
}
|
||||||
@@ -216,20 +165,6 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void MaterialField(Rect rect, GUIContent label, SerializedProperty sp, int index)
|
|
||||||
{
|
|
||||||
if (sp == null || sp.arraySize <= index)
|
|
||||||
{
|
|
||||||
EditorGUI.BeginDisabledGroup(true);
|
|
||||||
EditorGUI.ObjectField(rect, label, null, typeof(Material), true);
|
|
||||||
EditorGUI.EndDisabledGroup();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
EditorGUI.PropertyField(rect, sp.GetArrayElementAtIndex(index), label);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implement this function to make a custom inspector.
|
/// Implement this function to make a custom inspector.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -238,6 +173,7 @@ namespace Coffee.UIExtensions
|
|||||||
var current = target as UIParticle;
|
var current = target as UIParticle;
|
||||||
if (!current) return;
|
if (!current) return;
|
||||||
|
|
||||||
|
Profiler.BeginSample("(UIP:E) OnInspectorGUI");
|
||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
|
|
||||||
// Maskable
|
// Maskable
|
||||||
@@ -249,13 +185,8 @@ namespace Coffee.UIExtensions
|
|||||||
EditorGUI.EndDisabledGroup();
|
EditorGUI.EndDisabledGroup();
|
||||||
|
|
||||||
// AnimatableProperties
|
// AnimatableProperties
|
||||||
var mats = current.particles
|
current.GetMaterials(s_TempMaterials);
|
||||||
.Where(x => x)
|
AnimatablePropertyEditor.Draw(_animatableProperties, s_TempMaterials);
|
||||||
.Select(x => x.GetComponent<ParticleSystemRenderer>().sharedMaterial)
|
|
||||||
.Where(x => x)
|
|
||||||
.ToArray();
|
|
||||||
|
|
||||||
AnimatablePropertyEditor.Draw(_animatableProperties, mats);
|
|
||||||
|
|
||||||
// Mesh sharing
|
// Mesh sharing
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
@@ -263,9 +194,12 @@ namespace Coffee.UIExtensions
|
|||||||
if (EditorGUI.EndChangeCheck())
|
if (EditorGUI.EndChangeCheck())
|
||||||
{
|
{
|
||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
foreach (var uip in targets.OfType<UIParticle>())
|
foreach (var t in targets)
|
||||||
{
|
{
|
||||||
uip.ResetGroupId();
|
if (t is UIParticle uip)
|
||||||
|
{
|
||||||
|
uip.ResetGroupId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,16 +207,29 @@ namespace Coffee.UIExtensions
|
|||||||
EditorGUILayout.PropertyField(_positionMode);
|
EditorGUILayout.PropertyField(_positionMode);
|
||||||
|
|
||||||
// Auto Scaling
|
// Auto Scaling
|
||||||
DrawAutoScaling(_autoScalingMode, targets.OfType<UIParticle>());
|
EditorGUILayout.PropertyField(_autoScalingMode);
|
||||||
|
|
||||||
|
// Custom View Size
|
||||||
|
EditorGUILayout.PropertyField(_useCustomView);
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
EditorGUI.BeginDisabledGroup(!_useCustomView.boolValue);
|
||||||
|
EditorGUI.indentLevel++;
|
||||||
|
EditorGUILayout.PropertyField(_customViewSize);
|
||||||
|
EditorGUI.indentLevel--;
|
||||||
|
EditorGUI.EndDisabledGroup();
|
||||||
|
if (EditorGUI.EndChangeCheck())
|
||||||
|
{
|
||||||
|
_customViewSize.floatValue = Mathf.Max(0.1f, _customViewSize.floatValue);
|
||||||
|
}
|
||||||
|
|
||||||
// Target ParticleSystems.
|
// Target ParticleSystems.
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
EditorGUI.BeginDisabledGroup(targets.OfType<UIParticle>().Any(x => !x.canvas));
|
|
||||||
_ro.DoLayoutList();
|
_ro.DoLayoutList();
|
||||||
EditorGUI.EndDisabledGroup();
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
|
|
||||||
if (EditorGUI.EndChangeCheck())
|
if (EditorGUI.EndChangeCheck())
|
||||||
{
|
{
|
||||||
|
EditorApplication.QueuePlayerLoopUpdate();
|
||||||
foreach (var uip in targets.OfType<UIParticle>())
|
foreach (var uip in targets.OfType<UIParticle>())
|
||||||
{
|
{
|
||||||
uip.RefreshParticles(uip.particles);
|
uip.RefreshParticles(uip.particles);
|
||||||
@@ -290,7 +237,8 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Non-UI built-in shader is not supported.
|
// Non-UI built-in shader is not supported.
|
||||||
foreach (var mat in current.materials)
|
Profiler.BeginSample("(UIP:E) Non-UI built-in shader is not supported.");
|
||||||
|
foreach (var mat in s_TempMaterials)
|
||||||
{
|
{
|
||||||
if (!mat || !mat.shader) continue;
|
if (!mat || !mat.shader) continue;
|
||||||
var shader = mat.shader;
|
var shader = mat.shader;
|
||||||
@@ -303,15 +251,18 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Profiler.EndSample();
|
||||||
|
|
||||||
// Does the shader support UI masks?
|
// Does the shader support UI masks?
|
||||||
|
Profiler.BeginSample("(UIP:E) Does the shader support UI masks?");
|
||||||
if (current.maskable && current.GetComponentInParent<Mask>(false))
|
if (current.maskable && current.GetComponentInParent<Mask>(false))
|
||||||
{
|
{
|
||||||
foreach (var mat in current.materials)
|
foreach (var mat in s_TempMaterials)
|
||||||
{
|
{
|
||||||
if (!mat || !mat.shader) continue;
|
if (!mat || !mat.shader) continue;
|
||||||
var shader = mat.shader;
|
var shader = mat.shader;
|
||||||
if (s_Shaders.Contains(shader)) continue;
|
if (!s_Shaders.Add(shader)) continue;
|
||||||
s_Shaders.Add(shader);
|
|
||||||
foreach (var propName in s_MaskablePropertyNames)
|
foreach (var propName in s_MaskablePropertyNames)
|
||||||
{
|
{
|
||||||
if (mat.HasProperty(propName)) continue;
|
if (mat.HasProperty(propName)) continue;
|
||||||
@@ -325,7 +276,9 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s_TempMaterials.Clear();
|
||||||
s_Shaders.Clear();
|
s_Shaders.Clear();
|
||||||
|
Profiler.EndSample();
|
||||||
|
|
||||||
// UIParticle for trail should be removed.
|
// UIParticle for trail should be removed.
|
||||||
var label = "This UIParticle component should be removed. The UIParticle for trails is no longer needed.";
|
var label = "This UIParticle component should be removed. The UIParticle for trails is no longer needed.";
|
||||||
@@ -364,12 +317,14 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Profiler.EndSample();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsBuiltInObject(Object obj)
|
private static bool IsBuiltInObject(Object obj)
|
||||||
{
|
{
|
||||||
return AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out var guid, out long _)
|
return AssetDatabase.IsMainAsset(obj)
|
||||||
&& Regex.IsMatch(guid, "^0{16}.0{15}$", RegexOptions.Compiled);
|
&& AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out var guid, out long _)
|
||||||
|
&& s_RegexBuiltInGuid.IsMatch(guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_2018 || UNITY_2019
|
#if UNITY_2018 || UNITY_2019
|
||||||
@@ -463,7 +418,7 @@ namespace Coffee.UIExtensions
|
|||||||
{
|
{
|
||||||
EditorGUI.BeginDisabledGroup(true);
|
EditorGUI.BeginDisabledGroup(true);
|
||||||
var obj = UIParticleUpdater.GetPrimary(spGroupId.intValue);
|
var obj = UIParticleUpdater.GetPrimary(spGroupId.intValue);
|
||||||
EditorGUILayout.ObjectField("Primary", obj, typeof(UIParticle), false);
|
EditorGUILayout.ObjectField(s_ContentPrimary, obj, typeof(UIParticle), false);
|
||||||
EditorGUI.EndDisabledGroup();
|
EditorGUI.EndDisabledGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -473,43 +428,11 @@ namespace Coffee.UIExtensions
|
|||||||
return showMax;
|
return showMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DrawAutoScaling(SerializedProperty prop, IEnumerable<UIParticle> uiParticles)
|
private static void DrawAutoScaling(SerializedProperty prop)
|
||||||
{
|
{
|
||||||
EditorGUILayout.PropertyField(prop);
|
EditorGUILayout.PropertyField(prop);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_2021_2_OR_NEWER
|
|
||||||
private static void WindowFunction()
|
|
||||||
#else
|
|
||||||
private static void WindowFunction(Object _, SceneView __)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (s_SerializedObject == null || !s_SerializedObject.targetObject) return;
|
|
||||||
var uiParticles = s_SerializedObject.targetObjects.OfType<UIParticle>().ToArray();
|
|
||||||
if (uiParticles.Any(x => !x || !x.canvas)) return;
|
|
||||||
|
|
||||||
s_SerializedObject.Update();
|
|
||||||
using (new EditorGUILayout.VerticalScope(GUILayout.Width(220f)))
|
|
||||||
{
|
|
||||||
var labelWidth = EditorGUIUtility.labelWidth;
|
|
||||||
EditorGUIUtility.labelWidth = 100;
|
|
||||||
EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_Enabled"));
|
|
||||||
s_XYZMode = DrawFloatOrVector3Field(s_SerializedObject.FindProperty("m_Scale3D"), s_XYZMode);
|
|
||||||
EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_PositionMode"));
|
|
||||||
DrawAutoScaling(s_SerializedObject.FindProperty("m_AutoScalingMode"), uiParticles);
|
|
||||||
EditorGUIUtility.labelWidth = labelWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
s_SerializedObject.ApplyModifiedProperties();
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DestroyUIParticle(UIParticle p, bool ignoreCurrent = false)
|
private void DestroyUIParticle(UIParticle p, bool ignoreCurrent = false)
|
||||||
{
|
{
|
||||||
if (!p || (ignoreCurrent && target == p)) return;
|
if (!p || (ignoreCurrent && target == p)) return;
|
||||||
|
|||||||
221
README.md
221
README.md
@@ -1,61 +1,85 @@
|
|||||||
# Particle Effect For UGUI (UI Particle)
|
# <img alt="UIParticleIcon" src="https://github.com/mob-sakai/ParticleEffectForUGUI/assets/12690315/d76e105e-a840-4f61-a1f6-8cf311c0812d" width="26"/> Particle Effect For UGUI (UI Particle) <!-- omit in toc -->
|
||||||
|
|
||||||
This package provides a component to render particle effects for uGUI in Unity 2018.2 or later.
|
|
||||||
The particle rendering is maskable and sortable, without the need for an extra Camera, RenderTexture, or Canvas.
|
|
||||||
|
|
||||||
[](https://openupm.com/packages/com.coffee.ui-particle/)
|
[](https://openupm.com/packages/com.coffee.ui-particle/)
|
||||||
[](https://github.com/mob-sakai/ParticleEffectForUGUI/releases)
|
[](https://github.com/mob-sakai/ParticleEffectForUGUI/releases)
|
||||||
[](https://github.com/mob-sakai/ParticleEffectForUGUI/blob/main/LICENSE.txt)
|
[](https://github.com/mob-sakai/ParticleEffectForUGUI/blob/main/LICENSE.md)
|
||||||

|

|
||||||
|

|
||||||
|

|
||||||

|

|
||||||
[](http://makeapullrequest.com)
|
[](http://makeapullrequest.com)
|
||||||
|
[](https://github.com/mob-sakai/ParticleEffectForUGUI/subscription)
|
||||||
[](https://twitter.com/intent/follow?screen_name=mob_sakai)
|
[](https://twitter.com/intent/follow?screen_name=mob_sakai)
|
||||||
|
|
||||||
<< [📝 Description](#-description) | [🎮 Demo](#-demo) | [⚙ Installation](#-installation) | [🚀 Usage](#-usage) | [🛠 Development Note](#-development-note) | [🤝 Contributing](#-contributing) >>
|
<< [📝 Description](#-description-) | [📌 Key Features](#-key-features) | [🎮 Demo](#-demo) | [⚙ Installation](#-installation) | [🚀 Usage](#-usage) | [🛠 Development Note](#-development-note) | [🤝 Contributing](#-contributing) >>
|
||||||
|
|
||||||
<br><br>
|
## 📝 Description <!-- omit in toc -->
|
||||||
|
|
||||||
## 📝 Description
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
This package utilizes the new APIs `MeshBake/MashTrailBake` (introduced with Unity 2018.2) to render particles through
|
This package uses the new APIs `MeshBake/MeshTrailBake` (introduced in Unity 2018.2) to render particles through `CanvasRenderer`.
|
||||||
CanvasRenderer.
|
You can render, mask, and sort your `ParticleSystems` for UI without the need for an additional `Camera`, `RenderTexture`, or `Canvas`.
|
||||||
You can render, mask, and sort your ParticleSystems for UI without the necessity of an additional Camera, RenderTexture,
|
|
||||||
or Canvas.
|
|
||||||
|
|
||||||
### Features
|
- [📌 Key Features](#-key-features)
|
||||||
|
- [🎮 Demo](#-demo)
|
||||||
|
- [⚙ Installation](#-installation)
|
||||||
|
- [Install via OpenUPM](#install-via-openupm)
|
||||||
|
- [Install via UPM (with Package Manager UI)](#install-via-upm-with-package-manager-ui)
|
||||||
|
- [Install via UPM (Manually)](#install-via-upm-manually)
|
||||||
|
- [Install as Embedded Package](#install-as-embedded-package)
|
||||||
|
- [🚀 Usage](#-usage)
|
||||||
|
- [Component: UIParticle](#component-uiparticle)
|
||||||
|
- [Basic Usage](#basic-usage)
|
||||||
|
- [Usage with Your Existing ParticleSystem Prefab](#usage-with-your-existing-particlesystem-prefab)
|
||||||
|
- [Usage with `Mask` or `RectMask2D` Component](#usage-with-mask-or-rectmask2d-component)
|
||||||
|
- [Usage with Script](#usage-with-script)
|
||||||
|
- [Component: UIParticleAttractor](#component-uiparticleattractor)
|
||||||
|
- [Project Settings](#project-settings)
|
||||||
|
- [🛠 Development Note](#-development-note)
|
||||||
|
- [Compares the Baking mesh approach with the conventional approach](#compares-the-baking-mesh-approach-with-the-conventional-approach)
|
||||||
|
- [Performance test results](#performance-test-results)
|
||||||
|
- [🔍 FAQ: Why Are My UIParticles Not Displayed Correctly?](#-faq-why-are-my-uiparticles-not-displayed-correctly)
|
||||||
|
- [Shader Limitation](#shader-limitation)
|
||||||
|
- [Built-in shaders are not supported](#built-in-shaders-are-not-supported)
|
||||||
|
- [(Unity 2018 or 2019) UV.zw components will be discarded](#unity-2018-or-2019-uvzw-components-will-be-discarded)
|
||||||
|
- [(Unity 2018 or 2019) Custom vertex streams](#unity-2018-or-2019-custom-vertex-streams)
|
||||||
|
- [Overheads](#overheads)
|
||||||
|
- [How to Make a Custom Shader to Support `Mask` and `RectMask2D` Component](#how-to-make-a-custom-shader-to-support-mask-and-rectmask2d-component)
|
||||||
|
- [🤝 Contributing](#-contributing)
|
||||||
|
- [Issues](#issues)
|
||||||
|
- [Pull Requests](#pull-requests)
|
||||||
|
- [Support](#support)
|
||||||
|
- [License](#license)
|
||||||
|
- [Author](#author)
|
||||||
|
- [See Also](#see-also)
|
||||||
|
|
||||||
* Easy to use: The package is ready to use out of the box.
|
<br><br>
|
||||||
* Sort particle effects and other UI by sibling index.
|
|
||||||
* No extra Camera, RenderTexture, or Canvas required.
|
|
||||||
* Masking options for Mask or RectMask2D.
|
|
||||||
* Support for the Trail module.
|
|
||||||
* Support for CanvasGroup alpha.
|
|
||||||
* No allocations needed to render particles.
|
|
||||||
* Compatibility with overlay, camera space, and world space.
|
|
||||||
* Support for Universal Render Pipeline (URP) and High Definition Render Pipeline (HDRP).
|
|
||||||
* Support for disabling `Enter Play Mode Options > Reload Domain`.
|
|
||||||
* Support for changing material property with AnimationClip (AnimatableProperty).
|
|
||||||
![AnimatableProperty.gif][AnimatableProperty.gif]
|
|
||||||
* [4.0.0+] Support for 8+ materials.
|
|
||||||
* [4.0.0+] Correct world space particle position adjustment when changing window size for standalone platforms (Windows,
|
|
||||||
MacOSX, and Linux).
|
|
||||||
* [4.0.0+] Adaptive scaling for UI.
|
|
||||||
* [4.0.0+] Mesh sharing group to improve performance.
|
|
||||||
![MeshSharing.gif][MeshSharing.gif]
|
|
||||||
* [4.0.0+] Particle attractor component.
|
|
||||||
![ParticleAttractor.gif][ParticleAttractor.gif]
|
|
||||||
* [4.1.0+] Relative/Absolute particle position mode.
|
|
||||||
![AbsolutePosition.gif][AbsolutePosition.gif]
|
|
||||||
|
|
||||||
[AnimatableProperty.gif]: https://user-images.githubusercontent.com/12690315/53286323-2d94a980-37b0-11e9-8afb-c4a207805ff2.gif
|
## 📌 Key Features
|
||||||
|
|
||||||
[MeshSharing.gif]: https://user-images.githubusercontent.com/12690315/174311048-c882df81-6c34-4eba-b0aa-5645457692f1.gif
|
* **Easy to use:** The package is ready to use out of the box.
|
||||||
|
* **Sortable:** Sort particle effects and other UI elements by sibling index.
|
||||||
[ParticleAttractor.gif]: https://user-images.githubusercontent.com/12690315/174311027-462929a4-13f0-4ec4-86ea-9c832f2eecf1.gif
|
* **Maskable:** Supports `Mask` or `RectMask2D`.
|
||||||
|
* **No extra components required:** No need for an additional `Camera`, `RenderTexture`, or `Canvas`.
|
||||||
[AbsolutePosition.gif]: https://user-images.githubusercontent.com/12690315/175751579-5a2357e8-2ecf-4afd-83c8-66e9771bde39.gif
|
* **Trail module support:** Fully supports the Trail module.
|
||||||
|
* **CanvasGroup alpha support:** Integrates with `CanvasGroup` alpha.
|
||||||
|
* **No allocations:** Efficiently renders particles without allocations.
|
||||||
|
* **Any canvas render mode support:** Works with overlay, camera space, and world space.
|
||||||
|
* **Any Render pipeline support:** Compatible with Universal Render Pipeline (URP) and High Definition Render Pipeline (HDRP).
|
||||||
|
* **Disabling domain reload support:** Supports disabling `Enter Play Mode Options > Reload Domain`.
|
||||||
|
* **Animatable material properties:** Supports changing material properties with AnimationClip (AnimatableProperty).
|
||||||
|

|
||||||
|
* **Multiple materials:** Supports 8+ materials.
|
||||||
|
* **Correct positioning:** Adjusts world space particle positions correctly when changing window size for standalone platforms (Windows, MacOSX, and Linux).
|
||||||
|
* **Adaptive scaling:** Provides adaptive scaling for UI (AutoScalingMode).
|
||||||
|
* **Performance optimization:** Mesh sharing group to improve performance.
|
||||||
|
<img alt="MeshSharing.gif" src="https://user-images.githubusercontent.com/12690315/174311048-c882df81-6c34-4eba-b0aa-5645457692f1.gif" width="450"/>
|
||||||
|
* **Particle attractor:** Includes a particle attractor component.
|
||||||
|
<img alt="ParticleAttractor.gif" src="https://user-images.githubusercontent.com/12690315/174311027-462929a4-13f0-4ec4-86ea-9c832f2eecf1.gif" width="450"/>
|
||||||
|
* **Emission position mode:** Supports relative/absolute particle emission position modes.
|
||||||
|
<img alt="AbsolutePosition.gif" src="https://user-images.githubusercontent.com/12690315/175751579-5a2357e8-2ecf-4afd-83c8-66e9771bde39.gif" width="450"/>
|
||||||
|
* **Custom view size:** Fixes min/max particle size mismatch.
|
||||||
|

|
||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
@@ -76,66 +100,86 @@ or Canvas.
|
|||||||
|
|
||||||
[JMO]: https://assetstore.unity.com/publishers/1669
|
[JMO]: https://assetstore.unity.com/publishers/1669
|
||||||
|
|
||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
## ⚙ Installation
|
## ⚙ Installation
|
||||||
|
|
||||||
_This package requires Unity 2018.3 or later._
|
_This package requires **Unity 2018.3 or later**._
|
||||||
|
|
||||||
#### Install via OpenUPM
|
#### Install via OpenUPM
|
||||||
|
|
||||||
This package is available on [OpenUPM](https://openupm.com) package registry.
|
- This package is available on [OpenUPM](https://openupm.com) package registry.
|
||||||
This is the preferred method of installation, as you can easily receive updates as they're released.
|
- This is the preferred method of installation, as you can easily receive updates as they're released.
|
||||||
|
- If you have [openupm-cli](https://github.com/openupm/openupm-cli) installed, then run the following command in your project's directory:
|
||||||
|
```
|
||||||
|
openupm add com.coffee.ui-particle
|
||||||
|
```
|
||||||
|
- To update the package, use Package Manager UI (`Window > Package Manager`) or run the following command with `@{version}`:
|
||||||
|
```
|
||||||
|
openupm add com.coffee.ui-particle@4.9.0
|
||||||
|
```
|
||||||
|
|
||||||
If you have [openupm-cli](https://github.com/openupm/openupm-cli) installed, then run the following command in your
|
#### Install via UPM (with Package Manager UI)
|
||||||
project's directory:
|
|
||||||
|
|
||||||
```sh
|
- Click `Window > Package Manager` to open Package Manager UI.
|
||||||
openupm add com.coffee.ui-particle
|
- Click `+ > Add package from git URL...` and input the repository URL: `https://github.com/mob-sakai/ParticleEffectForUGUI.git`
|
||||||
```
|

|
||||||
|
- To update the package, change suffix `#{version}` to the target version.
|
||||||
|
- e.g. `https://github.com/mob-sakai/ParticleEffectForUGUI.git#4.9.0`
|
||||||
|
|
||||||
#### Install via UPM (using Git URL)
|
#### Install via UPM (Manually)
|
||||||
|
|
||||||
Navigate to your project's Packages folder and open the `manifest.json` file. Then add this package somewhere in
|
- Open the `Packages/manifest.json` file in your project. Then add this package somewhere in the `dependencies` block:
|
||||||
the `dependencies` block:
|
```json
|
||||||
|
{
|
||||||
```json
|
"dependencies": {
|
||||||
{
|
"com.coffee.ui-particle": "https://github.com/mob-sakai/ParticleEffectForUGUI.git",
|
||||||
"dependencies": {
|
...
|
||||||
"com.coffee.ui-particle": "https://github.com/mob-sakai/ParticleEffectForUGUI.git",
|
}
|
||||||
...
|
|
||||||
}
|
}
|
||||||
}
|
```
|
||||||
```
|
|
||||||
|
|
||||||
To update the package, change suffix `#{version}` to the target version.
|
- To update the package, change suffix `#{version}` to the target version.
|
||||||
|
- e.g. `"com.coffee.ui-particle": "https://github.com/mob-sakai/ParticleEffectForUGUI.git#4.9.0",`
|
||||||
|
|
||||||
* e.g. `"com.coffee.ui-particle": "https://github.com/mob-sakai/ParticleEffectForUGUI.git#4.6.0",`
|
#### Install as Embedded Package
|
||||||
|
|
||||||
Or, use [UpmGitExtension](https://github.com/mob-sakai/UpmGitExtension) to install and update the package.
|
1. Download a source code zip file from [Releases](https://github.com/mob-sakai/ParticleEffectForUGUI.git/releases) and extract it.
|
||||||
|
2. Place it in your project's `Packages` directory.
|
||||||
|

|
||||||
|
- If you want to fix bugs or add features, install it as an embedded package.
|
||||||
|
- To update the package, you need to re-download it and replace the contents.
|
||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
## 🚀 Usage
|
## 🚀 Usage
|
||||||
|
|
||||||
### UIParticle Component
|
### Component: UIParticle
|
||||||
|
|
||||||
`UIParticle` controls the ParticleSystems that are attached to its own game objects and child game objects.
|
`UIParticle` controls the ParticleSystems that are attached to its own game objects and child game objects.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
- **Maskable**: Does this graphic allow masking.
|
- **Maskable**: Does this graphic allow maskable.
|
||||||
- **Scale**: Scale the rendering. When the `3D` toggle is enabled, 3D scale (x, y, z) is supported.
|
- **Scale**: Scale the rendering particles. When the `3D` toggle is enabled, 3D scale (x, y, z) is supported.
|
||||||
- **Animatable Properties**: If you want to update material properties (e.g., `_MainTex_ST`, `_Color`) in AnimationClip,
|
- **Animatable Properties**: If you want to update material properties (e.g., `_MainTex_ST`, `_Color`) in AnimationClip,
|
||||||
use this to mark the changes.
|
use this to mark as animatable.
|
||||||
- **Mesh Sharing**: Particle simulation results are shared within the same group. A large number of the same effects can
|
- **Mesh Sharing**: Particle simulation results are shared within the same group. A large number of the same effects can
|
||||||
be displayed with a small load. When the `Random` toggle is enabled, it will be grouped randomly.
|
be displayed with a small load. When the `Random` toggle is enabled, it will be grouped randomly.
|
||||||
|
- **None:** Disable mesh sharing.
|
||||||
|
- **Auto:** Automatically select Primary/Replica.
|
||||||
|
- **Primary:** Provides particle simulation results to the same group.
|
||||||
|
- **Primary Simulator:** Primary, but do not render the particle (simulation only).
|
||||||
|
- **Replica:** Render simulation results provided by the primary.
|
||||||
- **Position Mode**: Emission position mode.
|
- **Position Mode**: Emission position mode.
|
||||||
- **Absolute:** Emit from the world position of the `ParticleSystem`.
|
- **Absolute:** The particles will be emitted from the world position.
|
||||||
- **Relative:** Emit from the scaled position of the `ParticleSystem`.
|
- **Relative:** The particles will be emitted from the scaled position.
|
||||||
- **Auto Scaling**: `Transform.lossyScale` (=world scale) will be set to `(1, 1, 1)` on update. It prevents the
|
- **Auto Scaling Mode**: How to automatically adjust when the Canvas scale is changed by the screen size or reference resolution.
|
||||||
root-Canvas scale from affecting the hierarchy-scaled `ParticleSystem`.
|
- **None:** Do nothing.
|
||||||
|
- **Transform:** Transform.lossyScale (=world scale) will be set to (1, 1, 1).
|
||||||
|
- **UIParticle:** UIParticle.scale will be adjusted.
|
||||||
|
- **Use Custom View:** Use this if the particles are not displayed correctly due to min/max particle size.
|
||||||
|
- **Custom view size:** Change the bake view size.
|
||||||
- **Rendering Order**: The ParticleSystem list to be rendered. You can change the order and the materials.
|
- **Rendering Order**: The ParticleSystem list to be rendered. You can change the order and the materials.
|
||||||
|
|
||||||
**NOTE:** Press the `Refresh` button to reconstruct the rendering order based on children ParticleSystem's sorting order
|
**NOTE:** Press the `Refresh` button to reconstruct the rendering order based on children ParticleSystem's sorting order
|
||||||
@@ -143,7 +187,7 @@ and z-position.
|
|||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
#### Basic Usage
|
### Basic Usage
|
||||||
|
|
||||||
1. Select `GameObject/UI/ParticleSystem` to create UIParticle with a ParticleSystem.
|
1. Select `GameObject/UI/ParticleSystem` to create UIParticle with a ParticleSystem.
|
||||||

|

|
||||||
@@ -152,7 +196,7 @@ and z-position.
|
|||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
#### With Your Existing ParticleSystem Prefab
|
### Usage with Your Existing ParticleSystem Prefab
|
||||||
|
|
||||||
1. Select `GameObject/UI/ParticleSystem (Empty)` to create UIParticle.
|
1. Select `GameObject/UI/ParticleSystem (Empty)` to create UIParticle.
|
||||||

|

|
||||||
@@ -161,7 +205,7 @@ and z-position.
|
|||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
#### With `Mask` or `RectMask2D` Component
|
### Usage with `Mask` or `RectMask2D` Component
|
||||||
|
|
||||||
If you want to mask particles, set a stencil-supported shader (such as `UI/UIAdditive`) to the material for
|
If you want to mask particles, set a stencil-supported shader (such as `UI/UIAdditive`) to the material for
|
||||||
ParticleSystem.
|
ParticleSystem.
|
||||||
@@ -173,12 +217,13 @@ section.
|
|||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
### Script usage
|
### Usage with Script
|
||||||
|
|
||||||
```cs
|
```cs
|
||||||
// Instant ParticleSystem prefab with UIParticle on runtime.
|
// Instantiate ParticleSystem prefab with UIParticle on runtime.
|
||||||
var go = GameObject.Instantiate(prefab);
|
var go = GameObject.Instantiate(prefab);
|
||||||
var uiParticle = go.AddComponent<UIParticle>();
|
var uiParticle = go.AddComponent<UIParticle>();
|
||||||
|
uiParticle.scale = 100;
|
||||||
|
|
||||||
// Control by ParticleSystem.
|
// Control by ParticleSystem.
|
||||||
particleSystem.Play();
|
particleSystem.Play();
|
||||||
@@ -191,14 +236,14 @@ uiParticle.Stop();
|
|||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
### UIParticleAttractor component
|
### Component: UIParticleAttractor
|
||||||
|
|
||||||
`UIParticleAttractor` attracts particles generated by the specified ParticleSystem.
|
`UIParticleAttractor` attracts particles generated by the specified ParticleSystem.
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
- **Particle System**: Attracts particles generated by the specified particle system.
|
- **Particle Systems**: Attracts particles generated by the specified ParticleSystems.
|
||||||
- **Destination Radius**: Once the particle is within the radius, the particle lifetime will become 0, and `OnAttracted`
|
- **Destination Radius**: Once the particle is within the radius, the particle lifetime will become 0, and `OnAttracted`
|
||||||
will be called.
|
will be called.
|
||||||
- **Delay Rate**: Delay to start attracting. It is a percentage of the particle's start lifetime.
|
- **Delay Rate**: Delay to start attracting. It is a percentage of the particle's start lifetime.
|
||||||
@@ -212,6 +257,14 @@ uiParticle.Stop();
|
|||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
|
### Project Settings
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- Click `Edit > Project Settings` to open the Project Settings window and then select `UI > UI Particle` category.
|
||||||
|
|
||||||
|
<br><br>
|
||||||
|
|
||||||
## 🛠 Development Note
|
## 🛠 Development Note
|
||||||
|
|
||||||
### Compares the Baking mesh approach with the conventional approach
|
### Compares the Baking mesh approach with the conventional approach
|
||||||
@@ -343,7 +396,7 @@ When improving performance, keep the following in mind:
|
|||||||
- Consider a single material, atlasing the sprites, and using `Sprite` mode in the `Texture Sheet Animation` module
|
- Consider a single material, atlasing the sprites, and using `Sprite` mode in the `Texture Sheet Animation` module
|
||||||
in the ParticleSystem.
|
in the ParticleSystem.
|
||||||
|
|
||||||
### How to Make a Custom Shader to Support Mask/RectMask2D Component
|
### How to Make a Custom Shader to Support `Mask` and `RectMask2D` Component
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Shader tips</summary>
|
<summary>Shader tips</summary>
|
||||||
|
|||||||
8
Runtime/Internal.meta
Normal file
8
Runtime/Internal.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 53aa3f36032944b3fb1455e774c52396
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Runtime/Internal/Extensions.meta
Normal file
8
Runtime/Internal/Extensions.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8cf8018dee45a4c42a19eec890eaa5b1
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
134
Runtime/Internal/Extensions/CanvasExtensions.cs
Normal file
134
Runtime/Internal/Extensions/CanvasExtensions.cs
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
#if UNITY_2021_3_0 || UNITY_2021_3_1 || UNITY_2021_3_2 || UNITY_2021_3_3 || UNITY_2021_3_4 || UNITY_2021_3_5 || UNITY_2021_3_6 || UNITY_2021_3_7 || UNITY_2021_3_8 || UNITY_2021_3_9
|
||||||
|
#elif UNITY_2021_3_10 || UNITY_2021_3_11 || UNITY_2021_3_12 || UNITY_2021_3_13 || UNITY_2021_3_14 || UNITY_2021_3_15 || UNITY_2021_3_16 || UNITY_2021_3_17 || UNITY_2021_3_18 || UNITY_2021_3_19
|
||||||
|
#elif UNITY_2021_3_20 || UNITY_2021_3_21 || UNITY_2021_3_22 || UNITY_2021_3_23 || UNITY_2021_3_24 || UNITY_2021_3_25 || UNITY_2021_3_26 || UNITY_2021_3_27 || UNITY_2021_3_28 || UNITY_2021_3_29
|
||||||
|
#elif UNITY_2021_3_30 || UNITY_2021_3_31 || UNITY_2021_3_32 || UNITY_2021_3_33
|
||||||
|
#elif UNITY_2022_2_0 || UNITY_2022_2_1 || UNITY_2022_2_2 || UNITY_2022_2_3 || UNITY_2022_2_4 || UNITY_2022_2_5 || UNITY_2022_2_6 || UNITY_2022_2_7 || UNITY_2022_2_8 || UNITY_2022_2_9
|
||||||
|
#elif UNITY_2022_2_10 || UNITY_2022_2_11 || UNITY_2022_2_12 || UNITY_2022_2_13 || UNITY_2022_2_14
|
||||||
|
#elif UNITY_2021_3 || UNITY_2022_2 || UNITY_2022_3 || UNITY_2023_2_OR_NEWER
|
||||||
|
#define CANVAS_SUPPORT_ALWAYS_GAMMA
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Profiling;
|
||||||
|
#if UNITY_MODULE_VR
|
||||||
|
using UnityEngine.XR;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Coffee.UIParticleInternal
|
||||||
|
{
|
||||||
|
internal static class CanvasExtensions
|
||||||
|
{
|
||||||
|
public static bool ShouldGammaToLinearInShader(this Canvas canvas)
|
||||||
|
{
|
||||||
|
return QualitySettings.activeColorSpace == ColorSpace.Linear &&
|
||||||
|
#if CANVAS_SUPPORT_ALWAYS_GAMMA
|
||||||
|
canvas.vertexColorAlwaysGammaSpace;
|
||||||
|
#else
|
||||||
|
false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool ShouldGammaToLinearInMesh(this Canvas canvas)
|
||||||
|
{
|
||||||
|
return QualitySettings.activeColorSpace == ColorSpace.Linear &&
|
||||||
|
#if CANVAS_SUPPORT_ALWAYS_GAMMA
|
||||||
|
!canvas.vertexColorAlwaysGammaSpace;
|
||||||
|
#else
|
||||||
|
true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsStereoCanvas(this Canvas canvas)
|
||||||
|
{
|
||||||
|
#if UNITY_MODULE_VR
|
||||||
|
if (FrameCache.TryGet<bool>(canvas, nameof(IsStereoCanvas), out var stereo)) return stereo;
|
||||||
|
|
||||||
|
stereo =
|
||||||
|
canvas != null && canvas.renderMode != RenderMode.ScreenSpaceOverlay && canvas.worldCamera != null
|
||||||
|
&& XRSettings.enabled && !string.IsNullOrEmpty(XRSettings.loadedDeviceName);
|
||||||
|
FrameCache.Set(canvas, nameof(IsStereoCanvas), stereo);
|
||||||
|
return stereo;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the view-projection matrix for a Canvas.
|
||||||
|
/// </summary>
|
||||||
|
public static void GetViewProjectionMatrix(this Canvas canvas, out Matrix4x4 vpMatrix)
|
||||||
|
{
|
||||||
|
canvas.GetViewProjectionMatrix(Camera.MonoOrStereoscopicEye.Mono, out vpMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the view-projection matrix for a Canvas.
|
||||||
|
/// </summary>
|
||||||
|
public static void GetViewProjectionMatrix(this Canvas canvas, Camera.MonoOrStereoscopicEye eye,
|
||||||
|
out Matrix4x4 vpMatrix)
|
||||||
|
{
|
||||||
|
if (FrameCache.TryGet(canvas, nameof(GetViewProjectionMatrix), out vpMatrix)) return;
|
||||||
|
|
||||||
|
canvas.GetViewProjectionMatrix(eye, out var viewMatrix, out var projectionMatrix);
|
||||||
|
vpMatrix = viewMatrix * projectionMatrix;
|
||||||
|
FrameCache.Set(canvas, nameof(GetViewProjectionMatrix), vpMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the view and projection matrices for a Canvas.
|
||||||
|
/// </summary>
|
||||||
|
public static void GetViewProjectionMatrix(this Canvas canvas, out Matrix4x4 vMatrix, out Matrix4x4 pMatrix)
|
||||||
|
{
|
||||||
|
canvas.GetViewProjectionMatrix(Camera.MonoOrStereoscopicEye.Mono, out vMatrix, out pMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the view and projection matrices for a Canvas.
|
||||||
|
/// </summary>
|
||||||
|
public static void GetViewProjectionMatrix(this Canvas canvas, Camera.MonoOrStereoscopicEye eye,
|
||||||
|
out Matrix4x4 vMatrix, out Matrix4x4 pMatrix)
|
||||||
|
{
|
||||||
|
if (FrameCache.TryGet(canvas, "GetViewMatrix", (int)eye, out vMatrix) &&
|
||||||
|
FrameCache.TryGet(canvas, "GetProjectionMatrix", (int)eye, out pMatrix))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get view and projection matrices.
|
||||||
|
Profiler.BeginSample("(COF)[CanvasExt] GetViewProjectionMatrix");
|
||||||
|
var rootCanvas = canvas.rootCanvas;
|
||||||
|
var cam = rootCanvas.worldCamera;
|
||||||
|
if (rootCanvas && rootCanvas.renderMode != RenderMode.ScreenSpaceOverlay && cam)
|
||||||
|
{
|
||||||
|
if (eye == Camera.MonoOrStereoscopicEye.Mono)
|
||||||
|
{
|
||||||
|
vMatrix = cam.worldToCameraMatrix;
|
||||||
|
pMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pMatrix = cam.GetStereoProjectionMatrix((Camera.StereoscopicEye)eye);
|
||||||
|
vMatrix = cam.GetStereoViewMatrix((Camera.StereoscopicEye)eye);
|
||||||
|
pMatrix = GL.GetGPUProjectionMatrix(pMatrix, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var pos = rootCanvas.transform.position;
|
||||||
|
vMatrix = Matrix4x4.TRS(
|
||||||
|
new Vector3(-pos.x, -pos.y, -1000),
|
||||||
|
Quaternion.identity,
|
||||||
|
new Vector3(1, 1, -1f));
|
||||||
|
pMatrix = Matrix4x4.TRS(
|
||||||
|
new Vector3(0, 0, -1),
|
||||||
|
Quaternion.identity,
|
||||||
|
new Vector3(1 / pos.x, 1 / pos.y, -2 / 10000f));
|
||||||
|
}
|
||||||
|
|
||||||
|
FrameCache.Set(canvas, "GetViewMatrix", (int)eye, vMatrix);
|
||||||
|
FrameCache.Set(canvas, "GetProjectionMatrix", (int)eye, pMatrix);
|
||||||
|
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: b0beae5bb1cb142b9ab90dc0d371f026
|
guid: 9dd767b8c0f95478386e7d5079cd44df
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
77
Runtime/Internal/Extensions/Color32Extensions.cs
Normal file
77
Runtime/Internal/Extensions/Color32Extensions.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Profiling;
|
||||||
|
|
||||||
|
namespace Coffee.UIParticleInternal
|
||||||
|
{
|
||||||
|
internal static class Color32Extensions
|
||||||
|
{
|
||||||
|
private static readonly List<Color32> s_Colors = new List<Color32>();
|
||||||
|
private static byte[] s_LinearToGammaLut;
|
||||||
|
private static byte[] s_GammaToLinearLut;
|
||||||
|
|
||||||
|
public static byte LinearToGamma(this byte self)
|
||||||
|
{
|
||||||
|
if (s_LinearToGammaLut == null)
|
||||||
|
{
|
||||||
|
s_LinearToGammaLut = new byte[256];
|
||||||
|
for (var i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
s_LinearToGammaLut[i] = (byte)(Mathf.LinearToGammaSpace(i / 255f) * 255f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s_LinearToGammaLut[self];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte GammaToLinear(this byte self)
|
||||||
|
{
|
||||||
|
if (s_GammaToLinearLut == null)
|
||||||
|
{
|
||||||
|
s_GammaToLinearLut = new byte[256];
|
||||||
|
for (var i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
s_GammaToLinearLut[i] = (byte)(Mathf.GammaToLinearSpace(i / 255f) * 255f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s_GammaToLinearLut[self];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void LinearToGamma(this Mesh self)
|
||||||
|
{
|
||||||
|
Profiler.BeginSample("(COF)[ColorExt] LinearToGamma (Mesh)");
|
||||||
|
self.GetColors(s_Colors);
|
||||||
|
var count = s_Colors.Count;
|
||||||
|
for (var i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
var c = s_Colors[i];
|
||||||
|
c.r = c.r.LinearToGamma();
|
||||||
|
c.g = c.g.LinearToGamma();
|
||||||
|
c.b = c.b.LinearToGamma();
|
||||||
|
s_Colors[i] = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.SetColors(s_Colors);
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void GammaToLinear(this Mesh self)
|
||||||
|
{
|
||||||
|
Profiler.BeginSample("(COF)[ColorExt] GammaToLinear (Mesh)");
|
||||||
|
self.GetColors(s_Colors);
|
||||||
|
var count = s_Colors.Count;
|
||||||
|
for (var i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
var c = s_Colors[i];
|
||||||
|
c.r = c.r.GammaToLinear();
|
||||||
|
c.g = c.g.GammaToLinear();
|
||||||
|
c.b = c.b.GammaToLinear();
|
||||||
|
s_Colors[i] = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.SetColors(s_Colors);
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: d188d31b140094ebc84a9caafbc7ac71
|
guid: 0ef431b9df32c410ea5fa46be81def6b
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
198
Runtime/Internal/Extensions/ComponentExtensions.cs
Normal file
198
Runtime/Internal/Extensions/ComponentExtensions.cs
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Profiling;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
|
namespace Coffee.UIParticleInternal
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Extension methods for Component class.
|
||||||
|
/// </summary>
|
||||||
|
internal static class ComponentExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Get components in children of a specific type in the hierarchy of a GameObject.
|
||||||
|
/// </summary>
|
||||||
|
public static T[] GetComponentsInChildren<T>(this Component self, int depth)
|
||||||
|
where T : Component
|
||||||
|
{
|
||||||
|
var results = ListPool<T>.Rent();
|
||||||
|
self.GetComponentsInChildren_Internal(results, depth);
|
||||||
|
var array = results.ToArray();
|
||||||
|
ListPool<T>.Return(ref results);
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get components in children of a specific type in the hierarchy of a GameObject.
|
||||||
|
/// </summary>
|
||||||
|
public static void GetComponentsInChildren<T>(this Component self, List<T> results, int depth)
|
||||||
|
where T : Component
|
||||||
|
{
|
||||||
|
results.Clear();
|
||||||
|
self.GetComponentsInChildren_Internal(results, depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void GetComponentsInChildren_Internal<T>(this Component self, List<T> results, int depth)
|
||||||
|
where T : Component
|
||||||
|
{
|
||||||
|
if (!self || results == null || depth < 0) return;
|
||||||
|
|
||||||
|
var tr = self.transform;
|
||||||
|
if (tr.TryGetComponent<T>(out var t))
|
||||||
|
{
|
||||||
|
results.Add(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (depth - 1 < 0) return;
|
||||||
|
var childCount = tr.childCount;
|
||||||
|
for (var i = 0; i < childCount; i++)
|
||||||
|
{
|
||||||
|
tr.GetChild(i).GetComponentsInChildren_Internal(results, depth - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get or add a component of a specific type to a GameObject.
|
||||||
|
/// </summary>
|
||||||
|
public static T GetOrAddComponent<T>(this Component self) where T : Component
|
||||||
|
{
|
||||||
|
if (!self) return null;
|
||||||
|
return self.TryGetComponent<T>(out var component)
|
||||||
|
? component
|
||||||
|
: self.gameObject.AddComponent<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the root component of a specific type in the hierarchy of a GameObject.
|
||||||
|
/// </summary>
|
||||||
|
public static T GetRootComponent<T>(this Component self) where T : Component
|
||||||
|
{
|
||||||
|
T component = null;
|
||||||
|
var transform = self.transform;
|
||||||
|
while (transform)
|
||||||
|
{
|
||||||
|
if (transform.TryGetComponent<T>(out var c))
|
||||||
|
{
|
||||||
|
component = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
transform = transform.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a component of a specific type in the parent hierarchy of a GameObject.
|
||||||
|
/// </summary>
|
||||||
|
public static T GetComponentInParent<T>(this Component self, bool includeSelf, Transform stopAfter,
|
||||||
|
Predicate<T> valid)
|
||||||
|
where T : Component
|
||||||
|
{
|
||||||
|
var tr = includeSelf ? self.transform : self.transform.parent;
|
||||||
|
while (tr)
|
||||||
|
{
|
||||||
|
if (tr.TryGetComponent<T>(out var c) && valid(c)) return c;
|
||||||
|
if (tr == stopAfter) return null;
|
||||||
|
tr = tr.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a component of a specific type to the children of a GameObject.
|
||||||
|
/// </summary>
|
||||||
|
public static void AddComponentOnChildren<T>(this Component self, HideFlags hideFlags, bool includeSelf)
|
||||||
|
where T : Component
|
||||||
|
{
|
||||||
|
if (self == null) return;
|
||||||
|
|
||||||
|
Profiler.BeginSample("(COF)[ComponentExt] AddComponentOnChildren > Self");
|
||||||
|
if (includeSelf && !self.TryGetComponent<T>(out _))
|
||||||
|
{
|
||||||
|
var c = self.gameObject.AddComponent<T>();
|
||||||
|
c.hideFlags = hideFlags;
|
||||||
|
}
|
||||||
|
|
||||||
|
Profiler.EndSample();
|
||||||
|
|
||||||
|
Profiler.BeginSample("(COF)[ComponentExt] AddComponentOnChildren > Child");
|
||||||
|
var childCount = self.transform.childCount;
|
||||||
|
for (var i = 0; i < childCount; i++)
|
||||||
|
{
|
||||||
|
var child = self.transform.GetChild(i);
|
||||||
|
if (child.TryGetComponent<T>(out _)) continue;
|
||||||
|
|
||||||
|
var c = child.gameObject.AddComponent<T>();
|
||||||
|
c.hideFlags = hideFlags;
|
||||||
|
}
|
||||||
|
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !UNITY_2021_2_OR_NEWER && !UNITY_2020_3_45 && !UNITY_2020_3_46 && !UNITY_2020_3_47 && !UNITY_2020_3_48
|
||||||
|
public static T GetComponentInParent<T>(this Component self, bool includeInactive) where T : Component
|
||||||
|
{
|
||||||
|
if (!self) return null;
|
||||||
|
if (!includeInactive) return self.GetComponentInParent<T>();
|
||||||
|
|
||||||
|
var current = self.transform;
|
||||||
|
while (current)
|
||||||
|
{
|
||||||
|
if (current.TryGetComponent<T>(out var c)) return c;
|
||||||
|
current = current.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
/// <summary>
|
||||||
|
/// Verify whether it can be converted to the specified component.
|
||||||
|
/// </summary>
|
||||||
|
internal static bool CanConvertTo<T>(this Object context) where T : MonoBehaviour
|
||||||
|
{
|
||||||
|
return context && context.GetType() != typeof(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert to the specified component.
|
||||||
|
/// </summary>
|
||||||
|
internal static void ConvertTo<T>(this Object context) where T : MonoBehaviour
|
||||||
|
{
|
||||||
|
var target = context as MonoBehaviour;
|
||||||
|
if (target == null) return;
|
||||||
|
|
||||||
|
var so = new SerializedObject(target);
|
||||||
|
so.Update();
|
||||||
|
|
||||||
|
var oldEnable = target.enabled;
|
||||||
|
target.enabled = false;
|
||||||
|
|
||||||
|
// Find MonoScript of the specified component.
|
||||||
|
foreach (var script in Resources.FindObjectsOfTypeAll<MonoScript>())
|
||||||
|
{
|
||||||
|
if (script.GetClass() != typeof(T))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set 'm_Script' to convert.
|
||||||
|
so.FindProperty("m_Script").objectReferenceValue = script;
|
||||||
|
so.ApplyModifiedProperties();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (so.targetObject is MonoBehaviour mb)
|
||||||
|
{
|
||||||
|
mb.enabled = oldEnable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Runtime/Internal/Extensions/ComponentExtensions.cs.meta
Normal file
11
Runtime/Internal/Extensions/ComponentExtensions.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8455ee485a5ee4cacbdf558f66af65fb
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
48
Runtime/Internal/Extensions/Misc.cs
Normal file
48
Runtime/Internal/Extensions/Misc.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Coffee.UIParticleInternal
|
||||||
|
{
|
||||||
|
internal static class Misc
|
||||||
|
{
|
||||||
|
public static void Destroy(Object obj)
|
||||||
|
{
|
||||||
|
if (!obj) return;
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if (!Application.isPlaying)
|
||||||
|
{
|
||||||
|
Object.DestroyImmediate(obj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
Object.Destroy(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DestroyImmediate(Object obj)
|
||||||
|
{
|
||||||
|
if (!obj) return;
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if (Application.isEditor)
|
||||||
|
{
|
||||||
|
Object.DestroyImmediate(obj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
Object.Destroy(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Conditional("UNITY_EDITOR")]
|
||||||
|
public static void SetDirty(Object obj)
|
||||||
|
{
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if (!obj) return;
|
||||||
|
EditorUtility.SetDirty(obj);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Runtime/Internal/Extensions/Misc.cs.meta
Normal file
11
Runtime/Internal/Extensions/Misc.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 39ed6a6b0a72e482488bd298b2ae762e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
58
Runtime/Internal/Extensions/SpriteExtensions.cs
Normal file
58
Runtime/Internal/Extensions/SpriteExtensions.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.U2D;
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
using System.Reflection;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Coffee.UIParticleInternal
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Extension methods for Sprite class.
|
||||||
|
/// </summary>
|
||||||
|
internal static class SpriteExtensions
|
||||||
|
{
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
private static readonly Type s_SpriteEditorExtensionType =
|
||||||
|
Type.GetType("UnityEditor.Experimental.U2D.SpriteEditorExtension, UnityEditor")
|
||||||
|
?? Type.GetType("UnityEditor.U2D.SpriteEditorExtension, UnityEditor");
|
||||||
|
|
||||||
|
private static readonly MethodInfo s_GetActiveAtlasTextureMethod = s_SpriteEditorExtensionType
|
||||||
|
.GetMethod("GetActiveAtlasTexture", BindingFlags.Static | BindingFlags.NonPublic);
|
||||||
|
|
||||||
|
private static readonly MethodInfo s_GetActiveAtlasMethod = s_SpriteEditorExtensionType
|
||||||
|
.GetMethod("GetActiveAtlas", BindingFlags.Static | BindingFlags.NonPublic);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the actual texture of a sprite in play mode or edit mode.
|
||||||
|
/// </summary>
|
||||||
|
public static Texture2D GetActualTexture(this Sprite self)
|
||||||
|
{
|
||||||
|
if (!self) return null;
|
||||||
|
|
||||||
|
if (Application.isPlaying) return self.texture;
|
||||||
|
|
||||||
|
var ret = s_GetActiveAtlasTextureMethod.Invoke(null, new object[] { self }) as Texture2D;
|
||||||
|
return ret ? ret : self.texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the active sprite atlas of a sprite in play mode or edit mode.
|
||||||
|
/// </summary>
|
||||||
|
public static SpriteAtlas GetActiveAtlas(this Sprite self)
|
||||||
|
{
|
||||||
|
if (!self) return null;
|
||||||
|
|
||||||
|
return s_GetActiveAtlasMethod.Invoke(null, new object[] { self }) as SpriteAtlas;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/// <summary>
|
||||||
|
/// Get the actual texture of a sprite in play mode.
|
||||||
|
/// </summary>
|
||||||
|
internal static Texture2D GetActualTexture(this Sprite self)
|
||||||
|
{
|
||||||
|
return self ? self.texture : null;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Runtime/Internal/Extensions/SpriteExtensions.cs.meta
Normal file
11
Runtime/Internal/Extensions/SpriteExtensions.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a7a2e11131111447cb7fc0394a14da65
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
46
Runtime/Internal/Extensions/Vector3Extensions.cs
Normal file
46
Runtime/Internal/Extensions/Vector3Extensions.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Coffee.UIParticleInternal
|
||||||
|
{
|
||||||
|
internal static class Vector3Extensions
|
||||||
|
{
|
||||||
|
public static Vector3 Inverse(this Vector3 self)
|
||||||
|
{
|
||||||
|
self.x = Mathf.Approximately(self.x, 0) ? 1 : 1 / self.x;
|
||||||
|
self.y = Mathf.Approximately(self.y, 0) ? 1 : 1 / self.y;
|
||||||
|
self.z = Mathf.Approximately(self.z, 0) ? 1 : 1 / self.z;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 GetScaled(this Vector3 self, Vector3 other1)
|
||||||
|
{
|
||||||
|
self.Scale(other1);
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 GetScaled(this Vector3 self, Vector3 other1, Vector3 other2)
|
||||||
|
{
|
||||||
|
self.Scale(other1);
|
||||||
|
self.Scale(other2);
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 GetScaled(this Vector3 self, Vector3 other1, Vector3 other2, Vector3 other3)
|
||||||
|
{
|
||||||
|
self.Scale(other1);
|
||||||
|
self.Scale(other2);
|
||||||
|
self.Scale(other3);
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsVisible(this Vector3 self)
|
||||||
|
{
|
||||||
|
return 0 < Mathf.Abs(self.x * self.y * self.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsVisible2D(this Vector3 self)
|
||||||
|
{
|
||||||
|
return 0 < Mathf.Abs(self.x * self.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Runtime/Internal/Extensions/Vector3Extensions.cs.meta
Normal file
11
Runtime/Internal/Extensions/Vector3Extensions.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6a7b5fb989e4b48c8bc7ecce834060f5
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Runtime/Internal/ProjectSettings.meta
Normal file
8
Runtime/Internal/ProjectSettings.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 398e06c9985ad4291a95f0749c2927fb
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
219
Runtime/Internal/ProjectSettings/PreloadedProjectSettings.cs
Normal file
219
Runtime/Internal/ProjectSettings/PreloadedProjectSettings.cs
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEditor.Build;
|
||||||
|
using UnityEditor.Build.Reporting;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Coffee.UIParticleInternal
|
||||||
|
{
|
||||||
|
public abstract class PreloadedProjectSettings : ScriptableObject
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
{
|
||||||
|
private class PreprocessBuildWithReport : IPreprocessBuildWithReport
|
||||||
|
{
|
||||||
|
int IOrderedCallback.callbackOrder => 0;
|
||||||
|
|
||||||
|
void IPreprocessBuildWithReport.OnPreprocessBuild(BuildReport report)
|
||||||
|
{
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[InitializeOnLoadMethod]
|
||||||
|
[InitializeOnEnterPlayMode]
|
||||||
|
private static void Initialize()
|
||||||
|
{
|
||||||
|
const BindingFlags flags = BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy;
|
||||||
|
foreach (var t in TypeCache.GetTypesDerivedFrom(typeof(PreloadedProjectSettings<>)))
|
||||||
|
{
|
||||||
|
var defaultSettings = GetDefaultSettings(t);
|
||||||
|
if (!defaultSettings)
|
||||||
|
{
|
||||||
|
// When create a new instance, automatically set it as default settings.
|
||||||
|
defaultSettings = t.GetProperty("instance", flags)
|
||||||
|
?.GetValue(null, null) as PreloadedProjectSettings;
|
||||||
|
}
|
||||||
|
else if (GetPreloadedSettings(t).Length != 1)
|
||||||
|
{
|
||||||
|
SetDefaultSettings(defaultSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorApplication.QueuePlayerLoopUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static string GetDefaultName(Type type, bool nicify)
|
||||||
|
{
|
||||||
|
var typeName = type.Name.Replace("ProjectSettings", "");
|
||||||
|
return nicify
|
||||||
|
? ObjectNames.NicifyVariableName(typeName)
|
||||||
|
: typeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object[] GetPreloadedSettings(Type type)
|
||||||
|
{
|
||||||
|
return PlayerSettings.GetPreloadedAssets()
|
||||||
|
.Where(x => x && x.GetType() == type)
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static PreloadedProjectSettings GetDefaultSettings(Type type)
|
||||||
|
{
|
||||||
|
return GetPreloadedSettings(type).FirstOrDefault() as PreloadedProjectSettings
|
||||||
|
?? AssetDatabase.FindAssets($"t:{nameof(PreloadedProjectSettings)}")
|
||||||
|
.Select(AssetDatabase.GUIDToAssetPath)
|
||||||
|
.Select(AssetDatabase.LoadAssetAtPath<PreloadedProjectSettings>)
|
||||||
|
.FirstOrDefault(x => x && x.GetType() == type);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void SetDefaultSettings(PreloadedProjectSettings asset)
|
||||||
|
{
|
||||||
|
if (!asset) return;
|
||||||
|
var type = asset.GetType();
|
||||||
|
if (string.IsNullOrEmpty(AssetDatabase.GetAssetPath(asset)))
|
||||||
|
{
|
||||||
|
if (!AssetDatabase.IsValidFolder("Assets/ProjectSettings"))
|
||||||
|
{
|
||||||
|
AssetDatabase.CreateFolder("Assets", "ProjectSettings");
|
||||||
|
}
|
||||||
|
|
||||||
|
var assetPath = $"Assets/ProjectSettings/{GetDefaultName(type, false)}.asset";
|
||||||
|
assetPath = AssetDatabase.GenerateUniqueAssetPath(assetPath);
|
||||||
|
AssetDatabase.CreateAsset(asset, assetPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
var preloadedAssets = PlayerSettings.GetPreloadedAssets();
|
||||||
|
var projectSettings = GetPreloadedSettings(type);
|
||||||
|
PlayerSettings.SetPreloadedAssets(preloadedAssets
|
||||||
|
.Where(x => x)
|
||||||
|
.Except(projectSettings.Except(new[] { asset }))
|
||||||
|
.Append(asset)
|
||||||
|
.Distinct()
|
||||||
|
.ToArray());
|
||||||
|
|
||||||
|
AssetDatabase.Refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public abstract class PreloadedProjectSettings<T> : PreloadedProjectSettings
|
||||||
|
where T : PreloadedProjectSettings<T>
|
||||||
|
{
|
||||||
|
private static T s_Instance;
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
private string _jsonText;
|
||||||
|
|
||||||
|
public static T instance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (s_Instance) return s_Instance;
|
||||||
|
|
||||||
|
s_Instance = GetDefaultSettings(typeof(T)) as T;
|
||||||
|
if (s_Instance) return s_Instance;
|
||||||
|
|
||||||
|
s_Instance = CreateInstance<T>();
|
||||||
|
if (!s_Instance)
|
||||||
|
{
|
||||||
|
s_Instance = null;
|
||||||
|
return s_Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetDefaultSettings(s_Instance);
|
||||||
|
return s_Instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPlayModeStateChanged(PlayModeStateChange state)
|
||||||
|
{
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case PlayModeStateChange.ExitingEditMode:
|
||||||
|
_jsonText = EditorJsonUtility.ToJson(this);
|
||||||
|
break;
|
||||||
|
case PlayModeStateChange.ExitingPlayMode:
|
||||||
|
if (_jsonText != null)
|
||||||
|
{
|
||||||
|
EditorJsonUtility.FromJsonOverwrite(_jsonText, this);
|
||||||
|
_jsonText = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
public static T instance => s_Instance ? s_Instance : s_Instance = CreateInstance<T>();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This function is called when the object becomes enabled and active.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnEnable()
|
||||||
|
{
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
var isDefaultSettings = !s_Instance || s_Instance == this || GetDefaultSettings(typeof(T)) == this;
|
||||||
|
if (!isDefaultSettings)
|
||||||
|
{
|
||||||
|
DestroyImmediate(this, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (s_Instance) return;
|
||||||
|
s_Instance = this as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This function is called when the behaviour becomes disabled.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnDisable()
|
||||||
|
{
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
|
||||||
|
#endif
|
||||||
|
if (s_Instance != this) return;
|
||||||
|
|
||||||
|
s_Instance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
protected sealed class PreloadedProjectSettingsProvider : SettingsProvider
|
||||||
|
{
|
||||||
|
private Editor _editor;
|
||||||
|
private PreloadedProjectSettings<T> _target;
|
||||||
|
|
||||||
|
public PreloadedProjectSettingsProvider(string path) : base(path, SettingsScope.Project)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnGUI(string searchContext)
|
||||||
|
{
|
||||||
|
if (!_target)
|
||||||
|
{
|
||||||
|
if (_editor)
|
||||||
|
{
|
||||||
|
DestroyImmediate(_editor);
|
||||||
|
_editor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_target = instance;
|
||||||
|
_editor = Editor.CreateEditor(_target);
|
||||||
|
}
|
||||||
|
|
||||||
|
_editor.OnInspectorGUI();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 790ea008741dc411497c8794745319eb
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Runtime/Internal/Utilities.meta
Normal file
8
Runtime/Internal/Utilities.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1b2877595f27c4a70a426991d515434f
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
88
Runtime/Internal/Utilities/FastAction.cs
Executable file
88
Runtime/Internal/Utilities/FastAction.cs
Executable file
@@ -0,0 +1,88 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Profiling;
|
||||||
|
|
||||||
|
namespace Coffee.UIParticleInternal
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Base class for a fast action.
|
||||||
|
/// </summary>
|
||||||
|
internal class FastActionBase<T>
|
||||||
|
{
|
||||||
|
private static readonly ObjectPool<LinkedListNode<T>> s_NodePool =
|
||||||
|
new ObjectPool<LinkedListNode<T>>(() => new LinkedListNode<T>(default), _ => true, x => x.Value = default);
|
||||||
|
|
||||||
|
private readonly LinkedList<T> _delegates = new LinkedList<T>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a delegate to the action.
|
||||||
|
/// </summary>
|
||||||
|
public void Add(T rhs)
|
||||||
|
{
|
||||||
|
if (rhs == null) return;
|
||||||
|
Profiler.BeginSample("(COF)[FastAction] Add Action");
|
||||||
|
var node = s_NodePool.Rent();
|
||||||
|
node.Value = rhs;
|
||||||
|
_delegates.AddLast(node);
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a delegate from the action.
|
||||||
|
/// </summary>
|
||||||
|
public void Remove(T rhs)
|
||||||
|
{
|
||||||
|
if (rhs == null) return;
|
||||||
|
Profiler.BeginSample("(COF)[FastAction] Remove Action");
|
||||||
|
var node = _delegates.Find(rhs);
|
||||||
|
if (node != null)
|
||||||
|
{
|
||||||
|
_delegates.Remove(node);
|
||||||
|
s_NodePool.Return(ref node);
|
||||||
|
}
|
||||||
|
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invokes the action with a callback function.
|
||||||
|
/// </summary>
|
||||||
|
protected void Invoke(Action<T> callback)
|
||||||
|
{
|
||||||
|
var node = _delegates.First;
|
||||||
|
while (node != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
callback(node.Value);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
node = node.Next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
_delegates.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A fast action without parameters.
|
||||||
|
/// </summary>
|
||||||
|
internal class FastAction : FastActionBase<Action>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Invoke all the registered delegates.
|
||||||
|
/// </summary>
|
||||||
|
public void Invoke()
|
||||||
|
{
|
||||||
|
Invoke(action => action.Invoke());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Runtime/Internal/Utilities/FastAction.cs.meta
Normal file
11
Runtime/Internal/Utilities/FastAction.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a7c8c268a827b4787a8e050f1fe95ad5
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
101
Runtime/Internal/Utilities/FrameCache.cs
Normal file
101
Runtime/Internal/Utilities/FrameCache.cs
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Coffee.UIParticleInternal
|
||||||
|
{
|
||||||
|
internal static class FrameCache
|
||||||
|
{
|
||||||
|
private static readonly Dictionary<Type, IFrameCache> s_Caches = new Dictionary<Type, IFrameCache>();
|
||||||
|
|
||||||
|
static FrameCache()
|
||||||
|
{
|
||||||
|
s_Caches.Clear();
|
||||||
|
UIExtraCallbacks.onLateAfterCanvasRebuild += ClearAllCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||||
|
private static void Clear()
|
||||||
|
{
|
||||||
|
s_Caches.Clear();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tries to retrieve a value from the frame cache with a specified key.
|
||||||
|
/// </summary>
|
||||||
|
public static bool TryGet<T>(object key1, string key2, out T result)
|
||||||
|
{
|
||||||
|
return GetFrameCache<T>().TryGet((key1.GetHashCode(), key2.GetHashCode()), out result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tries to retrieve a value from the frame cache with a specified key.
|
||||||
|
/// </summary>
|
||||||
|
public static bool TryGet<T>(object key1, string key2, int key3, out T result)
|
||||||
|
{
|
||||||
|
return GetFrameCache<T>().TryGet((key1.GetHashCode(), key2.GetHashCode() + key3), out result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets a value in the frame cache with a specified key.
|
||||||
|
/// </summary>
|
||||||
|
public static void Set<T>(object key1, string key2, T result)
|
||||||
|
{
|
||||||
|
GetFrameCache<T>().Set((key1.GetHashCode(), key2.GetHashCode()), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets a value in the frame cache with a specified key.
|
||||||
|
/// </summary>
|
||||||
|
public static void Set<T>(object key1, string key2, int key3, T result)
|
||||||
|
{
|
||||||
|
GetFrameCache<T>().Set((key1.GetHashCode(), key2.GetHashCode() + key3), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ClearAllCache()
|
||||||
|
{
|
||||||
|
foreach (var cache in s_Caches.Values)
|
||||||
|
{
|
||||||
|
cache.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static FrameCacheContainer<T> GetFrameCache<T>()
|
||||||
|
{
|
||||||
|
var t = typeof(T);
|
||||||
|
if (s_Caches.TryGetValue(t, out var frameCache)) return frameCache as FrameCacheContainer<T>;
|
||||||
|
|
||||||
|
frameCache = new FrameCacheContainer<T>();
|
||||||
|
s_Caches.Add(t, frameCache);
|
||||||
|
|
||||||
|
return (FrameCacheContainer<T>)frameCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface IFrameCache
|
||||||
|
{
|
||||||
|
void Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class FrameCacheContainer<T> : IFrameCache
|
||||||
|
{
|
||||||
|
private readonly Dictionary<(int, int), T> _caches = new Dictionary<(int, int), T>();
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
_caches.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryGet((int, int) key, out T result)
|
||||||
|
{
|
||||||
|
return _caches.TryGetValue(key, out result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Set((int, int) key, T result)
|
||||||
|
{
|
||||||
|
_caches[key] = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Runtime/Internal/Utilities/FrameCache.cs.meta
Normal file
11
Runtime/Internal/Utilities/FrameCache.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5f129e3b07ffb4d3bbb4cc5f6bd94087
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
254
Runtime/Internal/Utilities/Logging.cs
Normal file
254
Runtime/Internal/Utilities/Logging.cs
Normal file
@@ -0,0 +1,254 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
#if ENABLE_COFFEE_LOGGER
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
#else
|
||||||
|
using Conditional = System.Diagnostics.ConditionalAttribute;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Coffee.UIParticleInternal
|
||||||
|
{
|
||||||
|
internal static class Logging
|
||||||
|
{
|
||||||
|
#if !ENABLE_COFFEE_LOGGER
|
||||||
|
private const string k_DisableSymbol = "DISABLE_COFFEE_LOGGER";
|
||||||
|
|
||||||
|
[Conditional(k_DisableSymbol)]
|
||||||
|
#endif
|
||||||
|
private static void Log_Internal(LogType type, object tag, object message, Object context)
|
||||||
|
{
|
||||||
|
#if ENABLE_COFFEE_LOGGER
|
||||||
|
AppendTag(s_Sb, tag);
|
||||||
|
s_Sb.Append(message);
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case LogType.Error:
|
||||||
|
case LogType.Assert:
|
||||||
|
case LogType.Exception:
|
||||||
|
Debug.LogError(s_Sb, context);
|
||||||
|
break;
|
||||||
|
case LogType.Warning:
|
||||||
|
Debug.LogWarning(s_Sb, context);
|
||||||
|
break;
|
||||||
|
case LogType.Log:
|
||||||
|
Debug.Log(s_Sb, context);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
s_Sb.Length = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !ENABLE_COFFEE_LOGGER
|
||||||
|
[Conditional(k_DisableSymbol)]
|
||||||
|
#endif
|
||||||
|
public static void LogIf(bool enable, object tag, object message, Object context = null)
|
||||||
|
{
|
||||||
|
if (!enable) return;
|
||||||
|
Log_Internal(LogType.Log, tag, message, context ? context : tag as Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !ENABLE_COFFEE_LOGGER
|
||||||
|
[Conditional(k_DisableSymbol)]
|
||||||
|
#endif
|
||||||
|
public static void Log(object tag, object message, Object context = null)
|
||||||
|
{
|
||||||
|
Log_Internal(LogType.Log, tag, message, context ? context : tag as Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !ENABLE_COFFEE_LOGGER
|
||||||
|
[Conditional(k_DisableSymbol)]
|
||||||
|
#endif
|
||||||
|
public static void LogWarning(object tag, object message, Object context = null)
|
||||||
|
{
|
||||||
|
Log_Internal(LogType.Warning, tag, message, context ? context : tag as Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void LogError(object tag, object message, Object context = null)
|
||||||
|
{
|
||||||
|
#if ENABLE_COFFEE_LOGGER
|
||||||
|
Log_Internal(LogType.Error, tag, message, context ? context : tag as Object);
|
||||||
|
#else
|
||||||
|
Debug.LogError($"{tag}: {message}", context);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !ENABLE_COFFEE_LOGGER
|
||||||
|
[Conditional(k_DisableSymbol)]
|
||||||
|
#endif
|
||||||
|
public static void LogMulticast(Type type, string fieldName, object instance = null, string message = null)
|
||||||
|
{
|
||||||
|
#if ENABLE_COFFEE_LOGGER
|
||||||
|
AppendTag(s_Sb, instance ?? type);
|
||||||
|
|
||||||
|
var handler = type
|
||||||
|
.GetField(fieldName,
|
||||||
|
BindingFlags.Static | BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic)
|
||||||
|
?.GetValue(instance);
|
||||||
|
|
||||||
|
var list = ((MulticastDelegate)handler)?.GetInvocationList() ?? Array.Empty<Delegate>();
|
||||||
|
s_Sb.Append("<color=orange>");
|
||||||
|
s_Sb.Append(type.Name);
|
||||||
|
s_Sb.Append(".");
|
||||||
|
s_Sb.Append(fieldName);
|
||||||
|
s_Sb.Append(" has ");
|
||||||
|
s_Sb.Append(list.Length);
|
||||||
|
s_Sb.Append(" callbacks");
|
||||||
|
if (message != null)
|
||||||
|
{
|
||||||
|
s_Sb.Append(" (");
|
||||||
|
s_Sb.Append(message);
|
||||||
|
s_Sb.Append(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
s_Sb.Append(":</color>");
|
||||||
|
|
||||||
|
for (var i = 0; i < list.Length; i++)
|
||||||
|
{
|
||||||
|
s_Sb.Append("\n - ");
|
||||||
|
s_Sb.Append(list[i].Method.DeclaringType?.Name);
|
||||||
|
s_Sb.Append(".");
|
||||||
|
s_Sb.Append(list[i].Method.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.Log(s_Sb);
|
||||||
|
s_Sb.Length = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !ENABLE_COFFEE_LOGGER
|
||||||
|
[Conditional(k_DisableSymbol)]
|
||||||
|
#endif
|
||||||
|
private static void AppendTag(StringBuilder sb, object tag)
|
||||||
|
{
|
||||||
|
#if ENABLE_COFFEE_LOGGER
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sb.Append("f");
|
||||||
|
sb.Append(Time.frameCount);
|
||||||
|
sb.Append(":<color=#");
|
||||||
|
AppendReadableCode(sb, tag);
|
||||||
|
sb.Append("><b>[");
|
||||||
|
|
||||||
|
switch (tag)
|
||||||
|
{
|
||||||
|
case string name:
|
||||||
|
sb.Append(name);
|
||||||
|
break;
|
||||||
|
case Type type:
|
||||||
|
AppendType(sb, type);
|
||||||
|
break;
|
||||||
|
case Object uObject:
|
||||||
|
AppendType(sb, tag.GetType());
|
||||||
|
sb.Append(" #");
|
||||||
|
sb.Append(uObject.name);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
AppendType(sb, tag.GetType());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append("]</b></color> ");
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
sb.Append("f");
|
||||||
|
sb.Append(Time.frameCount);
|
||||||
|
sb.Append(":<b>[");
|
||||||
|
sb.Append(tag);
|
||||||
|
sb.Append("]</b> ");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !ENABLE_COFFEE_LOGGER
|
||||||
|
[Conditional(k_DisableSymbol)]
|
||||||
|
#endif
|
||||||
|
private static void AppendType(StringBuilder sb, Type type)
|
||||||
|
{
|
||||||
|
#if ENABLE_COFFEE_LOGGER
|
||||||
|
if (s_TypeNameCache.TryGetValue(type, out var name))
|
||||||
|
{
|
||||||
|
sb.Append(name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// New type found
|
||||||
|
var start = sb.Length;
|
||||||
|
if (0 < start && sb[start - 1] == '<' && (type.Name == "Material" || type.Name == "Color"))
|
||||||
|
{
|
||||||
|
sb.Append('@');
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append(type.Name);
|
||||||
|
if (type.IsGenericType)
|
||||||
|
{
|
||||||
|
sb.Length -= 2;
|
||||||
|
sb.Append("<");
|
||||||
|
foreach (var gType in type.GetGenericArguments())
|
||||||
|
{
|
||||||
|
AppendType(sb, gType);
|
||||||
|
sb.Append(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Length -= 2;
|
||||||
|
sb.Append(">");
|
||||||
|
}
|
||||||
|
|
||||||
|
s_TypeNameCache.Add(type, sb.ToString(start, sb.Length - start));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !ENABLE_COFFEE_LOGGER
|
||||||
|
[Conditional(k_DisableSymbol)]
|
||||||
|
#endif
|
||||||
|
private static void AppendReadableCode(StringBuilder sb, object tag)
|
||||||
|
{
|
||||||
|
#if ENABLE_COFFEE_LOGGER
|
||||||
|
int hash;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
switch (tag)
|
||||||
|
{
|
||||||
|
case string text:
|
||||||
|
hash = text.GetHashCode();
|
||||||
|
break;
|
||||||
|
case Type type:
|
||||||
|
type = type.IsGenericType ? type.GetGenericTypeDefinition() : type;
|
||||||
|
hash = type.FullName?.GetHashCode() ?? 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
hash = tag.GetType().FullName?.GetHashCode() ?? 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
sb.Append("FFFFFF");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
hash = hash & (s_Codes.Length - 1);
|
||||||
|
if (s_Codes[hash] == null)
|
||||||
|
{
|
||||||
|
var hue = hash / (float)s_Codes.Length;
|
||||||
|
var modifier = 1f - Mathf.Clamp01(Mathf.Abs(hue - 0.65f) / 0.2f);
|
||||||
|
var saturation = 0.7f + modifier * -0.2f;
|
||||||
|
var value = 0.8f + modifier * 0.3f;
|
||||||
|
s_Codes[hash] = ColorUtility.ToHtmlStringRGB(Color.HSVToRGB(hue, saturation, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append(s_Codes[hash]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if ENABLE_COFFEE_LOGGER
|
||||||
|
private static readonly StringBuilder s_Sb = new StringBuilder();
|
||||||
|
private static readonly string[] s_Codes = new string[64];
|
||||||
|
private static readonly Dictionary<Type, string> s_TypeNameCache = new Dictionary<Type, string>();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Runtime/Internal/Utilities/Logging.cs.meta
Normal file
11
Runtime/Internal/Utilities/Logging.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8255313895da84e7cbdc876be3795334
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
92
Runtime/Internal/Utilities/MaterialRepository.cs
Normal file
92
Runtime/Internal/Utilities/MaterialRepository.cs
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Profiling;
|
||||||
|
|
||||||
|
namespace Coffee.UIParticleInternal
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides functionality to manage materials.
|
||||||
|
/// </summary>
|
||||||
|
internal static class MaterialRepository
|
||||||
|
{
|
||||||
|
private static readonly ObjectRepository<Material> s_Repository = new ObjectRepository<Material>();
|
||||||
|
|
||||||
|
public static int count => s_Repository.count;
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||||
|
private static void Clear()
|
||||||
|
{
|
||||||
|
s_Repository.Clear();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves a cached material based on the hash.
|
||||||
|
/// </summary>
|
||||||
|
public static bool Valid(Hash128 hash, Material material)
|
||||||
|
{
|
||||||
|
Profiler.BeginSample("(COF)[MaterialRegistry] Valid");
|
||||||
|
var ret = s_Repository.Valid(hash, material);
|
||||||
|
Profiler.EndSample();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds or retrieves a cached material based on the hash.
|
||||||
|
/// </summary>
|
||||||
|
public static void Get(Hash128 hash, ref Material material, Func<Material> onCreate)
|
||||||
|
{
|
||||||
|
Profiler.BeginSample("(COF)[MaterialRepository] Get");
|
||||||
|
s_Repository.Get(hash, ref material, onCreate);
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds or retrieves a cached material based on the hash.
|
||||||
|
/// </summary>
|
||||||
|
public static void Get(Hash128 hash, ref Material material, string shaderName)
|
||||||
|
{
|
||||||
|
Profiler.BeginSample("(COF)[MaterialRepository] Get");
|
||||||
|
s_Repository.Get(hash, ref material, x => new Material(Shader.Find(x))
|
||||||
|
{
|
||||||
|
hideFlags = HideFlags.DontSave | HideFlags.NotEditable
|
||||||
|
}, shaderName);
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds or retrieves a cached material based on the hash.
|
||||||
|
/// </summary>
|
||||||
|
public static void Get(Hash128 hash, ref Material material, string shaderName, string[] keywords)
|
||||||
|
{
|
||||||
|
Profiler.BeginSample("(COF)[MaterialRepository] Get");
|
||||||
|
s_Repository.Get(hash, ref material, x => new Material(Shader.Find(x.shaderName))
|
||||||
|
{
|
||||||
|
hideFlags = HideFlags.DontSave | HideFlags.NotEditable,
|
||||||
|
shaderKeywords = x.keywords
|
||||||
|
}, (shaderName, keywords));
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds or retrieves a cached material based on the hash.
|
||||||
|
/// </summary>
|
||||||
|
public static void Get<T>(Hash128 hash, ref Material material, Func<T, Material> onCreate, T source)
|
||||||
|
{
|
||||||
|
Profiler.BeginSample("(COF)[MaterialRepository] Get");
|
||||||
|
s_Repository.Get(hash, ref material, onCreate, source);
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a soft mask material from the cache.
|
||||||
|
/// </summary>
|
||||||
|
public static void Release(ref Material material)
|
||||||
|
{
|
||||||
|
Profiler.BeginSample("(COF)[MaterialRepository] Release");
|
||||||
|
s_Repository.Release(ref material);
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Runtime/Internal/Utilities/MaterialRepository.cs.meta
Normal file
11
Runtime/Internal/Utilities/MaterialRepository.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 702912f2ee2ec49bb8003a64151ae4f7
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
85
Runtime/Internal/Utilities/ObjectPool.cs
Normal file
85
Runtime/Internal/Utilities/ObjectPool.cs
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Coffee.UIParticleInternal
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Object pool.
|
||||||
|
/// </summary>
|
||||||
|
internal class ObjectPool<T>
|
||||||
|
{
|
||||||
|
private readonly Func<T> _onCreate; // Delegate for creating instances
|
||||||
|
private readonly Action<T> _onReturn; // Delegate for returning instances to the pool
|
||||||
|
private readonly Predicate<T> _onValid; // Delegate for checking if instances are valid
|
||||||
|
private readonly Stack<T> _pool = new Stack<T>(32); // Object pool
|
||||||
|
private int _count; // Total count of created instances
|
||||||
|
|
||||||
|
public ObjectPool(Func<T> onCreate, Predicate<T> onValid, Action<T> onReturn)
|
||||||
|
{
|
||||||
|
_onCreate = onCreate;
|
||||||
|
_onValid = onValid;
|
||||||
|
_onReturn = onReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rent an instance from the pool.
|
||||||
|
/// When you no longer need it, return it with <see cref="Return" />.
|
||||||
|
/// </summary>
|
||||||
|
public T Rent()
|
||||||
|
{
|
||||||
|
while (0 < _pool.Count)
|
||||||
|
{
|
||||||
|
var instance = _pool.Pop();
|
||||||
|
if (_onValid(instance))
|
||||||
|
{
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are no instances in the pool, create a new one.
|
||||||
|
Logging.Log(this, $"A new instance is created (pooled: {_pool.Count}, created: {++_count}).");
|
||||||
|
return _onCreate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return an instance to the pool and assign null.
|
||||||
|
/// Be sure to return the instance obtained with <see cref="Rent" /> with this method.
|
||||||
|
/// </summary>
|
||||||
|
public void Return(ref T instance)
|
||||||
|
{
|
||||||
|
if (instance == null || _pool.Contains(instance)) return; // Ignore if already pooled or null.
|
||||||
|
|
||||||
|
_onReturn(instance); // Return the instance to the pool.
|
||||||
|
_pool.Push(instance);
|
||||||
|
Logging.Log(this, $"An instance is released (pooled: {_pool.Count}, created: {_count}).");
|
||||||
|
instance = default; // Set the reference to null.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Object pool for <see cref="List{T}" />.
|
||||||
|
/// </summary>
|
||||||
|
internal static class ListPool<T>
|
||||||
|
{
|
||||||
|
private static readonly ObjectPool<List<T>> s_ListPool =
|
||||||
|
new ObjectPool<List<T>>(() => new List<T>(), _ => true, x => x.Clear());
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rent an instance from the pool.
|
||||||
|
/// When you no longer need it, return it with <see cref="Return" />.
|
||||||
|
/// </summary>
|
||||||
|
public static List<T> Rent()
|
||||||
|
{
|
||||||
|
return s_ListPool.Rent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return an instance to the pool and assign null.
|
||||||
|
/// Be sure to return the instance obtained with <see cref="Rent" /> with this method.
|
||||||
|
/// </summary>
|
||||||
|
public static void Return(ref List<T> toRelease)
|
||||||
|
{
|
||||||
|
s_ListPool.Return(ref toRelease);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Runtime/Internal/Utilities/ObjectPool.cs.meta
Normal file
11
Runtime/Internal/Utilities/ObjectPool.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 632cb1ba34e6a4e80b55a32bb63ca369
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
209
Runtime/Internal/Utilities/ObjectRepository.cs
Normal file
209
Runtime/Internal/Utilities/ObjectRepository.cs
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Profiling;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
|
namespace Coffee.UIParticleInternal
|
||||||
|
{
|
||||||
|
internal class ObjectRepository<T> where T : Object
|
||||||
|
{
|
||||||
|
private readonly Dictionary<Hash128, Entry> _cache = new Dictionary<Hash128, Entry>(8);
|
||||||
|
private readonly Dictionary<int, Hash128> _objectKey = new Dictionary<int, Hash128>(8);
|
||||||
|
private readonly string _name;
|
||||||
|
private readonly Action<T> _onRelease;
|
||||||
|
private readonly Stack<Entry> _pool = new Stack<Entry>(8);
|
||||||
|
|
||||||
|
public ObjectRepository(Action<T> onRelease = null)
|
||||||
|
{
|
||||||
|
_name = $"{typeof(T).Name}Repository";
|
||||||
|
if (onRelease == null)
|
||||||
|
{
|
||||||
|
_onRelease = x =>
|
||||||
|
{
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if (!Application.isPlaying)
|
||||||
|
{
|
||||||
|
Object.DestroyImmediate(x, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
Object.Destroy(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_onRelease = onRelease;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
_pool.Push(new Entry());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int count => _cache.Count;
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
foreach (var kv in _cache)
|
||||||
|
{
|
||||||
|
var entry = kv.Value;
|
||||||
|
if (entry == null) continue;
|
||||||
|
|
||||||
|
entry.Release(_onRelease);
|
||||||
|
_pool.Push(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
_cache.Clear();
|
||||||
|
_objectKey.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Valid(Hash128 hash, T obj)
|
||||||
|
{
|
||||||
|
return _cache.TryGetValue(hash, out var entry) && entry.storedObject == obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds or retrieves a cached object based on the hash.
|
||||||
|
/// </summary>
|
||||||
|
public void Get(Hash128 hash, ref T obj, Func<T> onCreate)
|
||||||
|
{
|
||||||
|
if (GetFromCache(hash, ref obj)) return;
|
||||||
|
Add(hash, ref obj, onCreate());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds or retrieves a cached object based on the hash.
|
||||||
|
/// </summary>
|
||||||
|
public void Get<TS>(Hash128 hash, ref T obj, Func<TS, T> onCreate, TS source)
|
||||||
|
{
|
||||||
|
if (GetFromCache(hash, ref obj)) return;
|
||||||
|
Add(hash, ref obj, onCreate(source));
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool GetFromCache(Hash128 hash, ref T obj)
|
||||||
|
{
|
||||||
|
// Find existing entry.
|
||||||
|
Profiler.BeginSample("(COF)[ObjectRepository] GetFromCache");
|
||||||
|
if (_cache.TryGetValue(hash, out var entry))
|
||||||
|
{
|
||||||
|
if (!entry.storedObject)
|
||||||
|
{
|
||||||
|
Release(ref entry.storedObject);
|
||||||
|
Profiler.EndSample();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entry.storedObject != obj)
|
||||||
|
{
|
||||||
|
// if the object is different, release the old one.
|
||||||
|
Release(ref obj);
|
||||||
|
++entry.reference;
|
||||||
|
obj = entry.storedObject;
|
||||||
|
Logging.Log(_name, $"Get(total#{count}): {entry}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Profiler.EndSample();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Profiler.EndSample();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Add(Hash128 hash, ref T obj, T newObject)
|
||||||
|
{
|
||||||
|
if (!newObject)
|
||||||
|
{
|
||||||
|
Release(ref obj);
|
||||||
|
obj = newObject;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create and add a new entry.
|
||||||
|
Profiler.BeginSample("(COF)[ObjectRepository] Add");
|
||||||
|
var newEntry = 0 < _pool.Count ? _pool.Pop() : new Entry();
|
||||||
|
newEntry.storedObject = newObject;
|
||||||
|
newEntry.hash = hash;
|
||||||
|
newEntry.reference = 1;
|
||||||
|
_cache[hash] = newEntry;
|
||||||
|
_objectKey[newObject.GetInstanceID()] = hash;
|
||||||
|
Logging.Log(_name, $"<color=#03c700>Add</color>(total#{count}): {newEntry}");
|
||||||
|
Release(ref obj);
|
||||||
|
obj = newObject;
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Release a object.
|
||||||
|
/// </summary>
|
||||||
|
public void Release(ref T obj)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(obj, null)) return;
|
||||||
|
|
||||||
|
// Find and release the entry.
|
||||||
|
Profiler.BeginSample("(COF)[ObjectRepository] Release");
|
||||||
|
var id = obj.GetInstanceID();
|
||||||
|
if (_objectKey.TryGetValue(id, out var hash)
|
||||||
|
&& _cache.TryGetValue(hash, out var entry))
|
||||||
|
{
|
||||||
|
entry.reference--;
|
||||||
|
if (entry.reference <= 0 || !entry.storedObject)
|
||||||
|
{
|
||||||
|
Remove(entry);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logging.Log(_name, $"Release(total#{_cache.Count}): {entry}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logging.Log(_name, $"Release(total#{_cache.Count}): <color=red>Already released: {obj}</color>");
|
||||||
|
}
|
||||||
|
|
||||||
|
obj = null;
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Remove(Entry entry)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(entry, null)) return;
|
||||||
|
|
||||||
|
Profiler.BeginSample("(COF)[ObjectRepository] Remove");
|
||||||
|
_cache.Remove(entry.hash);
|
||||||
|
_objectKey.Remove(entry.storedObject.GetInstanceID());
|
||||||
|
_pool.Push(entry);
|
||||||
|
entry.reference = 0;
|
||||||
|
Logging.Log(_name, $"<color=#f29e03>Remove</color>(total#{_cache.Count}): {entry}");
|
||||||
|
entry.Release(_onRelease);
|
||||||
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Entry
|
||||||
|
{
|
||||||
|
public Hash128 hash;
|
||||||
|
public int reference;
|
||||||
|
public T storedObject;
|
||||||
|
|
||||||
|
public void Release(Action<T> onRelease)
|
||||||
|
{
|
||||||
|
reference = 0;
|
||||||
|
if (storedObject)
|
||||||
|
{
|
||||||
|
onRelease?.Invoke(storedObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
storedObject = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"h{(uint)hash.GetHashCode()} (refs#{reference}), {storedObject}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Runtime/Internal/Utilities/ObjectRepository.cs.meta
Normal file
11
Runtime/Internal/Utilities/ObjectRepository.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a713d67bdb31e45e296e5f18460717e2
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
93
Runtime/Internal/Utilities/UIExtraCallbacks.cs
Executable file
93
Runtime/Internal/Utilities/UIExtraCallbacks.cs
Executable file
@@ -0,0 +1,93 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace Coffee.UIParticleInternal
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides additional callbacks related to canvas and UI system.
|
||||||
|
/// </summary>
|
||||||
|
internal static class UIExtraCallbacks
|
||||||
|
{
|
||||||
|
private static bool s_IsInitializedAfterCanvasRebuild;
|
||||||
|
private static readonly FastAction s_AfterCanvasRebuildAction = new FastAction();
|
||||||
|
private static readonly FastAction s_LateAfterCanvasRebuildAction = new FastAction();
|
||||||
|
private static readonly FastAction s_BeforeCanvasRebuildAction = new FastAction();
|
||||||
|
|
||||||
|
static UIExtraCallbacks()
|
||||||
|
{
|
||||||
|
Canvas.willRenderCanvases += OnBeforeCanvasRebuild;
|
||||||
|
Logging.LogMulticast(typeof(Canvas), "willRenderCanvases", message: "ctor");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that occurs after canvas rebuilds.
|
||||||
|
/// </summary>
|
||||||
|
public static event Action onLateAfterCanvasRebuild
|
||||||
|
{
|
||||||
|
add => s_LateAfterCanvasRebuildAction.Add(value);
|
||||||
|
remove => s_LateAfterCanvasRebuildAction.Remove(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that occurs before canvas rebuilds.
|
||||||
|
/// </summary>
|
||||||
|
public static event Action onBeforeCanvasRebuild
|
||||||
|
{
|
||||||
|
add => s_BeforeCanvasRebuildAction.Add(value);
|
||||||
|
remove => s_BeforeCanvasRebuildAction.Remove(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that occurs after canvas rebuilds.
|
||||||
|
/// </summary>
|
||||||
|
public static event Action onAfterCanvasRebuild
|
||||||
|
{
|
||||||
|
add => s_AfterCanvasRebuildAction.Add(value);
|
||||||
|
remove => s_AfterCanvasRebuildAction.Remove(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the UIExtraCallbacks to ensure proper event handling.
|
||||||
|
/// </summary>
|
||||||
|
private static void InitializeAfterCanvasRebuild()
|
||||||
|
{
|
||||||
|
if (s_IsInitializedAfterCanvasRebuild) return;
|
||||||
|
s_IsInitializedAfterCanvasRebuild = true;
|
||||||
|
|
||||||
|
CanvasUpdateRegistry.IsRebuildingLayout();
|
||||||
|
Canvas.willRenderCanvases += OnAfterCanvasRebuild;
|
||||||
|
Logging.LogMulticast(typeof(Canvas), "willRenderCanvases",
|
||||||
|
message: "InitializeAfterCanvasRebuild");
|
||||||
|
}
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
[InitializeOnLoadMethod]
|
||||||
|
#endif
|
||||||
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||||
|
private static void InitializeOnLoad()
|
||||||
|
{
|
||||||
|
Canvas.willRenderCanvases -= OnAfterCanvasRebuild;
|
||||||
|
s_IsInitializedAfterCanvasRebuild = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Callback method called before canvas rebuilds.
|
||||||
|
/// </summary>
|
||||||
|
private static void OnBeforeCanvasRebuild()
|
||||||
|
{
|
||||||
|
s_BeforeCanvasRebuildAction.Invoke();
|
||||||
|
InitializeAfterCanvasRebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Callback method called after canvas rebuilds.
|
||||||
|
/// </summary>
|
||||||
|
private static void OnAfterCanvasRebuild()
|
||||||
|
{
|
||||||
|
s_AfterCanvasRebuildAction.Invoke();
|
||||||
|
s_LateAfterCanvasRebuildAction.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Runtime/Internal/Utilities/UIExtraCallbacks.cs.meta
Normal file
11
Runtime/Internal/Utilities/UIExtraCallbacks.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9ea318e6e3e6c46aa97c72e28230bdc9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Coffee.UIParticleExtensions
|
|
||||||
{
|
|
||||||
internal class ModifiedMaterial
|
|
||||||
{
|
|
||||||
private static readonly List<MatEntry> s_Entries = new List<MatEntry>();
|
|
||||||
|
|
||||||
public static Material Add(Material baseMat, Texture texture, int id, int props)
|
|
||||||
{
|
|
||||||
MatEntry e;
|
|
||||||
for (var i = 0; i < s_Entries.Count; i++)
|
|
||||||
{
|
|
||||||
e = s_Entries[i];
|
|
||||||
if (e.baseMat != baseMat || e.texture != texture || e.id != id || e.props != props) continue;
|
|
||||||
++e.count;
|
|
||||||
return e.customMat;
|
|
||||||
}
|
|
||||||
|
|
||||||
e = new MatEntry
|
|
||||||
{
|
|
||||||
count = 1,
|
|
||||||
baseMat = baseMat,
|
|
||||||
texture = texture,
|
|
||||||
id = id,
|
|
||||||
props = props,
|
|
||||||
customMat = new Material(baseMat)
|
|
||||||
{
|
|
||||||
name = $"{baseMat.name}_{id}",
|
|
||||||
hideFlags = HideFlags.DontSave | HideFlags.NotEditable,
|
|
||||||
mainTexture = texture ? texture : baseMat.mainTexture
|
|
||||||
}
|
|
||||||
};
|
|
||||||
s_Entries.Add(e);
|
|
||||||
//Debug.LogFormat(">>>> ModifiedMaterial.Add -> count = count:{0}, mat:{1}, tex:{2}, id:{3}", s_Entries.Count, baseMat, texture, id);
|
|
||||||
return e.customMat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Remove(Material customMat)
|
|
||||||
{
|
|
||||||
if (!customMat) return;
|
|
||||||
|
|
||||||
for (var i = 0; i < s_Entries.Count; ++i)
|
|
||||||
{
|
|
||||||
var e = s_Entries[i];
|
|
||||||
if (e.customMat != customMat) continue;
|
|
||||||
if (--e.count == 0)
|
|
||||||
{
|
|
||||||
//Debug.LogFormat(">>>> ModifiedMaterial.Remove -> count:{0}, mat:{1}, tex:{2}, id:{3}", s_Entries.Count - 1, e.customMat, e.texture, e.id);
|
|
||||||
Misc.DestroyImmediate(e.customMat);
|
|
||||||
e.customMat = null;
|
|
||||||
e.baseMat = null;
|
|
||||||
e.texture = null;
|
|
||||||
s_Entries.RemoveAt(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MatEntry
|
|
||||||
{
|
|
||||||
public Material baseMat;
|
|
||||||
public int count;
|
|
||||||
public Material customMat;
|
|
||||||
public int id;
|
|
||||||
public int props;
|
|
||||||
public Texture texture;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using Coffee.UIParticleExtensions;
|
using Coffee.UIParticleInternal;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Rendering;
|
using UnityEngine.Rendering;
|
||||||
using UnityEngine.Serialization;
|
using UnityEngine.Serialization;
|
||||||
@@ -44,23 +44,26 @@ namespace Coffee.UIExtensions
|
|||||||
|
|
||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
|
[Obsolete]
|
||||||
internal bool m_IsTrail;
|
internal bool m_IsTrail;
|
||||||
|
|
||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
[FormerlySerializedAs("m_IgnoreParent")]
|
[FormerlySerializedAs("m_IgnoreParent")]
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
|
[Obsolete]
|
||||||
private bool m_IgnoreCanvasScaler;
|
private bool m_IgnoreCanvasScaler;
|
||||||
|
|
||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private bool m_AbsoluteMode;
|
[Obsolete]
|
||||||
|
internal bool m_AbsoluteMode;
|
||||||
|
|
||||||
[Tooltip("Particle effect scale")]
|
[Tooltip("Scale the rendering particles. When the `3D` toggle is enabled, 3D scale (x, y, z) is supported.")]
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private Vector3 m_Scale3D = new Vector3(10, 10, 10);
|
private Vector3 m_Scale3D = new Vector3(10, 10, 10);
|
||||||
|
|
||||||
[Tooltip("Animatable material properties.\n" +
|
[Tooltip("If you want to update material properties (e.g. _MainTex_ST, _Color) in AnimationClip, " +
|
||||||
"If you want to change the material properties of the ParticleSystem in Animation, enable it.")]
|
"use this to mark as animatable.")]
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
internal AnimatableProperty[] m_AnimatableProperties = new AnimatableProperty[0];
|
internal AnimatableProperty[] m_AnimatableProperties = new AnimatableProperty[0];
|
||||||
|
|
||||||
@@ -68,12 +71,13 @@ namespace Coffee.UIExtensions
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
private List<ParticleSystem> m_Particles = new List<ParticleSystem>();
|
private List<ParticleSystem> m_Particles = new List<ParticleSystem>();
|
||||||
|
|
||||||
[Tooltip("Mesh sharing.\n" +
|
[Tooltip("Particle simulation results are shared within the same group. " +
|
||||||
"None: disable mesh sharing.\n" +
|
"A large number of the same effects can be displayed with a small load.\n" +
|
||||||
"Auto: automatically select Primary/Replica.\n" +
|
"None: Disable mesh sharing.\n" +
|
||||||
"Primary: provides particle simulation results to the same group.\n" +
|
"Auto: Automatically select Primary/Replica.\n" +
|
||||||
|
"Primary: Provides particle simulation results to the same group.\n" +
|
||||||
"Primary Simulator: Primary, but do not render the particle (simulation only).\n" +
|
"Primary Simulator: Primary, but do not render the particle (simulation only).\n" +
|
||||||
"Replica: render simulation results provided by the primary.")]
|
"Replica: Render simulation results provided by the primary.")]
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private MeshSharing m_MeshSharing = MeshSharing.None;
|
private MeshSharing m_MeshSharing = MeshSharing.None;
|
||||||
|
|
||||||
@@ -85,26 +89,40 @@ namespace Coffee.UIExtensions
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
private int m_GroupMaxId;
|
private int m_GroupMaxId;
|
||||||
|
|
||||||
[Tooltip("Relative: The particles will be emitted from the scaled position of ParticleSystem.\n" +
|
[Tooltip("Emission position mode.\n" +
|
||||||
"Absolute: The particles will be emitted from the world position of ParticleSystem.")]
|
"Relative: The particles will be emitted from the scaled position.\n" +
|
||||||
|
"Absolute: The particles will be emitted from the world position.")]
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private PositionMode m_PositionMode = PositionMode.Relative;
|
private PositionMode m_PositionMode = PositionMode.Relative;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
[Tooltip("Prevent the root-Canvas scale from affecting the hierarchy-scaled ParticleSystem.")]
|
[Obsolete]
|
||||||
private bool m_AutoScaling = true;
|
internal bool m_AutoScaling;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
[Tooltip("Transform: Transform.lossyScale (=world scale) will be set to (1, 1, 1)." +
|
[Tooltip(
|
||||||
"UIParticle: UIParticle.scale will be adjusted.")]
|
"How to automatically adjust when the Canvas scale is changed by the screen size or reference resolution.\n" +
|
||||||
|
"None: Do nothing.\n" +
|
||||||
|
"Transform: Transform.lossyScale (=world scale) will be set to (1, 1, 1).\n" +
|
||||||
|
"UIParticle: UIParticle.scale will be adjusted.")]
|
||||||
private AutoScalingMode m_AutoScalingMode = AutoScalingMode.Transform;
|
private AutoScalingMode m_AutoScalingMode = AutoScalingMode.Transform;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
[Tooltip("Use a custom view.\n" +
|
||||||
|
"Use this if the particles are not displayed correctly due to min/max particle size.")]
|
||||||
|
private bool m_UseCustomView;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
[Tooltip("Custom view size.\n" +
|
||||||
|
"Change the bake view size.")]
|
||||||
|
private float m_CustomViewSize = 10;
|
||||||
|
|
||||||
private readonly List<UIParticleRenderer> _renderers = new List<UIParticleRenderer>();
|
private readonly List<UIParticleRenderer> _renderers = new List<UIParticleRenderer>();
|
||||||
private int _groupId;
|
|
||||||
private Camera _bakeCamera;
|
private Camera _bakeCamera;
|
||||||
private DrivenRectTransformTracker _tracker;
|
private int _groupId;
|
||||||
private Vector3 _storedScale;
|
|
||||||
private bool _isScaleStored;
|
private bool _isScaleStored;
|
||||||
|
private Vector3 _storedScale;
|
||||||
|
private DrivenRectTransformTracker _tracker;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Should this graphic be considered a target for ray-casting?
|
/// Should this graphic be considered a target for ray-casting?
|
||||||
@@ -116,7 +134,8 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Mesh sharing.
|
/// Particle simulation results are shared within the same group.
|
||||||
|
/// A large number of the same effects can be displayed with a small load.
|
||||||
/// None: disable mesh sharing.
|
/// None: disable mesh sharing.
|
||||||
/// Auto: automatically select Primary/Replica.
|
/// Auto: automatically select Primary/Replica.
|
||||||
/// Primary: provides particle simulation results to the same group.
|
/// Primary: provides particle simulation results to the same group.
|
||||||
@@ -159,9 +178,9 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Particle position mode.
|
/// Emission position mode.
|
||||||
/// Relative: The particles will be emitted from the scaled position of the ParticleSystem.
|
/// Relative: The particles will be emitted from the scaled position.
|
||||||
/// Absolute: The particles will be emitted from the world position of the ParticleSystem.
|
/// Absolute: The particles will be emitted from the world position.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PositionMode positionMode
|
public PositionMode positionMode
|
||||||
{
|
{
|
||||||
@@ -174,6 +193,7 @@ namespace Coffee.UIExtensions
|
|||||||
/// Relative: The particles will be emitted from the scaled position of the ParticleSystem.
|
/// Relative: The particles will be emitted from the scaled position of the ParticleSystem.
|
||||||
/// Absolute: The particles will be emitted from the world position of the ParticleSystem.
|
/// Absolute: The particles will be emitted from the world position of the ParticleSystem.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete("The absoluteMode is now obsolete. Please use the autoScalingMode instead.", false)]
|
||||||
public bool absoluteMode
|
public bool absoluteMode
|
||||||
{
|
{
|
||||||
get => m_PositionMode == PositionMode.Absolute;
|
get => m_PositionMode == PositionMode.Absolute;
|
||||||
@@ -191,8 +211,12 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Auto scaling mode.
|
/// How to automatically adjust when the Canvas scale is changed by the screen size or reference resolution.
|
||||||
|
/// <para/>
|
||||||
|
/// None: Do nothing.
|
||||||
|
/// <para/>
|
||||||
/// Transform: Transform.lossyScale (=world scale) will be set to (1, 1, 1).
|
/// Transform: Transform.lossyScale (=world scale) will be set to (1, 1, 1).
|
||||||
|
/// <para/>
|
||||||
/// UIParticle: UIParticle.scale will be adjusted.
|
/// UIParticle: UIParticle.scale will be adjusted.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AutoScalingMode autoScalingMode
|
public AutoScalingMode autoScalingMode
|
||||||
@@ -211,6 +235,26 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Use a custom view.
|
||||||
|
/// Use this if the particles are not displayed correctly due to min/max particle size.
|
||||||
|
/// </summary>
|
||||||
|
public bool useCustomView
|
||||||
|
{
|
||||||
|
get => m_UseCustomView;
|
||||||
|
set => m_UseCustomView = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Custom view size.
|
||||||
|
/// Change the bake view size.
|
||||||
|
/// </summary>
|
||||||
|
public float customViewSize
|
||||||
|
{
|
||||||
|
get => m_CustomViewSize;
|
||||||
|
set => m_CustomViewSize = Mathf.Max(0.1f, value);
|
||||||
|
}
|
||||||
|
|
||||||
internal bool useMeshSharing => m_MeshSharing != MeshSharing.None;
|
internal bool useMeshSharing => m_MeshSharing != MeshSharing.None;
|
||||||
|
|
||||||
internal bool isPrimary =>
|
internal bool isPrimary =>
|
||||||
@@ -256,24 +300,6 @@ namespace Coffee.UIExtensions
|
|||||||
|
|
||||||
public List<ParticleSystem> particles => m_Particles;
|
public List<ParticleSystem> particles => m_Particles;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get all base materials to render.
|
|
||||||
/// </summary>
|
|
||||||
public IEnumerable<Material> materials
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
for (var i = 0; i < _renderers.Count; i++)
|
|
||||||
{
|
|
||||||
var r = _renderers[i];
|
|
||||||
if (!r || !r.material) continue;
|
|
||||||
yield return r.material;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Material materialForRendering => null;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Paused.
|
/// Paused.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -334,6 +360,7 @@ namespace Coffee.UIExtensions
|
|||||||
|
|
||||||
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
||||||
{
|
{
|
||||||
|
#pragma warning disable CS0612 // Type or member is obsolete
|
||||||
if (m_IgnoreCanvasScaler || m_AutoScaling)
|
if (m_IgnoreCanvasScaler || m_AutoScaling)
|
||||||
{
|
{
|
||||||
m_IgnoreCanvasScaler = false;
|
m_IgnoreCanvasScaler = false;
|
||||||
@@ -346,31 +373,47 @@ namespace Coffee.UIExtensions
|
|||||||
m_AbsoluteMode = false;
|
m_AbsoluteMode = false;
|
||||||
m_PositionMode = PositionMode.Absolute;
|
m_PositionMode = PositionMode.Absolute;
|
||||||
}
|
}
|
||||||
|
#pragma warning restore CS0612 // Type or member is obsolete
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Play the ParticleSystems.
|
||||||
|
/// </summary>
|
||||||
public void Play()
|
public void Play()
|
||||||
{
|
{
|
||||||
particles.Exec(p => p.Simulate(0, false, true));
|
particles.Exec(p => p.Simulate(0, false, true));
|
||||||
isPaused = false;
|
isPaused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pause the ParticleSystems.
|
||||||
|
/// </summary>
|
||||||
public void Pause()
|
public void Pause()
|
||||||
{
|
{
|
||||||
particles.Exec(p => p.Pause());
|
particles.Exec(p => p.Pause());
|
||||||
isPaused = true;
|
isPaused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unpause the ParticleSystems.
|
||||||
|
/// </summary>
|
||||||
public void Resume()
|
public void Resume()
|
||||||
{
|
{
|
||||||
isPaused = false;
|
isPaused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stop the ParticleSystems.
|
||||||
|
/// </summary>
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
particles.Exec(p => p.Stop());
|
particles.Exec(p => p.Stop());
|
||||||
isPaused = true;
|
isPaused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Start emission of the ParticleSystems.
|
||||||
|
/// </summary>
|
||||||
public void StartEmission()
|
public void StartEmission()
|
||||||
{
|
{
|
||||||
particles.Exec(p =>
|
particles.Exec(p =>
|
||||||
@@ -380,6 +423,9 @@ namespace Coffee.UIExtensions
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stop emission of the ParticleSystems.
|
||||||
|
/// </summary>
|
||||||
public void StopEmission()
|
public void StopEmission()
|
||||||
{
|
{
|
||||||
particles.Exec(p =>
|
particles.Exec(p =>
|
||||||
@@ -389,24 +435,52 @@ namespace Coffee.UIExtensions
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clear the particles of the ParticleSystems.
|
||||||
|
/// </summary>
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
particles.Exec(p => p.Clear());
|
particles.Exec(p => p.Clear());
|
||||||
isPaused = true;
|
isPaused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get all base materials to render.
|
||||||
|
/// </summary>
|
||||||
|
public void GetMaterials(List<Material> result)
|
||||||
|
{
|
||||||
|
if (result == null) return;
|
||||||
|
|
||||||
|
for (var i = 0; i < _renderers.Count; i++)
|
||||||
|
{
|
||||||
|
var r = _renderers[i];
|
||||||
|
if (!r || !r.material) continue;
|
||||||
|
result.Add(r.material);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Refresh UIParticle using the ParticleSystem instance.
|
||||||
|
/// </summary>
|
||||||
public void SetParticleSystemInstance(GameObject instance)
|
public void SetParticleSystemInstance(GameObject instance)
|
||||||
{
|
{
|
||||||
SetParticleSystemInstance(instance, true);
|
SetParticleSystemInstance(instance, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Refresh UIParticle using the ParticleSystem instance.
|
||||||
|
/// </summary>
|
||||||
public void SetParticleSystemInstance(GameObject instance, bool destroyOldParticles)
|
public void SetParticleSystemInstance(GameObject instance, bool destroyOldParticles)
|
||||||
{
|
{
|
||||||
if (!instance) return;
|
if (!instance) return;
|
||||||
|
|
||||||
foreach (Transform child in transform)
|
var childCount = transform.childCount;
|
||||||
|
for (var i = 0; i < childCount; i++)
|
||||||
{
|
{
|
||||||
var go = child.gameObject;
|
var go = transform.GetChild(i).gameObject;
|
||||||
|
if (go.TryGetComponent<Camera>(out var cam) && cam == _bakeCamera) continue;
|
||||||
|
if (go.TryGetComponent<UIParticleRenderer>(out var _)) continue;
|
||||||
|
|
||||||
go.SetActive(false);
|
go.SetActive(false);
|
||||||
if (destroyOldParticles)
|
if (destroyOldParticles)
|
||||||
{
|
{
|
||||||
@@ -421,6 +495,10 @@ namespace Coffee.UIExtensions
|
|||||||
RefreshParticles(instance);
|
RefreshParticles(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Refresh UIParticle using the prefab.
|
||||||
|
/// The prefab is automatically instantiated.
|
||||||
|
/// </summary>
|
||||||
public void SetParticleSystemPrefab(GameObject prefab)
|
public void SetParticleSystemPrefab(GameObject prefab)
|
||||||
{
|
{
|
||||||
if (!prefab) return;
|
if (!prefab) return;
|
||||||
@@ -428,16 +506,31 @@ namespace Coffee.UIExtensions
|
|||||||
SetParticleSystemInstance(Instantiate(prefab.gameObject), true);
|
SetParticleSystemInstance(Instantiate(prefab.gameObject), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Refresh UIParticle.
|
||||||
|
/// Collect ParticleSystems under the GameObject and refresh the UIParticle.
|
||||||
|
/// </summary>
|
||||||
public void RefreshParticles()
|
public void RefreshParticles()
|
||||||
{
|
{
|
||||||
RefreshParticles(gameObject);
|
RefreshParticles(gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Refresh UIParticle.
|
||||||
|
/// Collect ParticleSystems under the GameObject and refresh the UIParticle.
|
||||||
|
/// </summary>
|
||||||
private void RefreshParticles(GameObject root)
|
private void RefreshParticles(GameObject root)
|
||||||
{
|
{
|
||||||
if (!root) return;
|
if (!root) return;
|
||||||
root.GetComponentsInChildren(true, particles);
|
root.GetComponentsInChildren(true, particles);
|
||||||
particles.RemoveAll(x => x.GetComponentInParent<UIParticle>(true) != this);
|
for (var i = particles.Count - 1; 0 <= i; i--)
|
||||||
|
{
|
||||||
|
var ps = particles[i];
|
||||||
|
if (!ps || ps.GetComponentInParent<UIParticle>(true) != this)
|
||||||
|
{
|
||||||
|
particles.RemoveAt(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 0; i < particles.Count; i++)
|
for (var i = 0; i < particles.Count; i++)
|
||||||
{
|
{
|
||||||
@@ -452,31 +545,39 @@ namespace Coffee.UIExtensions
|
|||||||
RefreshParticles(particles);
|
RefreshParticles(particles);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RefreshParticles(List<ParticleSystem> particles)
|
/// <summary>
|
||||||
|
/// Refresh UIParticle using a list of ParticleSystems.
|
||||||
|
/// </summary>
|
||||||
|
public void RefreshParticles(List<ParticleSystem> particleSystems)
|
||||||
{
|
{
|
||||||
|
// Collect children UIParticleRenderer components.
|
||||||
// #246: Nullptr exceptions when using nested UIParticle components in hierarchy
|
// #246: Nullptr exceptions when using nested UIParticle components in hierarchy
|
||||||
_renderers.Clear();
|
_renderers.Clear();
|
||||||
foreach (Transform child in transform)
|
var childCount = transform.childCount;
|
||||||
|
for (var i = 0; i < childCount; i++)
|
||||||
{
|
{
|
||||||
var uiParticleRenderer = child.GetComponent<UIParticleRenderer>();
|
var child = transform.GetChild(i);
|
||||||
|
if (child.TryGetComponent(out UIParticleRenderer uiParticleRenderer))
|
||||||
if (uiParticleRenderer != null)
|
|
||||||
{
|
{
|
||||||
_renderers.Add(uiParticleRenderer);
|
_renderers.Add(uiParticleRenderer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset the UIParticleRenderer components.
|
||||||
for (var i = 0; i < _renderers.Count; i++)
|
for (var i = 0; i < _renderers.Count; i++)
|
||||||
{
|
{
|
||||||
_renderers[i].Reset(i);
|
_renderers[i].Reset(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the ParticleSystem to the UIParticleRenderer. If the trail is enabled, set it additionally.
|
||||||
var j = 0;
|
var j = 0;
|
||||||
for (var i = 0; i < particles.Count; i++)
|
for (var i = 0; i < particleSystems.Count; i++)
|
||||||
{
|
{
|
||||||
var ps = particles[i];
|
var ps = particleSystems[i];
|
||||||
if (!ps) continue;
|
if (!ps) continue;
|
||||||
GetRenderer(j++).Set(this, ps, false);
|
GetRenderer(j++).Set(this, ps, false);
|
||||||
|
|
||||||
|
// If the trail is enabled, set it additionally.
|
||||||
if (ps.trails.enabled)
|
if (ps.trails.enabled)
|
||||||
{
|
{
|
||||||
GetRenderer(j++).Set(this, ps, true);
|
GetRenderer(j++).Set(this, ps, true);
|
||||||
@@ -501,8 +602,12 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
var currentScale = transform.localScale;
|
var currentScale = transform.localScale;
|
||||||
_storedScale = currentScale;
|
if (!_isScaleStored)
|
||||||
_isScaleStored = true;
|
{
|
||||||
|
_storedScale = currentScale.IsVisible() ? currentScale : Vector3.one;
|
||||||
|
_isScaleStored = true;
|
||||||
|
}
|
||||||
|
|
||||||
_tracker.Add(this, rectTransform, DrivenTransformProperties.Scale);
|
_tracker.Add(this, rectTransform, DrivenTransformProperties.Scale);
|
||||||
var newScale = parentScale.Inverse();
|
var newScale = parentScale.Inverse();
|
||||||
if (currentScale != newScale)
|
if (currentScale != newScale)
|
||||||
@@ -518,11 +623,10 @@ namespace Coffee.UIExtensions
|
|||||||
for (var i = 0; i < _renderers.Count; i++)
|
for (var i = 0; i < _renderers.Count; i++)
|
||||||
{
|
{
|
||||||
var r = _renderers[i];
|
var r = _renderers[i];
|
||||||
if (!r)
|
if (r) continue;
|
||||||
{
|
|
||||||
RefreshParticles(particles);
|
RefreshParticles(particles);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var bakeCamera = GetBakeCamera();
|
var bakeCamera = GetBakeCamera();
|
||||||
@@ -530,6 +634,7 @@ namespace Coffee.UIExtensions
|
|||||||
{
|
{
|
||||||
var r = _renderers[i];
|
var r = _renderers[i];
|
||||||
if (!r) continue;
|
if (!r) continue;
|
||||||
|
|
||||||
r.UpdateMesh(bakeCamera);
|
r.UpdateMesh(bakeCamera);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -581,7 +686,16 @@ namespace Coffee.UIExtensions
|
|||||||
private Camera GetBakeCamera()
|
private Camera GetBakeCamera()
|
||||||
{
|
{
|
||||||
if (!canvas) return Camera.main;
|
if (!canvas) return Camera.main;
|
||||||
if (_bakeCamera) return _bakeCamera;
|
if (!useCustomView && canvas.renderMode != RenderMode.ScreenSpaceOverlay && canvas.rootCanvas.worldCamera)
|
||||||
|
{
|
||||||
|
return canvas.rootCanvas.worldCamera;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_bakeCamera)
|
||||||
|
{
|
||||||
|
_bakeCamera.orthographicSize = useCustomView ? customViewSize : 10;
|
||||||
|
return _bakeCamera;
|
||||||
|
}
|
||||||
|
|
||||||
// Find existing baking camera.
|
// Find existing baking camera.
|
||||||
var childCount = transform.childCount;
|
var childCount = transform.childCount;
|
||||||
@@ -598,11 +712,7 @@ namespace Coffee.UIExtensions
|
|||||||
// Create baking camera.
|
// Create baking camera.
|
||||||
if (!_bakeCamera)
|
if (!_bakeCamera)
|
||||||
{
|
{
|
||||||
var go = new GameObject("[generated] UIParticle BakingCamera")
|
var go = new GameObject("[generated] UIParticle BakingCamera");
|
||||||
{
|
|
||||||
// hideFlags = HideFlags.HideAndDontSave
|
|
||||||
hideFlags = HideFlags.DontSave
|
|
||||||
};
|
|
||||||
go.SetActive(false);
|
go.SetActive(false);
|
||||||
go.transform.SetParent(transform, false);
|
go.transform.SetParent(transform, false);
|
||||||
_bakeCamera = go.AddComponent<Camera>();
|
_bakeCamera = go.AddComponent<Camera>();
|
||||||
@@ -610,7 +720,7 @@ namespace Coffee.UIExtensions
|
|||||||
|
|
||||||
// Setup baking camera.
|
// Setup baking camera.
|
||||||
_bakeCamera.enabled = false;
|
_bakeCamera.enabled = false;
|
||||||
_bakeCamera.orthographicSize = 1000;
|
_bakeCamera.orthographicSize = useCustomView ? customViewSize : 10;
|
||||||
_bakeCamera.transform.SetPositionAndRotation(new Vector3(0, 0, -1000), Quaternion.identity);
|
_bakeCamera.transform.SetPositionAndRotation(new Vector3(0, 0, -1000), Quaternion.identity);
|
||||||
_bakeCamera.orthographic = true;
|
_bakeCamera.orthographic = true;
|
||||||
_bakeCamera.farClipPlane = 2000f;
|
_bakeCamera.farClipPlane = 2000f;
|
||||||
@@ -621,6 +731,9 @@ namespace Coffee.UIExtensions
|
|||||||
_bakeCamera.renderingPath = RenderingPath.Forward;
|
_bakeCamera.renderingPath = RenderingPath.Forward;
|
||||||
_bakeCamera.useOcclusionCulling = false;
|
_bakeCamera.useOcclusionCulling = false;
|
||||||
|
|
||||||
|
_bakeCamera.gameObject.SetActive(false);
|
||||||
|
_bakeCamera.gameObject.hideFlags = UIParticleProjectSettings.globalHideFlags;
|
||||||
|
|
||||||
return _bakeCamera;
|
return _bakeCamera;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using Coffee.UIParticleExtensions;
|
using System.Collections.Generic;
|
||||||
|
using Coffee.UIParticleInternal;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
|
||||||
namespace Coffee.UIExtensions
|
namespace Coffee.UIExtensions
|
||||||
{
|
{
|
||||||
[ExecuteAlways]
|
[ExecuteAlways]
|
||||||
public class UIParticleAttractor : MonoBehaviour
|
public class UIParticleAttractor : MonoBehaviour, ISerializationCallbackReceiver
|
||||||
{
|
{
|
||||||
public enum Movement
|
public enum Movement
|
||||||
{
|
{
|
||||||
@@ -22,8 +23,12 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
|
[HideInInspector]
|
||||||
private ParticleSystem m_ParticleSystem;
|
private ParticleSystem m_ParticleSystem;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private List<ParticleSystem> m_ParticleSystems = new List<ParticleSystem>();
|
||||||
|
|
||||||
[Range(0.1f, 10f)]
|
[Range(0.1f, 10f)]
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private float m_DestinationRadius = 1;
|
private float m_DestinationRadius = 1;
|
||||||
@@ -45,7 +50,7 @@ namespace Coffee.UIExtensions
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
private UnityEvent m_OnAttracted;
|
private UnityEvent m_OnAttracted;
|
||||||
|
|
||||||
private UIParticle _uiParticle;
|
private List<UIParticle> _uiParticles = new List<UIParticle>();
|
||||||
|
|
||||||
public float destinationRadius
|
public float destinationRadius
|
||||||
{
|
{
|
||||||
@@ -84,25 +89,46 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The target ParticleSystem to attract.
|
/// The target ParticleSystems to attract. Use <see cref="AddParticleSystem"/> and
|
||||||
|
/// <see cref="RemoveParticleSystem"/> to modify the list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
#if UNITY_EDITOR
|
public IReadOnlyList<ParticleSystem> particleSystems => m_ParticleSystems;
|
||||||
public new ParticleSystem particleSystem
|
|
||||||
#else
|
public void AddParticleSystem(ParticleSystem ps)
|
||||||
public ParticleSystem particleSystem
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
get => m_ParticleSystem;
|
if (m_ParticleSystems == null)
|
||||||
set
|
|
||||||
{
|
{
|
||||||
m_ParticleSystem = value;
|
m_ParticleSystems = new List<ParticleSystem>();
|
||||||
ApplyParticleSystem();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var i = m_ParticleSystems.IndexOf(ps);
|
||||||
|
if (0 <= i) return; // Already added: skip
|
||||||
|
|
||||||
|
m_ParticleSystems.Add(ps);
|
||||||
|
_uiParticles.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveParticleSystem(ParticleSystem ps)
|
||||||
|
{
|
||||||
|
if (m_ParticleSystems == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var i = m_ParticleSystems.IndexOf(ps);
|
||||||
|
if (i < 0) return; // Not found. skip
|
||||||
|
|
||||||
|
m_ParticleSystems.RemoveAt(i);
|
||||||
|
_uiParticles.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
UpgradeIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
ApplyParticleSystem();
|
|
||||||
UIParticleUpdater.Register(this);
|
UIParticleUpdater.Register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,85 +139,96 @@ namespace Coffee.UIExtensions
|
|||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
_uiParticle = null;
|
_uiParticles = null;
|
||||||
m_ParticleSystem = null;
|
m_ParticleSystems = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Attract()
|
internal void Attract()
|
||||||
{
|
{
|
||||||
if (m_ParticleSystem == null) return;
|
// Collect UIParticle if needed (same size as m_ParticleSystems)
|
||||||
|
CollectUIParticlesIfNeeded();
|
||||||
|
|
||||||
var count = m_ParticleSystem.particleCount;
|
for (var particleIndex = 0; particleIndex < m_ParticleSystems.Count; particleIndex++)
|
||||||
if (count == 0) return;
|
|
||||||
|
|
||||||
var particles = ParticleSystemExtensions.GetParticleArray(count);
|
|
||||||
m_ParticleSystem.GetParticles(particles, count);
|
|
||||||
|
|
||||||
var dstPos = GetDestinationPosition();
|
|
||||||
for (var i = 0; i < count; i++)
|
|
||||||
{
|
{
|
||||||
// Attracted
|
var particleSystem = m_ParticleSystems[particleIndex];
|
||||||
var p = particles[i];
|
|
||||||
if (0f < p.remainingLifetime && Vector3.Distance(p.position, dstPos) < m_DestinationRadius)
|
|
||||||
{
|
|
||||||
p.remainingLifetime = 0f;
|
|
||||||
particles[i] = p;
|
|
||||||
|
|
||||||
if (m_OnAttracted != null)
|
// Skip: The ParticleSystem is not active
|
||||||
|
if (particleSystem == null || !particleSystem.gameObject.activeInHierarchy) continue;
|
||||||
|
|
||||||
|
// Skip: No active particles
|
||||||
|
var count = particleSystem.particleCount;
|
||||||
|
if (count == 0) continue;
|
||||||
|
|
||||||
|
var particles = ParticleSystemExtensions.GetParticleArray(count);
|
||||||
|
particleSystem.GetParticles(particles, count);
|
||||||
|
|
||||||
|
var uiParticle = _uiParticles[particleIndex];
|
||||||
|
var dstPos = GetDestinationPosition(uiParticle, particleSystem);
|
||||||
|
for (var i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
// Attracted
|
||||||
|
var p = particles[i];
|
||||||
|
if (0f < p.remainingLifetime && Vector3.Distance(p.position, dstPos) < m_DestinationRadius)
|
||||||
{
|
{
|
||||||
try
|
p.remainingLifetime = 0f;
|
||||||
|
particles[i] = p;
|
||||||
|
|
||||||
|
if (m_OnAttracted != null)
|
||||||
{
|
{
|
||||||
m_OnAttracted.Invoke();
|
try
|
||||||
}
|
{
|
||||||
catch (Exception e)
|
m_OnAttracted.Invoke();
|
||||||
{
|
}
|
||||||
Debug.LogException(e);
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
// Calc attracting time
|
||||||
|
var delayTime = p.startLifetime * m_DelayRate;
|
||||||
|
var duration = p.startLifetime - delayTime;
|
||||||
|
var time = Mathf.Max(0, p.startLifetime - p.remainingLifetime - delayTime);
|
||||||
|
|
||||||
|
// Delay
|
||||||
|
if (time <= 0) continue;
|
||||||
|
|
||||||
|
// Attract
|
||||||
|
p.position = GetAttractedPosition(p.position, dstPos, duration, time);
|
||||||
|
p.velocity *= 0.5f;
|
||||||
|
particles[i] = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calc attracting time
|
particleSystem.SetParticles(particles, count);
|
||||||
var delayTime = p.startLifetime * m_DelayRate;
|
|
||||||
var duration = p.startLifetime - delayTime;
|
|
||||||
var time = Mathf.Max(0, p.startLifetime - p.remainingLifetime - delayTime);
|
|
||||||
|
|
||||||
// Delay
|
|
||||||
if (time <= 0) continue;
|
|
||||||
|
|
||||||
// Attract
|
|
||||||
p.position = GetAttractedPosition(p.position, dstPos, duration, time);
|
|
||||||
p.velocity *= 0.5f;
|
|
||||||
particles[i] = p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ParticleSystem.SetParticles(particles, count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector3 GetDestinationPosition()
|
private Vector3 GetDestinationPosition(UIParticle uiParticle, ParticleSystem particleSystem)
|
||||||
{
|
{
|
||||||
var isUI = _uiParticle && _uiParticle.enabled;
|
var isUI = uiParticle && uiParticle.enabled;
|
||||||
var psPos = m_ParticleSystem.transform.position;
|
var psPos = particleSystem.transform.position;
|
||||||
var attractorPos = transform.position;
|
var attractorPos = transform.position;
|
||||||
var dstPos = attractorPos;
|
var dstPos = attractorPos;
|
||||||
var isLocalSpace = m_ParticleSystem.IsLocalSpace();
|
var isLocalSpace = particleSystem.IsLocalSpace();
|
||||||
|
|
||||||
if (isLocalSpace)
|
if (isLocalSpace)
|
||||||
{
|
{
|
||||||
dstPos = m_ParticleSystem.transform.InverseTransformPoint(dstPos);
|
dstPos = particleSystem.transform.InverseTransformPoint(dstPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isUI)
|
if (isUI)
|
||||||
{
|
{
|
||||||
var inverseScale = _uiParticle.parentScale.Inverse();
|
var inverseScale = uiParticle.parentScale.Inverse();
|
||||||
var scale3d = _uiParticle.scale3DForCalc;
|
var scale3d = uiParticle.scale3DForCalc;
|
||||||
dstPos = dstPos.GetScaled(inverseScale, scale3d.Inverse());
|
dstPos = dstPos.GetScaled(inverseScale, scale3d.Inverse());
|
||||||
|
|
||||||
// Relative mode
|
// Relative mode
|
||||||
if (_uiParticle.positionMode == UIParticle.PositionMode.Relative)
|
if (uiParticle.positionMode == UIParticle.PositionMode.Relative)
|
||||||
{
|
{
|
||||||
var diff = _uiParticle.transform.position - psPos;
|
var diff = uiParticle.transform.position - psPos;
|
||||||
diff.Scale(scale3d - inverseScale);
|
diff.Scale(scale3d - inverseScale);
|
||||||
diff.Scale(scale3d.Inverse());
|
diff.Scale(scale3d.Inverse());
|
||||||
dstPos += diff;
|
dstPos += diff;
|
||||||
@@ -237,25 +274,59 @@ namespace Coffee.UIExtensions
|
|||||||
return Vector3.MoveTowards(current, target, speed);
|
return Vector3.MoveTowards(current, target, speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyParticleSystem()
|
private void CollectUIParticlesIfNeeded()
|
||||||
{
|
{
|
||||||
_uiParticle = null;
|
if (m_ParticleSystems.Count == 0 || _uiParticles.Count != 0) return;
|
||||||
if (m_ParticleSystem == null)
|
|
||||||
{
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
if (Application.isPlaying)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
Debug.LogError("No particle system attached to particle attractor script", this);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
// Expand capacity
|
||||||
|
if (_uiParticles.Capacity < m_ParticleSystems.Capacity)
|
||||||
|
{
|
||||||
|
_uiParticles.Capacity = m_ParticleSystems.Capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
_uiParticle = m_ParticleSystem.GetComponentInParent<UIParticle>(true);
|
// Find UIParticle that controls the ParticleSystem
|
||||||
if (_uiParticle && !_uiParticle.particles.Contains(m_ParticleSystem))
|
for (var i = 0; i < m_ParticleSystems.Count; i++)
|
||||||
{
|
{
|
||||||
_uiParticle = null;
|
var ps = m_ParticleSystems[i];
|
||||||
|
if (ps == null)
|
||||||
|
{
|
||||||
|
_uiParticles.Add(null);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var uiParticle = ps.GetComponentInParent<UIParticle>(true);
|
||||||
|
_uiParticles.Add(uiParticle.particles.Contains(ps) ? uiParticle : null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
private void OnValidate()
|
||||||
|
{
|
||||||
|
_uiParticles.Clear();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
||||||
|
{
|
||||||
|
UpgradeIfNeeded();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpgradeIfNeeded()
|
||||||
|
{
|
||||||
|
// Multiple ParticleSystems support: from 'm_ParticleSystem' to 'm_ParticleSystems'
|
||||||
|
if (m_ParticleSystem != null)
|
||||||
|
{
|
||||||
|
if (!m_ParticleSystems.Contains(m_ParticleSystem))
|
||||||
|
{
|
||||||
|
m_ParticleSystems.Add(m_ParticleSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ParticleSystem = null;
|
||||||
|
Debug.Log($"Upgraded!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ MonoImporter:
|
|||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
defaultReferences: []
|
defaultReferences: []
|
||||||
executionOrder: 0
|
executionOrder: 0
|
||||||
icon: {instanceID: 0}
|
icon: {fileID: 2800000, guid: 5f0675613942149309588d556e33d990, type: 3}
|
||||||
userData:
|
userData:
|
||||||
assetBundleName:
|
assetBundleName:
|
||||||
assetBundleVariant:
|
assetBundleVariant:
|
||||||
|
|||||||
40
Runtime/UIParticleProjectSettings.cs
Normal file
40
Runtime/UIParticleProjectSettings.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#pragma warning disable CS0414
|
||||||
|
using Coffee.UIParticleInternal;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Coffee.UIExtensions
|
||||||
|
{
|
||||||
|
public class UIParticleProjectSettings : PreloadedProjectSettings<UIParticleProjectSettings>
|
||||||
|
{
|
||||||
|
[Header("Setting")]
|
||||||
|
[SerializeField]
|
||||||
|
internal bool m_EnableLinearToGamma = true;
|
||||||
|
|
||||||
|
public static bool enableLinearToGamma
|
||||||
|
{
|
||||||
|
get => instance.m_EnableLinearToGamma;
|
||||||
|
set => instance.m_EnableLinearToGamma = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Header("Editor")]
|
||||||
|
[Tooltip("Hide the automatically generated objects.\n" +
|
||||||
|
" - UIParticleRenderer\n" +
|
||||||
|
" - UIParticle BakingCamera")]
|
||||||
|
[SerializeField]
|
||||||
|
private bool m_HideGeneratedObjects = true;
|
||||||
|
|
||||||
|
public static HideFlags globalHideFlags => instance.m_HideGeneratedObjects
|
||||||
|
? HideFlags.DontSave | HideFlags.NotEditable | HideFlags.HideInHierarchy | HideFlags.HideInInspector
|
||||||
|
: HideFlags.DontSave | HideFlags.NotEditable;
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
[SettingsProvider]
|
||||||
|
private static SettingsProvider CreateSettingsProvider()
|
||||||
|
{
|
||||||
|
return new PreloadedProjectSettingsProvider("Project/UI/UI Particle");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Runtime/UIParticleProjectSettings.cs.meta
Normal file
11
Runtime/UIParticleProjectSettings.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f22a23b9d98e440478697f4adf30e61c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {fileID: 2800000, guid: 5f0675613942149309588d556e33d990, type: 3}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
#endif
|
#endif
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Coffee.UIParticleExtensions;
|
using Coffee.UIParticleInternal;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Profiling;
|
using UnityEngine.Profiling;
|
||||||
@@ -21,27 +21,24 @@ namespace Coffee.UIExtensions
|
|||||||
[AddComponentMenu("")]
|
[AddComponentMenu("")]
|
||||||
internal class UIParticleRenderer : MaskableGraphic
|
internal class UIParticleRenderer : MaskableGraphic
|
||||||
{
|
{
|
||||||
private static readonly List<Component> s_Components = new List<Component>();
|
|
||||||
private static readonly CombineInstance[] s_CombineInstances = { new CombineInstance() };
|
private static readonly CombineInstance[] s_CombineInstances = { new CombineInstance() };
|
||||||
private static readonly List<Material> s_Materials = new List<Material>(2);
|
private static readonly List<Material> s_Materials = new List<Material>(2);
|
||||||
private static MaterialPropertyBlock s_Mpb;
|
private static MaterialPropertyBlock s_Mpb;
|
||||||
private static readonly List<UIParticleRenderer> s_Renderers = new List<UIParticleRenderer>();
|
|
||||||
private static readonly List<Color32> s_Colors = new List<Color32>();
|
|
||||||
private static readonly Vector3[] s_Corners = new Vector3[4];
|
private static readonly Vector3[] s_Corners = new Vector3[4];
|
||||||
private Material _currentMaterialForRendering;
|
|
||||||
private bool _delay;
|
private bool _delay;
|
||||||
private int _index;
|
private int _index;
|
||||||
|
private bool _isPrevStored;
|
||||||
private bool _isTrail;
|
private bool _isTrail;
|
||||||
private Bounds _lastBounds;
|
private Bounds _lastBounds;
|
||||||
|
private Material _materialForRendering;
|
||||||
private Material _modifiedMaterial;
|
private Material _modifiedMaterial;
|
||||||
private UIParticle _parent;
|
private UIParticle _parent;
|
||||||
private ParticleSystem _particleSystem;
|
private ParticleSystem _particleSystem;
|
||||||
private float _prevCanvasScale;
|
private float _prevCanvasScale;
|
||||||
private Vector3 _prevPsPos;
|
private Vector3 _prevPsPos;
|
||||||
private Vector3 _prevScale;
|
private Vector3 _prevScale;
|
||||||
private bool _isPrevStored;
|
|
||||||
private Vector2Int _prevScreenSize;
|
private Vector2Int _prevScreenSize;
|
||||||
private bool _prewarm;
|
private bool _preWarm;
|
||||||
private ParticleSystemRenderer _renderer;
|
private ParticleSystemRenderer _renderer;
|
||||||
|
|
||||||
public override Texture mainTexture => _isTrail ? null : _particleSystem.GetTextureForSprite();
|
public override Texture mainTexture => _isTrail ? null : _particleSystem.GetTextureForSprite();
|
||||||
@@ -92,6 +89,19 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Material materialForRendering
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!_materialForRendering)
|
||||||
|
{
|
||||||
|
_materialForRendering = base.materialForRendering;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _materialForRendering;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Reset(int index = -1)
|
public void Reset(int index = -1)
|
||||||
{
|
{
|
||||||
if (_renderer)
|
if (_renderer)
|
||||||
@@ -111,16 +121,14 @@ namespace Coffee.UIExtensions
|
|||||||
if (this && isActiveAndEnabled)
|
if (this && isActiveAndEnabled)
|
||||||
{
|
{
|
||||||
material = null;
|
material = null;
|
||||||
workerMesh.Clear();
|
canvasRenderer.Clear();
|
||||||
canvasRenderer.SetMesh(workerMesh);
|
|
||||||
_lastBounds = new Bounds();
|
_lastBounds = new Bounds();
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ModifiedMaterial.Remove(_modifiedMaterial);
|
MaterialRepository.Release(ref _modifiedMaterial);
|
||||||
_modifiedMaterial = null;
|
_materialForRendering = null;
|
||||||
_currentMaterialForRendering = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +136,7 @@ namespace Coffee.UIExtensions
|
|||||||
{
|
{
|
||||||
base.OnEnable();
|
base.OnEnable();
|
||||||
|
|
||||||
|
hideFlags = UIParticleProjectSettings.globalHideFlags;
|
||||||
if (!s_CombineInstances[0].mesh)
|
if (!s_CombineInstances[0].mesh)
|
||||||
{
|
{
|
||||||
s_CombineInstances[0].mesh = new Mesh
|
s_CombineInstances[0].mesh = new Mesh
|
||||||
@@ -136,17 +145,14 @@ namespace Coffee.UIExtensions
|
|||||||
hideFlags = HideFlags.HideAndDontSave
|
hideFlags = HideFlags.HideAndDontSave
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentMaterialForRendering = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDisable()
|
protected override void OnDisable()
|
||||||
{
|
{
|
||||||
base.OnDisable();
|
base.OnDisable();
|
||||||
|
|
||||||
ModifiedMaterial.Remove(_modifiedMaterial);
|
MaterialRepository.Release(ref _modifiedMaterial);
|
||||||
_modifiedMaterial = null;
|
_materialForRendering = null;
|
||||||
_currentMaterialForRendering = null;
|
|
||||||
_isPrevStored = false;
|
_isPrevStored = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +161,7 @@ namespace Coffee.UIExtensions
|
|||||||
// Create renderer object.
|
// Create renderer object.
|
||||||
var go = new GameObject("[generated] UIParticleRenderer", typeof(UIParticleRenderer))
|
var go = new GameObject("[generated] UIParticleRenderer", typeof(UIParticleRenderer))
|
||||||
{
|
{
|
||||||
hideFlags = HideFlags.HideAndDontSave,
|
hideFlags = UIParticleProjectSettings.globalHideFlags,
|
||||||
layer = parent.gameObject.layer
|
layer = parent.gameObject.layer
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -179,12 +185,9 @@ namespace Coffee.UIExtensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override Material GetModifiedMaterial(Material baseMaterial)
|
public override Material GetModifiedMaterial(Material baseMaterial)
|
||||||
{
|
{
|
||||||
_currentMaterialForRendering = null;
|
|
||||||
|
|
||||||
if (!IsActive() || !_parent)
|
if (!IsActive() || !_parent)
|
||||||
{
|
{
|
||||||
ModifiedMaterial.Remove(_modifiedMaterial);
|
MaterialRepository.Release(ref _modifiedMaterial);
|
||||||
_modifiedMaterial = null;
|
|
||||||
return baseMaterial;
|
return baseMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,23 +197,30 @@ namespace Coffee.UIExtensions
|
|||||||
var texture = mainTexture;
|
var texture = mainTexture;
|
||||||
if (texture == null && _parent.m_AnimatableProperties.Length == 0)
|
if (texture == null && _parent.m_AnimatableProperties.Length == 0)
|
||||||
{
|
{
|
||||||
ModifiedMaterial.Remove(_modifiedMaterial);
|
MaterialRepository.Release(ref _modifiedMaterial);
|
||||||
_modifiedMaterial = null;
|
|
||||||
return modifiedMaterial;
|
return modifiedMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
var hash = new Hash128(
|
||||||
var id = _parent.m_AnimatableProperties.Length == 0 ? 0 : GetInstanceID();
|
modifiedMaterial ? (uint)modifiedMaterial.GetInstanceID() : 0,
|
||||||
|
texture ? (uint)texture.GetInstanceID() : 0,
|
||||||
|
0 < _parent.m_AnimatableProperties.Length ? (uint)GetInstanceID() : 0,
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
var props = EditorJsonUtility.ToJson(modifiedMaterial).GetHashCode();
|
(uint)EditorJsonUtility.ToJson(modifiedMaterial).GetHashCode()
|
||||||
#else
|
#else
|
||||||
var props = 0;
|
0
|
||||||
#endif
|
#endif
|
||||||
modifiedMaterial = ModifiedMaterial.Add(modifiedMaterial, texture, id, props);
|
);
|
||||||
ModifiedMaterial.Remove(_modifiedMaterial);
|
if (!MaterialRepository.Valid(hash, _modifiedMaterial))
|
||||||
_modifiedMaterial = modifiedMaterial;
|
{
|
||||||
|
MaterialRepository.Get(hash, ref _modifiedMaterial, x => new Material(x.mat)
|
||||||
|
{
|
||||||
|
hideFlags = HideFlags.HideAndDontSave,
|
||||||
|
mainTexture = x.texture ? x.texture : x.mat.mainTexture
|
||||||
|
}, (mat: modifiedMaterial, texture));
|
||||||
|
}
|
||||||
|
|
||||||
return modifiedMaterial;
|
return _modifiedMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Set(UIParticle parent, ParticleSystem ps, bool isTrail)
|
public void Set(UIParticle parent, ParticleSystem ps, bool isTrail)
|
||||||
@@ -221,20 +231,20 @@ namespace Coffee.UIExtensions
|
|||||||
gameObject.layer = parent.gameObject.layer;
|
gameObject.layer = parent.gameObject.layer;
|
||||||
|
|
||||||
_particleSystem = ps;
|
_particleSystem = ps;
|
||||||
_prewarm = _particleSystem.main.prewarm;
|
_preWarm = _particleSystem.main.prewarm;
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if (Application.isPlaying)
|
if (Application.isPlaying)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (_particleSystem.isPlaying || _prewarm)
|
if (_particleSystem.isPlaying || _preWarm)
|
||||||
{
|
{
|
||||||
_particleSystem.Clear();
|
_particleSystem.Clear();
|
||||||
_particleSystem.Pause();
|
_particleSystem.Pause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_renderer = ps.GetComponent<ParticleSystemRenderer>();
|
ps.TryGetComponent(out _renderer);
|
||||||
_renderer.enabled = false;
|
_renderer.enabled = false;
|
||||||
|
|
||||||
//_emitter = emitter;
|
//_emitter = emitter;
|
||||||
@@ -406,95 +416,67 @@ namespace Coffee.UIExtensions
|
|||||||
_lastBounds = bounds;
|
_lastBounds = bounds;
|
||||||
|
|
||||||
// Convert linear color to gamma color.
|
// Convert linear color to gamma color.
|
||||||
if (QualitySettings.activeColorSpace == ColorSpace.Linear)
|
if (UIParticleProjectSettings.enableLinearToGamma && canvas.ShouldGammaToLinearInMesh())
|
||||||
{
|
{
|
||||||
Profiler.BeginSample("[UIParticleRenderer] Convert Linear to Gamma");
|
workerMesh.LinearToGamma();
|
||||||
workerMesh.GetColors(s_Colors);
|
|
||||||
var count_c = s_Colors.Count;
|
|
||||||
for (var i = 0; i < count_c; i++)
|
|
||||||
{
|
|
||||||
var c = s_Colors[i];
|
|
||||||
c.r = c.r.LinearToGamma();
|
|
||||||
c.g = c.g.LinearToGamma();
|
|
||||||
c.b = c.b.LinearToGamma();
|
|
||||||
s_Colors[i] = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
workerMesh.SetColors(s_Colors);
|
|
||||||
Profiler.EndSample();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GetComponents(typeof(IMeshModifier), s_Components);
|
var components = ListPool<Component>.Rent();
|
||||||
for (var i = 0; i < s_Components.Count; i++)
|
GetComponents(typeof(IMeshModifier), components);
|
||||||
|
for (var i = 0; i < components.Count; i++)
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0618 // Type or member is obsolete
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
((IMeshModifier)s_Components[i]).ModifyMesh(workerMesh);
|
((IMeshModifier)components[i]).ModifyMesh(workerMesh);
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
}
|
}
|
||||||
|
|
||||||
s_Components.Clear();
|
ListPool<Component>.Return(ref components);
|
||||||
}
|
}
|
||||||
|
|
||||||
Profiler.EndSample();
|
Profiler.EndSample();
|
||||||
|
|
||||||
|
|
||||||
// Get grouped renderers.
|
|
||||||
s_Renderers.Clear();
|
|
||||||
if (_parent.useMeshSharing)
|
|
||||||
{
|
|
||||||
UIParticleUpdater.GetGroupedRenderers(_parent.groupId, _index, s_Renderers);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set mesh to the CanvasRenderer.
|
|
||||||
Profiler.BeginSample("[UIParticleRenderer] Set Mesh");
|
|
||||||
for (var i = 0; i < s_Renderers.Count; i++)
|
|
||||||
{
|
|
||||||
if (s_Renderers[i] == this) continue;
|
|
||||||
s_Renderers[i].canvasRenderer.SetMesh(workerMesh);
|
|
||||||
s_Renderers[i]._lastBounds = _lastBounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_parent.canRender)
|
|
||||||
{
|
|
||||||
workerMesh.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
canvasRenderer.SetMesh(workerMesh);
|
|
||||||
Profiler.EndSample();
|
|
||||||
|
|
||||||
// Update animatable material properties.
|
// Update animatable material properties.
|
||||||
Profiler.BeginSample("[UIParticleRenderer] Update Animatable Material Properties");
|
Profiler.BeginSample("[UIParticleRenderer] Update Animatable Material Properties");
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
if (_modifiedMaterial != material)
|
|
||||||
{
|
|
||||||
_renderer.GetSharedMaterials(s_Materials);
|
|
||||||
material = s_Materials[_isTrail ? 1 : 0];
|
|
||||||
s_Materials.Clear();
|
|
||||||
SetMaterialDirty();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
UpdateMaterialProperties();
|
UpdateMaterialProperties();
|
||||||
|
Profiler.EndSample();
|
||||||
|
|
||||||
|
// Get grouped renderers.
|
||||||
|
Profiler.BeginSample("[UIParticleRenderer] Set Mesh");
|
||||||
|
var renderers = ListPool<UIParticleRenderer>.Rent();
|
||||||
if (_parent.useMeshSharing)
|
if (_parent.useMeshSharing)
|
||||||
{
|
{
|
||||||
if (!_currentMaterialForRendering)
|
UIParticleUpdater.GetGroupedRenderers(_parent.groupId, _index, renderers);
|
||||||
{
|
}
|
||||||
_currentMaterialForRendering = materialForRendering;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < s_Renderers.Count; i++)
|
for (var i = 0; i < renderers.Count; i++)
|
||||||
{
|
{
|
||||||
if (s_Renderers[i] == this) continue;
|
var r = renderers[i];
|
||||||
|
if (r == this) continue;
|
||||||
|
|
||||||
s_Renderers[i].canvasRenderer.materialCount = 1;
|
r.canvasRenderer.SetMesh(workerMesh);
|
||||||
s_Renderers[i].canvasRenderer.SetMaterial(_currentMaterialForRendering, 0);
|
r._lastBounds = _lastBounds;
|
||||||
}
|
r.canvasRenderer.materialCount = 1;
|
||||||
|
r.canvasRenderer.SetMaterial(materialForRendering, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ListPool<UIParticleRenderer>.Return(ref renderers);
|
||||||
|
|
||||||
|
if (_parent.canRender)
|
||||||
|
{
|
||||||
|
canvasRenderer.SetMesh(workerMesh);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
workerMesh.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
Profiler.EndSample();
|
Profiler.EndSample();
|
||||||
|
}
|
||||||
|
|
||||||
s_Renderers.Clear();
|
public override void SetMaterialDirty()
|
||||||
|
{
|
||||||
|
_materialForRendering = null;
|
||||||
|
base.SetMaterialDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -560,13 +542,16 @@ namespace Coffee.UIExtensions
|
|||||||
return Matrix4x4.Translate(psPos)
|
return Matrix4x4.Translate(psPos)
|
||||||
* Matrix4x4.Scale(scale);
|
* Matrix4x4.Scale(scale);
|
||||||
case ParticleSystemSimulationSpace.World:
|
case ParticleSystemSimulationSpace.World:
|
||||||
|
if (_isTrail)
|
||||||
|
{
|
||||||
|
return Matrix4x4.Translate(psPos)
|
||||||
|
* Matrix4x4.Scale(scale)
|
||||||
|
* Matrix4x4.Translate(-psPos);
|
||||||
|
}
|
||||||
return Matrix4x4.Scale(scale);
|
return Matrix4x4.Scale(scale);
|
||||||
case ParticleSystemSimulationSpace.Custom:
|
case ParticleSystemSimulationSpace.Custom:
|
||||||
return Matrix4x4.Translate(_particleSystem.main.customSimulationSpace.position.GetScaled(scale))
|
return Matrix4x4.Translate(_particleSystem.main.customSimulationSpace.position.GetScaled(scale))
|
||||||
//* Matrix4x4.Translate(wpos)
|
* Matrix4x4.Scale(scale);
|
||||||
* Matrix4x4.Scale(scale)
|
|
||||||
//* Matrix4x4.Translate(-wpos)
|
|
||||||
;
|
|
||||||
default:
|
default:
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
@@ -582,7 +567,8 @@ namespace Coffee.UIExtensions
|
|||||||
var screenSize = new Vector2Int(Screen.width, Screen.height);
|
var screenSize = new Vector2Int(Screen.width, Screen.height);
|
||||||
var isWorldSpace = _particleSystem.IsWorldSpace();
|
var isWorldSpace = _particleSystem.IsWorldSpace();
|
||||||
var canvasScale = _parent.canvas ? _parent.canvas.scaleFactor : 1f;
|
var canvasScale = _parent.canvas ? _parent.canvas.scaleFactor : 1f;
|
||||||
var resolutionChanged = _prevScreenSize != screenSize || _prevCanvasScale != canvasScale;
|
var resolutionChanged = _prevScreenSize != screenSize
|
||||||
|
|| !Mathf.Approximately(_prevCanvasScale, canvasScale);
|
||||||
if (resolutionChanged && isWorldSpace && _isPrevStored)
|
if (resolutionChanged && isWorldSpace && _isPrevStored)
|
||||||
{
|
{
|
||||||
// Update particle array size and get particles.
|
// Update particle array size and get particles.
|
||||||
@@ -590,7 +576,7 @@ namespace Coffee.UIExtensions
|
|||||||
var particles = ParticleSystemExtensions.GetParticleArray(size);
|
var particles = ParticleSystemExtensions.GetParticleArray(size);
|
||||||
_particleSystem.GetParticles(particles, size);
|
_particleSystem.GetParticles(particles, size);
|
||||||
|
|
||||||
// Resolusion resolver:
|
// Resolution resolver:
|
||||||
// (psPos / scale) / (prevPsPos / prevScale) -> psPos * scale.inv * prevPsPos.inv * prevScale
|
// (psPos / scale) / (prevPsPos / prevScale) -> psPos * scale.inv * prevPsPos.inv * prevScale
|
||||||
var modifier = psPos.GetScaled(
|
var modifier = psPos.GetScaled(
|
||||||
scale.Inverse(),
|
scale.Inverse(),
|
||||||
@@ -625,11 +611,11 @@ namespace Coffee.UIExtensions
|
|||||||
? Time.unscaledDeltaTime
|
? Time.unscaledDeltaTime
|
||||||
: Time.deltaTime;
|
: Time.deltaTime;
|
||||||
|
|
||||||
// Prewarm:
|
// Pre-warm:
|
||||||
if (0 < deltaTime && _prewarm)
|
if (0 < deltaTime && _preWarm)
|
||||||
{
|
{
|
||||||
deltaTime += main.duration;
|
deltaTime += main.duration;
|
||||||
_prewarm = false;
|
_preWarm = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get world position.
|
// get world position.
|
||||||
@@ -704,12 +690,12 @@ namespace Coffee.UIExtensions
|
|||||||
if (s_Mpb.isEmpty) return;
|
if (s_Mpb.isEmpty) return;
|
||||||
|
|
||||||
// #41: Copy the value from MaterialPropertyBlock to CanvasRenderer
|
// #41: Copy the value from MaterialPropertyBlock to CanvasRenderer
|
||||||
if (!_modifiedMaterial) return;
|
if (!materialForRendering) return;
|
||||||
|
|
||||||
for (var i = 0; i < _parent.m_AnimatableProperties.Length; i++)
|
for (var i = 0; i < _parent.m_AnimatableProperties.Length; i++)
|
||||||
{
|
{
|
||||||
var ap = _parent.m_AnimatableProperties[i];
|
var ap = _parent.m_AnimatableProperties[i];
|
||||||
ap.UpdateMaterialProperties(_modifiedMaterial, s_Mpb);
|
ap.UpdateMaterialProperties(materialForRendering, s_Mpb);
|
||||||
}
|
}
|
||||||
|
|
||||||
s_Mpb.Clear();
|
s_Mpb.Clear();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ MonoImporter:
|
|||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
defaultReferences: []
|
defaultReferences: []
|
||||||
executionOrder: 0
|
executionOrder: 0
|
||||||
icon: {instanceID: 0}
|
icon: {fileID: 2800000, guid: 5f0675613942149309588d556e33d990, type: 3}
|
||||||
userData:
|
userData:
|
||||||
assetBundleName:
|
assetBundleName:
|
||||||
assetBundleVariant:
|
assetBundleVariant:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Coffee.UIParticleInternal;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -39,12 +40,12 @@ namespace Coffee.UIExtensions
|
|||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
[InitializeOnLoadMethod]
|
[InitializeOnLoadMethod]
|
||||||
|
#else
|
||||||
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||||
#endif
|
#endif
|
||||||
[RuntimeInitializeOnLoadMethod]
|
|
||||||
private static void InitializeOnLoad()
|
private static void InitializeOnLoad()
|
||||||
{
|
{
|
||||||
Canvas.willRenderCanvases -= Refresh;
|
UIExtraCallbacks.onAfterCanvasRebuild += Refresh;
|
||||||
Canvas.willRenderCanvases += Refresh;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Refresh()
|
private static void Refresh()
|
||||||
|
|||||||
8
Runtime/Utilities.meta
Normal file
8
Runtime/Utilities.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 66c42f0f30de84ca4bd8305a1188af85
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,96 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace Coffee.UIParticleExtensions
|
namespace Coffee.UIParticleInternal
|
||||||
{
|
{
|
||||||
public static class Color32Extensions
|
internal static class ParticleSystemExtensions
|
||||||
{
|
|
||||||
private static byte[] s_LinearToGammaLut;
|
|
||||||
|
|
||||||
public static byte LinearToGamma(this byte self)
|
|
||||||
{
|
|
||||||
if (s_LinearToGammaLut == null)
|
|
||||||
{
|
|
||||||
s_LinearToGammaLut = new byte[256];
|
|
||||||
for (var i = 0; i < 256; i++)
|
|
||||||
{
|
|
||||||
s_LinearToGammaLut[i] = (byte)(Mathf.LinearToGammaSpace(i / 255f) * 255f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return s_LinearToGammaLut[self];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Vector3Extensions
|
|
||||||
{
|
|
||||||
public static Vector3 Inverse(this Vector3 self)
|
|
||||||
{
|
|
||||||
self.x = Mathf.Approximately(self.x, 0) ? 1 : 1 / self.x;
|
|
||||||
self.y = Mathf.Approximately(self.y, 0) ? 1 : 1 / self.y;
|
|
||||||
self.z = Mathf.Approximately(self.z, 0) ? 1 : 1 / self.z;
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector3 GetScaled(this Vector3 self, Vector3 other1)
|
|
||||||
{
|
|
||||||
self.Scale(other1);
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector3 GetScaled(this Vector3 self, Vector3 other1, Vector3 other2)
|
|
||||||
{
|
|
||||||
self.Scale(other1);
|
|
||||||
self.Scale(other2);
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector3 GetScaled(this Vector3 self, Vector3 other1, Vector3 other2, Vector3 other3)
|
|
||||||
{
|
|
||||||
self.Scale(other1);
|
|
||||||
self.Scale(other2);
|
|
||||||
self.Scale(other3);
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsVisible(this Vector3 self)
|
|
||||||
{
|
|
||||||
return 0 < Mathf.Abs(self.x * self.y * self.z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static class SpriteExtensions
|
|
||||||
{
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
private static readonly Type s_SpriteEditorExtensionType =
|
|
||||||
Type.GetType("UnityEditor.Experimental.U2D.SpriteEditorExtension, UnityEditor")
|
|
||||||
?? Type.GetType("UnityEditor.U2D.SpriteEditorExtension, UnityEditor");
|
|
||||||
|
|
||||||
private static readonly MethodInfo s_GetActiveAtlasTextureMethodInfo = s_SpriteEditorExtensionType
|
|
||||||
.GetMethod("GetActiveAtlasTexture", BindingFlags.Static | BindingFlags.NonPublic);
|
|
||||||
|
|
||||||
public static Texture2D GetActualTexture(this Sprite self)
|
|
||||||
{
|
|
||||||
if (!self) return null;
|
|
||||||
|
|
||||||
if (Application.isPlaying) return self.texture;
|
|
||||||
var ret = s_GetActiveAtlasTextureMethodInfo.Invoke(null, new object[] { self }) as Texture2D;
|
|
||||||
return ret
|
|
||||||
? ret
|
|
||||||
: self.texture;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
internal static Texture2D GetActualTexture(this Sprite self)
|
|
||||||
{
|
|
||||||
return self ? self.texture : null;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ParticleSystemExtensions
|
|
||||||
{
|
{
|
||||||
private static ParticleSystem.Particle[] s_TmpParticles = new ParticleSystem.Particle[2048];
|
private static ParticleSystem.Particle[] s_TmpParticles = new ParticleSystem.Particle[2048];
|
||||||
|
|
||||||
@@ -250,59 +165,11 @@ namespace Coffee.UIParticleExtensions
|
|||||||
|
|
||||||
public static void Exec(this List<ParticleSystem> self, Action<ParticleSystem> action)
|
public static void Exec(this List<ParticleSystem> self, Action<ParticleSystem> action)
|
||||||
{
|
{
|
||||||
self.RemoveAll(p => !p);
|
foreach (var p in self)
|
||||||
self.ForEach(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static class Misc
|
|
||||||
{
|
|
||||||
public static void Destroy(Object obj)
|
|
||||||
{
|
|
||||||
if (!obj) return;
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
if (!Application.isPlaying)
|
|
||||||
{
|
{
|
||||||
Object.DestroyImmediate(obj);
|
if (!p) continue;
|
||||||
}
|
action.Invoke(p);
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
Object.Destroy(obj);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DestroyImmediate(Object obj)
|
|
||||||
{
|
|
||||||
if (!obj) return;
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
if (Application.isEditor)
|
|
||||||
{
|
|
||||||
Object.DestroyImmediate(obj);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
Object.Destroy(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !UNITY_2021_2_OR_NEWER && !UNITY_2020_3_45 && !UNITY_2020_3_46 && !UNITY_2020_3_47 && !UNITY_2020_3_48
|
|
||||||
public static T GetComponentInParent<T>(this Component self, bool includeInactive) where T : Component
|
|
||||||
{
|
|
||||||
if (!self) return null;
|
|
||||||
if (!includeInactive) return self.GetComponentInParent<T>();
|
|
||||||
|
|
||||||
var current = self.transform;
|
|
||||||
while (current)
|
|
||||||
{
|
|
||||||
var component = current.GetComponent<T>();
|
|
||||||
if (component) return component;
|
|
||||||
current = current.parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
11
Runtime/Utilities/ParticleSystemExtensions.cs.meta
Normal file
11
Runtime/Utilities/ParticleSystemExtensions.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e51604bfb810e44519e2710fd1b8af90
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -51,7 +51,11 @@ namespace Coffee.UIExtensions.Demo
|
|||||||
|
|
||||||
public void EnableAnimations(bool flag)
|
public void EnableAnimations(bool flag)
|
||||||
{
|
{
|
||||||
|
#if UNITY_2023_1_OR_NEWER
|
||||||
|
foreach (var animator in FindObjectsByType<Animator>(FindObjectsInactive.Include, FindObjectsSortMode.None))
|
||||||
|
#else
|
||||||
foreach (var animator in FindObjectsOfType<Animator>())
|
foreach (var animator in FindObjectsOfType<Animator>())
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
animator.enabled = flag;
|
animator.enabled = flag;
|
||||||
}
|
}
|
||||||
@@ -79,7 +83,11 @@ namespace Coffee.UIExtensions.Demo
|
|||||||
|
|
||||||
public void UIParticle_Scale(float scale)
|
public void UIParticle_Scale(float scale)
|
||||||
{
|
{
|
||||||
|
#if UNITY_2023_1_OR_NEWER
|
||||||
|
foreach (var uip in FindObjectsByType<UIParticle>(FindObjectsInactive.Include, FindObjectsSortMode.None))
|
||||||
|
#else
|
||||||
foreach (var uip in FindObjectsOfType<UIParticle>())
|
foreach (var uip in FindObjectsOfType<UIParticle>())
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
uip.scale = scale;
|
uip.scale = scale;
|
||||||
}
|
}
|
||||||
@@ -87,7 +95,11 @@ namespace Coffee.UIExtensions.Demo
|
|||||||
|
|
||||||
public void ParticleSystem_WorldSpaseSimulation(bool flag)
|
public void ParticleSystem_WorldSpaseSimulation(bool flag)
|
||||||
{
|
{
|
||||||
|
#if UNITY_2023_1_OR_NEWER
|
||||||
|
foreach (var p in FindObjectsByType<ParticleSystem>(FindObjectsInactive.Include, FindObjectsSortMode.None))
|
||||||
|
#else
|
||||||
foreach (var p in FindObjectsOfType<ParticleSystem>())
|
foreach (var p in FindObjectsOfType<ParticleSystem>())
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
var main = p.main;
|
var main = p.main;
|
||||||
main.simulationSpace = flag
|
main.simulationSpace = flag
|
||||||
@@ -123,7 +135,11 @@ namespace Coffee.UIExtensions.Demo
|
|||||||
|
|
||||||
public void ParticleSystem_SetScale(float scale)
|
public void ParticleSystem_SetScale(float scale)
|
||||||
{
|
{
|
||||||
|
#if UNITY_2023_1_OR_NEWER
|
||||||
|
foreach (var ps in FindObjectsByType<ParticleSystem>(FindObjectsInactive.Include, FindObjectsSortMode.None))
|
||||||
|
#else
|
||||||
foreach (var ps in FindObjectsOfType<ParticleSystem>())
|
foreach (var ps in FindObjectsOfType<ParticleSystem>())
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
ps.transform.localScale = new Vector3(scale, scale, scale);
|
ps.transform.localScale = new Vector3(scale, scale, scale);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ TextureImporter:
|
|||||||
compressionQuality: 50
|
compressionQuality: 50
|
||||||
spriteMode: 1
|
spriteMode: 1
|
||||||
spriteExtrude: 1
|
spriteExtrude: 1
|
||||||
spriteMeshType: 1
|
spriteMeshType: 0
|
||||||
alignment: 0
|
alignment: 0
|
||||||
spritePivot: {x: 0.5, y: 0.5}
|
spritePivot: {x: 0.5, y: 0.5}
|
||||||
spritePixelsToUnits: 100
|
spritePixelsToUnits: 100
|
||||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||||
spriteGenerateFallbackPhysicsShape: 1
|
spriteGenerateFallbackPhysicsShape: 0
|
||||||
alphaUsage: 1
|
alphaUsage: 1
|
||||||
alphaIsTransparency: 1
|
alphaIsTransparency: 1
|
||||||
spriteTessellationDetail: -1
|
spriteTessellationDetail: -1
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ TextureImporter:
|
|||||||
generateCubemap: 6
|
generateCubemap: 6
|
||||||
cubemapConvolution: 0
|
cubemapConvolution: 0
|
||||||
seamlessCubemap: 0
|
seamlessCubemap: 0
|
||||||
textureFormat: 1
|
textureFormat: 4
|
||||||
maxTextureSize: 2048
|
maxTextureSize: 2048
|
||||||
textureSettings:
|
textureSettings:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -42,12 +42,12 @@ TextureImporter:
|
|||||||
compressionQuality: 50
|
compressionQuality: 50
|
||||||
spriteMode: 1
|
spriteMode: 1
|
||||||
spriteExtrude: 1
|
spriteExtrude: 1
|
||||||
spriteMeshType: 1
|
spriteMeshType: 0
|
||||||
alignment: 0
|
alignment: 0
|
||||||
spritePivot: {x: 0.5, y: 0.5}
|
spritePivot: {x: 0.5, y: 0.5}
|
||||||
spritePixelsToUnits: 100
|
spritePixelsToUnits: 100
|
||||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||||
spriteGenerateFallbackPhysicsShape: 1
|
spriteGenerateFallbackPhysicsShape: 0
|
||||||
alphaUsage: 1
|
alphaUsage: 1
|
||||||
alphaIsTransparency: 1
|
alphaIsTransparency: 1
|
||||||
spriteTessellationDetail: -1
|
spriteTessellationDetail: -1
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ TextureImporter:
|
|||||||
compressionQuality: 50
|
compressionQuality: 50
|
||||||
spriteMode: 1
|
spriteMode: 1
|
||||||
spriteExtrude: 1
|
spriteExtrude: 1
|
||||||
spriteMeshType: 1
|
spriteMeshType: 0
|
||||||
alignment: 0
|
alignment: 0
|
||||||
spritePivot: {x: 0.5, y: 0.5}
|
spritePivot: {x: 0.5, y: 0.5}
|
||||||
spritePixelsToUnits: 100
|
spritePixelsToUnits: 100
|
||||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||||
spriteGenerateFallbackPhysicsShape: 1
|
spriteGenerateFallbackPhysicsShape: 0
|
||||||
alphaUsage: 0
|
alphaUsage: 0
|
||||||
alphaIsTransparency: 1
|
alphaIsTransparency: 1
|
||||||
spriteTessellationDetail: -1
|
spriteTessellationDetail: -1
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ TextureImporter:
|
|||||||
generateCubemap: 6
|
generateCubemap: 6
|
||||||
cubemapConvolution: 0
|
cubemapConvolution: 0
|
||||||
seamlessCubemap: 0
|
seamlessCubemap: 0
|
||||||
textureFormat: -1
|
textureFormat: 4
|
||||||
maxTextureSize: 2048
|
maxTextureSize: 2048
|
||||||
textureSettings:
|
textureSettings:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -42,12 +42,12 @@ TextureImporter:
|
|||||||
compressionQuality: 50
|
compressionQuality: 50
|
||||||
spriteMode: 1
|
spriteMode: 1
|
||||||
spriteExtrude: 1
|
spriteExtrude: 1
|
||||||
spriteMeshType: 1
|
spriteMeshType: 0
|
||||||
alignment: 0
|
alignment: 0
|
||||||
spritePivot: {x: 0.5, y: 0.5}
|
spritePivot: {x: 0.5, y: 0.5}
|
||||||
spritePixelsToUnits: 100
|
spritePixelsToUnits: 100
|
||||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||||
spriteGenerateFallbackPhysicsShape: 1
|
spriteGenerateFallbackPhysicsShape: 0
|
||||||
alphaUsage: 1
|
alphaUsage: 1
|
||||||
alphaIsTransparency: 1
|
alphaIsTransparency: 1
|
||||||
spriteTessellationDetail: -1
|
spriteTessellationDetail: -1
|
||||||
|
|||||||
@@ -40,7 +40,10 @@
|
|||||||
Lighting Off
|
Lighting Off
|
||||||
ZWrite Off
|
ZWrite Off
|
||||||
ZTest [unity_GUIZTestMode]
|
ZTest [unity_GUIZTestMode]
|
||||||
Fog { Mode Off }
|
Fog
|
||||||
|
{
|
||||||
|
Mode Off
|
||||||
|
}
|
||||||
Blend One One
|
Blend One One
|
||||||
|
|
||||||
ColorMask [_ColorMask]
|
ColorMask [_ColorMask]
|
||||||
@@ -61,21 +64,21 @@
|
|||||||
|
|
||||||
struct appdata_t
|
struct appdata_t
|
||||||
{
|
{
|
||||||
float4 vertex : POSITION;
|
float4 vertex : POSITION;
|
||||||
float4 color : COLOR;
|
float4 color : COLOR;
|
||||||
float2 texcoord : TEXCOORD0;
|
float2 texcoord : TEXCOORD0;
|
||||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||||
};
|
};
|
||||||
|
|
||||||
struct v2f
|
struct v2f
|
||||||
{
|
{
|
||||||
float4 vertex : SV_POSITION;
|
float4 vertex : SV_POSITION;
|
||||||
fixed4 color : COLOR;
|
fixed4 color : COLOR;
|
||||||
float2 texcoord : TEXCOORD0;
|
float2 texcoord : TEXCOORD0;
|
||||||
float4 worldPosition : TEXCOORD1;
|
float4 worldPosition : TEXCOORD1;
|
||||||
UNITY_VERTEX_OUTPUT_STEREO
|
UNITY_VERTEX_OUTPUT_STEREO
|
||||||
};
|
};
|
||||||
|
|
||||||
fixed4 _Color;
|
fixed4 _Color;
|
||||||
sampler2D _MainTex;
|
sampler2D _MainTex;
|
||||||
float4 _MainTex_ST;
|
float4 _MainTex_ST;
|
||||||
@@ -114,4 +117,4 @@
|
|||||||
ENDCG
|
ENDCG
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "com.coffee.ui-particle",
|
"name": "com.coffee.ui-particle",
|
||||||
"displayName": "UI Particle",
|
"displayName": "UI Particle",
|
||||||
"description": "This package provides a component to render particle effects for uGUI.\nThe particle rendering is maskable and sortable, without the need for an extra Camera, RenderTexture, or Canvas.",
|
"description": "This package provides a component to render particle effects for uGUI.\nThe particle rendering is maskable and sortable, without the need for an extra Camera, RenderTexture, or Canvas.",
|
||||||
"version": "4.7.1",
|
"version": "4.10.2",
|
||||||
"unity": "2018.2",
|
"unity": "2018.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
Reference in New Issue
Block a user