FiE-Game/Assets/Photon Unity Networking/UtilityScripts/ManualPhotonViewAllocator.cs

32 lines
917 B
C#
Raw Normal View History

2023-07-19 19:11:02 +02:00
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(PhotonView))]
public class ManualPhotonViewAllocator : MonoBehaviour
{
public GameObject Prefab;
public void AllocateManualPhotonView()
{
PhotonView pv = this.gameObject.GetPhotonView();
if (pv == null)
{
Debug.LogError("Can't do manual instantiation without PhotonView component.");
return;
}
int viewID = PhotonNetwork.AllocateViewID();
pv.RPC("InstantiateRpc", PhotonTargets.AllBuffered, viewID);
}
[PunRPC]
public void InstantiateRpc(int viewID)
{
GameObject go = GameObject.Instantiate(Prefab, InputToEvent.inputHitPos + new Vector3(0, 5f, 0), Quaternion.identity) as GameObject;
go.GetPhotonView().viewID = viewID;
OnClickDestroy ocd = go.GetComponent<OnClickDestroy>();
ocd.DestroyByRpc = true;
}
}