骑士插图,UI调整

This commit is contained in:
SoulliesOfficial
2025-12-03 09:22:57 -05:00
parent c65462e73b
commit a4c28b955f
317 changed files with 143921 additions and 4004 deletions

View File

@@ -0,0 +1,116 @@
using UnityEngine;
namespace AnimatorPlus.Example
{
public class CharacterControllerExample : MonoBehaviour
{
public global::AnimatorPlus.AnimatorPlus animatorPlus;
public bool IsRootMotion = true;
public bool NotPlayingClipUntilLastAnimFinished = true;
[Header("Character Movement")]
[Range(0,2)]public float MoveSpeed = 1.6f;
[Range(0,20)]public float RotSpeed = 10;
[Header("Play Anim When Click Left Mouse Button,Cancel When Right Mouse Button")]
public AnimationClip AnimationClip;
public float fadeInTime = 0.2f;
public float fadeOutTime = 0.2f;
private float animClipPlayTimer;
private void Start()
{
animatorPlus = GetComponentInChildren<global::AnimatorPlus.AnimatorPlus>();
}
private void Update()
{
animatorPlus.IsRootMotion = IsRootMotion;
if (IsRootMotion)
{
UpdateRootMotion();
}
else
{
UpdateInPlace();
}
}
void UpdateRootMotion()
{
if (animatorPlus.AnimatorPlayWeight > 0.1f)// not accept move input during animClip is playing
{
//Move the character
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
var inputMove = new Vector3(h, 0, v);
//Turn the character
if (inputMove.magnitude > 0)
transform.forward = Vector3.RotateTowards(transform.forward, inputMove.normalized, Time.deltaTime * RotSpeed, 0);
animatorPlus.Animator.SetFloat("Speed", inputMove.magnitude * MoveSpeed);
}
if (Input.GetMouseButton(0))
{
if (!NotPlayingClipUntilLastAnimFinished || animClipPlayTimer < Time.time)
{
animatorPlus.PlayAnimationClip(AnimationClip, fadeInTime, fadeOutTime);
animClipPlayTimer = Time.time + AnimationClip.length - fadeOutTime;
}
}
else if (Input.GetMouseButton(1))
{
animatorPlus.PlayAnimator(fadeOutTime);
if(NotPlayingClipUntilLastAnimFinished)
animClipPlayTimer = 0;
}
//If using root motion, update the position based on the delta position from the animatorPlus
transform.position += animatorPlus.DeltaPosition;
transform.rotation *= animatorPlus.DeltaRotation;
}
void UpdateInPlace()
{
if (animatorPlus.AnimatorPlayWeight > 0.1f) // not accept move input during animClip is playing
{
//Move the character
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
var inputMove = new Vector3(h, 0, v);
//Turn the character
if (inputMove.magnitude > 0)
transform.forward = Vector3.RotateTowards(transform.forward, inputMove.normalized, Time.deltaTime * RotSpeed, 0);
//If not using root motion, update the position based on the input vector
transform.position += (inputMove.magnitude > 0.2f? 1:0 ) * Time.deltaTime * MoveSpeed * transform.forward;
animatorPlus.Animator.SetFloat("Speed", inputMove.magnitude * MoveSpeed);
}
if (Input.GetMouseButton(0))
{
if (!NotPlayingClipUntilLastAnimFinished || animClipPlayTimer < Time.time)
{
animatorPlus.PlayAnimationClip(AnimationClip, fadeInTime, fadeOutTime);
animClipPlayTimer = Time.time + AnimationClip.length - fadeOutTime;
}
}
else if (Input.GetMouseButton(1))
{
animatorPlus.PlayAnimator(fadeOutTime);
if(NotPlayingClipUntilLastAnimFinished)
animClipPlayTimer = 0;
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 46cb8ffd74b84664bb93402385aaf7c2

View File

@@ -0,0 +1,36 @@
using UnityEngine;
using UnityEngine.UI;
namespace AnimatorPlus.Example
{
public class ExampleUI_CharacterContol : MonoBehaviour
{
public Button Button1;
public Button Button2;
public GameObject Character1;
public GameObject Character2;
public void Start()
{
Button1.onClick.AddListener(Button1Click);
Button2.onClick.AddListener(Button2Click);
}
void Button1Click()
{
Character1.SetActive(true);
Character1.transform.position = Vector3.zero;
Character2.SetActive(false);
}
void Button2Click()
{
Character2.SetActive(true);
Character2.transform.position = Vector3.zero;
Character1.SetActive(false);
}
}
}

View File

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

View File

@@ -0,0 +1,33 @@
using UnityEngine;
namespace AnimatorPlus.Example
{
public class PlayAnimationExample : MonoBehaviour
{
public AnimatorPlus animatorPlus;
public AnimationClip animationClip;
public AvatarMask avatarMask;
public float fadeTime = 0.2f;
public float fadeInTime = 0.2f;
public float fadeOutTime = 0.2f;
public void PlayAnimator()
{
animatorPlus.PlayAnimator(fadeTime);
}
public void OnSliderValueChanged(float value)
{
animatorPlus.Animator.SetFloat("Speed", value);
}
public void PlayAnimationClip()
{
animatorPlus.PlayAnimationClip(animationClip, fadeInTime,fadeTime);
}
public void PlayAnimationClipWithMask()
{
animatorPlus.PlayAnimationClip(animationClip, fadeTime, fadeTime, avatarMask);
}
}
}

View File

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