Giant animation polish

This commit is contained in:
Szymon Miś
2025-09-09 02:27:50 +02:00
parent 312dae2f4d
commit 2437efe614
4 changed files with 827 additions and 593 deletions

View File

@@ -0,0 +1,48 @@
using UnityEngine;
public class RandomizeAnimatorIntWeighted : StateMachineBehaviour
{
[Header("Animator parameter name (must be int type)")]
public string parameterName = "Randomized";
[Header("Weights for each slot (index = int value)")]
public int[] weights = { 35, 35, 15, 15 };
// Example: {70, 20, 10} means index 0 has 70% chance, 1 has 20%, 2 has 10%
// Called when the animator enters this state
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (weights == null || weights.Length == 0)
{
return;
}
int total = 0;
foreach (int w in weights)
{
total += Mathf.Max(0, w);
}
if (total <= 0)
{
return;
}
int randomValue = Random.Range(0, total);
int cumulative = 0;
int chosenIndex = 0;
for (int i = 0; i < weights.Length; i++)
{
cumulative += Mathf.Max(0, weights[i]);
if (randomValue < cumulative)
{
chosenIndex = i;
break;
}
}
animator.SetFloat(parameterName, (float)chosenIndex);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d20bc7e4150a82f4ba03191390f832f8

File diff suppressed because it is too large Load Diff