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
5 Commits
4.10.1
...
5.0.0-prev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db00e26221 | ||
|
|
6dde9e5399 | ||
|
|
9f31c57f59 | ||
|
|
81b4489329 | ||
|
|
dd94bba43c |
13
CHANGELOG.md
13
CHANGELOG.md
@@ -1,3 +1,16 @@
|
||||
# [5.0.0-preview.11](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v5.0.0-preview.10...v5.0.0-preview.11) (2024-09-29)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* change the default value of `UIParticle.scale` from `10` to `1` ([4e188dd](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/4e188dd39ee32dd1339066a6946e43ba3580c324))
|
||||
* UIParticle no longer inherits from MaskableGraphic ([52eb28c](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/52eb28cdafe7c9009d5a4b76978e002798440e8d))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* Some members inherited from MaskableGraphic will no longer be available.
|
||||
|
||||
## [4.10.1](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v4.10.0...v4.10.1) (2024-09-29)
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -26,7 +25,7 @@ namespace Coffee.UIExtensions
|
||||
{
|
||||
[CustomEditor(typeof(UIParticle))]
|
||||
[CanEditMultipleObjects]
|
||||
internal class UIParticleEditor : GraphicEditor
|
||||
internal class UIParticleEditor : Editor
|
||||
{
|
||||
//################################
|
||||
// Constant or Static Members.
|
||||
@@ -81,10 +80,8 @@ namespace Coffee.UIExtensions
|
||||
/// <summary>
|
||||
/// This function is called when the object becomes enabled and active.
|
||||
/// </summary>
|
||||
protected override void OnEnable()
|
||||
private void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
_maskable = serializedObject.FindProperty("m_Maskable");
|
||||
_scale3D = serializedObject.FindProperty("m_Scale3D");
|
||||
_animatableProperties = serializedObject.FindProperty("m_AnimatableProperties");
|
||||
@@ -437,9 +434,11 @@ namespace Coffee.UIExtensions
|
||||
{
|
||||
if (!p || (ignoreCurrent && target == p)) return;
|
||||
|
||||
var cr = p.canvasRenderer;
|
||||
DestroyImmediate(p);
|
||||
DestroyImmediate(cr);
|
||||
Misc.DestroyImmediate(p);
|
||||
if (p.TryGetComponent<CanvasRenderer>(out var cr))
|
||||
{
|
||||
Misc.DestroyImmediate(cr);
|
||||
}
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
var stage = PrefabStageUtility.GetCurrentPrefabStage();
|
||||
|
||||
15
README.md
15
README.md
@@ -11,7 +11,7 @@
|
||||
[](https://github.com/mob-sakai/ParticleEffectForUGUI/subscription)
|
||||
[](https://twitter.com/intent/follow?screen_name=mob_sakai)
|
||||
|
||||
<< [📝 Description](#-description-) | [📌 Key Features](#-key-features) | [🎮 Demo](#-demo) | [⚙ Installation](#-installation) | [🚀 Usage](#-usage) | [🛠 Development Note](#-development-note) | [🤝 Contributing](#-contributing) >>
|
||||
<< [📝 Description](#-description-) | [📌 Key Features](#-key-features) | [🎮 Demo](#-demo) | [⚙ Installation](#-installation) | [🔄 Upgrading to 5.x](#-upgrading-from-3x4x-to-5x) | [🚀 Usage](#-usage) | [🛠 Development Note](#-development-note) | [🤝 Contributing](#-contributing) >>
|
||||
|
||||
## 📝 Description <!-- omit in toc -->
|
||||
|
||||
@@ -27,6 +27,8 @@ You can render, mask, and sort your `ParticleSystems` for UI without the need fo
|
||||
- [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)
|
||||
- [🔄 Upgrading from 3.x/4.x to 5.x](#-upgrading-from-3x4x-to-5x)
|
||||
- [Breaking Changes](#breaking-changes)
|
||||
- [🚀 Usage](#-usage)
|
||||
- [Component: UIParticle](#component-uiparticle)
|
||||
- [Basic Usage](#basic-usage)
|
||||
@@ -152,6 +154,17 @@ _This package requires **Unity 2018.3 or later**._
|
||||
|
||||
<br><br>
|
||||
|
||||
## 🔄 Upgrading from 3.x/4.x to 5.x
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
- The default value of `UIParticle.scale` has been changed from `10` to `1`.
|
||||
- `UIParticle` no longer inherits from `MaskableGraphic`.
|
||||
- Add project settings for UIParticle
|
||||
- enableLinearToGamma: Enables LinearToGamma during mesh baking
|
||||
|
||||
<br><br>
|
||||
|
||||
## 🚀 Usage
|
||||
|
||||
### Component: UIParticle
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Coffee.UIParticleInternal
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for Graphic class.
|
||||
/// </summary>
|
||||
internal static class GraphicExtensions
|
||||
{
|
||||
private static readonly Vector3[] s_WorldCorners = new Vector3[4];
|
||||
private static readonly Bounds s_ScreenBounds = new Bounds(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(1, 1, 1));
|
||||
|
||||
/// <summary>
|
||||
/// Check if a Graphic component is currently in the screen view.
|
||||
/// </summary>
|
||||
public static void GetMaterialsForRendering(this Graphic self, List<Material> result)
|
||||
{
|
||||
result.Clear();
|
||||
if (!self) return;
|
||||
|
||||
var cr = self.canvasRenderer;
|
||||
var count = cr.materialCount;
|
||||
var popCount = cr.popMaterialCount;
|
||||
|
||||
if (result.Capacity < count + popCount)
|
||||
{
|
||||
result.Capacity = count + popCount;
|
||||
}
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
result.Add(cr.GetMaterial(i));
|
||||
}
|
||||
|
||||
for (var i = 0; i < popCount; i++)
|
||||
{
|
||||
result.Add(cr.GetPopMaterial(i));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a Graphic component is currently in the screen view.
|
||||
/// </summary>
|
||||
public static bool IsInScreen(this Graphic self)
|
||||
{
|
||||
if (!self || !self.canvas) return false;
|
||||
|
||||
if (FrameCache.TryGet(self, nameof(IsInScreen), out bool result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
Profiler.BeginSample("(COF)[GraphicExt] IsInScreen");
|
||||
var cam = self.canvas.renderMode != RenderMode.ScreenSpaceOverlay
|
||||
? self.canvas.worldCamera
|
||||
: null;
|
||||
var min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
|
||||
var max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
|
||||
self.rectTransform.GetWorldCorners(s_WorldCorners);
|
||||
var screenSize = GetScreenSize();
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
if (cam)
|
||||
{
|
||||
s_WorldCorners[i] = cam.WorldToViewportPoint(s_WorldCorners[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
s_WorldCorners[i] = RectTransformUtility.WorldToScreenPoint(null, s_WorldCorners[i]);
|
||||
s_WorldCorners[i].x /= screenSize.x;
|
||||
s_WorldCorners[i].y /= screenSize.y;
|
||||
}
|
||||
|
||||
s_WorldCorners[i].z = 0;
|
||||
min = Vector3.Min(s_WorldCorners[i], min);
|
||||
max = Vector3.Max(s_WorldCorners[i], max);
|
||||
}
|
||||
|
||||
var bounds = new Bounds(min, Vector3.zero);
|
||||
bounds.Encapsulate(max);
|
||||
result = bounds.Intersects(s_ScreenBounds);
|
||||
FrameCache.Set(self, nameof(IsInScreen), result);
|
||||
Profiler.EndSample();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual main texture of a Graphic component.
|
||||
/// </summary>
|
||||
public static Texture GetActualMainTexture(this Graphic self)
|
||||
{
|
||||
var image = self as Image;
|
||||
if (image == null) return self.mainTexture;
|
||||
|
||||
var sprite = image.overrideSprite;
|
||||
return sprite ? sprite.GetActualTexture() : self.mainTexture;
|
||||
}
|
||||
|
||||
private static Vector2Int GetScreenSize()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying && !Camera.current)
|
||||
{
|
||||
var res = UnityStats.screenRes.Split('x');
|
||||
return new Vector2Int(int.Parse(res[0]), int.Parse(res[1]));
|
||||
}
|
||||
#endif
|
||||
return new Vector2Int(Screen.width, Screen.height);
|
||||
}
|
||||
|
||||
public static float GetParentGroupAlpha(this Graphic self)
|
||||
{
|
||||
var alpha = self.canvasRenderer.GetAlpha();
|
||||
if (Mathf.Approximately(alpha, 0)) return 1;
|
||||
|
||||
var inheritedAlpha = self.canvasRenderer.GetInheritedAlpha();
|
||||
return Mathf.Clamp01(inheritedAlpha / alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3803b037cd2ed45459dd660072f223dd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,9 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Coffee.UIParticleInternal;
|
||||
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
|
||||
{
|
||||
@@ -60,7 +60,7 @@ namespace Coffee.UIExtensions
|
||||
|
||||
[Tooltip("Scale the rendering particles. When the `3D` toggle is enabled, 3D scale (x, y, z) is supported.")]
|
||||
[SerializeField]
|
||||
private Vector3 m_Scale3D = new Vector3(10, 10, 10);
|
||||
private Vector3 m_Scale3D = new Vector3(1, 1, 1);
|
||||
|
||||
[Tooltip("If you want to update material properties (e.g. _MainTex_ST, _Color) in AnimationClip, " +
|
||||
"use this to mark as animatable.")]
|
||||
@@ -117,20 +117,48 @@ namespace Coffee.UIExtensions
|
||||
"Change the bake view size.")]
|
||||
private float m_CustomViewSize = 10;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_Maskable = true;
|
||||
|
||||
private readonly List<UIParticleRenderer> _renderers = new List<UIParticleRenderer>();
|
||||
private Camera _bakeCamera;
|
||||
private Canvas _canvas;
|
||||
private int _groupId;
|
||||
private bool _isScaleStored;
|
||||
private Vector3 _storedScale;
|
||||
private DrivenRectTransformTracker _tracker;
|
||||
|
||||
/// <summary>
|
||||
/// Should this graphic be considered a target for ray-casting?
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Does this graphic allow masking.
|
||||
/// </summary>
|
||||
public bool maskable
|
||||
{
|
||||
get => m_Maskable;
|
||||
set
|
||||
{
|
||||
if (value == m_Maskable) return;
|
||||
m_Maskable = value;
|
||||
UpdateRendererMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -307,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);
|
||||
@@ -325,7 +353,7 @@ namespace Coffee.UIExtensions
|
||||
RefreshParticles();
|
||||
}
|
||||
|
||||
base.OnEnable();
|
||||
UpdateRendererMaterial();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -342,9 +370,15 @@ namespace Coffee.UIExtensions
|
||||
_isScaleStored = false;
|
||||
UIParticleUpdater.Unregister(this);
|
||||
_renderers.ForEach(r => r.Reset());
|
||||
UnregisterDirtyMaterialCallback(UpdateRendererMaterial);
|
||||
_canvas = null;
|
||||
}
|
||||
|
||||
base.OnDisable();
|
||||
/// <summary>
|
||||
/// Called when the state of the parent Canvas is changed.
|
||||
/// </summary>
|
||||
protected override void OnCanvasHierarchyChanged()
|
||||
{
|
||||
_canvas = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -354,6 +388,14 @@ namespace Coffee.UIExtensions
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is called when a direct or indirect parent of the transform of the GameObject has changed.
|
||||
/// </summary>
|
||||
protected override void OnTransformParentChanged()
|
||||
{
|
||||
_canvas = null;
|
||||
}
|
||||
|
||||
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
||||
{
|
||||
}
|
||||
@@ -646,17 +688,6 @@ namespace Coffee.UIExtensions
|
||||
: Random.Range(m_GroupId, m_GroupMaxId + 1);
|
||||
}
|
||||
|
||||
protected override void UpdateMaterial()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Call to update the geometry of the Graphic onto the CanvasRenderer.
|
||||
/// </summary>
|
||||
protected override void UpdateGeometry()
|
||||
{
|
||||
}
|
||||
|
||||
private void UpdateRendererMaterial()
|
||||
{
|
||||
for (var i = 0; i < _renderers.Count; i++)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "com.coffee.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.",
|
||||
"version": "4.10.1",
|
||||
"version": "5.0.0-preview.11",
|
||||
"unity": "2018.2",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
|
||||
Reference in New Issue
Block a user