Skip to content

Commit

Permalink
Merge pull request #22 from techno-dwarf-works/feature/refactoring
Browse files Browse the repository at this point in the history
Version 0.0.19
  • Loading branch information
OpOpYaDev authored and OpOpYaDev committed Jul 15, 2024
1 parent 5ec15f5 commit e6a2790
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 58 deletions.
44 changes: 22 additions & 22 deletions Editor/Extensions/AnimatorControllerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ public static class AnimatorControllerExtensions
{
#region Get Parameters

public static string[] GetAllIntegerNames(this AnimatorController animator)
public static string[] GetAllIntegerNames(this AnimatorController self)
{
return animator.GetParameterNamesOfType(AnimatorControllerParameterType.Int);
return self.GetParameterNamesOfType(AnimatorControllerParameterType.Int);
}

public static string[] GetAllFloatNames(this AnimatorController animator)
public static string[] GetAllFloatNames(this AnimatorController self)
{
return animator.GetParameterNamesOfType(AnimatorControllerParameterType.Float);
return self.GetParameterNamesOfType(AnimatorControllerParameterType.Float);
}

public static string[] GetAllBoolNames(this AnimatorController animator)
public static string[] GetAllBoolNames(this AnimatorController self)
{
return animator.GetParameterNamesOfType(AnimatorControllerParameterType.Bool);
return self.GetParameterNamesOfType(AnimatorControllerParameterType.Bool);
}

private static string[] GetAllTriggerNames(this AnimatorController animator)
private static string[] GetAllTriggerNames(this AnimatorController self)
{
return animator.GetParameterNamesOfType(AnimatorControllerParameterType.Trigger);
return self.GetParameterNamesOfType(AnimatorControllerParameterType.Trigger);
}

public static string[] GetParameterNamesOfType(this AnimatorController animator, AnimatorControllerParameterType parameterType)
public static string[] GetParameterNamesOfType(this AnimatorController self, AnimatorControllerParameterType parameterType)
{
return animator.GetParametersOfType(parameterType)
return self.GetParametersOfType(parameterType)
.Select(p => p.name)
.ToArray();
}
Expand All @@ -39,37 +39,37 @@ public static string[] GetParameterNamesOfType(this AnimatorController animator,

#region Has Parameters

public static bool HasParameter(this AnimatorController animator, string name)
public static bool HasParameter(this AnimatorController self, string name)
{
var names = animator.parameters.Select(p => p.name);
var names = self.parameters.Select(p => p.name);
return names.Contains(name);
}

public static bool HasInteger(this AnimatorController animator, string name)
public static bool HasInteger(this AnimatorController self, string name)
{
return animator.GetAllIntegerNames().Contains(name);
return self.GetAllIntegerNames().Contains(name);
}

public static bool HasFloat(this AnimatorController animator, string name)
public static bool HasFloat(this AnimatorController self, string name)
{
return animator.GetAllFloatNames().Contains(name);
return self.GetAllFloatNames().Contains(name);
}

public static bool HasBool(this AnimatorController animator, string name)
public static bool HasBool(this AnimatorController self, string name)
{
return animator.GetAllBoolNames().Contains(name);
return self.GetAllBoolNames().Contains(name);
}

public static bool HasTrigger(this AnimatorController animator, string name)
public static bool HasTrigger(this AnimatorController self, string name)
{
return animator.GetAllTriggerNames().Contains(name);
return self.GetAllTriggerNames().Contains(name);
}

#endregion

private static AnimatorControllerParameter[] GetParametersOfType(this AnimatorController animator, AnimatorControllerParameterType parameterType)
private static AnimatorControllerParameter[] GetParametersOfType(this AnimatorController self, AnimatorControllerParameterType parameterType)
{
return animator.parameters
return self.parameters
.Where(p => p.type == parameterType)
.ToArray();
}
Expand Down
70 changes: 35 additions & 35 deletions Runtime/Extensions/AnimatorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
using Parameter = UnityEngine.AnimatorControllerParameter;
using ParameterType = UnityEngine.AnimatorControllerParameterType;

namespace Better.Commons.EditorAddons.Extensions
namespace Better.Commons.Runtime.Extensions
{
public static class AnimatorExtensions
{
#region Get Parameters

public static string[] GetAllIntegerNames(this Animator animator)
public static string[] GetAllIntegerNames(this Animator self)
{
return animator.GetParameterNamesOfType(AnimatorControllerParameterType.Int);
return self.GetParameterNamesOfType(AnimatorControllerParameterType.Int);
}

public static string[] GetAllFloatNames(this Animator animator)
public static string[] GetAllFloatNames(this Animator self)
{
return animator.GetParameterNamesOfType(AnimatorControllerParameterType.Float);
return self.GetParameterNamesOfType(AnimatorControllerParameterType.Float);
}

public static string[] GetAllBoolNames(this Animator animator)
public static string[] GetAllBoolNames(this Animator self)
{
return animator.GetParameterNamesOfType(AnimatorControllerParameterType.Bool);
return self.GetParameterNamesOfType(AnimatorControllerParameterType.Bool);
}

private static string[] GetAllTriggerNames(this Animator animator)
private static string[] GetAllTriggerNames(this Animator self)
{
return animator.GetParameterNamesOfType(AnimatorControllerParameterType.Trigger);
return self.GetParameterNamesOfType(AnimatorControllerParameterType.Trigger);
}

public static string[] GetParameterNamesOfType(this Animator animator, ParameterType parameterType)
public static string[] GetParameterNamesOfType(this Animator self, ParameterType parameterType)
{
return animator.GetParametersOfType(parameterType)
return self.GetParametersOfType(parameterType)
.Select(p => p.name)
.ToArray();
}
Expand All @@ -40,78 +40,78 @@ public static string[] GetParameterNamesOfType(this Animator animator, Parameter

#region Has Parameters

public static bool HasParameter(this Animator animator, string name)
public static bool HasParameter(this Animator self, string name)
{
var names = animator.parameters.Select(p => p.name);
var names = self.parameters.Select(p => p.name);
return names.Contains(name);
}

public static bool HasInteger(this Animator animator, string name)
public static bool HasInteger(this Animator self, string name)
{
return animator.GetAllIntegerNames().Contains(name);
return self.GetAllIntegerNames().Contains(name);
}

public static bool HasFloat(this Animator animator, string name)
public static bool HasFloat(this Animator self, string name)
{
return animator.GetAllFloatNames().Contains(name);
return self.GetAllFloatNames().Contains(name);
}

public static bool HasBool(this Animator animator, string name)
public static bool HasBool(this Animator self, string name)
{
return animator.GetAllBoolNames().Contains(name);
return self.GetAllBoolNames().Contains(name);
}

public static bool HasTrigger(this Animator animator, string name)
public static bool HasTrigger(this Animator self, string name)
{
return animator.GetAllTriggerNames().Contains(name);
return self.GetAllTriggerNames().Contains(name);
}

#endregion

#region Set Parameters

public static void ResetAllTriggers(this Animator animator)
public static void ResetAllTriggers(this Animator self)
{
var names = animator.GetAllTriggerNames();
var names = self.GetAllTriggerNames();

for (var i = 0; i < names.Length; i++)
{
animator.ResetTrigger(names[i]);
self.ResetTrigger(names[i]);
}
}

public static void SetAllBools(this Animator animator, bool value)
public static void SetAllBools(this Animator self, bool value)
{
var names = animator.GetAllBoolNames();
var names = self.GetAllBoolNames();
for (var i = 0; i < names.Length; i++)
{
animator.SetBool(names[i], value);
self.SetBool(names[i], value);
}
}

public static void SetAllIntegers(this Animator animator, int value)
public static void SetAllIntegers(this Animator self, int value)
{
var names = animator.GetAllIntegerNames();
var names = self.GetAllIntegerNames();
for (var i = 0; i < names.Length; i++)
{
animator.SetInteger(names[i], value);
self.SetInteger(names[i], value);
}
}

public static void SetAllFloats(this Animator animator, float value)
public static void SetAllFloats(this Animator self, float value)
{
var names = animator.GetAllFloatNames();
var names = self.GetAllFloatNames();
for (var i = 0; i < names.Length; i++)
{
animator.SetFloat(names[i], value);
self.SetFloat(names[i], value);
}
}

#endregion

private static Parameter[] GetParametersOfType(this Animator animator, ParameterType parameterType)
private static Parameter[] GetParametersOfType(this Animator self, ParameterType parameterType)
{
return animator.parameters
return self.parameters
.Where(p => p.type == parameterType)
.ToArray();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.tdw.better.commons",
"displayName": "Better Commons",
"version": "0.0.18",
"version": "0.0.19",
"unity": "2021.3",
"description": " ",
"dependencies": {
Expand Down

0 comments on commit e6a2790

Please sign in to comment.