12 protected ResourceName m_PlayerDelegatePrefab;
14 protected int m_iPlayerID;
15 protected SCR_EditablePlayerDelegateComponent m_PlayerDelegate;
16 protected ref map<int, SCR_EditablePlayerDelegateComponent> m_Delegates =
new map<int, SCR_EditablePlayerDelegateComponent>;
17 protected ref ScriptInvoker m_OnLimitedEditorChanged =
new ScriptInvoker;
23 void RegisterDelegate(SCR_EditablePlayerDelegateComponent delegate)
25 m_Delegates.Set(delegate.GetPlayerID(), delegate);
27 delegate.GetOnLimitedEditorChanged().Insert(OnLimitedEditorChanged);
28 OnLimitedEditorChanged(delegate.GetPlayerID(), delegate.HasLimitedEditor());
34 void UnegisterDelegate(SCR_EditablePlayerDelegateComponent delegate)
36 m_Delegates.Remove(delegate.GetPlayerID());
38 delegate.GetOnLimitedEditorChanged().Remove(OnLimitedEditorChanged);
39 OnLimitedEditorChanged(delegate.GetPlayerID(),
true);
46 int GetDelegates(out notnull map<int, SCR_EditablePlayerDelegateComponent> outDelegates)
48 return outDelegates.Copy(m_Delegates);
55 SCR_EditablePlayerDelegateComponent GetDelegate(
int playerID)
57 SCR_EditablePlayerDelegateComponent delegate;
58 m_Delegates.Find(playerID, delegate);
64 bool HasPlayerWithUnlimitedEditor()
66 if (!m_Delegates || m_Delegates.IsEmpty())
69 for (
int i, count = m_Delegates.Count(); i < count; i++)
71 if (!m_Delegates.GetElement(i))
74 if (!m_Delegates.GetElement(i).HasLimitedEditor())
83 ScriptInvoker GetOnLimitedEditorChanged()
85 return m_OnLimitedEditorChanged;
88 protected void OnLimitedEditorChanged(
int playerID,
bool isLimited)
90 m_OnLimitedEditorChanged.Invoke(playerID, isLimited);
93 protected void OnSpawnServer(
int playerID, IEntity controlledEntity)
96 m_PlayerDelegate.SetControlledEntity(controlledEntity);
98 protected void OnDeathServer(
int playerId, IEntity playerEntity, IEntity killerEntity, notnull
Instigator killer)
101 m_PlayerDelegate.SetControlledEntity(
null);
104 protected void OnPlayerDeletedServer(
int playerID, IEntity controlledEntity)
106 OnDeathServer(playerID, controlledEntity,
null,
Instigator.CreateInstigator(
null));
109 override void EOnEditorInitServer()
111 Resource entityResource = Resource.Load(m_PlayerDelegatePrefab);
113 if (!componentSource)
115 Print(
string.Format(
"SCR_EditablePlayerDelegateComponent missing in '%1'!", m_PlayerDelegatePrefab.GetPath()), LogLevel.WARNING);
119 if (!componentSource.GetClassName().ToType().IsInherited(SCR_EditablePlayerDelegateComponent))
121 Print(
string.Format(
"'%1' contains editable entity entity of type %2, must be SCR_EditablePlayerDelegateComponent!", m_PlayerDelegatePrefab.GetPath(), componentSource.GetClassName()), LogLevel.WARNING);
128 IEntity delegateEntity =
GetGame().SpawnEntityPrefab(entityResource);
129 m_PlayerDelegate = SCR_EditablePlayerDelegateComponent.Cast(SCR_EditablePlayerDelegateComponent.GetEditableEntity(delegateEntity));
130 m_PlayerDelegate.InitPlayerDelegate(editorManager,
m_iPlayerID);
131 m_PlayerDelegate.RestoreParentEntity();
136 gameMode.GetOnPlayerSpawned().Insert(OnSpawnServer);
137 gameMode.GetOnPlayerKilled().Insert(OnDeathServer);
138 gameMode.GetOnPlayerDeleted().Insert(OnPlayerDeletedServer);
140 m_PlayerDelegate.SetControlledEntity(SCR_PossessingManagerComponent.GetPlayerMainEntity(
m_iPlayerID));
145 if (playerController && playerController.GetPlayerId() ==
m_iPlayerID)
147 m_PlayerDelegate.SetControlledEntity(playerController.GetMainEntity());
151 override void EOnEditorDeleteServer()
153 if (m_PlayerDelegate)
154 m_PlayerDelegate.Delete();
159 gameMode.GetOnPlayerSpawned().Remove(OnSpawnServer);
160 gameMode.GetOnPlayerKilled().Remove(OnDeathServer);
161 gameMode.GetOnPlayerDeleted().Remove(OnPlayerDeletedServer);