public override void Deserialize(NetworkReader reader)
        {
            StatesChanged = (NetworkStateChanges)reader.ReadInt16();

            State           = new NetworkState();
            State.MessageId = reader.ReadInt32();
            if (StatesChanged.HasFlag(NetworkStateChanges.Scale))
            {
                State.StageScale = reader.ReadSingle();
            }
            if (StatesChanged.HasFlag(NetworkStateChanges.Offset))
            {
                State.StageOffset = reader.ReadSingle();
            }
            if (StatesChanged.HasFlag(NetworkStateChanges.Explode))
            {
                State.Explode = reader.ReadBoolean();
            }
            if (StatesChanged.HasFlag(NetworkStateChanges.Rotation))
            {
                State.StageRotation = reader.ReadSingle();
            }
            if (StatesChanged.HasFlag(NetworkStateChanges.Asset))
            {
                State.AssetInfo = AssetInfo.Deserialize(reader);
            }
        }
    private void OnStateChange(NetworkState newState, bool force = false, NetworkStateChanges changes = NetworkStateChanges.All)
    {
        if (myId == newState.MessageId && !force)
        {
            return;
        }

        localState.Merge(newState, changes);
        if (!isServer)  // everybody keeps a local copy of the server state in case they become the server
        {
            serverState = localState;
        }

        if (changes.HasFlag(NetworkStateChanges.Scale))
        {
            MasterController.Instance.DoSetStageScale(localState.StageScale);
        }
        if (changes.HasFlag(NetworkStateChanges.Offset))
        {
            MasterController.Instance.DoSetVerticalOffset(localState.StageOffset);
        }
        if (changes.HasFlag(NetworkStateChanges.Rotation))
        {
            MasterController.Instance.DoSetStageRotation(localState.StageRotation);
        }
        if (changes.HasFlag(NetworkStateChanges.Explode))
        {
            MasterController.Instance.DoSetExplode(localState.Explode);
        }
        if (changes.HasFlag(NetworkStateChanges.Asset))
        {
            MasterController.Instance.DoLoadBundle(localState.AssetInfo);
        }
    }
        public override string ToString()
        {
            string ret = "Changes: " + StatesChanged + "\n";

            if (StatesChanged.HasFlag(NetworkStateChanges.Scale))
            {
                ret += "StageScale: " + State.StageScale.ToString("0.00") + "\n";
            }
            if (StatesChanged.HasFlag(NetworkStateChanges.Offset))
            {
                ret += "StageOffset: " + State.StageOffset.ToString("0.00") + "\n";
            }
            if (StatesChanged.HasFlag(NetworkStateChanges.Rotation))
            {
                ret += "StageRotation: " + State.StageRotation.ToString("0.00") + "\n";
            }
            if (StatesChanged.HasFlag(NetworkStateChanges.Explode))
            {
                ret += "Explode: " + State.Explode + "\n";
            }

            if (StatesChanged.HasFlag(NetworkStateChanges.Asset))
            {
                ret += "AssetInfoID: " + State.AssetInfo.Id.ToString() + "\n";
                ret += "AssetInfoOwnerId: " + State.AssetInfo.OwnerId.ToString() + "\n";
            }
            return(ret);
        }
 public void Merge(NetworkState other, NetworkStateChanges changes)
 {
     MessageId = other.MessageId;
     if (changes.HasFlag(NetworkStateChanges.Scale))
     {
         StageScale = other.StageScale;
     }
     if (changes.HasFlag(NetworkStateChanges.Offset))
     {
         StageOffset = other.StageOffset;
     }
     if (changes.HasFlag(NetworkStateChanges.Rotation))
     {
         StageRotation = other.StageRotation;
     }
     if (changes.HasFlag(NetworkStateChanges.Explode))
     {
         Explode = other.Explode;
     }
     if (changes.HasFlag(NetworkStateChanges.Asset))
     {
         AssetInfo = other.AssetInfo;
     }
 }