123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using Unity.Netcode;
- using UnityEngine;
- using UnityEngine.Video;
- //空间坐标系同步
- public class MRCCommonBehavior : NetworkBehaviour
- {
- //位置和旋转
- private NetworkVariable<Vector3> spacePos;
- private NetworkVariable<Quaternion> spaceRot;
-
- public void SyncSpaceCordinateServer(Vector3 pos, Quaternion rot)
- {
- spacePos.Value = pos;
- spaceRot.Value = rot;
- }
- public void SyncSpaceCordinateClient()
- {
- //同步
- }
- //生成物体
- public override void OnNetworkSpawn()
- {
- base.OnNetworkSpawn();
- if(!NetworkManager.Singleton.IsClient)
- {
- enabled = false;
- }
- else
- {
- NetworkManager.OnClientConnectedCallback += OnClientConnected;
- NetworkManager.OnClientDisconnectCallback += OnClientDisconnected;
- }
- }
- private void OnClientConnected(ulong clientId)
- {
- }
- private void OnClientDisconnected(ulong clientId)
- {
- }
- //删除物体
- public override void OnNetworkDespawn()
- {
- base.OnNetworkDespawn();
- }
- //获得所有权
- public override void OnGainedOwnership()
- {
- base.OnGainedOwnership();
- }
- //失去所有权
- public override void OnLostOwnership()
- {
- base.OnLostOwnership();
- }
- //更改了该物体的父物体
- public override void OnNetworkObjectParentChanged(NetworkObject parentNetworkObject)
- {
- base.OnNetworkObjectParentChanged(parentNetworkObject);
- }
- public void TestSend()
- {
- //向某个客户端发送消息
- //var message = new DestroyObjectMessage
- //{
- // NetworkObjectId = NetworkObjectId,
- // DestroyGameObject =
- //};
- //NetworkManager.Singleton.SendMessage(ref message, NetworkDelivery.ReliableSequenced, clientId);
- }
- }
|