Skip to content

Commit

Permalink
uGUI上でのパーティクル表示に対応 (#86)
Browse files Browse the repository at this point in the history
* UIParticle対応のシェーダーの追加

* UIParticleに対応

* コードクリーンアップ
  • Loading branch information
CyTakayukiKiyohara authored Oct 11, 2024
1 parent 792f4a3 commit 101ab75
Show file tree
Hide file tree
Showing 20 changed files with 1,064 additions and 325 deletions.
2 changes: 1 addition & 1 deletion Assets/Nova/Editor/Core/Scripts/CustomCoord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public enum CustomCoord
Coord2Z = 22,
Coord2W = 32
}
}
}
47 changes: 30 additions & 17 deletions Assets/Nova/Editor/Core/Scripts/MaterialEditorUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// --------------------------------------------------------------

using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
Expand Down Expand Up @@ -246,10 +247,10 @@ public static void DrawSmallTexture(MaterialEditor editor, string label, Materia
/// <param name="editor"></param>
/// <param name="textureProperty"></param>
/// <param name="drawTilingAndOffset"></param>
public static void DrawTexture(MaterialEditor editor, MaterialProperty textureProperty,
bool drawTilingAndOffset)
public static void DrawTexture<TCustomCoord>(MaterialEditor editor, MaterialProperty textureProperty,
bool drawTilingAndOffset) where TCustomCoord : Enum
{
DrawTexture(editor, textureProperty, drawTilingAndOffset, null, null, null, null);
DrawTexture<TCustomCoord>(editor, textureProperty, drawTilingAndOffset, null, null, null, null);
}

/// <summary>
Expand All @@ -261,18 +262,18 @@ public static void DrawTexture(MaterialEditor editor, MaterialProperty texturePr
/// <param name="offsetCoordYProperty"></param>
/// <param name="channelsXProperty"></param>
/// <param name="channelsYProperty"></param>
public static void DrawTexture(MaterialEditor editor, MaterialProperty textureProperty,
public static void DrawTexture<TCustomCoord>(MaterialEditor editor, MaterialProperty textureProperty,
MaterialProperty offsetCoordXProperty, MaterialProperty offsetCoordYProperty,
MaterialProperty channelsXProperty, MaterialProperty channelsYProperty)
MaterialProperty channelsXProperty, MaterialProperty channelsYProperty) where TCustomCoord : Enum
{
DrawTexture(editor, textureProperty, true,
DrawTexture<TCustomCoord>(editor, textureProperty, true,
offsetCoordXProperty, offsetCoordYProperty, channelsXProperty, channelsYProperty);
}

private static void DrawTexture(MaterialEditor editor, MaterialProperty textureProperty,
private static void DrawTexture<TCustomCoord>(MaterialEditor editor, MaterialProperty textureProperty,
bool drawTilingAndOffset,
MaterialProperty offsetCoordXProperty, MaterialProperty offsetCoordYProperty,
MaterialProperty channelsXProperty, MaterialProperty channelsYProperty)
MaterialProperty channelsXProperty, MaterialProperty channelsYProperty) where TCustomCoord : Enum
{
var propertyCount = 0;
if (drawTilingAndOffset) propertyCount += 2;
Expand Down Expand Up @@ -402,15 +403,15 @@ private static void DrawTexture(MaterialEditor editor, MaterialProperty textureP
var xPropertyRect = xRect;
xPropertyRect.xMin += 12;
EditorGUI.LabelField(xRect, new GUIContent("X"));
DrawEnumContentsProperty<CustomCoord>(editor, xPropertyRect, offsetCoordXProperty);
DrawEnumContentsProperty<TCustomCoord>(editor, xPropertyRect, offsetCoordXProperty);

var yRect = xRect;
yRect.x += yRect.width + 2;
yRect.xMax -= 2;
var yPropertyRect = yRect;
yPropertyRect.xMin += 12;
EditorGUI.LabelField(yRect, new GUIContent("Y"));
DrawEnumContentsProperty<CustomCoord>(editor, yPropertyRect, offsetCoordYProperty);
DrawEnumContentsProperty<TCustomCoord>(editor, yPropertyRect, offsetCoordYProperty);
}

// Channels
Expand Down Expand Up @@ -446,8 +447,8 @@ private static void DrawTexture(MaterialEditor editor, MaterialProperty textureP
/// <param name="label"></param>
/// <param name="property"></param>
/// <param name="coordProperty"></param>
public static void DrawPropertyAndCustomCoord(MaterialEditor editor, string label, MaterialProperty property,
MaterialProperty coordProperty)
public static void DrawPropertyAndCustomCoord<T>(MaterialEditor editor, string label, MaterialProperty property,
MaterialProperty coordProperty) where T : Enum
{
var fullRect = EditorGUILayout.GetControlRect();
var contentsRect = fullRect;
Expand All @@ -462,17 +463,22 @@ public static void DrawPropertyAndCustomCoord(MaterialEditor editor, string labe

using (new ResetIndentLevelScope())
{
var coord = (CustomCoord)coordProperty.floatValue;
T coord = (T)Enum.ToObject(typeof(T), Convert.ToInt32(coordProperty.floatValue));
if (!Enum.IsDefined(typeof(T), coord))
{
EditorGUILayout.HelpBox(
$"Invalid coord value\n", MessageType.Error, true);
}
using (var ccs = new EditorGUI.ChangeCheckScope())
{
EditorGUI.showMixedValue = coordProperty.hasMixedValue;
coord = (CustomCoord)EditorGUI.EnumPopup(coordRect, coord);
coord = (T)EditorGUI.EnumPopup(coordRect, coord);
EditorGUI.showMixedValue = false;

if (ccs.changed)
{
editor.RegisterPropertyChangeUndo(coordProperty.name);
coordProperty.floatValue = (int)coord;
coordProperty.floatValue = Convert.ToInt32(coord);
}
}
}
Expand Down Expand Up @@ -667,9 +673,16 @@ public static void DrawEnumContentsProperty<T>(MaterialEditor editor, Rect rect,
var value = (T)Enum.ToObject(typeof(T), (int)property.floatValue);
using (var ccs = new EditorGUI.ChangeCheckScope())
{
EditorGUI.showMixedValue = property.hasMixedValue;

EditorGUI.showMixedValue = property.hasMixedValue;
if (!Enum.IsDefined(typeof(T), value))
{
EditorGUILayout.HelpBox(
$"Invalid coord value\n", MessageType.Error, true);
}

var intValue = Convert.ToInt32(EditorGUI.EnumPopup(rect, value));


EditorGUI.showMixedValue = false;

if (ccs.changed)
Expand Down
16 changes: 8 additions & 8 deletions Assets/Nova/Editor/Core/Scripts/ParticlesDistortionGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ private void DrawRenderSettingsProperties(MaterialEditor editor, MaterialPropert

private void DrawDistortionProperties(MaterialEditor editor, MaterialProperty[] properties)
{
MaterialEditorUtility.DrawTexture(editor, _baseMapProp.Value, _baseMapOffsetXCoordProp.Value,
MaterialEditorUtility.DrawTexture<CustomCoord>(editor, _baseMapProp.Value, _baseMapOffsetXCoordProp.Value,
_baseMapOffsetYCoordProp.Value,
_baseMapChannelsXProp.Value, _baseMapChannelsYProp.Value);
MaterialEditorUtility.DrawPropertyAndCustomCoord(editor, "Intensity",
MaterialEditorUtility.DrawPropertyAndCustomCoord<CustomCoord>(editor, "Intensity",
_distortionIntensityProp.Value, _distortionIntensityCoordProp.Value);
MaterialEditorUtility.DrawPropertyAndCustomCoord(editor, "Rotation",
MaterialEditorUtility.DrawPropertyAndCustomCoord<CustomCoord>(editor, "Rotation",
_baseMapRotationProp.Value, _baseMapRotationCoordProp.Value);
using (new EditorGUI.IndentLevelScope())
{
Expand All @@ -158,9 +158,9 @@ private void DrawDistortionProperties(MaterialEditor editor, MaterialProperty[]

private void DrawFlowMapProperties(MaterialEditor editor, MaterialProperty[] properties)
{
MaterialEditorUtility.DrawTexture(editor, _flowMapProp.Value, _flowMapOffsetXCoordProp.Value,
MaterialEditorUtility.DrawTexture<CustomCoord>(editor, _flowMapProp.Value, _flowMapOffsetXCoordProp.Value,
_flowMapOffsetYCoordProp.Value, _flowMapChannelsXProp.Value, _flowMapChannelsYProp.Value);
MaterialEditorUtility.DrawPropertyAndCustomCoord(editor, "Intensity", _flowIntensityProp.Value,
MaterialEditorUtility.DrawPropertyAndCustomCoord<CustomCoord>(editor, "Intensity", _flowIntensityProp.Value,
_flowIntensityCoordProp.Value);
MaterialEditorUtility.DrawEnumFlagsProperty<FlowMapTargetDistortion>(editor, "Targets",
_flowMapTargetProp.Value);
Expand All @@ -173,11 +173,11 @@ private void DrawAlphaTransitionProperties(MaterialEditor editor, MaterialProper
var mode = (AlphaTransitionMode)_alphaTransitionModeProp.Value.floatValue;
if (mode != AlphaTransitionMode.None)
{
MaterialEditorUtility.DrawTexture(editor, _alphaTransitionMapProp.Value,
MaterialEditorUtility.DrawTexture<CustomCoord>(editor, _alphaTransitionMapProp.Value,
_alphaTransitionMapOffsetXCoordProp.Value, _alphaTransitionMapOffsetYCoordProp.Value,
_alphaTransitionMapChannelsXProp.Value, null);

MaterialEditorUtility.DrawPropertyAndCustomCoord(editor, "Progress",
MaterialEditorUtility.DrawPropertyAndCustomCoord<CustomCoord>(editor, "Progress",
_alphaTransitionProgressProp.Value, _alphaTransitionProgressCoordProp.Value);
if (mode == AlphaTransitionMode.Dissolve)
editor.ShaderProperty(_dissolveSharpnessProp.Value, "Edge Sharpness");
Expand Down Expand Up @@ -283,4 +283,4 @@ private void DrawTransparencyProperties(MaterialEditor editor, MaterialProperty[

#endregion
}
}
}
Loading

0 comments on commit 101ab75

Please sign in to comment.