Skip to content

Commit

Permalink
3.0.0-preview.38
Browse files Browse the repository at this point in the history
# [3.0.0-preview.38](v3.0.0-preview.37...v3.0.0-preview.38) (2020-10-04)

### Bug Fixes

* delete unused file in package ([2e69974](2e69974))
* material dirty on validate (on editor) ([fa34301](fa34301))

### Features

* display material properties in inspector ([313c1fc](313c1fc)), closes [#104](#104)
* support 3D scaling ([a508c3b](a508c3b)), closes [#105](#105)
  • Loading branch information
semantic-release-bot committed Oct 4, 2020
1 parent 7bf1bae commit 8b32815
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 25 deletions.
Empty file removed .releaserc
Empty file.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# [3.0.0-preview.38](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.37...v3.0.0-preview.38) (2020-10-04)


### Bug Fixes

* delete unused file in package ([2e69974](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/2e699749a8f0f620505621a13a628aa87f192875))
* material dirty on validate (on editor) ([fa34301](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/fa3430130cdffa3f934e926645958ad9f19edc5d))


### Features

* display material properties in inspector ([313c1fc](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/313c1fc159429034f84b2e7c30424158c43b71e9)), closes [#104](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/104)
* support 3D scaling ([a508c3b](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/a508c3bb86ad6694722868303385b20adc914134)), closes [#105](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/105)

# [3.0.0-preview.37](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.36...v3.0.0-preview.37) (2020-10-01)


Expand Down
60 changes: 48 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ Unity 2018.2 supports embedded packages.

1. Open `Package Manager` window
2. Select `UI Particle` package in package list
3. Click `Import Sample` button
3. Click `Import Sample` button
![demo](https://user-images.githubusercontent.com/12690315/95017806-83bd1480-0696-11eb-8c24-c56f45ab1ac2.png)
4. The demo project is imported into `Assets/Samples/UI Particle/{version}/Demo`
5. Open `UIParticle_Demo` scene and play it

Expand All @@ -137,22 +138,58 @@ Unity 2018.2 supports embedded packages.

## Usage

### UIParticle component

`UIParticle` controls the ParticleSystems that is attached to its own game objects and child game objects.

| Properties | Screenshot |
| -- | -- |
| **Ignore Canvas Scale:** Ignore the scale of the root canvas. This prevents it from displaying small even in hierarchy scaling mode of ParticleSystem. <br>**Scale:** Scale the rendering. When the `3D` toggle is enabled, 3D scale (x,y,z) is supported. <br>**AnimatableProperties:** If you want update material properties (e.g. `_MainTex_ST`, `_Color`) in AnimationClip, use this to mark the changes. <br>**Rendering Order:** The ParticleSystems to be rendered. You can change the rendering order and the materials. | ![][inspector] |

[inspector]:https://user-images.githubusercontent.com/12690315/95017219-1cea2c00-0693-11eb-9490-c52b8d0fdbb6.png

NOTE: Press `Refresh` button to reconstruct rendering order based on children ParticleSystem's sorting order and z position.

<br><br>

### Basically usage

1. Select `Game Object/UI/ParticleSystem` to create UIParticle.
2. (Option) If you want to mask particles, set **a UI shader** such as `UI/UIAdditive` to material for ParticleSystem.
![](https://user-images.githubusercontent.com/12690315/42674022-134e3a40-86a9-11e8-8f44-a110d2f14185.gif)
3. Adjust the Scale property to change the size of the effect.
![](https://user-images.githubusercontent.com/12690315/49148937-19c1de80-f34c-11e8-87fc-138192777540.gif)
1. Select `Game Object/UI/ParticleSystem` to create UIParticle with a ParticleSystem.
![particle](https://user-images.githubusercontent.com/12690315/95007361-cad0e880-0649-11eb-8835-f145d62c5977.png)
2. Adjust the ParticleSystem as you like.
![particle1](https://user-images.githubusercontent.com/12690315/95007359-ca385200-0649-11eb-8383-627c9750bda8.png)

<br><br>

### With your ParticleSystem prefab

### With VFX assets
1. Select `Game Object/UI/ParticleSystem (Empty)` to create UIParticle.
![empty](https://user-images.githubusercontent.com/12690315/95007362-cb697f00-0649-11eb-8a09-29b0a13791e4.png)
2. Drag & drop your ParticleSystem prefab on UIParticle.
![particle3](https://user-images.githubusercontent.com/12690315/95007356-c6a4cb00-0649-11eb-9316-562f4bce3f31.png)

1. Select `Game Object/UI/ParticleSystem (Empty)` to create UIParticle.
2. Drag & drop VFX asset on UIParticle.
3. Click `Refresh` to setup.
4. Adjust the Scale property to change the size of the effect.
<br><br>

### With `Mask` or `MaskRect2D` component

If you want to mask particles, set a stencil supported shader (such as `UI/UIAdditive`) to material for ParticleSystem.

![](https://user-images.githubusercontent.com/12690315/95017591-3b512700-0695-11eb-864e-04166ea1809a.png)


<br><br>

### Script usage

```cs
// Instant ParticleSystem prefab with UIParticle on runtime.
var go = GameObject.Instantiate(prefab);
var uiParticle = go.AddComponent<UIParticle>();

// Play/Stop the controled ParticleSystems.
uiParticle.Play();
uiParticle.Stop();
```

<br><br><br><br>

Expand Down Expand Up @@ -224,5 +261,4 @@ With your support, I can spend more time on development. :)
* GitHub page : https://github.com/mob-sakai/ParticleEffectForUGUI
* Releases : https://github.com/mob-sakai/ParticleEffectForUGUI/releases
* Issue tracker : https://github.com/mob-sakai/ParticleEffectForUGUI/issues
* Current project : https://github.com/mob-sakai/ParticleEffectForUGUI/projects/1
* Change log : https://github.com/mob-sakai/ParticleEffectForUGUI/blob/upm/CHANGELOG.md
101 changes: 95 additions & 6 deletions Scripts/Editor/UIParticleEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ internal class UIParticleEditor : GraphicEditor
private static readonly GUIContent s_ContentRenderingOrder = new GUIContent("Rendering Order");
private static readonly GUIContent s_ContentRefresh = new GUIContent("Refresh");
private static readonly GUIContent s_ContentFix = new GUIContent("Fix");
private static readonly GUIContent s_ContentMaterial = new GUIContent("Material");
private static readonly GUIContent s_ContentTrailMaterial = new GUIContent("Trail Material");
private static readonly GUIContent s_Content3D = new GUIContent("3D");
private static readonly GUIContent s_ContentScale = new GUIContent("Scale");
private static readonly List<UIParticle> s_TempParents = new List<UIParticle>();
private static readonly List<UIParticle> s_TempChildren = new List<UIParticle>();

Expand All @@ -26,6 +30,7 @@ internal class UIParticleEditor : GraphicEditor
private SerializedProperty _spAnimatableProperties;

private ReorderableList _ro;
private bool _xyzMode;

private static readonly List<string> s_MaskablePropertyNames = new List<string>
{
Expand All @@ -47,24 +52,48 @@ internal class UIParticleEditor : GraphicEditor
protected override void OnEnable()
{
base.OnEnable();
_spScale = serializedObject.FindProperty("m_Scale");
_spScale = serializedObject.FindProperty("m_Scale3D");
_spIgnoreCanvasScaler = serializedObject.FindProperty("m_IgnoreCanvasScaler");
_spAnimatableProperties = serializedObject.FindProperty("m_AnimatableProperties");

var sp = serializedObject.FindProperty("m_Particles");
_ro = new ReorderableList(sp.serializedObject, sp, true, true, false, false);
_ro.elementHeight = EditorGUIUtility.singleLineHeight + 4;
_ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true);
_ro.elementHeight = EditorGUIUtility.singleLineHeight * 3 + 4;
_ro.drawElementCallback = (rect, index, active, focused) =>
{
EditorGUI.BeginDisabledGroup(sp.hasMultipleDifferentValues);
rect.y += 1;
rect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.ObjectField(rect, sp.GetArrayElementAtIndex(index), GUIContent.none);
var p = sp.GetArrayElementAtIndex(index);
EditorGUI.ObjectField(rect, p, GUIContent.none);

rect.x += 15;
rect.width -= 15;
var ps = p.objectReferenceValue as ParticleSystem;
var materials = ps
? new SerializedObject(ps.GetComponent<ParticleSystemRenderer>()).FindProperty("m_Materials")
: null;
rect.y += rect.height + 1;
MaterialField(rect, s_ContentMaterial, materials, 0);
rect.y += rect.height + 1;
MaterialField(rect, s_ContentTrailMaterial, materials, 1);
EditorGUI.EndDisabledGroup();
if (materials != null)
{
materials.serializedObject.ApplyModifiedProperties();
}
};
_ro.drawHeaderCallback += rect =>
{
EditorGUI.LabelField(new Rect(rect.x, rect.y, 150, rect.height), s_ContentRenderingOrder);

if (GUI.Button(new Rect(rect.width - 80, rect.y - 1, 80, rect.height), s_ContentRefresh, EditorStyles.miniButton))
#if UNITY_2019_3_OR_NEWER
rect = new Rect(rect.width - 55, rect.y, 80, rect.height);
#else
rect = new Rect(rect.width - 55, rect.y - 1, 80, rect.height);
#endif

if (GUI.Button(rect, s_ContentRefresh, EditorStyles.miniButton))
{
foreach (UIParticle t in targets)
{
Expand All @@ -74,6 +103,20 @@ protected override void OnEnable()
};
}

private static void MaterialField(Rect rect, GUIContent label, SerializedProperty sp, int index)
{
if (sp == null || sp.arraySize <= index)
{
EditorGUI.BeginDisabledGroup(true);
EditorGUI.ObjectField(rect, label, null, typeof(Material), true);
EditorGUI.EndDisabledGroup();
}
else
{
EditorGUI.PropertyField(rect, sp.GetArrayElementAtIndex(index), label);
}
}

/// <summary>
/// Implement this function to make a custom inspector.
/// </summary>
Expand All @@ -98,16 +141,25 @@ public override void OnInspectorGUI()
}

// Scale
EditorGUILayout.PropertyField(_spScale);
_xyzMode = DrawFloatOrVector3Field(_spScale, _xyzMode);

// AnimatableProperties
var mats = current.particles
.Where(x => x)
.Select(x => x.GetComponent<ParticleSystemRenderer>().sharedMaterial)
.Where(x => x)
.ToArray();

// Animated properties
EditorGUI.BeginChangeCheck();
AnimatedPropertiesEditor.DrawAnimatableProperties(_spAnimatableProperties, mats);
if (EditorGUI.EndChangeCheck())
{
foreach (UIParticle t in targets)
t.SetMaterialDirty();
}

// Target ParticleSystems.
_ro.DoLayoutList();

serializedObject.ApplyModifiedProperties();
Expand Down Expand Up @@ -180,5 +232,42 @@ bool FixButton(bool show, string text)
}
}
}

private static bool DrawFloatOrVector3Field(SerializedProperty sp, bool showXyz)
{
var x = sp.FindPropertyRelative("x");
var y = sp.FindPropertyRelative("y");
var z = sp.FindPropertyRelative("z");

showXyz |= !Mathf.Approximately(x.floatValue, y.floatValue) ||
!Mathf.Approximately(y.floatValue, z.floatValue) ||
y.hasMultipleDifferentValues ||
z.hasMultipleDifferentValues;

EditorGUILayout.BeginHorizontal();
if (showXyz)
{
EditorGUILayout.PropertyField(sp);
}
else
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(x, s_ContentScale);
if (EditorGUI.EndChangeCheck())
z.floatValue = y.floatValue = x.floatValue;
}

x.floatValue = Mathf.Max(0.001f, x.floatValue);
y.floatValue = Mathf.Max(0.001f, y.floatValue);
z.floatValue = Mathf.Max(0.001f, z.floatValue);

EditorGUI.BeginChangeCheck();
showXyz = GUILayout.Toggle(showXyz, s_Content3D, EditorStyles.miniButton, GUILayout.Width(30));
if (EditorGUI.EndChangeCheck() && !showXyz)
z.floatValue = y.floatValue = x.floatValue;
EditorGUILayout.EndHorizontal();

return showXyz;
}
}
}
39 changes: 37 additions & 2 deletions Scripts/UIParticle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class UIParticle : MaskableGraphic
[Tooltip("Particle effect scale")] [SerializeField]
float m_Scale = 100;

[Tooltip("Particle effect scale")] [SerializeField]
private Vector3 m_Scale3D;

[Tooltip("Animatable material properties. If you want to change the material properties of the ParticleSystem in Animation, enable it.")] [SerializeField]
internal AnimatableProperty[] m_AnimatableProperties = new AnimatableProperty[0];

Expand Down Expand Up @@ -74,8 +77,27 @@ public bool ignoreCanvasScaler
/// </summary>
public float scale
{
get { return m_Scale; }
set { m_Scale = Mathf.Max(0.001f, value); }
get { return m_Scale3D.x; }
set
{
m_Scale = Mathf.Max(0.001f, value);
m_Scale3D = new Vector3(m_Scale, m_Scale, m_Scale);
}
}

/// <summary>
/// Particle effect scale.
/// </summary>
public Vector3 scale3D
{
get { return m_Scale3D; }
set
{
if (m_Scale3D == value) return;
m_Scale3D.x = Mathf.Max(0.001f, value.x);
m_Scale3D.y = Mathf.Max(0.001f, value.y);
m_Scale3D.z = Mathf.Max(0.001f, value.z);
}
}

internal Mesh bakedMesh
Expand Down Expand Up @@ -410,6 +432,14 @@ private void InitializeIfNeeded()
}

#if UNITY_EDITOR
protected override void OnValidate()
{
SetLayoutDirty();
SetVerticesDirty();
m_ShouldRecalculateStencil = true;
RecalculateClipping();
}

void ISerializationCallbackReceiver.OnBeforeSerialize()
{
if (Application.isPlaying) return;
Expand All @@ -418,6 +448,11 @@ void ISerializationCallbackReceiver.OnBeforeSerialize()

void ISerializationCallbackReceiver.OnAfterDeserialize()
{
if (m_Scale3D == Vector3.zero)
{
scale = m_Scale;
}

UnityEditor.EditorApplication.delayCall += () =>
{
if (Application.isPlaying || !this) return;
Expand Down
12 changes: 8 additions & 4 deletions Scripts/UIParticleUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,17 @@ private static void BakeMesh(UIParticle particle)
var rootMatrix = Matrix4x4.Rotate(root.rotation).inverse
* Matrix4x4.Scale(root.lossyScale).inverse;
var scale = particle.ignoreCanvasScaler
? particle.canvas.rootCanvas.transform.localScale.x * particle.scale
: particle.scale;
var scaleMatrix = Matrix4x4.Scale(scale * Vector3.one);
? Vector3.Scale( particle.canvas.rootCanvas.transform.localScale, particle.scale3D)
: particle.scale3D;
var scaleMatrix = Matrix4x4.Scale(scale);

// Cache position
var position = particle.transform.position;
var diff = (position - particle.cachedPosition) * (1 - 1 / scale);
var diff = position - particle.cachedPosition;
diff.x *= 1f - 1f / Mathf.Max(0.001f, scale.x);
diff.y *= 1f - 1f / Mathf.Max(0.001f, scale.y);
diff.z *= 1f - 1f / Mathf.Max(0.001f, scale.z);

particle.cachedPosition = position;

for (var i = 0; i < particle.particles.Count; i++)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "3.0.0-preview.37",
"version": "3.0.0-preview.38",
"unity": "2018.2",
"license": "MIT",
"repository": {
Expand Down

0 comments on commit 8b32815

Please sign in to comment.