Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uGUI上でのパーティクル表示に対応 #86

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading