Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Jun 27, 2024
1 parent be90172 commit 80b4e27
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 103 deletions.
8 changes: 6 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true

csharp_style_namespace_declarations = block_scoped
csharp_style_implicit_object_creation_when_type_is_apparent = false
resharper_object_creation_when_type_evident = explicitly_typed

Expand Down Expand Up @@ -86,6 +87,9 @@ csharp_style_var_elsewhere = true:suggestion
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

#
resharper_keep_existing_embedded_arrangement = true

# Arguments
csharp_arguments_literal = named:suggestion
csharp_arguments_string_literal = named:suggestion
Expand Down Expand Up @@ -134,7 +138,7 @@ dotnet_naming_style._camel_case.capitalization = camel_case

# Code style defaults
dotnet_sort_system_directives_first = true
csharp_preserve_single_line_statements = false:none
csharp_preserve_single_line_statements = false
csharp_prefer_static_local_function = true:suggestion
csharp_prefer_simple_using_statement = false:none
csharp_style_prefer_switch_expression = true:suggestion
Expand Down Expand Up @@ -186,7 +190,7 @@ csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = do_not_ignore
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
Expand Down
2 changes: 1 addition & 1 deletion Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"com.unity.ide.rider": "3.0.27",
"com.unity.ide.rider": "3.0.31",
"com.unity.test-framework": "1.1.33",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.physics": "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"url": "https://packages.unity.com"
},
"com.unity.ide.rider": {
"version": "3.0.27",
"version": "3.0.31",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion Packages/src/.releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"release-4.x",
{
"name": "release-preview",
"prerelease": true
"prerelease": "preview"
}
],
"plugins": [
Expand Down
41 changes: 20 additions & 21 deletions Packages/src/Editor/AnimatablePropertyEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,35 @@ private static string CollectActiveNames(SerializedProperty sp, List<string> res
}
else
{
result.Aggregate(s_Sb, (a, b) => s_Sb.AppendFormat("{0}, ", b));
result.Aggregate(s_Sb, (a, b) =>
{
s_Sb.Append(b);
return s_Sb.Append(", ");
});
s_Sb.Length -= 2;
}

return s_Sb.ToString();
}

public static void Draw(SerializedProperty sp, Material[] mats)
public static void Draw(SerializedProperty sp, List<Material> mats)
{
bool isClicked;
using (new EditorGUILayout.HorizontalScope(GUILayout.ExpandWidth(false)))
{
var pos = EditorGUILayout.GetControlRect(true);
var label = new GUIContent(sp.displayName, sp.tooltip);
var rect = EditorGUI.PrefixLabel(pos, label);
var text = sp.hasMultipleDifferentValues
? "-"
: CollectActiveNames(sp, s_ActiveNames);
isClicked = GUI.Button(rect, text, EditorStyles.popup);
}
var pos = EditorGUILayout.GetControlRect(true);
var label = new GUIContent(sp.displayName, sp.tooltip);
var rect = EditorGUI.PrefixLabel(pos, label);
var text = sp.hasMultipleDifferentValues
? "-"
: CollectActiveNames(sp, s_ActiveNames);

if (!isClicked) return;
if (!GUI.Button(rect, text, EditorStyles.popup)) return;

var gm = new GenericMenu();
gm.AddItem(s_ContentNothing, s_ActiveNames.Count == 0, () =>
gm.AddItem(s_ContentNothing, s_ActiveNames.Count == 0, x =>
{
sp.ClearArray();
sp.serializedObject.ApplyModifiedProperties();
});
var current = (SerializedProperty)x;
current.ClearArray();
current.serializedObject.ApplyModifiedProperties();
}, sp);

if (!sp.hasMultipleDifferentValues)
{
Expand All @@ -73,7 +73,7 @@ public static void Draw(SerializedProperty sp, Material[] mats)
}

