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;
  } 
 }
}

相关文章:

  • 2021-09-25
  • 2022-12-23
  • 2021-06-18
  • 2021-09-14
  • 2021-11-13
  • 2021-08-17
  • 2021-12-27
  • 2022-03-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
  • 2021-05-18
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
相关资源
相似解决方案