480 lines
17 KiB
C#
480 lines
17 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using KWS;
|
|
using Obi;
|
|
using Photon.Pun;
|
|
using RootMotion.FinalIK;
|
|
using Smooth;
|
|
using UFS2.Gameplay;
|
|
using UnityEngine;
|
|
|
|
public class MultiplayerRodEntity : MonoBehaviourPun, IPunObservable, IPunInstantiateMagicCallback
|
|
{
|
|
public struct InstantiationData
|
|
{
|
|
public int rodID;
|
|
|
|
public int reelID;
|
|
|
|
public int floatID;
|
|
|
|
public int feederID;
|
|
|
|
public int hookID;
|
|
|
|
public int baitID;
|
|
|
|
public int lineID;
|
|
|
|
public int weightID;
|
|
|
|
public InstantiationData(int rodID, int reelID, int floatID, int feederID, int hookID, int baitID, int lineID, int weightID)
|
|
{
|
|
this.rodID = rodID;
|
|
this.reelID = reelID;
|
|
this.floatID = floatID;
|
|
this.feederID = feederID;
|
|
this.hookID = hookID;
|
|
this.baitID = baitID;
|
|
this.lineID = lineID;
|
|
this.weightID = weightID;
|
|
}
|
|
|
|
public object[] ToObjectArray()
|
|
{
|
|
return new object[8] { rodID, reelID, floatID, feederID, hookID, baitID, lineID, weightID };
|
|
}
|
|
|
|
public void FromObjectArray(object[] arr)
|
|
{
|
|
if (arr == null || arr.Length != 8)
|
|
{
|
|
throw new ArgumentException("Array must be exactly 8 elements long");
|
|
}
|
|
rodID = Convert.ToInt32(arr[0]);
|
|
reelID = Convert.ToInt32(arr[1]);
|
|
floatID = Convert.ToInt32(arr[2]);
|
|
feederID = Convert.ToInt32(arr[3]);
|
|
hookID = Convert.ToInt32(arr[4]);
|
|
baitID = Convert.ToInt32(arr[5]);
|
|
lineID = Convert.ToInt32(arr[6]);
|
|
weightID = Convert.ToInt32(arr[7]);
|
|
}
|
|
}
|
|
|
|
[SerializeField]
|
|
private Transform lineConnector_1;
|
|
|
|
[SerializeField]
|
|
private Transform lineConnector_2;
|
|
|
|
[SerializeField]
|
|
private SmoothSyncPUN2 smoothSync;
|
|
|
|
private FRod fRod;
|
|
|
|
private Transform visualRoot;
|
|
|
|
private LineRenderer rodLineRenderer;
|
|
|
|
private List<Transform> rodLineRendererPoints;
|
|
|
|
private Animator reelAnimator;
|
|
|
|
private CCDIK rodCCDIK;
|
|
|
|
private Transform remoteRodJoiner;
|
|
|
|
private Transform remoteBaitTransform;
|
|
|
|
private int enableTimer = 2;
|
|
|
|
private float reeling;
|
|
|
|
private float rodBendIKWeight;
|
|
|
|
private bool isInHand;
|
|
|
|
private bool isVisible;
|
|
|
|
public Transform ReelHandleRemote { get; private set; }
|
|
|
|
public FRod FRod => fRod;
|
|
|
|
public void Init(FRod fRod)
|
|
{
|
|
this.fRod = fRod;
|
|
rodCCDIK = fRod.GetComponent<CCDIK>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
SetNameAndParent();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (base.photonView.IsMine)
|
|
{
|
|
UpdateLocal();
|
|
}
|
|
else
|
|
{
|
|
UpdateRemote();
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (!base.photonView.IsMine && (bool)remoteBaitTransform)
|
|
{
|
|
FishEntityManager.RemoveTransformCull(remoteBaitTransform);
|
|
}
|
|
}
|
|
|
|
private void SetNameAndParent()
|
|
{
|
|
base.name = "MultiplayerEquipment_Actor_" + base.photonView.ControllerActorNr;
|
|
}
|
|
|
|
private void UpdateLocal()
|
|
{
|
|
if (!(fRod == null))
|
|
{
|
|
base.transform.SetPositionAndRotation(fRod.transform.position, fRod.transform.rotation);
|
|
if (fRod.currentFloat != null)
|
|
{
|
|
lineConnector_1.SetPositionAndRotation(fRod.currentFloat.transform.position, fRod.currentFloat.transform.rotation);
|
|
}
|
|
if (fRod.currentLure != null)
|
|
{
|
|
lineConnector_1.SetPositionAndRotation(fRod.currentLure.transform.position, fRod.currentLure.transform.rotation);
|
|
}
|
|
lineConnector_2.SetPositionAndRotation(lineConnector_1.position, lineConnector_1.rotation);
|
|
if (fRod.currentFeeder != null)
|
|
{
|
|
lineConnector_2.SetPositionAndRotation(fRod.currentFeeder.transform.position, fRod.currentFeeder.transform.rotation);
|
|
}
|
|
if (fRod.currentHook != null)
|
|
{
|
|
lineConnector_2.SetPositionAndRotation(fRod.currentHook.transform.position, fRod.currentHook.transform.rotation);
|
|
}
|
|
reeling = fRod.currentReel.animator.GetFloat("Reeling");
|
|
rodBendIKWeight = rodCCDIK.solver.IKPositionWeight;
|
|
isInHand = fRod.currentPlayer != null;
|
|
isVisible = true;
|
|
if (fRod.currentPlayer != null && fRod.currentPlayer.FullBodyAvatar != null && (fRod.currentPlayer.FullBodyAvatar.CurrentTPPAnimation == FullBodyAvatar.TPPAnimation.MiddleFishView || fRod.currentPlayer.FullBodyAvatar.CurrentTPPAnimation == FullBodyAvatar.TPPAnimation.BigFishView))
|
|
{
|
|
isVisible = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void UpdateRemote()
|
|
{
|
|
if (visualRoot == null)
|
|
{
|
|
return;
|
|
}
|
|
if (enableTimer > 0)
|
|
{
|
|
enableTimer--;
|
|
return;
|
|
}
|
|
if (!visualRoot.gameObject.activeSelf)
|
|
{
|
|
visualRoot.gameObject.SetActive(value: true);
|
|
lineConnector_1.gameObject.SetActive(value: true);
|
|
lineConnector_2.gameObject.SetActive(value: true);
|
|
}
|
|
rodLineRenderer.positionCount = rodLineRendererPoints.Count;
|
|
rodLineRenderer.SetPositions(rodLineRendererPoints.Select((Transform element) => element.position).ToArray());
|
|
reelAnimator.SetFloat("Reeling", reeling);
|
|
rodCCDIK.solver.target = lineConnector_1;
|
|
rodCCDIK.solver.SetIKPositionWeight(rodBendIKWeight);
|
|
if (!remoteRodJoiner)
|
|
{
|
|
FullBodyAvatar fullBodyAvatar = FullBodyAvatar.ExistingRemotePlayerAvatars.FirstOrDefault((FullBodyAvatar avatar) => avatar.GetComponentInParent<PhotonView>()?.Owner?.ActorNumber == base.photonView.Owner.ActorNumber);
|
|
if (fullBodyAvatar != null && fullBodyAvatar.CurrentAvatarSetup.rHandRodJoiner != null)
|
|
{
|
|
remoteRodJoiner = fullBodyAvatar.CurrentAvatarSetup.rHandRodJoiner;
|
|
}
|
|
}
|
|
if (isInHand && (bool)remoteRodJoiner)
|
|
{
|
|
smoothSync.enabled = false;
|
|
base.transform.position = remoteRodJoiner.position;
|
|
base.transform.rotation = remoteRodJoiner.rotation;
|
|
}
|
|
else
|
|
{
|
|
smoothSync.enabled = true;
|
|
}
|
|
visualRoot.gameObject.SetActive(isVisible);
|
|
}
|
|
|
|
private void StripForMultiplayer(GameObject gameObject, bool stripRigidbody = false, bool stripCollider = false, bool stripJoint = false)
|
|
{
|
|
if (gameObject == null)
|
|
{
|
|
return;
|
|
}
|
|
FRod[] componentsInChildren = gameObject.GetComponentsInChildren<FRod>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren[i]);
|
|
}
|
|
FFishingLine[] componentsInChildren2 = gameObject.GetComponentsInChildren<FFishingLine>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren2.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren2[i]);
|
|
}
|
|
FReel[] componentsInChildren3 = gameObject.GetComponentsInChildren<FReel>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren3.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren3[i]);
|
|
}
|
|
FReelEvents[] componentsInChildren4 = gameObject.GetComponentsInChildren<FReelEvents>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren4.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren4[i]);
|
|
}
|
|
FFloat[] componentsInChildren5 = gameObject.GetComponentsInChildren<FFloat>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren5.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren5[i]);
|
|
}
|
|
FHook[] componentsInChildren6 = gameObject.GetComponentsInChildren<FHook>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren6.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren6[i]);
|
|
}
|
|
FBait[] componentsInChildren7 = gameObject.GetComponentsInChildren<FBait>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren7.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren7[i]);
|
|
}
|
|
FLure[] componentsInChildren8 = gameObject.GetComponentsInChildren<FLure>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren8.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren8[i]);
|
|
}
|
|
FLine[] componentsInChildren9 = gameObject.GetComponentsInChildren<FLine>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren9.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren9[i]);
|
|
}
|
|
FWeight[] componentsInChildren10 = gameObject.GetComponentsInChildren<FWeight>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren10.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren10[i]);
|
|
}
|
|
FWaterDisplacement[] componentsInChildren11 = gameObject.GetComponentsInChildren<FWaterDisplacement>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren11.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren11[i]);
|
|
}
|
|
KWS_InteractWithWater[] componentsInChildren12 = gameObject.GetComponentsInChildren<KWS_InteractWithWater>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren12.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren12[i]);
|
|
}
|
|
ObiRigidbody[] componentsInChildren13 = gameObject.GetComponentsInChildren<ObiRigidbody>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren13.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren13[i]);
|
|
}
|
|
if (stripCollider)
|
|
{
|
|
Collider[] componentsInChildren14 = gameObject.GetComponentsInChildren<Collider>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren14.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren14[i]);
|
|
}
|
|
}
|
|
if (stripJoint)
|
|
{
|
|
ConfigurableJoint[] componentsInChildren15 = gameObject.GetComponentsInChildren<ConfigurableJoint>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren15.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren15[i]);
|
|
}
|
|
FixedJoint[] componentsInChildren16 = gameObject.GetComponentsInChildren<FixedJoint>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren16.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren16[i]);
|
|
}
|
|
}
|
|
if (stripRigidbody)
|
|
{
|
|
Rigidbody[] componentsInChildren17 = gameObject.GetComponentsInChildren<Rigidbody>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren17.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren17[i]);
|
|
}
|
|
}
|
|
AudioSource[] componentsInChildren18 = gameObject.GetComponentsInChildren<AudioSource>(includeInactive: true);
|
|
for (int i = 0; i < componentsInChildren18.Length; i++)
|
|
{
|
|
UnityEngine.Object.Destroy(componentsInChildren18[i]);
|
|
}
|
|
}
|
|
|
|
public void SetDefaultLayer(GameObject gameObject)
|
|
{
|
|
if (!(gameObject == null))
|
|
{
|
|
SetLayerRecursively(gameObject, 0);
|
|
}
|
|
static void SetLayerRecursively(GameObject obj, int layer)
|
|
{
|
|
obj.layer = layer;
|
|
foreach (Transform item in obj.transform)
|
|
{
|
|
SetLayerRecursively(item.gameObject, layer);
|
|
}
|
|
}
|
|
}
|
|
|
|
private GameObject Spawn(GameObject prefab)
|
|
{
|
|
GameObject obj = UnityEngine.Object.Instantiate(prefab, base.transform.position, base.transform.rotation, visualRoot.transform);
|
|
obj.transform.localPosition = Vector3.zero;
|
|
obj.transform.localRotation = Quaternion.identity;
|
|
return obj;
|
|
}
|
|
|
|
public void OnPhotonInstantiate(PhotonMessageInfo info)
|
|
{
|
|
if (base.photonView.IsMine)
|
|
{
|
|
return;
|
|
}
|
|
InstantiationData instantiationData = default(InstantiationData);
|
|
instantiationData.FromObjectArray(info.photonView.InstantiationData);
|
|
visualRoot = new GameObject("VisualRoot").transform;
|
|
visualRoot.SetParent(base.transform);
|
|
visualRoot.localPosition = Vector3.zero;
|
|
visualRoot.localRotation = Quaternion.identity;
|
|
visualRoot.gameObject.SetActive(value: false);
|
|
lineConnector_1.gameObject.SetActive(value: false);
|
|
lineConnector_2.gameObject.SetActive(value: false);
|
|
GameObject modelPrefab = GameManager.Instance.gameRods[GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Rod, instantiationData.rodID)].GetModelPrefab();
|
|
GameObject gameObject = Spawn(modelPrefab);
|
|
rodLineRenderer = gameObject.GetComponent<LineRenderer>();
|
|
gameObject.GetComponent<FRod>().SetupIK();
|
|
rodCCDIK = gameObject.GetComponent<CCDIK>();
|
|
rodCCDIK.solver.OnPostUpdate = null;
|
|
GameObject gameObject2 = null;
|
|
if (instantiationData.reelID != -1)
|
|
{
|
|
modelPrefab = GameManager.Instance.gameReels[GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Reel, instantiationData.reelID)].GetModelPrefab();
|
|
gameObject2 = Spawn(modelPrefab);
|
|
gameObject2.transform.SetParent(gameObject.GetComponent<FRod>().reelContainer);
|
|
gameObject2.transform.localPosition = Vector3.zero;
|
|
gameObject2.transform.localEulerAngles = Vector3.zero;
|
|
reelAnimator = gameObject2.GetComponent<FReel>().animator;
|
|
ReelHandleRemote = gameObject2.GetComponent<FReel>().handle;
|
|
}
|
|
GameObject gameObject3 = null;
|
|
if (instantiationData.floatID != -1)
|
|
{
|
|
modelPrefab = GameManager.Instance.gameFloats[GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Float, instantiationData.floatID)].GetModelPrefab();
|
|
gameObject3 = Spawn(modelPrefab);
|
|
gameObject3.transform.SetParent(lineConnector_1);
|
|
gameObject3.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
|
|
lineConnector_1.Find("Anchor").localPosition = gameObject3.GetComponent<Joint>().anchor;
|
|
}
|
|
GameObject gameObject4 = null;
|
|
if (instantiationData.feederID != -1)
|
|
{
|
|
modelPrefab = GameManager.Instance.gameFeeders[GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Feeder, instantiationData.feederID)].GetModelPrefab();
|
|
gameObject4 = Spawn(modelPrefab);
|
|
gameObject4.transform.SetParent(lineConnector_2);
|
|
gameObject4.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
|
|
lineConnector_2.Find("Anchor").localPosition = gameObject4.GetComponent<Joint>().anchor;
|
|
}
|
|
GameObject gameObject5 = null;
|
|
if (instantiationData.hookID != -1)
|
|
{
|
|
modelPrefab = GameManager.Instance.gameHooks[GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Hook, instantiationData.hookID)].GetModelPrefab();
|
|
gameObject5 = Spawn(modelPrefab);
|
|
gameObject5.transform.SetParent(lineConnector_2);
|
|
gameObject5.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
|
|
lineConnector_2.Find("Anchor").localPosition = gameObject5.GetComponent<Joint>().anchor;
|
|
}
|
|
GameObject gameObject6 = null;
|
|
if (instantiationData.baitID != -1)
|
|
{
|
|
modelPrefab = GameManager.Instance.gameBaits[GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Bait, instantiationData.baitID)].GetModelPrefab();
|
|
gameObject6 = Spawn(modelPrefab);
|
|
FBait component2;
|
|
if (gameObject6.TryGetComponent<FLure>(out var _))
|
|
{
|
|
gameObject6.transform.SetParent(lineConnector_1);
|
|
gameObject6.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
|
|
lineConnector_1.Find("Anchor").localPosition = gameObject6.GetComponent<Joint>().anchor;
|
|
}
|
|
else if (gameObject6.TryGetComponent<FBait>(out component2))
|
|
{
|
|
gameObject6.transform.SetParent(gameObject5.GetComponent<FHook>().baitContainer);
|
|
gameObject6.transform.localPosition = Vector3.zero;
|
|
}
|
|
}
|
|
GameObject gameObject7 = null;
|
|
if (instantiationData.lineID != -1)
|
|
{
|
|
modelPrefab = GameManager.Instance.gameLines[GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Line, instantiationData.lineID)].GetModelPrefab();
|
|
gameObject7 = Spawn(modelPrefab);
|
|
rodLineRenderer.material = gameObject7.GetComponent<FLine>().lineMat;
|
|
gameObject2.GetComponent<FReel>().SpoolObject.GetComponent<MeshRenderer>().material = gameObject7.GetComponent<FLine>().szpulaMat;
|
|
}
|
|
FReel component3 = gameObject2.GetComponent<FReel>();
|
|
rodLineRendererPoints = new List<Transform>();
|
|
rodLineRendererPoints.Add(component3.szpulaCenterPoint);
|
|
rodLineRendererPoints.Add(component3.linePointRoter);
|
|
Transform[] rodLinePoints = gameObject.GetComponent<FFishingLine>().rodLinePoints;
|
|
for (int num = rodLinePoints.Length - 1; num >= 0; num--)
|
|
{
|
|
rodLineRendererPoints.Add(rodLinePoints[num]);
|
|
}
|
|
rodLineRendererPoints.Add(lineConnector_1.Find("Anchor"));
|
|
rodLineRendererPoints.Add(lineConnector_2.Find("Anchor"));
|
|
remoteBaitTransform = rodLineRendererPoints.Last();
|
|
FishEntityManager.AddTransformCull(remoteBaitTransform);
|
|
StripForMultiplayer(gameObject, stripRigidbody: true, stripCollider: true, stripJoint: true);
|
|
StripForMultiplayer(gameObject2, stripRigidbody: true, stripCollider: true, stripJoint: true);
|
|
StripForMultiplayer(gameObject3, stripRigidbody: true, stripCollider: true, stripJoint: true);
|
|
StripForMultiplayer(gameObject4, stripRigidbody: true, stripCollider: true, stripJoint: true);
|
|
StripForMultiplayer(gameObject5, stripRigidbody: true, stripCollider: true, stripJoint: true);
|
|
StripForMultiplayer(gameObject6, stripRigidbody: true, stripCollider: true, stripJoint: true);
|
|
StripForMultiplayer(gameObject7, stripRigidbody: true, stripCollider: true, stripJoint: true);
|
|
SetDefaultLayer(gameObject);
|
|
SetDefaultLayer(gameObject2);
|
|
SetDefaultLayer(gameObject3);
|
|
SetDefaultLayer(gameObject4);
|
|
SetDefaultLayer(gameObject5);
|
|
SetDefaultLayer(gameObject6);
|
|
SetDefaultLayer(gameObject7);
|
|
}
|
|
|
|
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
|
|
{
|
|
if (stream.IsWriting)
|
|
{
|
|
stream.SendNext(reeling);
|
|
stream.SendNext(rodBendIKWeight);
|
|
stream.SendNext(isInHand);
|
|
stream.SendNext(isVisible);
|
|
}
|
|
else
|
|
{
|
|
reeling = (float)stream.ReceiveNext();
|
|
rodBendIKWeight = (float)stream.ReceiveNext();
|
|
isInHand = (bool)stream.ReceiveNext();
|
|
isVisible = (bool)stream.ReceiveNext();
|
|
}
|
|
}
|
|
}
|