3.0.0-preview.18

# [3.0.0-preview.18](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.17...v3.0.0-preview.18) (2020-08-19)

### Bug Fixes

* AsmdefEx is no longer required ([50e749c](50e749c183))
* fix camera for baking mesh ([6395a4f](6395a4fa74))
* support .Net Framework 3.5 (again) ([23fcb06](23fcb06bf9))

### Features

* 3.0.0 updater ([f99292b](f99292b9a1))
* add menu to create UIParticle ([14f1c78](14f1c782ff))
* Combine baked meshes to improve performance ([633d058](633d058756))
* improve performance ([77c056a](77c056ad5f))
* optimization for vertices transforms and adding node for trails ([e070e8d](e070e8d5ee)), closes [#75](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/75)
* option to ignoring canvas scaling ([fe85fed](fe85fed3c0))
* support 3d scaling ([42a84bc](42a84bc5e1))
* support custom simulation space ([a83e647](a83e64761c)), closes [#78](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/78)
* support for particle systems including trail only ([f389d39](f389d39953)), closes [#61](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/61)

### BREAKING CHANGES

* The bake-task has changed significantly. It may look different from previous versions.
This commit is contained in:
semantic-release-bot
2020-08-19 19:42:16 +00:00
parent 785709fa02
commit eccb3ecb5e
20 changed files with 1057 additions and 1403 deletions

View File

@@ -1,129 +1,32 @@
#if IGNORE_ACCESS_CHECKS // [ASMDEFEX] DO NOT REMOVE THIS LINE MANUALLY.
using UnityEditor;
using UnityEditor.UI;
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using System;
using ShaderPropertyType = Coffee.UIExtensions.UIParticle.AnimatableProperty.ShaderPropertyType;
namespace Coffee.UIExtensions
{
[CustomEditor(typeof(UIParticle))]
[CanEditMultipleObjects]
public class UIParticleEditor : GraphicEditor
internal 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.
//################################
static readonly GUIContent s_ContentParticleMaterial = new GUIContent("Particle Material", "The material for rendering particles");
static readonly GUIContent s_ContentTrailMaterial = new GUIContent("Trail Material", "The material for rendering particle trails");
static readonly List<ParticleSystem> s_ParticleSystems = new List<ParticleSystem>();
static readonly Color s_GizmoColor = new Color(1f, 0.7f, 0.7f, 0.9f);
private static readonly GUIContent s_ContentParticleMaterial = new GUIContent("Particle Material", "The material for rendering particles");
private static readonly GUIContent s_ContentTrailMaterial = new GUIContent("Trail Material", "The material for rendering particle trails");
private static readonly GUIContent s_ContentAdvancedOptions = new GUIContent("Advanced Options");
private static readonly GUIContent s_Content3D = new GUIContent("3D");
private static readonly GUIContent s_ContentScale = new GUIContent("Scale");
private static readonly List<ParticleSystem> s_ParticleSystems = new List<ParticleSystem>();
static readonly List<string> s_MaskablePropertyNames = new List<string>()
private SerializedProperty _spParticleSystem;
private SerializedProperty _spScale3D;
private SerializedProperty _spIgnoreCanvasScaler;
private SerializedProperty _spAnimatableProperties;
private bool _xyzMode;
private static readonly List<string> s_MaskablePropertyNames = new List<string>
{
"_Stencil",
"_StencilComp",
@@ -133,6 +36,7 @@ namespace Coffee.UIExtensions
"_ColorMask",
};
//################################
// Public/Protected Members.
//################################
@@ -143,16 +47,9 @@ namespace Coffee.UIExtensions
{
base.OnEnable();
_spParticleSystem = serializedObject.FindProperty("m_ParticleSystem");
_spTrailParticle = serializedObject.FindProperty("m_TrailParticle");
_spScale = serializedObject.FindProperty("m_Scale");
_spIgnoreParent = serializedObject.FindProperty("m_IgnoreParent");
_spScale3D = serializedObject.FindProperty("m_Scale3D");
_spIgnoreCanvasScaler = serializedObject.FindProperty("m_IgnoreCanvasScaler");
_spAnimatableProperties = serializedObject.FindProperty("m_AnimatableProperties");
_particles = targets.Cast<UIParticle>().ToArray();
_shapeModuleUIs = null;
var targetsGos = targets.Cast<UIParticle>().Select(x => x.gameObject).ToArray();
_inspector = Resources.FindObjectsOfTypeAll<ParticleSystemInspector>()
.FirstOrDefault(x => x.targets.Cast<ParticleSystem>().Select(x => x.gameObject).SequenceEqual(targetsGos));
}
/// <summary>
@@ -160,15 +57,19 @@ namespace Coffee.UIExtensions
/// </summary>
public override void OnInspectorGUI()
{
var current = target as UIParticle;
if (current == null) return;
serializedObject.Update();
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(_spParticleSystem);
EditorGUI.EndDisabledGroup();
// Draw materials.
EditorGUI.indentLevel++;
var ps = _spParticleSystem.objectReferenceValue as ParticleSystem;
if (ps)
if (ps != null)
{
var pr = ps.GetComponent<ParticleSystemRenderer>();
var sp = new SerializedObject(pr).FindProperty("m_Materials");
@@ -194,22 +95,19 @@ namespace Coffee.UIExtensions
EditorGUI.indentLevel--;
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(_spTrailParticle);
EditorGUI.EndDisabledGroup();
// Advanced Options
EditorGUILayout.Space();
EditorGUILayout.LabelField(s_ContentAdvancedOptions, EditorStyles.boldLabel);
var current = target as UIParticle;
_xyzMode = DrawFloatOrVector3Field(_spScale3D, _xyzMode);
EditorGUILayout.PropertyField(_spIgnoreParent);
EditorGUI.BeginDisabledGroup(!current.isRoot);
EditorGUILayout.PropertyField(_spScale);
EditorGUI.EndDisabledGroup();
EditorGUILayout.PropertyField(_spIgnoreCanvasScaler);
// AnimatableProperties
AnimatedPropertiesEditor.DrawAnimatableProperties(_spAnimatableProperties, current.material);
current.GetComponentsInChildren<ParticleSystem>(true, s_ParticleSystems);
// Fix
current.GetComponentsInChildren(true, s_ParticleSystems);
if (s_ParticleSystems.Any(x => x.GetComponent<UIParticle>() == null))
{
GUILayout.BeginHorizontal();
@@ -229,75 +127,54 @@ namespace Coffee.UIExtensions
s_ParticleSystems.Clear();
// Does the shader support UI masks?
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;
}
if (mat.HasProperty(propName)) continue;
EditorGUILayout.HelpBox(string.Format("Shader '{0}' doesn't have '{1}' property. This graphic cannot be masked.", shader.name, propName), MessageType.Warning);
break;
}
}
serializedObject.ApplyModifiedProperties();
}
//################################
// Private Members.
//################################
SerializedProperty _spParticleSystem;
SerializedProperty _spTrailParticle;
SerializedProperty _spScale;
SerializedProperty _spIgnoreParent;
SerializedProperty _spAnimatableProperties;
UIParticle[] _particles;
ShapeModuleUI[] _shapeModuleUIs;
ParticleSystemInspector _inspector;
void OnSceneGUI()
private static bool DrawFloatOrVector3Field(SerializedProperty sp, bool showXyz)
{
_shapeModuleUIs = _shapeModuleUIs ?? _inspector?.m_ParticleEffectUI?.m_Emitters?.SelectMany(x => x.m_Modules).OfType<ShapeModuleUI>()?.ToArray();
if (_shapeModuleUIs == null || _shapeModuleUIs.Length == 0 || _shapeModuleUIs[0].GetParticleSystem() != (target as UIParticle).cachedParticleSystem)
return;
var x = sp.FindPropertyRelative("x");
var y = sp.FindPropertyRelative("y");
var z = sp.FindPropertyRelative("z");
Action postAction = () => { };
Color origin = ShapeModuleUI.s_GizmoColor.m_Color;
Color originDark = ShapeModuleUI.s_GizmoColor.m_Color;
ShapeModuleUI.s_GizmoColor.m_Color = s_GizmoColor;
ShapeModuleUI.s_GizmoColor.m_OptionalDarkColor = s_GizmoColor;
showXyz |= !Mathf.Approximately(x.floatValue, y.floatValue) ||
!Mathf.Approximately(y.floatValue, z.floatValue) ||
y.hasMultipleDifferentValues ||
z.hasMultipleDifferentValues;
_particles
.Distinct()
.Select(x => new {canvas = x.canvas, ps = x.cachedParticleSystem, scale = x.scale})
.Where(x => x.ps && x.canvas)
.ToList()
.ForEach(x =>
{
var trans = x.ps.transform;
var hasChanged = trans.hasChanged;
var localScale = trans.localScale;
postAction += () => trans.localScale = localScale;
trans.localScale = Vector3.Scale(localScale, x.canvas.rootCanvas.transform.localScale * x.scale);
});
try
EditorGUILayout.BeginHorizontal();
if (showXyz)
{
foreach (var ui in _shapeModuleUIs)
ui.OnSceneViewGUI();
EditorGUILayout.PropertyField(sp);
}
catch
else
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(x, s_ContentScale);
if (EditorGUI.EndChangeCheck())
z.floatValue = y.floatValue = x.floatValue;
}
postAction();
ShapeModuleUI.s_GizmoColor.m_Color = origin;
ShapeModuleUI.s_GizmoColor.m_OptionalDarkColor = originDark;
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;
}
}
}
#endif // [ASMDEFEX] DO NOT REMOVE THIS LINE MANUALLY.