Compare commits

...

16 Commits
2.0.0 ... 2.3.0

Author SHA1 Message Date
mob-sakai
9c525ad0f0 update documents for v2.3.0 2019-05-12 16:03:20 +09:00
mob-sakai
66a0ab7ad5 fix #47; World simulation bug 2019-05-08 00:06:46 +09:00
mob-sakai
888eac4e54 update documents for v2.2.1 2019-02-26 11:30:17 +09:00
mob-sakai
f6e64c325b close #45; Disable ParticleSystemRenderer on reset 2019-02-26 11:28:22 +09:00
mob-sakai
beb6fa8367 Format 2019-02-26 11:11:48 +09:00
mob-sakai
6c2ed22e3a fix #44; v2.2.0 has 2 warnings 2019-02-26 11:10:47 +09:00
mob-sakai
4c260061c8 update documents for v2.2.0 2019-02-23 23:39:55 +09:00
mob-sakai
fb2904160e Update demo 2019-02-23 23:28:50 +09:00
mob-sakai
7696451ac9 Refactor 2019-02-23 23:28:50 +09:00
mob-sakai
54098eea56 close #43; Display warning when material does not support Mask 2019-02-23 21:29:38 +09:00
mob-sakai
79bbc4de95 close #42; Support changing material property by AnimationClip 2019-02-23 16:40:57 +09:00
mob-sakai
b73a8adb4d update documents for v2.1.1 2019-02-15 22:21:57 +09:00
mob-sakai
9749e3e01c fix #39; UIParticle.Scale - Rendering Order Issue 2019-02-15 21:50:12 +09:00
mob-sakai
8c674cba2e update documents for v2.1.0 2019-02-07 10:44:25 +09:00
mob-sakai
87bdefce2b fix #37; When moving the transform in world simulation mode, particles don't behave as expected 2019-02-06 20:51:35 +09:00
mob-sakai
59fc95f1ea Update demo 2019-01-17 22:10:07 +09:00
7 changed files with 431 additions and 55 deletions

View File

