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

Version 0.0.18 #21

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System.Linq;
using UnityEditor.Animations;
using UnityEngine;

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

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

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

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

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

public static string[] GetParameterNamesOfType(this AnimatorController animator, AnimatorControllerParameterType parameterType)
{
return animator.GetParametersOfType(parameterType)
.Select(p => p.name)
.ToArray();
}

#endregion

#region Has Parameters

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

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

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

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

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

#endregion

private static AnimatorControllerParameter[] GetParametersOfType(this AnimatorController animator, AnimatorControllerParameterType parameterType)
{
return animator.parameters
.Where(p => p.type == parameterType)
.ToArray();
}
}
}
119 changes: 119 additions & 0 deletions Assets/BetterCommons/Runtime/Extensions/AnimatorExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System.Linq;
using UnityEngine;
using Parameter = UnityEngine.AnimatorControllerParameter;
using ParameterType = UnityEngine.AnimatorControllerParameterType;

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

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

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

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

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

public static string[] GetParameterNamesOfType(this Animator animator, ParameterType parameterType)
{
return animator.GetParametersOfType(parameterType)
.Select(p => p.name)
.ToArray();
}

#endregion

#region Has Parameters

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

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

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

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

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

#endregion

#region Set Parameters

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

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

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

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

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

#endregion

private static Parameter[] GetParametersOfType(this Animator animator, ParameterType parameterType)
{
return animator.parameters
.Where(p => p.type == parameterType)
.ToArray();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/BetterCommons/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.17",
"version": "0.0.18",
"unity": "2021.3",
"description": " ",
"dependencies": {
Expand Down
Loading