Added OnGainedOwnership and OnLostOwnership virtual methods
This commit is contained in:
parent
1fe6a74ad6
commit
87658b2ce9
@ -87,6 +87,16 @@ namespace MLAPI
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void OnGainedOwnership()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnLostOwnership()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected int RegisterMessageHandler(string name, Action<int, byte[]> action)
|
protected int RegisterMessageHandler(string name, Action<int, byte[]> action)
|
||||||
{
|
{
|
||||||
int counter = MessageManager.AddIncomingMessageHandler(name, action, networkId);
|
int counter = MessageManager.AddIncomingMessageHandler(name, action, networkId);
|
||||||
|
@ -61,6 +61,32 @@ namespace MLAPI
|
|||||||
SpawnManager.ChangeOwnership(NetworkId, newOwnerClientId);
|
SpawnManager.ChangeOwnership(NetworkId, newOwnerClientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void InvokeBehaviourOnLostOwnership()
|
||||||
|
{
|
||||||
|
NetworkedBehaviour[] netBehaviours = GetComponentsInChildren<NetworkedBehaviour>();
|
||||||
|
for (int i = 0; i < netBehaviours.Length; i++)
|
||||||
|
{
|
||||||
|
//We check if we are it's networkedObject owner incase a networkedObject exists as a child of our networkedObject.
|
||||||
|
if (netBehaviours[i].networkedObject == this)
|
||||||
|
{
|
||||||
|
netBehaviours[i].OnLostOwnership();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void InvokeBehaviourOnGainedOwnership()
|
||||||
|
{
|
||||||
|
NetworkedBehaviour[] netBehaviours = GetComponentsInChildren<NetworkedBehaviour>();
|
||||||
|
for (int i = 0; i < netBehaviours.Length; i++)
|
||||||
|
{
|
||||||
|
//We check if we are it's networkedObject owner incase a networkedObject exists as a child of our networkedObject.
|
||||||
|
if (netBehaviours[i].networkedObject == this)
|
||||||
|
{
|
||||||
|
netBehaviours[i].OnGainedOwnership();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal void InvokeBehaviourNetworkSpawn()
|
internal void InvokeBehaviourNetworkSpawn()
|
||||||
{
|
{
|
||||||
NetworkedBehaviour[] netBehaviours = GetComponentsInChildren<NetworkedBehaviour>();
|
NetworkedBehaviour[] netBehaviours = GetComponentsInChildren<NetworkedBehaviour>();
|
||||||
|
@ -645,6 +645,16 @@ namespace MLAPI
|
|||||||
{
|
{
|
||||||
uint netId = messageReader.ReadUInt32();
|
uint netId = messageReader.ReadUInt32();
|
||||||
int ownerClientId = messageReader.ReadInt32();
|
int ownerClientId = messageReader.ReadInt32();
|
||||||
|
if (SpawnManager.spawnedObjects[netId].OwnerClientId == MyClientId)
|
||||||
|
{
|
||||||
|
//We are current owner.
|
||||||
|
SpawnManager.spawnedObjects[netId].InvokeBehaviourOnLostOwnership();
|
||||||
|
}
|
||||||
|
if(ownerClientId == MyClientId)
|
||||||
|
{
|
||||||
|
//We are new owner.
|
||||||
|
SpawnManager.spawnedObjects[netId].InvokeBehaviourOnGainedOwnership();
|
||||||
|
}
|
||||||
SpawnManager.spawnedObjects[netId].OwnerClientId = ownerClientId;
|
SpawnManager.spawnedObjects[netId].OwnerClientId = ownerClientId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user