157 lines
5.5 KiB
C#
157 lines
5.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using System.Linq;
|
|
using Animancer;
|
|
using AYellowpaper.SerializedCollections;
|
|
using BITKit;
|
|
using Cysharp.Threading.Tasks;
|
|
using Unity.Mathematics;
|
|
using UnityEngine;
|
|
|
|
namespace Project.B.Animation
|
|
{
|
|
public class ScriptableHumanoidAnimationFactory : ScriptableObject,IHumanoidAnimationFactory
|
|
{
|
|
[SerializeReference, SubclassSelector] private IReference[] tags;
|
|
|
|
[SerializeField] public SerializedDictionary<float2, AnimationClip> idleAnimations;
|
|
[SerializeField] public SerializedDictionary<float2, AnimationClip> walkAnimations;
|
|
[SerializeField] public SerializedDictionary<float2, AnimationClip> crouchAnimations;
|
|
[SerializeField] public SerializedDictionary<float2, AnimationClip> inAirAnimations;
|
|
[SerializeField] public SerializedDictionary<float, AnimationClip> runAnimations;
|
|
[SerializeField] public SerializedDictionary<float, AnimationClip> sprintAnimations;
|
|
[SerializeField] public SerializedDictionary<float2, AnimationClip> knockedAnimations;
|
|
[SerializeField] public SerializedDictionary<float,AnimationClip> ladderAnimations;
|
|
[SerializeField] public SerializedDictionary<float2,AnimationClip> hitAnimations;
|
|
[SerializeField] public AnimationClip[] knockingAnimations;
|
|
[SerializeField] public AnimationClip[] revivedAnimations;
|
|
[SerializeField] public AnimationClip[] deathAnimations;
|
|
[SerializeField] public AnimationClip[] seatAnimations;
|
|
[SerializeField] public AnimationClip[] ladderEnterAnimations;
|
|
[SerializeField] public AnimationClip[] ladderExitAnimations;
|
|
public UniTask InitializeAsync()
|
|
{
|
|
return UniTask.CompletedTask;
|
|
}
|
|
public int Hash => tags.GetHashCode();
|
|
public IReadOnlyCollection<string> Tags => tags.Select(x => x.Value).ToImmutableArray();
|
|
|
|
public IWrapper<float2> CreateIdleAnimation()
|
|
{
|
|
var idle = new DirectionalMixerState();
|
|
foreach (var (parameter,clip) in idleAnimations)
|
|
{
|
|
idle.Add(clip, parameter);
|
|
}
|
|
return new MixerStateWrapperFloat2(idle);
|
|
}
|
|
|
|
public IWrapper<float2> CreateWalkAnimation()
|
|
{
|
|
var walk = new DirectionalMixerState();
|
|
foreach (var (parameter, clip) in walkAnimations)
|
|
{
|
|
walk.Add(clip, parameter);
|
|
}
|
|
return new MixerStateWrapperFloat2(walk);
|
|
}
|
|
|
|
public IWrapper<float2> CreateCrouchedAnimation()
|
|
{
|
|
var crouch = new DirectionalMixerState();
|
|
foreach (var (parameter, clip) in crouchAnimations)
|
|
{
|
|
crouch.Add(clip, parameter);
|
|
}
|
|
return new MixerStateWrapperFloat2(crouch);
|
|
}
|
|
|
|
public IWrapper<float2> CreateInAirAnimation()
|
|
{
|
|
var inAir = new DirectionalMixerState();
|
|
foreach (var (parameter, clip) in inAirAnimations)
|
|
{
|
|
inAir.Add(clip, parameter);
|
|
}
|
|
return new MixerStateWrapperFloat2(inAir);
|
|
}
|
|
|
|
public IWrapper<float2> CreateHitAnimation()
|
|
{
|
|
var hit = new DirectionalMixerState();
|
|
foreach (var (parameter, clip) in hitAnimations)
|
|
{
|
|
hit.Add(clip, parameter);
|
|
}
|
|
return new MixerStateWrapperFloat2(hit);
|
|
}
|
|
|
|
public IWrapper<float> CreateRunAnimation()
|
|
{
|
|
var state = new LinearMixerState()
|
|
{
|
|
{
|
|
idleAnimations[new float2(0, 0)], 0
|
|
},
|
|
};
|
|
foreach (var (parameter,clip) in runAnimations)
|
|
{
|
|
state.Add(clip, parameter);
|
|
}
|
|
return new MixerStateWrapperFloat(state);
|
|
}
|
|
|
|
public IWrapper<float> CreateSprintAnimation()
|
|
{
|
|
var state = new LinearMixerState()
|
|
{
|
|
{
|
|
idleAnimations[new float2(0, 0)], 0
|
|
},
|
|
};
|
|
foreach (var (parameter, clip) in sprintAnimations)
|
|
{
|
|
state.Add(clip, parameter);
|
|
}
|
|
return new MixerStateWrapperFloat(state);
|
|
}
|
|
|
|
public IWrapper<float2> CreateKnockedAnimation()
|
|
{
|
|
var knocked = new DirectionalMixerState();
|
|
foreach (var (parameter, clip) in knockedAnimations)
|
|
{
|
|
knocked.Add(clip, parameter);
|
|
}
|
|
return new MixerStateWrapperFloat2(knocked);
|
|
}
|
|
|
|
public object CreateKnockingAnimation()
|
|
{
|
|
return knockingAnimations.Random();
|
|
}
|
|
|
|
public object CreateRevivedAnimation() => revivedAnimations.Random();
|
|
|
|
public object CreateDeathAnimation()
|
|
{
|
|
return deathAnimations.Random();
|
|
}
|
|
public object CreateSeatAnimation() => seatAnimations.Random();
|
|
public object CreateLadderEnterAnimation() => ladderEnterAnimations.Random();
|
|
public IWrapper<float> CreateLadderAnimation()
|
|
{
|
|
var climb = new LinearMixerState();
|
|
foreach (var (parameter, clip) in ladderAnimations)
|
|
{
|
|
climb.Add(clip, parameter);
|
|
}
|
|
return new MixerStateWrapperFloat(climb);
|
|
}
|
|
|
|
public object CreateLadderExitAnimation() => ladderExitAnimations.Random();
|
|
}
|
|
|
|
}
|