Skip to content

Commit

Permalink
feat: Enumの簡易変換を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
pspkurara committed Nov 6, 2020
1 parent 6c3232f commit 16f3ac5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Packages/uGUI-Skinner/Runtime/ValueUtility.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Enum = System.Enum;
using Convert = System.Convert;

namespace Pspkurara.UI.Skinner
{
Expand All @@ -25,6 +25,11 @@ public static Vector4 ToVector(this Rect rect)
return new Vector4(rect.x, rect.y, rect.width, rect.height);
}

public static float ToFloat<T>(this T self) where T : Enum
{
return Convert.ToInt32(self);
}

public static float ToFloat(this bool self)
{
return self ? 1 : 0;
Expand All @@ -48,11 +53,17 @@ public static Rect ToRect(this Vector4 self)
{
return new Rect(self.x, self.y, self.z, self.w);
}

public static int ToInt(this float self)
{
return Mathf.RoundToInt(self);
}

public static T ToEnum<T>(this float self) where T : Enum
{
return (T)Enum.ToObject(typeof(T), self.ToInt());
}

public static bool ToBool(this float self)
{
return self.ToInt() > 0;
Expand Down

0 comments on commit 16f3ac5

Please sign in to comment.