using System.Collections.Generic; using Photon.Pun; using UnityEngine; public class MultiplayerRodSpawner : MonoBehaviour { [SerializeField] private MultiplayerRodEntity rod_prefab; private MultiplayerRodEntity spawnedRodInHands; private List spawnedRodInSupport; private void SceneLoader_OnBeginSceneLoad(string sceneLoadName) { spawnedRodInSupport = new List(); } private void InventoryManager_OnRodInHandChange(FRod fRod) { if (MultiplayerManager.InRoomLocationStatic) { if ((bool)spawnedRodInHands) { PhotonNetwork.Destroy(spawnedRodInHands.gameObject); spawnedRodInHands = null; } if (fRod != null) { GameManager.PlayerData.CSlots cSlots = Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[fRod.indexOfslot]; MultiplayerRodEntity.InstantiationData instantiationData = new MultiplayerRodEntity.InstantiationData(cSlots.rod.ID, cSlots.reel.isNull ? (-1) : cSlots.reel.ID, cSlots.ffloat.isNull ? (-1) : cSlots.ffloat.ID, cSlots.feeder.isNull ? (-1) : cSlots.feeder.ID, cSlots.hook.isNull ? (-1) : cSlots.hook.ID, cSlots.bait.isNull ? (-1) : cSlots.bait.ID, cSlots.line.isNull ? (-1) : cSlots.line.ID, cSlots.weight.isNull ? (-1) : cSlots.weight.ID); spawnedRodInHands = PhotonNetwork.Instantiate(rod_prefab.name, fRod.transform.position, fRod.transform.rotation, 0, instantiationData.ToObjectArray()).GetComponent(); spawnedRodInHands.Init(fRod); } } } private void RodSupport_OnRodPutDown(FRod fRod) { if (MultiplayerManager.InRoomLocationStatic) { GameManager.PlayerData.CSlots cSlots = Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[fRod.indexOfslot]; MultiplayerRodEntity.InstantiationData instantiationData = new MultiplayerRodEntity.InstantiationData(cSlots.rod.ID, cSlots.reel.isNull ? (-1) : cSlots.reel.ID, cSlots.ffloat.isNull ? (-1) : cSlots.ffloat.ID, cSlots.feeder.isNull ? (-1) : cSlots.feeder.ID, cSlots.hook.isNull ? (-1) : cSlots.hook.ID, cSlots.bait.isNull ? (-1) : cSlots.bait.ID, cSlots.line.isNull ? (-1) : cSlots.line.ID, cSlots.weight.isNull ? (-1) : cSlots.weight.ID); MultiplayerRodEntity component = PhotonNetwork.Instantiate(rod_prefab.name, fRod.transform.position, fRod.transform.rotation, 0, instantiationData.ToObjectArray()).GetComponent(); component.Init(fRod); spawnedRodInSupport.Add(component); } } private void RodSupport_OnRodTake(FRod fRod) { if (MultiplayerManager.InRoomLocationStatic) { MultiplayerRodEntity multiplayerRodEntity = spawnedRodInSupport.Find((MultiplayerRodEntity element) => element.FRod == fRod); if (multiplayerRodEntity != null) { spawnedRodInSupport.Remove(multiplayerRodEntity); PhotonNetwork.Destroy(multiplayerRodEntity.gameObject); } } } private void OnEnable() { SceneLoader.OnBeginSceneLoad += SceneLoader_OnBeginSceneLoad; InventoryManager.OnRodInHandChange += InventoryManager_OnRodInHandChange; RodSupport.OnRodPutDown += RodSupport_OnRodPutDown; RodSupport.OnRodTake += RodSupport_OnRodTake; BoatRodSupport.OnRodPutDown += RodSupport_OnRodPutDown; BoatRodSupport.OnRodTake += RodSupport_OnRodTake; } private void OnDisable() { SceneLoader.OnBeginSceneLoad -= SceneLoader_OnBeginSceneLoad; InventoryManager.OnRodInHandChange -= InventoryManager_OnRodInHandChange; RodSupport.OnRodPutDown -= RodSupport_OnRodPutDown; RodSupport.OnRodTake -= RodSupport_OnRodTake; BoatRodSupport.OnRodPutDown -= RodSupport_OnRodPutDown; BoatRodSupport.OnRodTake -= RodSupport_OnRodTake; } }