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

UV rotation UI improvement #79

Merged
merged 3 commits into from
Jun 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
44 changes: 42 additions & 2 deletions MToon/Editor/MToonInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class MToonInspector : ShaderGUI
private MaterialProperty _uvAnimScrollY;
private MaterialProperty _uvAnimRotation;

private MToon.RotationUnit uvRotationUnit = MToon.RotationUnit.Rounds ;
private float uvRotation;

public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
_version = FindProperty(Utils.PropVersion, properties);
Expand Down Expand Up @@ -92,7 +95,7 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro
_uvAnimScrollX = FindProperty(Utils.PropUvAnimScrollX, properties);
_uvAnimScrollY = FindProperty(Utils.PropUvAnimScrollY, properties);
_uvAnimRotation = FindProperty(Utils.PropUvAnimRotation, properties);

uvRotation = getUvRotationValue(uvRotationUnit, _uvAnimRotation.floatValue);
var materials = materialEditor.targets.Select(x => x as Material).ToArray();
Draw(materialEditor, materials);
}
Expand Down Expand Up @@ -317,7 +320,11 @@ private void Draw(MaterialEditor materialEditor, Material[] materials)
materialEditor.TexturePropertySingleLine(new GUIContent("Mask", "Auto Animation Mask Texture (R)"), _uvAnimMaskTexture);
materialEditor.ShaderProperty(_uvAnimScrollX, "Scroll X (per second)");
materialEditor.ShaderProperty(_uvAnimScrollY, "Scroll Y (per second)");
materialEditor.ShaderProperty(_uvAnimRotation, "Rotation (per second)");
uvRotationUnit = (MToon.RotationUnit)EditorGUILayout.EnumPopup("Rotation Unit", uvRotationUnit);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int から enum のキャストも dynamic なキャストになるのは危険なので、下の方に定義してある PopUpEnum<T> を使用していただければと思います。

uvRotation = EditorGUILayout.DelayedFloatField("Rotation value (per second)", uvRotation);
_uvAnimRotation.floatValue = getUvRoundValue( uvRotationUnit, uvRotation);
//materialEditor.ShaderProperty(_uvAnimRotation, "Rotation (per second)");

}
}
EditorGUILayout.EndVertical();
Expand Down Expand Up @@ -401,5 +408,38 @@ private static void TextureWithHdrColor(MaterialEditor materialEditor, string la
showAlpha: false);

}

private float getUvRoundValue(MToon.RotationUnit unit , float val)
{
if (unit == MToon.RotationUnit.Rounds)
{
return val;
}
else if (unit == MToon.RotationUnit.Degrees)
{
return val / 360.0f;
}
else if (unit == MToon.RotationUnit.Radians)
{
return val / 2.0f;
}
return val;
}
private float getUvRotationValue(MToon.RotationUnit unit,float val)
{
if (unit == MToon.RotationUnit.Rounds)
{
return val;
}
else if (unit == MToon.RotationUnit.Degrees)
{
return val * 360.0f;
}
else if (unit == MToon.RotationUnit.Radians)
{
return val * 2.0f;
}
return val;
}
}
}
7 changes: 7 additions & 0 deletions MToon/Scripts/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public enum CullMode
Back = 2,
}

public enum RotationUnit
{
Degrees = 0,
Radians = 1,
Rounds = 2
}

public struct RenderQueueRequirement
{
public int DefaultValue;
Expand Down