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
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c260061c8 | ||
|
|
fb2904160e | ||
|
|
7696451ac9 | ||
|
|
54098eea56 | ||
|
|
79bbc4de95 | ||
|
|
b73a8adb4d | ||
|
|
9749e3e01c | ||
|
|
8c674cba2e | ||
|
|
87bdefce2b | ||
|
|
59fc95f1ea |
104
CHANGELOG.md
104
CHANGELOG.md
@@ -1,20 +1,48 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## [2.0.0](https://github.com/mob-sakai/ParticleEffectForUGUI/tree/2.0.0) (2019-01-17)
|
## [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/v1.3.3...2.0.0)
|
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v2.1.1...v2.2.0)
|
||||||
|
|
||||||
**Install UIParticle with Unity Package Manager!**
|
**Implemented enhancements:**
|
||||||
|
|
||||||
Find the manifest.json file in the Packages folder of your project and edit it to look like this:
|
- Display warning when material does not support Mask [\#43](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/43)
|
||||||
```js
|
- Support changing material property by AnimationClip [\#42](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/42)
|
||||||
{
|
|
||||||
"dependencies": {
|
**Fixed bugs:**
|
||||||
"com.coffee.ui-particle": "https://github.com/mob-sakai/ParticleEffectForUGUI.git#2.0.0",
|
|
||||||
...
|
- 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.
|
||||||
|

|
||||||
|
|
||||||
|
**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.
|
To update the package, change `#2.0.0` to the target version.
|
||||||
|
|
||||||
**Implemented enhancements:**
|
**Implemented enhancements:**
|
||||||
@@ -55,7 +83,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)
|
[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.
|
||||||

|

|
||||||
|
|
||||||
**Fixed bugs:**
|
**Fixed bugs:**
|
||||||
@@ -75,18 +103,18 @@ With Gizmo you can control the scaled Shape.
|
|||||||
|
|
||||||
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v1.1.0...v1.2.0)
|
[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.
|
New scaling system solves the particle effect scaling problem in most cases.
|
||||||
* All ParticleSystem.ScalingModes are supported
|
* All ParticleSystem.ScalingModes are supported
|
||||||
* All Canvas.RenderModes are supported
|
* All Canvas.RenderModes are supported
|
||||||
* They look almost the same in all modes
|
* They look almost the same in all modes
|
||||||
|
|
||||||
New scaling system scales particle effect well even if you change the following parameters:
|
New scaling system scales particle effect well even if you change the following parameters:
|
||||||
* Camera.FieldOfView
|
* Camera.FieldOfView
|
||||||
* CanvasScaler.MatchWidthOrHeight
|
* CanvasScaler.MatchWidthOrHeight
|
||||||
* Canvas.PlaneDistance
|
* Canvas.PlaneDistance
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
**NOTE: If upgrading from v1.1.0, readjust the UIParticle.Scale property.**
|
**NOTE: If upgrading from v1.1.0, readjust the UIParticle.Scale property.**
|
||||||
|
|
||||||
**Implemented enhancements:**
|
**Implemented enhancements:**
|
||||||
@@ -103,11 +131,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)
|
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v1.0.0...v1.1.0)
|
||||||
|
|
||||||
Easily to use, easily to set up.
|
Easily to use, easily to set up.
|
||||||
|
|
||||||
* Adjust the Scale property to change the size of the effect.
|
* Adjust the Scale property to change the size of the effect.
|
||||||

|

|
||||||
* If your effect consists of multiple ParticleSystems, you can quickly set up UIParticles by clicking "Fix".
|
* If your effect consists of multiple ParticleSystems, you can quickly set up UIParticles by clicking "Fix".
|
||||||

|

|
||||||
|
|
||||||
**Implemented enhancements:**
|
**Implemented enhancements:**
|
||||||
@@ -123,9 +151,9 @@ Easily to use, easily to set up.
|
|||||||
|
|
||||||
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v0.1.0...v1.0.0)
|
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v0.1.0...v1.0.0)
|
||||||
|
|
||||||
Let's use particle for your UI!
|
Let's use particle for your UI!
|
||||||
UIParticle is use easy.
|
UIParticle is use easy.
|
||||||
The particle rendering is maskable and sortable, without Camera, RenderTexture or Canvas.
|
The particle rendering is maskable and sortable, without Camera, RenderTexture or Canvas.
|
||||||

|

|
||||||
|
|
||||||
**Implemented enhancements:**
|
**Implemented enhancements:**
|
||||||
@@ -137,9 +165,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)
|
[Full Changelog](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/6b89c14a5144e290e55d041bc0ad03756a113ae0...v0.1.0)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
This plugin uses new APIs `MeshBake/MashTrailBake` (added with Unity 2018.2) to render particles by CanvasRenderer.
|
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.
|
You can mask and sort particles for uGUI without Camera, RenderTexture, Canvas.
|
||||||
|
|
||||||
**Implemented enhancements:**
|
**Implemented enhancements:**
|
||||||
@@ -148,4 +176,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)*
|
||||||
|
|||||||
22
README.md
22
README.md
@@ -55,6 +55,8 @@ Compares this "Baking mesh" approach with the conventional approach:
|
|||||||

|

|
||||||
* Scaled gizmo
|
* Scaled gizmo
|
||||||

|

|
||||||
|
* Animatable material property
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -74,12 +76,13 @@ Find the manifest.json file in the Packages folder of your project and edit it t
|
|||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
"dependencies": {
|
"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.0",
|
||||||
...
|
...
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
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+)
|
#### Using .unitypackage file (for Unity 2018.2+)
|
||||||
|
|
||||||
@@ -124,6 +127,21 @@ Select `Assets > Import Package > Custom Package` from the menu.
|
|||||||
<br><br><br><br>
|
<br><br><br><br>
|
||||||
## Development Note
|
## Development Note
|
||||||
|
|
||||||
|
#### Animatable material property
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.Linq;
|
|||||||
using UnityEditor.IMGUI.Controls;
|
using UnityEditor.IMGUI.Controls;
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using ShaderPropertyType = Coffee.UIExtensions.UIParticle.AnimatableProperty.ShaderPropertyType;
|
||||||
|
|
||||||
namespace Coffee.UIExtensions
|
namespace Coffee.UIExtensions
|
||||||
{
|
{
|
||||||
@@ -13,6 +14,108 @@ namespace Coffee.UIExtensions
|
|||||||
[CanEditMultipleObjects]
|
[CanEditMultipleObjects]
|
||||||
public class UIParticleEditor : GraphicEditor
|
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.
|
// 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 readonly Color s_ShapeGizmoThicknessTint = new Color (0.7f, 0.7f, 0.7f, 1.0f);
|
||||||
static Material s_Material;
|
static Material s_Material;
|
||||||
|
|
||||||
|
static readonly List<string> s_MaskablePropertyNames = new List<string> ()
|
||||||
|
{
|
||||||
|
"_Stencil",
|
||||||
|
"_StencilComp",
|
||||||
|
"_StencilOp",
|
||||||
|
"_StencilWriteMask",
|
||||||
|
"_StencilReadMask",
|
||||||
|
"_ColorMask",
|
||||||
|
};
|
||||||
|
|
||||||
//################################
|
//################################
|
||||||
// Public/Protected Members.
|
// Public/Protected Members.
|
||||||
@@ -39,6 +151,7 @@ namespace Coffee.UIExtensions
|
|||||||
_spTrailParticle = serializedObject.FindProperty ("m_TrailParticle");
|
_spTrailParticle = serializedObject.FindProperty ("m_TrailParticle");
|
||||||
_spScale = serializedObject.FindProperty ("m_Scale");
|
_spScale = serializedObject.FindProperty ("m_Scale");
|
||||||
_spIgnoreParent = serializedObject.FindProperty ("m_IgnoreParent");
|
_spIgnoreParent = serializedObject.FindProperty ("m_IgnoreParent");
|
||||||
|
_spAnimatableProperties = serializedObject.FindProperty ("m_AnimatableProperties");
|
||||||
|
|
||||||
if (!s_Material)
|
if (!s_Material)
|
||||||
{
|
{
|
||||||
@@ -86,6 +199,9 @@ namespace Coffee.UIExtensions
|
|||||||
EditorGUILayout.PropertyField (_spScale);
|
EditorGUILayout.PropertyField (_spScale);
|
||||||
EditorGUI.EndDisabledGroup ();
|
EditorGUI.EndDisabledGroup ();
|
||||||
|
|
||||||
|
// AnimatableProperties
|
||||||
|
AnimatedPropertiesEditor.DrawAnimatableProperties (_spAnimatableProperties, current.material);
|
||||||
|
|
||||||
current.GetComponentsInChildren<ParticleSystem> (true, s_ParticleSystems);
|
current.GetComponentsInChildren<ParticleSystem> (true, s_ParticleSystems);
|
||||||
if (s_ParticleSystems.Any (x => x.GetComponent<UIParticle> () == null))
|
if (s_ParticleSystems.Any (x => x.GetComponent<UIParticle> () == null))
|
||||||
{
|
{
|
||||||
@@ -104,9 +220,28 @@ namespace Coffee.UIExtensions
|
|||||||
}
|
}
|
||||||
s_ParticleSystems.Clear ();
|
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 ();
|
serializedObject.ApplyModifiedProperties ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//################################
|
//################################
|
||||||
// Private Members.
|
// Private Members.
|
||||||
//################################
|
//################################
|
||||||
@@ -114,6 +249,7 @@ namespace Coffee.UIExtensions
|
|||||||
SerializedProperty _spTrailParticle;
|
SerializedProperty _spTrailParticle;
|
||||||
SerializedProperty _spScale;
|
SerializedProperty _spScale;
|
||||||
SerializedProperty _spIgnoreParent;
|
SerializedProperty _spIgnoreParent;
|
||||||
|
SerializedProperty _spAnimatableProperties;
|
||||||
UIParticle [] _particles;
|
UIParticle [] _particles;
|
||||||
ArcHandle _arcHandle = new ArcHandle ();
|
ArcHandle _arcHandle = new ArcHandle ();
|
||||||
BoxBoundsHandle _boxBoundsHandle = new BoxBoundsHandle ();
|
BoxBoundsHandle _boxBoundsHandle = new BoxBoundsHandle ();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Profiling;
|
using UnityEngine.Profiling;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
using ShaderPropertyType = Coffee.UIExtensions.UIParticle.AnimatableProperty.ShaderPropertyType;
|
||||||
|
|
||||||
|
|
||||||
namespace Coffee.UIExtensions
|
namespace Coffee.UIExtensions
|
||||||
@@ -35,6 +36,42 @@ namespace Coffee.UIExtensions
|
|||||||
[Tooltip ("Ignore parent scale")]
|
[Tooltip ("Ignore parent scale")]
|
||||||
[SerializeField] bool m_IgnoreParent = false;
|
[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;
|
||||||
|
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.
|
// Public/Protected Members.
|
||||||
@@ -57,9 +94,7 @@ namespace Coffee.UIExtensions
|
|||||||
if (!tex && _renderer)
|
if (!tex && _renderer)
|
||||||
{
|
{
|
||||||
Profiler.BeginSample ("Check material");
|
Profiler.BeginSample ("Check material");
|
||||||
var mat = m_IsTrail
|
var mat = material;
|
||||||
? _renderer.trailMaterial
|
|
||||||
: _renderer.sharedMaterial;
|
|
||||||
if (mat && mat.HasProperty (s_IdMainTex))
|
if (mat && mat.HasProperty (s_IdMainTex))
|
||||||
{
|
{
|
||||||
tex = mat.mainTexture;
|
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>
|
/// <summary>
|
||||||
/// Particle effect scale.
|
/// Particle effect scale.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -117,7 +181,15 @@ namespace Coffee.UIExtensions
|
|||||||
/// <param name="baseMaterial">Configured Material.</param>
|
/// <param name="baseMaterial">Configured Material.</param>
|
||||||
public override Material GetModifiedMaterial (Material baseMaterial)
|
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>
|
/// <summary>
|
||||||
@@ -129,6 +201,7 @@ namespace Coffee.UIExtensions
|
|||||||
if (s_ActiveParticles.Count == 0)
|
if (s_ActiveParticles.Count == 0)
|
||||||
{
|
{
|
||||||
Canvas.willRenderCanvases += UpdateMeshes;
|
Canvas.willRenderCanvases += UpdateMeshes;
|
||||||
|
s_Mpb = new MaterialPropertyBlock ();
|
||||||
}
|
}
|
||||||
s_ActiveParticles.Add (this);
|
s_ActiveParticles.Add (this);
|
||||||
|
|
||||||
@@ -236,6 +309,8 @@ namespace Coffee.UIExtensions
|
|||||||
UIParticle _parent;
|
UIParticle _parent;
|
||||||
List<UIParticle> _children = new List<UIParticle> ();
|
List<UIParticle> _children = new List<UIParticle> ();
|
||||||
Matrix4x4 scaleaMatrix = default (Matrix4x4);
|
Matrix4x4 scaleaMatrix = default (Matrix4x4);
|
||||||
|
Vector3 _worldPos;
|
||||||
|
static ParticleSystem.Particle [] s_Particles = new ParticleSystem.Particle [4096];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update meshes.
|
/// Update meshes.
|
||||||
@@ -264,7 +339,7 @@ namespace Coffee.UIExtensions
|
|||||||
|
|
||||||
if (m_ParticleSystem && canvas)
|
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;
|
Vector3 pos = rectTransform.localPosition;
|
||||||
if (Mathf.Abs (pos.z) < 0.01f)
|
if (Mathf.Abs (pos.z) < 0.01f)
|
||||||
@@ -284,21 +359,43 @@ namespace Coffee.UIExtensions
|
|||||||
|
|
||||||
Profiler.BeginSample ("Make Matrix");
|
Profiler.BeginSample ("Make Matrix");
|
||||||
scaleaMatrix = m_ParticleSystem.main.scalingMode == ParticleSystemScalingMode.Hierarchy
|
scaleaMatrix = m_ParticleSystem.main.scalingMode == ParticleSystemScalingMode.Hierarchy
|
||||||
? Matrix4x4.Scale (scale * Vector3.one)
|
? Matrix4x4.Scale (scale * Vector3.one)
|
||||||
: Matrix4x4.Scale (scale * rootCanvas.transform.localScale);
|
: Matrix4x4.Scale (scale * rootCanvas.transform.localScale);
|
||||||
Matrix4x4 matrix = default (Matrix4x4);
|
Matrix4x4 matrix = default (Matrix4x4);
|
||||||
switch (m_ParticleSystem.main.simulationSpace)
|
switch (m_ParticleSystem.main.simulationSpace)
|
||||||
{
|
{
|
||||||
case ParticleSystemSimulationSpace.Local:
|
case ParticleSystemSimulationSpace.Local:
|
||||||
matrix =
|
matrix =
|
||||||
scaleaMatrix
|
scaleaMatrix
|
||||||
* Matrix4x4.Rotate (m_ParticleSystem.transform.rotation).inverse
|
* Matrix4x4.Rotate (rectTransform.rotation).inverse
|
||||||
* Matrix4x4.Scale (m_ParticleSystem.transform.lossyScale).inverse;
|
* Matrix4x4.Scale (rectTransform.lossyScale).inverse;
|
||||||
break;
|
break;
|
||||||
case ParticleSystemSimulationSpace.World:
|
case ParticleSystemSimulationSpace.World:
|
||||||
matrix =
|
matrix =
|
||||||
scaleaMatrix
|
scaleaMatrix
|
||||||
* m_ParticleSystem.transform.worldToLocalMatrix;
|
* rectTransform.worldToLocalMatrix;
|
||||||
|
|
||||||
|
Vector3 newPos = rectTransform.position;
|
||||||
|
Vector3 delta = (newPos - _worldPos);
|
||||||
|
_worldPos = newPos;
|
||||||
|
if (canvas.renderMode != RenderMode.WorldSpace && !Mathf.Approximately (scale, 0) && 0 < delta.sqrMagnitude)
|
||||||
|
{
|
||||||
|
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;
|
break;
|
||||||
case ParticleSystemSimulationSpace.Custom:
|
case ParticleSystemSimulationSpace.Custom:
|
||||||
break;
|
break;
|
||||||
@@ -345,6 +442,10 @@ namespace Coffee.UIExtensions
|
|||||||
Profiler.BeginSample ("Set mesh and texture to CanvasRenderer");
|
Profiler.BeginSample ("Set mesh and texture to CanvasRenderer");
|
||||||
canvasRenderer.SetMesh (_mesh);
|
canvasRenderer.SetMesh (_mesh);
|
||||||
canvasRenderer.SetTexture (mainTexture);
|
canvasRenderer.SetTexture (mainTexture);
|
||||||
|
|
||||||
|
// Copy the value from MaterialPropertyBlock to CanvasRenderer (#41)
|
||||||
|
UpdateAnimatableMaterialProperties ();
|
||||||
|
|
||||||
Profiler.EndSample ();
|
Profiler.EndSample ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -403,5 +504,43 @@ namespace Coffee.UIExtensions
|
|||||||
_parent._children.Add (this);
|
_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
v2f OUT;
|
v2f OUT;
|
||||||
OUT.worldPosition = IN.vertex;
|
OUT.worldPosition = IN.vertex;
|
||||||
OUT.vertex = UnityObjectToClipPos(IN.vertex);
|
OUT.vertex = UnityObjectToClipPos(IN.vertex);
|
||||||
OUT.texcoord = IN.texcoord;
|
OUT.texcoord = TRANSFORM_TEX(IN.texcoord, _MainTex);
|
||||||
#ifdef UNITY_HALF_TEXEL_OFFSET
|
#ifdef UNITY_HALF_TEXEL_OFFSET
|
||||||
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
|
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Binary file not shown.
@@ -2,7 +2,7 @@
|
|||||||
"name": "com.coffee.ui-particle",
|
"name": "com.coffee.ui-particle",
|
||||||
"displayName": "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.",
|
"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.2.0",
|
||||||
"unity": "2018.2",
|
"unity": "2018.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
Reference in New Issue
Block a user