Optional predefined viewId for NetworkObjects

This commit is contained in:
Pascal Serrarens 2022-02-25 15:32:28 +01:00
parent 9034590707
commit 4648565214
3 changed files with 34 additions and 2 deletions

View File

@ -111,8 +111,13 @@ namespace Passer {
Photon.Pun.PhotonView photonView = gameObject.GetComponent<Photon.Pun.PhotonView>();
if (photonView == null)
photonView = gameObject.AddComponent<Photon.Pun.PhotonView>();
if (photonView.ViewID == 0)
if (photonView.ViewID == 0) {
NetworkObject networkObject = gameObject.GetComponent<NetworkObject>();
if (networkObject != null && networkObject.objectIdentity != 0)
photonView.ViewID = (int)networkObject.objectIdentity;
else
Photon.Pun.PhotonNetwork.AllocateViewID(photonView);
}
Photon.Pun.PhotonTransformView transformView = gameObject.GetComponent<Photon.Pun.PhotonTransformView>();
if (transformView == null) {

View File

@ -9,6 +9,8 @@ namespace Passer {
#endif
public static bool connected = true;
public ulong objectIdentity = 0;
private void Awake() {
connected = true;
}

View File

@ -286,6 +286,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 114210291444410636, guid: 521454b5ceb9644458f59eea86f90eb7,
type: 3}
propertyPath: objectIdentity
value: 1501
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 521454b5ceb9644458f59eea86f90eb7, type: 3}
--- !u!1 &752738249
@ -437,6 +442,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 114210291444410636, guid: 521454b5ceb9644458f59eea86f90eb7,
type: 3}
propertyPath: objectIdentity
value: 1500
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 521454b5ceb9644458f59eea86f90eb7, type: 3}
--- !u!1001 &1416409166
@ -494,6 +504,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 114210291444410636, guid: 521454b5ceb9644458f59eea86f90eb7,
type: 3}
propertyPath: objectIdentity
value: 1502
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 521454b5ceb9644458f59eea86f90eb7, type: 3}
--- !u!1 &1438776013
@ -700,6 +715,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 114210291444410636, guid: 521454b5ceb9644458f59eea86f90eb7,
type: 3}
propertyPath: objectIdentity
value: 1503
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 521454b5ceb9644458f59eea86f90eb7, type: 3}
--- !u!1001 &1542308458
@ -757,6 +777,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 114210291444410636, guid: 521454b5ceb9644458f59eea86f90eb7,
type: 3}
propertyPath: objectIdentity
value: 1504
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 521454b5ceb9644458f59eea86f90eb7, type: 3}
--- !u!1 &2030871860