refactor: apply refactor

pull/290/head
mob-sakai 2024-01-23 23:17:57 +09:00
parent cbe3105b0f
commit c61d22d221
16 changed files with 93 additions and 130 deletions

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using UnityEngine; using UnityEngine;

View File

@ -1,4 +1,4 @@
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization; using UnityEngine.Serialization;
namespace Coffee.UIExtensions.Demo namespace Coffee.UIExtensions.Demo

View File

@ -1,4 +1,4 @@
using System.Collections; using System.Collections;
using NUnit.Framework; using NUnit.Framework;
using UnityEngine.TestTools; using UnityEngine.TestTools;

View File

@ -1,4 +1,4 @@
using System.Collections; using System.Collections;
using NUnit.Framework; using NUnit.Framework;
using UnityEngine.TestTools; using UnityEngine.TestTools;

View File

@ -1,3 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEditor.UI;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_2021_2_OR_NEWER #if UNITY_2021_2_OR_NEWER
using UnityEditor.Overlays; using UnityEditor.Overlays;
#else #else
@ -8,17 +16,6 @@ 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Coffee.UIParticleExtensions;
using UnityEditor;
using UnityEditor.UI;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.UI;
using Object = UnityEngine.Object;
namespace Coffee.UIExtensions namespace Coffee.UIExtensions
{ {

View File

@ -1,4 +1,4 @@
using System; using System;
using UnityEngine; using UnityEngine;
namespace Coffee.UIExtensions namespace Coffee.UIExtensions
@ -19,10 +19,7 @@ namespace Coffee.UIExtensions
[SerializeField] private ShaderPropertyType m_Type = ShaderPropertyType.Vector; [SerializeField] private ShaderPropertyType m_Type = ShaderPropertyType.Vector;
public int id { get; private set; } public int id { get; private set; }
public ShaderPropertyType type public ShaderPropertyType type => m_Type;
{
get { return m_Type; }
}
void ISerializationCallbackReceiver.OnBeforeSerialize() void ISerializationCallbackReceiver.OnBeforeSerialize()
{ {

View File

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
namespace Coffee.UIParticleExtensions namespace Coffee.UIParticleExtensions

View File

@ -21,6 +21,13 @@ namespace Coffee.UIExtensions
[RequireComponent(typeof(CanvasRenderer))] [RequireComponent(typeof(CanvasRenderer))]
public class UIParticle : MaskableGraphic, ISerializationCallbackReceiver public class UIParticle : MaskableGraphic, ISerializationCallbackReceiver
{ {
public enum AutoScalingMode
{
None,
UIParticle,
Transform
}
public enum MeshSharing public enum MeshSharing
{ {
None, None,
@ -36,13 +43,6 @@ namespace Coffee.UIExtensions
Absolute Absolute
} }
public enum AutoScalingMode
{
None,
UIParticle,
Transform
}
[HideInInspector] [HideInInspector]
[SerializeField] [SerializeField]
internal bool m_IsTrail; internal bool m_IsTrail;
@ -113,7 +113,7 @@ namespace Coffee.UIExtensions
/// </summary> /// </summary>
public override bool raycastTarget public override bool raycastTarget
{ {
get { return false; } get => false;
set { } set { }
} }
@ -127,8 +127,8 @@ namespace Coffee.UIExtensions
/// </summary> /// </summary>
public MeshSharing meshSharing public MeshSharing meshSharing
{ {
get { return m_MeshSharing; } get => m_MeshSharing;
set { m_MeshSharing = value; } set => m_MeshSharing = value;
} }
/// <summary> /// <summary>
@ -137,7 +137,7 @@ namespace Coffee.UIExtensions
/// </summary> /// </summary>
public int groupId public int groupId
{ {
get { return _groupId; } get => _groupId;
set set
{ {
if (m_GroupId == value) return; if (m_GroupId == value) return;
@ -151,7 +151,7 @@ namespace Coffee.UIExtensions
public int groupMaxId public int groupMaxId
{ {
get { return m_GroupMaxId; } get => m_GroupMaxId;
set set
{ {
if (m_GroupMaxId == value) return; if (m_GroupMaxId == value) return;
@ -167,8 +167,8 @@ namespace Coffee.UIExtensions
/// </summary> /// </summary>
public PositionMode positionMode public PositionMode positionMode
{ {
get { return m_PositionMode; } get => m_PositionMode;
set { m_PositionMode = value; } set => m_PositionMode = value;
} }
/// <summary> /// <summary>
@ -178,8 +178,8 @@ namespace Coffee.UIExtensions
/// </summary> /// </summary>
public bool absoluteMode public bool absoluteMode
{ {
get { return m_PositionMode == PositionMode.Absolute; } get => m_PositionMode == PositionMode.Absolute;
set { positionMode = value ? PositionMode.Absolute : PositionMode.Relative; } set => positionMode = value ? PositionMode.Absolute : PositionMode.Relative;
} }
/// <summary> /// <summary>
@ -188,11 +188,8 @@ namespace Coffee.UIExtensions
[Obsolete("The autoScaling is now obsolete. Please use the autoScalingMode instead.", false)] [Obsolete("The autoScaling is now obsolete. Please use the autoScalingMode instead.", false)]
public bool autoScaling public bool autoScaling
{ {
get { return m_AutoScalingMode != AutoScalingMode.None; } get => m_AutoScalingMode != AutoScalingMode.None;
set set => autoScalingMode = value ? AutoScalingMode.Transform : AutoScalingMode.None;
{
autoScalingMode = value ? AutoScalingMode.Transform : AutoScalingMode.None;
}
} }
/// <summary> /// <summary>
@ -202,7 +199,7 @@ namespace Coffee.UIExtensions
/// </summary> /// </summary>
public AutoScalingMode autoScalingMode public AutoScalingMode autoScalingMode
{ {
get { return m_AutoScalingMode; } get => m_AutoScalingMode;
set set
{ {
if (m_AutoScalingMode == value) return; if (m_AutoScalingMode == value) return;
@ -211,49 +208,31 @@ namespace Coffee.UIExtensions
} }
} }
internal bool useMeshSharing internal bool useMeshSharing => m_MeshSharing != MeshSharing.None;
{
get { return m_MeshSharing != MeshSharing.None; }
}
internal bool isPrimary internal bool isPrimary =>
{ m_MeshSharing == MeshSharing.Primary
get
{
return m_MeshSharing == MeshSharing.Primary
|| m_MeshSharing == MeshSharing.PrimarySimulator; || m_MeshSharing == MeshSharing.PrimarySimulator;
}
}
internal bool canSimulate internal bool canSimulate =>
{ m_MeshSharing == MeshSharing.None
get
{
return m_MeshSharing == MeshSharing.None
|| m_MeshSharing == MeshSharing.Auto || m_MeshSharing == MeshSharing.Auto
|| m_MeshSharing == MeshSharing.Primary || m_MeshSharing == MeshSharing.Primary
|| m_MeshSharing == MeshSharing.PrimarySimulator; || m_MeshSharing == MeshSharing.PrimarySimulator;
}
}
internal bool canRender internal bool canRender =>
{ m_MeshSharing == MeshSharing.None
get
{
return m_MeshSharing == MeshSharing.None
|| m_MeshSharing == MeshSharing.Auto || m_MeshSharing == MeshSharing.Auto
|| m_MeshSharing == MeshSharing.Primary || m_MeshSharing == MeshSharing.Primary
|| m_MeshSharing == MeshSharing.Replica; || m_MeshSharing == MeshSharing.Replica;
}
}
/// <summary> /// <summary>
/// Particle effect scale. /// Particle effect scale.
/// </summary> /// </summary>
public float scale public float scale
{ {
get { return m_Scale3D.x; } get => m_Scale3D.x;
set { m_Scale3D = new Vector3(value, value, value); } set => m_Scale3D = new Vector3(value, value, value);
} }
/// <summary> /// <summary>
@ -261,22 +240,18 @@ namespace Coffee.UIExtensions
/// </summary> /// </summary>
public Vector3 scale3D public Vector3 scale3D
{ {
get { return m_Scale3D; } get => m_Scale3D;
set { m_Scale3D = value; } set => m_Scale3D = value;
} }
/// <summary> /// <summary>
/// Particle effect scale. /// Particle effect scale.
/// </summary> /// </summary>
public Vector3 scale3DForCalc public Vector3 scale3DForCalc => autoScalingMode == AutoScalingMode.UIParticle
{ ? m_Scale3D.GetScaled(canvasScale)
get { return autoScalingMode == AutoScalingMode.UIParticle ? m_Scale3D.GetScaled(canvasScale) : m_Scale3D; } : m_Scale3D;
}
public List<ParticleSystem> particles public List<ParticleSystem> particles => m_Particles;
{
get { return m_Particles; }
}
/// <summary> /// <summary>
/// Get all base materials to render. /// Get all base materials to render.
@ -294,10 +269,7 @@ namespace Coffee.UIExtensions
} }
} }
public override Material materialForRendering public override Material materialForRendering => null;
{
get { return null; }
}
/// <summary> /// <summary>
/// Paused. /// Paused.
@ -637,7 +609,10 @@ namespace Coffee.UIExtensions
// Create ortho-camera. // Create ortho-camera.
if (!_orthoCamera) if (!_orthoCamera)
{ {
var go = new GameObject("[generated] UIParticleOverlayCamera") { hideFlags = HideFlags.HideAndDontSave }; var go = new GameObject("[generated] UIParticleOverlayCamera")
{
hideFlags = HideFlags.HideAndDontSave
};
go.SetActive(false); go.SetActive(false);
go.transform.SetParent(transform, false); go.transform.SetParent(transform, false);
_orthoCamera = go.AddComponent<Camera>(); _orthoCamera = go.AddComponent<Camera>();

View File

@ -1,4 +1,4 @@
using System; using System;
using Coffee.UIParticleExtensions; using Coffee.UIParticleExtensions;
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
@ -49,38 +49,38 @@ namespace Coffee.UIExtensions
public float destinationRadius public float destinationRadius
{ {
get { return m_DestinationRadius; } get => m_DestinationRadius;
set { m_DestinationRadius = Mathf.Clamp(value, 0.1f, 10f); } set => m_DestinationRadius = Mathf.Clamp(value, 0.1f, 10f);
} }
public float delay public float delay
{ {
get { return m_DelayRate; } get => m_DelayRate;
set { m_DelayRate = value; } set => m_DelayRate = value;
} }
public float maxSpeed public float maxSpeed
{ {
get { return m_MaxSpeed; } get => m_MaxSpeed;
set { m_MaxSpeed = value; } set => m_MaxSpeed = value;
} }
public Movement movement public Movement movement
{ {
get { return m_Movement; } get => m_Movement;
set { m_Movement = value; } set => m_Movement = value;
} }
public UpdateMode updateMode public UpdateMode updateMode
{ {
get { return m_UpdateMode; } get => m_UpdateMode;
set { m_UpdateMode = value; } set => m_UpdateMode = value;
} }
public UnityEvent onAttracted public UnityEvent onAttracted
{ {
get { return m_OnAttracted; } get => m_OnAttracted;
set { m_OnAttracted = value; } set => m_OnAttracted = value;
} }
#if UNITY_EDITOR #if UNITY_EDITOR

View File

@ -1,4 +1,4 @@
#if UNITY_2022_3_0 || UNITY_2022_3_1 || UNITY_2022_3_2 || UNITY_2022_3_3 || UNITY_2022_3_4 || UNITY_2022_3_5 || UNITY_2022_3_6 || UNITY_2022_3_7 || UNITY_2022_3_8 || UNITY_2022_3_9 || UNITY_2022_3_10 #if UNITY_2022_3_0 || UNITY_2022_3_1 || UNITY_2022_3_2 || UNITY_2022_3_3 || UNITY_2022_3_4 || UNITY_2022_3_5 || UNITY_2022_3_6 || UNITY_2022_3_7 || UNITY_2022_3_8 || UNITY_2022_3_9 || UNITY_2022_3_10
#elif UNITY_2023_1_0 || UNITY_2023_1_1 || UNITY_2023_1_2 || UNITY_2023_1_3 || UNITY_2023_1_4 || UNITY_2023_1_5 || UNITY_2023_1_6 || UNITY_2023_1_7 || UNITY_2023_1_8 || UNITY_2023_1_9 #elif UNITY_2023_1_0 || UNITY_2023_1_1 || UNITY_2023_1_2 || UNITY_2023_1_3 || UNITY_2023_1_4 || UNITY_2023_1_5 || UNITY_2023_1_6 || UNITY_2023_1_7 || UNITY_2023_1_8 || UNITY_2023_1_9
#elif UNITY_2023_1_10 || UNITY_2023_1_11 || UNITY_2023_1_12 || UNITY_2023_1_13 || UNITY_2023_1_14 || UNITY_2023_1_15 || UNITY_2023_1_16 #elif UNITY_2023_1_10 || UNITY_2023_1_11 || UNITY_2023_1_12 || UNITY_2023_1_13 || UNITY_2023_1_14 || UNITY_2023_1_15 || UNITY_2023_1_16
#elif UNITY_2022_3_OR_NEWER #elif UNITY_2022_3_OR_NEWER
@ -36,22 +36,16 @@ namespace Coffee.UIExtensions
private Material _modifiedMaterial; private Material _modifiedMaterial;
private UIParticle _parent; private UIParticle _parent;
private ParticleSystem _particleSystem; private ParticleSystem _particleSystem;
private float _prevCanvasScale;
private Vector3 _prevPsPos; private Vector3 _prevPsPos;
private Vector3 _prevScale; private Vector3 _prevScale;
private Vector2Int _prevScreenSize; private Vector2Int _prevScreenSize;
private float _prevCanvasScale;
private bool _prewarm; private bool _prewarm;
private ParticleSystemRenderer _renderer; private ParticleSystemRenderer _renderer;
public override Texture mainTexture public override Texture mainTexture => _isTrail ? null : _particleSystem.GetTextureForSprite();
{
get { return _isTrail ? null : _particleSystem.GetTextureForSprite(); }
}
public override bool raycastTarget public override bool raycastTarget => false;
{
get { return false; }
}
private Rect rootCanvasRect private Rect rootCanvasRect
{ {
@ -337,7 +331,8 @@ namespace Coffee.UIExtensions
if (_isTrail && _parent.canSimulate && 0 < s_CombineInstances[0].mesh.vertexCount) if (_isTrail && _parent.canSimulate && 0 < s_CombineInstances[0].mesh.vertexCount)
{ {
#if PS_BAKE_API_V2 #if PS_BAKE_API_V2
_renderer.BakeTrailsMesh(s_CombineInstances[0].mesh, bakeCamera, ParticleSystemBakeMeshOptions.BakeRotationAndScale); _renderer.BakeTrailsMesh(s_CombineInstances[0].mesh, bakeCamera,
ParticleSystemBakeMeshOptions.BakeRotationAndScale);
#else #else
_renderer.BakeTrailsMesh(s_CombineInstances[0].mesh, bakeCamera, true); _renderer.BakeTrailsMesh(s_CombineInstances[0].mesh, bakeCamera, true);
#endif #endif
@ -345,7 +340,8 @@ namespace Coffee.UIExtensions
else if (_renderer.CanBakeMesh()) else if (_renderer.CanBakeMesh())
{ {
#if PS_BAKE_API_V2 #if PS_BAKE_API_V2
_renderer.BakeMesh(s_CombineInstances[0].mesh, bakeCamera, ParticleSystemBakeMeshOptions.BakeRotationAndScale); _renderer.BakeMesh(s_CombineInstances[0].mesh, bakeCamera,
ParticleSystemBakeMeshOptions.BakeRotationAndScale);
#else #else
_renderer.BakeMesh(s_CombineInstances[0].mesh, bakeCamera, true); _renderer.BakeMesh(s_CombineInstances[0].mesh, bakeCamera, true);
#endif #endif
@ -416,6 +412,7 @@ namespace Coffee.UIExtensions
c.b = c.b.LinearToGamma(); c.b = c.b.LinearToGamma();
s_Colors[i] = c; s_Colors[i] = c;
} }
workerMesh.SetColors(s_Colors); workerMesh.SetColors(s_Colors);
Profiler.EndSample(); Profiler.EndSample();
} }

View File

@ -11,10 +11,7 @@ namespace Coffee.UIExtensions
private static readonly HashSet<int> s_UpdatedGroupIds = new HashSet<int>(); private static readonly HashSet<int> s_UpdatedGroupIds = new HashSet<int>();
private static int s_FrameCount; private static int s_FrameCount;
public static int uiParticleCount public static int uiParticleCount => s_ActiveParticles.Count;
{
get { return s_ActiveParticles.Count; }
}
public static void Register(UIParticle particle) public static void Register(UIParticle particle)
{ {

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using UnityEngine; using UnityEngine;

View File

@ -1,4 +1,4 @@
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization; using UnityEngine.Serialization;
namespace Coffee.UIExtensions.Demo namespace Coffee.UIExtensions.Demo

View File

@ -1,4 +1,4 @@
using System; using System;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.Serialization; using UnityEngine.Serialization;

View File

@ -1,4 +1,4 @@
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization; using UnityEngine.Serialization;
using UnityEngine.UI; using UnityEngine.UI;

View File

@ -1,4 +1,4 @@
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization; using UnityEngine.Serialization;
namespace Coffee.UIExtensions.Demo namespace Coffee.UIExtensions.Demo