s_Names.Clear();
for (var j = 0; j < mats.Length; j++)
for (var j = 0; j < mats.Count; j++)
{
var mat = mats[j];
if (!mat || !mat.shader) continue;
Expand All @@ -82,8 +82,7 @@ public static void Draw(SerializedProperty sp, Material[] mats)
{
var name = ShaderUtil.GetPropertyName(mat.shader, i);
var type = (AnimatableProperty.ShaderPropertyType)ShaderUtil.GetPropertyType(mat.shader, i);
if (s_Names.Contains(name)) continue;
s_Names.Add(name);
if (!s_Names.Add(name)) continue;

AddMenu(gm, sp, new ShaderProperty(name, type), true);

Expand Down
47 changes: 28 additions & 19 deletions Packages/src/Editor/UIParticleEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using UnityEditor.UI;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.UI;
using Coffee.UIParticleExtensions;
#if UNITY_2021_2_OR_NEWER
Expand Down Expand Up @@ -42,6 +43,8 @@ internal class UIParticleEditor : GraphicEditor
private static readonly GUIContent s_ContentRandom = new GUIContent("Random");
private static readonly GUIContent s_ContentScale = new GUIContent("Scale");
private static readonly GUIContent s_ContentPrimary = new GUIContent("Primary");
private static readonly Regex s_RegexBuiltInGuid = new Regex(@"^0{16}.0{15}$", RegexOptions.Compiled);
private static readonly List<Material> s_TempMaterials = new List<Material>();
private static bool s_XYZMode;

private SerializedProperty _maskable;
Expand Down Expand Up @@ -169,6 +172,7 @@ public override void OnInspectorGUI()
var current = target as UIParticle;
if (!current) return;

Profiler.BeginSample("(UIP:E) OnInspectorGUI");
serializedObject.Update();

// Maskable
Expand All @@ -180,31 +184,29 @@ public override void OnInspectorGUI()
EditorGUI.EndDisabledGroup();

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

AnimatablePropertyEditor.Draw(_animatableProperties, mats);
current.GetMaterials(s_TempMaterials);
AnimatablePropertyEditor.Draw(_animatableProperties, s_TempMaterials);

// Mesh sharing
EditorGUI.BeginChangeCheck();
_showMax = DrawMeshSharing(_meshSharing, _groupId, _groupMaxId, _showMax);
if (EditorGUI.EndChangeCheck())
{
serializedObject.ApplyModifiedProperties();
foreach (var uip in targets.OfType<UIParticle>())
foreach (var t in targets)
{
uip.ResetGroupId();
if (t is UIParticle uip)
{
uip.ResetGroupId();
}
}
}

// Position Mode
EditorGUILayout.PropertyField(_positionMode);

// Auto Scaling
DrawAutoScaling(_autoScalingMode, targets.OfType<UIParticle>());
EditorGUILayout.PropertyField(_autoScalingMode);

// Custom View Size
EditorGUILayout.PropertyField(_useCustomView);
Expand All @@ -221,9 +223,7 @@ public override void OnInspectorGUI()

// Target ParticleSystems.
EditorGUI.BeginChangeCheck();
EditorGUI.BeginDisabledGroup(targets.OfType<UIParticle>().Any(x => !x.canvas));
_ro.DoLayoutList();
EditorGUI.EndDisabledGroup();
serializedObject.ApplyModifiedProperties();

if (EditorGUI.EndChangeCheck())
Expand All @@ -236,7 +236,8 @@ public override void OnInspectorGUI()
}

// Non-UI built-in shader is not supported.
foreach (var mat in current.materials)
Profiler.BeginSample("(UIP:E) Non-UI built-in shader is not supported.");
foreach (var mat in s_TempMaterials)
{
if (!mat || !mat.shader) continue;
var shader = mat.shader;
Expand All @@ -249,15 +250,18 @@ public override void OnInspectorGUI()
}
}

Profiler.EndSample();

// Does the shader support UI masks?
Profiler.BeginSample("(UIP:E) Does the shader support UI masks?");
if (current.maskable && current.GetComponentInParent<Mask>(false))
{
foreach (var mat in current.materials)
foreach (var mat in s_TempMaterials)
{
if (!mat || !mat.shader) continue;
var shader = mat.shader;
if (s_Shaders.Contains(shader)) continue;
s_Shaders.Add(shader);
if (!s_Shaders.Add(shader)) continue;

foreach (var propName in s_MaskablePropertyNames)
{
if (mat.HasProperty(propName)) continue;
Expand All @@ -271,7 +275,9 @@ public override void OnInspectorGUI()
}
}

s_TempMaterials.Clear();
s_Shaders.Clear();
Profiler.EndSample();

// UIParticle for trail should be removed.
var label = "This UIParticle component should be removed. The UIParticle for trails is no longer needed.";
Expand Down Expand Up @@ -310,12 +316,15 @@ public override void OnInspectorGUI()
}
}
#endif
Profiler.EndSample();
EditorApplication.delayCall += () => Profiler.enabled = false;
}

private static bool IsBuiltInObject(Object obj)
{
return AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out var guid, out long _)
&& Regex.IsMatch(guid, "^0{16}.0{15}$", RegexOptions.Compiled);
return AssetDatabase.IsMainAsset(obj)
&& AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out var guid, out long _)
&& s_RegexBuiltInGuid.IsMatch(guid);
}

#if UNITY_2018 || UNITY_2019
Expand Down Expand Up @@ -419,7 +428,7 @@ private static bool DrawMeshSharing(SerializedProperty spMeshSharing, Serialized
return showMax;
}

private static void DrawAutoScaling(SerializedProperty prop, IEnumerable<UIParticle> uiParticles)
private static void DrawAutoScaling(SerializedProperty prop)
{
EditorGUILayout.PropertyField(prop);
}
Expand Down
5 changes: 3 additions & 2 deletions Packages/src/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Particle Effect For UGUI (UI Particle)
# <img alt="UIParticleIcon" src="https://github.com/mob-sakai/ParticleEffectForUGUI/assets/12690315/d76e105e-a840-4f61-a1f6-8cf311c0812d" width="26"/> Particle Effect For UGUI (UI Particle)

This package provides a component to render particle effects for uGUI in Unity 2018.2 or later.
The particle rendering is maskable and sortable, without the need for an extra Camera, RenderTexture, or Canvas.
Expand Down Expand Up @@ -176,9 +176,10 @@ section.
### Script usage

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

// Control by ParticleSystem.
particleSystem.Play();
Expand Down
Loading

0 comments on commit 80b4e27

Please sign in to comment.