From 29e30a3f1b405e7dde7e9fde04adac7ec88a1766 Mon Sep 17 00:00:00 2001 From: mob-sakai <12690315+mob-sakai@users.noreply.github.com> Date: Thu, 27 Jun 2024 11:56:33 +0900 Subject: [PATCH] feat: UIParticle no longer inherits from MaskableGraphic BREAKING CHANGE: Some members inherited from MaskableGraphic will no longer be available. --- Packages/src/Editor/UIParticleEditor.cs | 9 +--- Packages/src/Runtime/UIParticle.cs | 71 ++++++++++++++++--------- 2 files changed, 49 insertions(+), 31 deletions(-) diff --git a/Packages/src/Editor/UIParticleEditor.cs b/Packages/src/Editor/UIParticleEditor.cs index c8a8d3d..2d15987 100644 --- a/Packages/src/Editor/UIParticleEditor.cs +++ b/Packages/src/Editor/UIParticleEditor.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using UnityEditor; -using UnityEditor.UI; using UnityEditorInternal; using UnityEngine; using UnityEngine.Profiling; @@ -25,7 +24,7 @@ namespace Coffee.UIExtensions { [CustomEditor(typeof(UIParticle))] [CanEditMultipleObjects] - internal class UIParticleEditor : GraphicEditor + internal class UIParticleEditor : Editor { //################################ // Constant or Static Members. @@ -80,10 +79,8 @@ namespace Coffee.UIExtensions /// /// This function is called when the object becomes enabled and active. /// - protected override void OnEnable() + private void OnEnable() { - base.OnEnable(); - _maskable = serializedObject.FindProperty("m_Maskable"); _scale3D = serializedObject.FindProperty("m_Scale3D"); _animatableProperties = serializedObject.FindProperty("m_AnimatableProperties"); @@ -436,9 +433,7 @@ namespace Coffee.UIExtensions { if (!p || (ignoreCurrent && target == p)) return; - var cr = p.canvasRenderer; DestroyImmediate(p); - DestroyImmediate(cr); #if UNITY_2018_3_OR_NEWER var stage = PrefabStageUtility.GetCurrentPrefabStage(); diff --git a/Packages/src/Runtime/UIParticle.cs b/Packages/src/Runtime/UIParticle.cs index 11193a3..1a37937 100644 --- a/Packages/src/Runtime/UIParticle.cs +++ b/Packages/src/Runtime/UIParticle.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; using Coffee.UIParticleExtensions; using UnityEngine; +using UnityEngine.EventSystems; using UnityEngine.Rendering; using UnityEngine.Serialization; -using UnityEngine.UI; using Random = UnityEngine.Random; [assembly: InternalsVisibleTo("Coffee.UIParticle.Editor")] @@ -18,7 +18,7 @@ namespace Coffee.UIExtensions [ExecuteAlways] [RequireComponent(typeof(RectTransform))] [RequireComponent(typeof(CanvasRenderer))] - public class UIParticle : MaskableGraphic, ISerializationCallbackReceiver + public class UIParticle : UIBehaviour, ISerializationCallbackReceiver { public enum AutoScalingMode { @@ -117,6 +117,9 @@ namespace Coffee.UIExtensions "Change the bake view size.")] private float m_CustomViewSize = 10; + [SerializeField] + private bool m_Maskable = true; + private readonly List _renderers = new List(); private Camera _bakeCamera; private Canvas _canvas; @@ -125,13 +128,37 @@ namespace Coffee.UIExtensions private Vector3 _storedScale; private DrivenRectTransformTracker _tracker; - /// - /// Should this graphic be considered a target for ray-casting? - /// - public override bool raycastTarget + public RectTransform rectTransform => transform as RectTransform; + + public Canvas canvas { - get => false; - set { } + get + { + if (_canvas) return _canvas; + + var tr = transform; + while (tr && !_canvas) + { + if (tr.TryGetComponent(out _canvas)) return _canvas; + tr = tr.parent; + } + + return null; + } + } + + /// + /// Does this graphic allow masking. + /// + public bool maskable + { + get => m_Maskable; + set + { + if (value == m_Maskable) return; + m_Maskable = value; + UpdateRendererMaterial(); + } } /// @@ -308,15 +335,15 @@ namespace Coffee.UIExtensions public Vector3 parentScale { get; private set; } - public Vector3 canvasScale { get; private set; } + private Vector3 canvasScale { get; set; } protected override void OnEnable() { _isScaleStored = false; ResetGroupId(); UIParticleUpdater.Register(this); - RegisterDirtyMaterialCallback(UpdateRendererMaterial); + // if (0 < particles.Count) { RefreshParticles(particles); @@ -326,7 +353,7 @@ namespace Coffee.UIExtensions RefreshParticles(); } - base.OnEnable(); + UpdateRendererMaterial(); } /// @@ -343,9 +370,15 @@ namespace Coffee.UIExtensions _isScaleStored = false; UIParticleUpdater.Unregister(this); _renderers.ForEach(r => r.Reset()); - UnregisterDirtyMaterialCallback(UpdateRendererMaterial); + _canvas = null; + } - base.OnDisable(); + /// + /// Called when the state of the parent Canvas is changed. + /// + protected override void OnCanvasHierarchyChanged() + { + _canvas = null; } /// @@ -360,6 +393,7 @@ namespace Coffee.UIExtensions /// protected override void OnTransformParentChanged() { + _canvas = null; } void ISerializationCallbackReceiver.OnBeforeSerialize() @@ -654,17 +688,6 @@ namespace Coffee.UIExtensions : Random.Range(m_GroupId, m_GroupMaxId + 1); } - protected override void UpdateMaterial() - { - } - - /// - /// Call to update the geometry of the Graphic onto the CanvasRenderer. - /// - protected override void UpdateGeometry() - { - } - private void UpdateRendererMaterial() { for (var i = 0; i < _renderers.Count; i++)