using UnityEngine;
using System.Collections;
using System;
public class NetworkSyncAnimation : MonoBehaviour {
public enum AniStates
{
walk = 0,
run,
kick,
punch,
jump,
jumpfall,
idle,
gotbit,
gothit,
walljump,
deathfall,
jetpackjump,
ledgefall,
buttstomp,
jumpland
}
public AniStates currentAnimation = AniStates.idle;
public AniStates lastAnimation = AniStates.idle;
public void SyncAnimation(String animationValue)
{
currentAnimation = (AniStates)Enum.Parse(typeof(AniStates), animationValue);
}
// Update is called once per frame
void Update () {
if (lastAnimation != currentAnimation)
{
lastAnimation = currentAnimation;
animation.CrossFade(Enum.GetName(typeof(AniStates), currentAnimation));
animation["run"].normalizedSpeed = 1.0F;
animation["walk"].normalizedSpeed = 1.0F;
}
}
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
if (stream.isWriting)
{
char ani = (char)currentAnimation;
stream.Serialize(ref ani);
}
else
{
char ani = (char)0;
stream.Serialize(ref ani);
currentAnimation = (AniStates)ani;
}
}
}
本文介绍了一个Unity中的网络同步动画系统实现方法。通过定义动画状态枚举,并使用MonoBehaviour类进行状态更新与同步,确保不同客户端间动画的一致性。文章详细展示了如何通过字符串接收远程动画状态并更新本地动画。
407

被折叠的 条评论
为什么被折叠?



