-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathSetIsOwner.cs
46 lines (39 loc) · 1.26 KB
/
SetIsOwner.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#if UNITY_EDITOR
using System;
using Unity.Netcode;
using UnityEditor;
using UnityEngine;
public class SetIsOwner : MonoBehaviour
{
public void Set(ulong clientID)
{
GetComponent<NetworkObject>().ChangeOwnership(clientID);
}
[CustomEditor(typeof(SetIsOwner))]
public class GameEventEditor : Editor
{
private string m_ClientID = "clientID (ulong)";
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
var gameEvent = (SetIsOwner)target;
if (NetworkManager.Singleton != null && (NetworkManager.Singleton.IsConnectedClient || NetworkManager.Singleton.IsListening))
{
GUILayout.TextArea($"Current owner: {gameEvent.GetComponent<NetworkObject>().OwnerClientId}");
m_ClientID = GUILayout.TextField(m_ClientID);
}
if (GUILayout.Button("Set"))
{
gameEvent.Set(Convert.ToUInt64(m_ClientID));
}
}
}
private void Update()
{
if (NetworkManager.Singleton != null && (NetworkManager.Singleton.IsConnectedClient || NetworkManager.Singleton.IsListening))
{
// Debug.Log(NetworkManager.Singleton.LocalClientId);
}
}
}
#endif