@@ -1,20 +1,67 @@
# Changelog
## [2.0.0](https://github.com/mob-sakai/ParticleEffectForUGUI/tree/2.0.0) (2019-01-17)
## [v2.3.0](https://github.com/mob-sakai/ParticleEffectForUGUI/tree/v2.3.0) (2019-05-12)
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v1.3.3...2.0.0)
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v2.2.1...v2.3.0)
**Install UIParticle with Unity Package Manager!**
Find the manifest.json file in the Packages folder of your project and edit it to look like this:
```js
{
"dependencies": {
"com.coffee.ui-particle": "https://github.com/mob-sakai/ParticleEffectForUGUI.git#2.0.0",
...
},
}
```
World simulation bug due to transform movement have been fixed
**Fixed bugs:**
- World simulation bug due to transform movement [\#47](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/47)
## [v2.2.1](https://github.com/mob-sakai/ParticleEffectForUGUI/tree/v2.2.1) (2019-02-26)
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v2.2.0...v2.2.1)
**Fixed bugs:**
- v2.2.0 has 2 warnings [\#44](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/44)
- Disable ParticleSystemRenderer on reset [\#45](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/45)
## [v2.2.0](https://github.com/mob-sakai/ParticleEffectForUGUI/tree/v2.2.0) (2019-02-23)
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v2.1.1...v2.2.0)
**Implemented enhancements:**
- Display warning when material does not support Mask [\#43](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/43)
- Support changing material property by AnimationClip [\#42](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/42)
**Fixed bugs:**
- UV Animation is not work. [\#41](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/41)
## [v2.1.1](https://github.com/mob-sakai/ParticleEffectForUGUI/tree/v2.1.1) (2019-02-15)
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v2.1.0...v2.1.1)
## [v2.1.0](https://github.com/mob-sakai/ParticleEffectForUGUI/tree/v2.1.0) (2019-02-07)
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v2.0.0...v2.1.0)
World simulation bug is fixed.
![](https://user-images.githubusercontent.com/12690315/52386223-71a56000-2ac8-11e9-9cdb-93175d24febe.gif)
**Fixed bugs:**
- When moving the transform in world simulation mode, particles don't behave as expected [\#37](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/37)
## [v2.0.0](https://github.com/mob-sakai/ParticleEffectForUGUI/tree/v2.0.0) (2019-01-17)
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v1.3.3...v2.0.0)
**Install UIParticle with Unity Package Manager!**
Find the manifest.json file in the Packages folder of your project and edit it to look like this:
```js
{
"dependencies": {
"com.coffee.ui-particle": "https://github.com/mob-sakai/ParticleEffectForUGUI.git#2.0.0",
...
},
}
```
To update the package, change `#2.0.0` to the target version.
**Implemented enhancements:**
@@ -55,7 +102,7 @@ To update the package, change `#2.0.0` to the target version.
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v1.2.1...v1.3.0)
With Gizmo you can control the scaled Shape.
With Gizmo you can control the scaled Shape.
![](https://user-images.githubusercontent.com/12690315/50343861-f31e4e80-056b-11e9-8f60-8bd0a8ff7adb.gif)
**Fixed bugs:**
@@ -75,18 +122,18 @@ With Gizmo you can control the scaled Shape.
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v1.1.0...v1.2.0)
New scaling system solves the particle effect scaling problem in most cases.
* All ParticleSystem.ScalingModes are supported
* All Canvas.RenderModes are supported
* They look almost the same in all modes
New scaling system scales particle effect well even if you change the following parameters:
* Camera.FieldOfView
* CanvasScaler.MatchWidthOrHeight
* Canvas.PlaneDistance
![](https://user-images.githubusercontent.com/12690315/49866926-6c22f500-fe4c-11e8-8393-d5a546e9e2d3.gif)
New scaling system solves the particle effect scaling problem in most cases.
* All ParticleSystem.ScalingModes are supported
* All Canvas.RenderModes are supported
* They look almost the same in all modes
New scaling system scales particle effect well even if you change the following parameters:
* Camera.FieldOfView
* CanvasScaler.MatchWidthOrHeight
* Canvas.PlaneDistance
![](https://user-images.githubusercontent.com/12690315/49866926-6c22f500-fe4c-11e8-8393-d5a546e9e2d3.gif)
**NOTE: If upgrading from v1.1.0, readjust the UIParticle.Scale property.**
**Implemented enhancements:**
@@ -103,11 +150,11 @@ New scaling system scales particle effect well even if you change the following
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v1.0.0...v1.1.0)
Easily to use, easily to set up.
* Adjust the Scale property to change the size of the effect.
![](https://user-images.githubusercontent.com/12690315/49148937-19c1de80-f34c-11e8-87fc-138192777540.gif)
* If your effect consists of multiple ParticleSystems, you can quickly set up UIParticles by clicking "Fix".
Easily to use, easily to set up.
* Adjust the Scale property to change the size of the effect.
![](https://user-images.githubusercontent.com/12690315/49148937-19c1de80-f34c-11e8-87fc-138192777540.gif)
* If your effect consists of multiple ParticleSystems, you can quickly set up UIParticles by clicking "Fix".
![](https://user-images.githubusercontent.com/12690315/49148942-1c243880-f34c-11e8-9cf5-d871d65c4dbe.png)
**Implemented enhancements:**
@@ -123,9 +170,9 @@ Easily to use, easily to set up.
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v0.1.0...v1.0.0)
Let's use particle for your UI!
UIParticle is use easy.
The particle rendering is maskable and sortable, without Camera, RenderTexture or Canvas.
Let's use particle for your UI!
UIParticle is use easy.
The particle rendering is maskable and sortable, without Camera, RenderTexture or Canvas.
![](https://user-images.githubusercontent.com/12690315/41771577-8da4b968-7650-11e8-9524-cd162c422d9d.gif)
**Implemented enhancements:**
@@ -137,9 +184,9 @@ The particle rendering is maskable and sortable, without Camera, RenderTexture o
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/6b89c14a5144e290e55d041bc0ad03756a113ae0...v0.1.0)
![](https://user-images.githubusercontent.com/12690315/41771577-8da4b968-7650-11e8-9524-cd162c422d9d.gif)
This plugin uses new APIs `MeshBake/MashTrailBake` (added with Unity 2018.2) to render particles by CanvasRenderer.
![](https://user-images.githubusercontent.com/12690315/41771577-8da4b968-7650-11e8-9524-cd162c422d9d.gif)
This plugin uses new APIs `MeshBake/MashTrailBake` (added with Unity 2018.2) to render particles by CanvasRenderer.
You can mask and sort particles for uGUI without Camera, RenderTexture, Canvas.
**Implemented enhancements:**
@@ -148,4 +195,4 @@ You can mask and sort particles for uGUI without Camera, RenderTexture, Canvas.
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*

View File

@@ -55,6 +55,8 @@ Compares this "Baking mesh" approach with the conventional approach:
![](https://user-images.githubusercontent.com/12690315/49866926-6c22f500-fe4c-11e8-8393-d5a546e9e2d3.gif)
* Scaled gizmo
![](https://user-images.githubusercontent.com/12690315/50343861-f31e4e80-056b-11e9-8f60-8bd0a8ff7adb.gif)
* Animatable material property
![](https://user-images.githubusercontent.com/12690315/53286323-2d94a980-37b0-11e9-8afb-c4a207805ff2.gif)
@@ -74,12 +76,13 @@ Find the manifest.json file in the Packages folder of your project and edit it t
```js
{
"dependencies": {
"com.coffee.ui-particle": "https://github.com/mob-sakai/ParticleEffectForUGUI.git#2.0.0",
"com.coffee.ui-particle": "https://github.com/mob-sakai/ParticleEffectForUGUI.git#2.2.1",
...
},
}
```
To update the package, change `#2.0.0` to the target version.
To update the package, change `#{version}` to the target version.
Or, use [UpmGitExtension](https://github.com/mob-sakai/UpmGitExtension).
#### Using .unitypackage file (for Unity 2018.2+)
@@ -124,6 +127,21 @@ Select `Assets > Import Package > Custom Package` from the menu.
<br><br><br><br>
## Development Note
#### Animatable material property
![](https://user-images.githubusercontent.com/12690315/53286323-2d94a980-37b0-11e9-8afb-c4a207805ff2.gif)
Animation clips can change the material properties of the Renderer, such as ParticleSystemRenderer.
It uses MaterialPropertyBlock so it does not create new material instances.
Using material properties, you can change UV animation, scale and color etc.
Well, there is a component called CanvasRenderer.
It is used by all Graphic components for UI (Text, Image, Raw Image, etc.) including UIParticle.
However, It is **NOT** a Renderer.
Therefore, in UIParticle, changing ParticleSystemRenderer's MaterialPropertyBlock by animation clip is ignored.
To prevent this, Use "Animatable Material Property".
"Animatable Material Property" gets the necessary properties from ParticleSystemRenderer's MaterialPropertyBlock and sets them to the CanvasRenderer's material.

View File

@@ -6,6 +6,7 @@ using System.Linq;
using UnityEditor.IMGUI.Controls;
using System;
using System.Reflection;
using ShaderPropertyType = Coffee.UIExtensions.UIParticle.AnimatableProperty.ShaderPropertyType;
namespace Coffee.UIExtensions
{
@@ -13,6 +14,108 @@ namespace Coffee.UIExtensions
[CanEditMultipleObjects]
public class UIParticleEditor : GraphicEditor
{
class AnimatedPropertiesEditor
{
static readonly List<string> s_ActiveNames = new List<string> ();
static readonly System.Text.StringBuilder s_Sb = new System.Text.StringBuilder ();
public string name;
public ShaderPropertyType type;
static string CollectActiveNames (SerializedProperty sp, List<string> result)
{
result.Clear ();
for (int i = 0; i < sp.arraySize; i++)
{
result.Add (sp.GetArrayElementAtIndex (i).FindPropertyRelative ("m_Name").stringValue);
}
s_Sb.Length = 0;
if (result.Count == 0)
{
s_Sb.Append ("Nothing");
}
else
{
result.Aggregate (s_Sb, (a, b) => s_Sb.AppendFormat ("{0}, ", b));
s_Sb.Length -= 2;
}
return s_Sb.ToString ();
}
public static void DrawAnimatableProperties (SerializedProperty sp, Material mat)
{
if (!mat || !mat.shader)
return;
bool isClicked = false;
using (new EditorGUILayout.HorizontalScope (GUILayout.ExpandWidth (false)))
{
var r = EditorGUI.PrefixLabel (EditorGUILayout.GetControlRect (true), new GUIContent (sp.displayName, sp.tooltip));
isClicked = GUI.Button (r, CollectActiveNames (sp, s_ActiveNames), EditorStyles.popup);
}
if (isClicked)
{
GenericMenu gm = new GenericMenu ();
gm.AddItem (new GUIContent ("Nothing"), s_ActiveNames.Count == 0, () =>
{
sp.ClearArray ();
sp.serializedObject.ApplyModifiedProperties ();
});
for (int i = 0; i < sp.arraySize; i++)
{
var p = sp.GetArrayElementAtIndex (i);
var name = p.FindPropertyRelative ("m_Name").stringValue;
var type = (ShaderPropertyType)p.FindPropertyRelative ("m_Type").intValue;
AddMenu (gm, sp, new AnimatedPropertiesEditor () { name = name, type = type }, false);
}
for (int i = 0; i < ShaderUtil.GetPropertyCount (mat.shader); i++)
{
var pName = ShaderUtil.GetPropertyName (mat.shader, i);
var type = (ShaderPropertyType)ShaderUtil.GetPropertyType (mat.shader, i);
AddMenu (gm, sp, new AnimatedPropertiesEditor () { name = pName, type = type }, true);
if (type == ShaderPropertyType.Texture)
{
AddMenu (gm, sp, new AnimatedPropertiesEditor () { name = pName + "_ST", type = ShaderPropertyType.Vector }, true);
AddMenu (gm, sp, new AnimatedPropertiesEditor () { name = pName + "_HDR", type = ShaderPropertyType.Vector }, true);
AddMenu (gm, sp, new AnimatedPropertiesEditor () { name = pName + "_TexelSize", type = ShaderPropertyType.Vector }, true);
}
}
gm.ShowAsContext ();
}
}
public static void AddMenu (GenericMenu menu, SerializedProperty sp, AnimatedPropertiesEditor property, bool add)
{
if (add && s_ActiveNames.Contains (property.name))
return;
menu.AddItem (new GUIContent (string.Format ("{0} ({1})", property.name, property.type)), s_ActiveNames.Contains (property.name), () =>
{
var index = s_ActiveNames.IndexOf (property.name);
if (0 <= index)
{
sp.DeleteArrayElementAtIndex (index);
}
else
{
sp.InsertArrayElementAtIndex (sp.arraySize);
var p = sp.GetArrayElementAtIndex (sp.arraySize - 1);
p.FindPropertyRelative ("m_Name").stringValue = property.name;
p.FindPropertyRelative ("m_Type").intValue = (int)property.type;
}
sp.serializedObject.ApplyModifiedProperties ();
});
}
}
//################################
// Constant or Static Members.
//################################
@@ -25,6 +128,15 @@ namespace Coffee.UIExtensions
static readonly Color s_ShapeGizmoThicknessTint = new Color (0.7f, 0.7f, 0.7f, 1.0f);
static Material s_Material;
static readonly List<string> s_MaskablePropertyNames = new List<string> ()
{
"_Stencil",
"_StencilComp",
"_StencilOp",
"_StencilWriteMask",
"_StencilReadMask",
"_ColorMask",
};
//################################
// Public/Protected Members.
@@ -39,6 +151,7 @@ namespace Coffee.UIExtensions
_spTrailParticle = serializedObject.FindProperty ("m_TrailParticle");
_spScale = serializedObject.FindProperty ("m_Scale");
_spIgnoreParent = serializedObject.FindProperty ("m_IgnoreParent");
_spAnimatableProperties = serializedObject.FindProperty ("m_AnimatableProperties");
if (!s_Material)
{
@@ -86,6 +199,9 @@ namespace Coffee.UIExtensions
EditorGUILayout.PropertyField (_spScale);
EditorGUI.EndDisabledGroup ();
// AnimatableProperties
AnimatedPropertiesEditor.DrawAnimatableProperties (_spAnimatableProperties, current.material);
current.GetComponentsInChildren<ParticleSystem> (true, s_ParticleSystems);
if (s_ParticleSystems.Any (x => x.GetComponent<UIParticle> () == null))
{
@@ -104,9 +220,28 @@ namespace Coffee.UIExtensions
}
s_ParticleSystems.Clear ();
if (current.maskable && current.material && current.material.shader)
{
var mat = current.material;
var shader = mat.shader;
foreach (var propName in s_MaskablePropertyNames)
{
if (!mat.HasProperty (propName))
{
EditorGUILayout.HelpBox (string.Format ("Shader {0} doesn't have '{1}' property. This graphic is not maskable.", shader.name, propName), MessageType.Warning);
break;
}
}
}
serializedObject.ApplyModifiedProperties ();
}
//################################
// Private Members.
//################################
@@ -114,6 +249,7 @@ namespace Coffee.UIExtensions
SerializedProperty _spTrailParticle;
SerializedProperty _spScale;
SerializedProperty _spIgnoreParent;
SerializedProperty _spAnimatableProperties;
UIParticle [] _particles;
ArcHandle _arcHandle = new ArcHandle ();
BoxBoundsHandle _boxBoundsHandle = new BoxBoundsHandle ();
@@ -174,7 +310,7 @@ namespace Coffee.UIExtensions
transformMatrix *= emitterMatrix;
Handles.matrix = transformMatrix;
if(uip.canvas.renderMode == RenderMode.ScreenSpaceOverlay || ps.main.scalingMode == ParticleSystemScalingMode.Hierarchy)
if (uip.canvas.renderMode == RenderMode.ScreenSpaceOverlay || ps.main.scalingMode == ParticleSystemScalingMode.Hierarchy)
{
Handles.matrix = Handles.matrix * Matrix4x4.Scale (Vector3.one * uip.scale);
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.UI;
using ShaderPropertyType = Coffee.UIExtensions.UIParticle.AnimatableProperty.ShaderPropertyType;
namespace Coffee.UIExtensions
@@ -35,6 +36,42 @@ namespace Coffee.UIExtensions
[Tooltip ("Ignore parent scale")]
[SerializeField] bool m_IgnoreParent = false;
[Tooltip ("Animatable material properties. AnimationでParticleSystemのマテリアルプロパティを変更する場合、有効にしてください。")]
[SerializeField] AnimatableProperty [] m_AnimatableProperties = new AnimatableProperty [0];
static MaterialPropertyBlock s_Mpb;
[System.Serializable]
public class AnimatableProperty : ISerializationCallbackReceiver
{
public enum ShaderPropertyType
{
Color,
Vector,
Float,
Range,
Texture,
};
[SerializeField]
string m_Name = "";
[SerializeField]
ShaderPropertyType m_Type = ShaderPropertyType.Vector;
public int id { get; private set; }
public ShaderPropertyType type { get { return m_Type; } }
public void OnBeforeSerialize ()
{
}
public void OnAfterDeserialize ()
{
id = Shader.PropertyToID (m_Name);
}
}
//################################
// Public/Protected Members.
@@ -57,9 +94,7 @@ namespace Coffee.UIExtensions
if (!tex && _renderer)
{
Profiler.BeginSample ("Check material");
var mat = m_IsTrail
? _renderer.trailMaterial
: _renderer.sharedMaterial;
var mat = material;
if (mat && mat.HasProperty (s_IdMainTex))
{
tex = mat.mainTexture;
@@ -70,6 +105,35 @@ namespace Coffee.UIExtensions
}
}
public override Material material
{
get
{
return _renderer
? m_IsTrail
? _renderer.trailMaterial
: _renderer.sharedMaterial
: null;
}
set
{
if (!_renderer)
{
}
else if (m_IsTrail && _renderer.trailMaterial != value)
{
_renderer.trailMaterial = value;
SetMaterialDirty ();
}
else if (!m_IsTrail && _renderer.sharedMaterial != value)
{
_renderer.sharedMaterial = value;
SetMaterialDirty ();
}
}
}
/// <summary>
/// Particle effect scale.
/// </summary>
@@ -117,7 +181,15 @@ namespace Coffee.UIExtensions
/// <param name="baseMaterial">Configured Material.</param>
public override Material GetModifiedMaterial (Material baseMaterial)
{
return base.GetModifiedMaterial (_renderer ? _renderer.sharedMaterial : baseMaterial);
Material mat = null;
if (!_renderer)
mat = baseMaterial;
else if (m_AnimatableProperties.Length == 0)
mat = _renderer.sharedMaterial;
else
mat = new Material (material);
return base.GetModifiedMaterial (mat);
}
/// <summary>
@@ -129,6 +201,7 @@ namespace Coffee.UIExtensions
if (s_ActiveParticles.Count == 0)
{
Canvas.willRenderCanvases += UpdateMeshes;
s_Mpb = new MaterialPropertyBlock ();
}
s_ActiveParticles.Add (this);
@@ -151,6 +224,13 @@ namespace Coffee.UIExtensions
_mesh.MarkDynamic ();
CheckTrail ();
if (cachedParticleSystem)
{
_oldPos = cachedParticleSystem.main.scalingMode == ParticleSystemScalingMode.Local
? rectTransform.localPosition
: rectTransform.position;
}
base.OnEnable ();
}
@@ -182,6 +262,21 @@ namespace Coffee.UIExtensions
base.OnDisable ();
}
#if UNITY_EDITOR
/// <summary>
/// Reset to default values.
/// </summary>
protected override void Reset ()
{
// Disable ParticleSystemRenderer on reset.
if (cachedParticleSystem)
{
cachedParticleSystem.GetComponent<ParticleSystemRenderer> ().enabled = false;
}
base.Reset ();
}
#endif
/// <summary>
/// Call to update the geometry of the Graphic onto the CanvasRenderer.
/// </summary>
@@ -236,6 +331,8 @@ namespace Coffee.UIExtensions
UIParticle _parent;
List<UIParticle> _children = new List<UIParticle> ();
Matrix4x4 scaleaMatrix = default (Matrix4x4);
Vector3 _oldPos;
static ParticleSystem.Particle [] s_Particles = new ParticleSystem.Particle [4096];
/// <summary>
/// Update meshes.
@@ -264,7 +361,7 @@ namespace Coffee.UIExtensions
if (m_ParticleSystem && canvas)
{
if (canvas.renderMode != RenderMode.ScreenSpaceOverlay)
// I do not know why, but it worked fine when setting `transform.localPosition.z` to `0.01`. (#34, #39)
{
Vector3 pos = rectTransform.localPosition;
if (Mathf.Abs (pos.z) < 0.01f)
@@ -283,22 +380,58 @@ namespace Coffee.UIExtensions
Profiler.EndSample ();
Profiler.BeginSample ("Make Matrix");
scaleaMatrix = m_ParticleSystem.main.scalingMode == ParticleSystemScalingMode.Hierarchy
? Matrix4x4.Scale (scale * Vector3.one)
: Matrix4x4.Scale (scale * rootCanvas.transform.localScale);
ParticleSystem.MainModule main = m_ParticleSystem.main;
scaleaMatrix = main.scalingMode == ParticleSystemScalingMode.Hierarchy
? Matrix4x4.Scale (scale * Vector3.one)
: Matrix4x4.Scale (scale * rootCanvas.transform.localScale);
Matrix4x4 matrix = default (Matrix4x4);
switch (m_ParticleSystem.main.simulationSpace)
switch (main.simulationSpace)
{
case ParticleSystemSimulationSpace.Local:
matrix =
scaleaMatrix
* Matrix4x4.Rotate (m_ParticleSystem.transform.rotation).inverse
* Matrix4x4.Scale (m_ParticleSystem.transform.lossyScale).inverse;
* Matrix4x4.Rotate (rectTransform.rotation).inverse
* Matrix4x4.Scale (rectTransform.lossyScale).inverse;
break;
case ParticleSystemSimulationSpace.World:
matrix =
scaleaMatrix
* m_ParticleSystem.transform.worldToLocalMatrix;
* rectTransform.worldToLocalMatrix;
bool isLocalScaling = main.scalingMode == ParticleSystemScalingMode.Local;
Vector3 newPos = rectTransform.position;
Vector3 delta = (newPos - _oldPos);
_oldPos = newPos;
if (!Mathf.Approximately (scale, 0) && 0 < delta.sqrMagnitude)
{
if(isLocalScaling)
{
var s = rootCanvas.transform.localScale * scale;
delta.x *= 1f - 1f / s.x;
delta.y *= 1f - 1f / s.y;
delta.z *= 1f - 1f / s.z;
}
else
{
delta = delta * (1 - 1 / scale);
}
int count = m_ParticleSystem.particleCount;
if (s_Particles.Length < count)
{
s_Particles = new ParticleSystem.Particle [s_Particles.Length * 2];
}
m_ParticleSystem.GetParticles (s_Particles);
for (int i = 0; i < count; i++)
{
var p = s_Particles [i];
p.position = p.position + delta;
s_Particles [i] = p;
}
m_ParticleSystem.SetParticles (s_Particles, count);
}
break;
case ParticleSystemSimulationSpace.Custom:
break;
@@ -345,6 +478,10 @@ namespace Coffee.UIExtensions
Profiler.BeginSample ("Set mesh and texture to CanvasRenderer");
canvasRenderer.SetMesh (_mesh);
canvasRenderer.SetTexture (mainTexture);
// Copy the value from MaterialPropertyBlock to CanvasRenderer (#41)
UpdateAnimatableMaterialProperties ();
Profiler.EndSample ();
}
}
@@ -403,5 +540,43 @@ namespace Coffee.UIExtensions
_parent._children.Add (this);
}
}
/// <summary>
/// Copy the value from MaterialPropertyBlock to CanvasRenderer (#41)
/// </summary>
void UpdateAnimatableMaterialProperties ()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
return;
#endif
if (0 == m_AnimatableProperties.Length)
return;
_renderer.GetPropertyBlock (s_Mpb);
for (int i = 0; i < canvasRenderer.materialCount; i++)
{
var mat = canvasRenderer.GetMaterial (i);
foreach (var ap in m_AnimatableProperties)
{
switch (ap.type)
{
case ShaderPropertyType.Color:
mat.SetColor (ap.id, s_Mpb.GetColor (ap.id));
break;
case ShaderPropertyType.Vector:
mat.SetVector (ap.id, s_Mpb.GetVector (ap.id));
break;
case ShaderPropertyType.Float:
case ShaderPropertyType.Range:
mat.SetFloat (ap.id, s_Mpb.GetFloat (ap.id));
break;
case ShaderPropertyType.Texture:
mat.SetTexture (ap.id, s_Mpb.GetTexture (ap.id));
break;
}
}
}
}
}
}

View File

@@ -77,7 +77,7 @@
v2f OUT;
OUT.worldPosition = IN.vertex;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.texcoord = IN.texcoord;
OUT.texcoord = TRANSFORM_TEX(IN.texcoord, _MainTex);
#ifdef UNITY_HALF_TEXEL_OFFSET
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
#endif

Binary file not shown.

View File

@@ -2,7 +2,7 @@
"name": "com.coffee.ui-particle",
"displayName": "UI Particle",
"description": "This plugin provide a component to render particle effect for uGUI.\nThe particle rendering is maskable and sortable, without Camera, RenderTexture or Canvas.",
"version": "2.0.0",
"version": "2.3.0",
"unity": "2018.2",
"license": "MIT",
"repository": {