139 lines
3.3 KiB
C#
139 lines
3.3 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class ModelViewerObject : MonoBehaviour
|
|
{
|
|
public Vector3 offsetPosition = Vector3.zero;
|
|
|
|
public Vector3 offsetRotation = Vector3.zero;
|
|
|
|
public float zoom;
|
|
|
|
public List<GameObject> objectsToHide = new List<GameObject>();
|
|
|
|
[HideInInspector]
|
|
public ModelViewerManager modelViewerManager;
|
|
|
|
private Fish fish;
|
|
|
|
private FishingReel reel;
|
|
|
|
private FishingRod rod;
|
|
|
|
private Bait bait;
|
|
|
|
private FishingLine fishingLine;
|
|
|
|
private FishAnimSwim fishAnimSwim;
|
|
|
|
private void Awake()
|
|
{
|
|
base.enabled = false;
|
|
fish = GetComponent<Fish>();
|
|
reel = GetComponent<FishingReel>();
|
|
rod = GetComponent<FishingRod>();
|
|
bait = GetComponent<Bait>();
|
|
fishingLine = GetComponent<FishingLine>();
|
|
fishAnimSwim = GetComponent<FishAnimSwim>();
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
base.transform.localPosition = offsetPosition;
|
|
base.transform.localEulerAngles = offsetRotation;
|
|
MonoBehaviour[] componentsInChildren = base.gameObject.GetComponentsInChildren<MonoBehaviour>();
|
|
MonoBehaviour[] array = componentsInChildren;
|
|
foreach (MonoBehaviour monoBehaviour in array)
|
|
{
|
|
if (monoBehaviour.GetComponent<FishPartAnim>() == null)
|
|
{
|
|
monoBehaviour.enabled = false;
|
|
}
|
|
}
|
|
foreach (GameObject item in objectsToHide)
|
|
{
|
|
if ((bool)item)
|
|
{
|
|
item.SetActive(false);
|
|
}
|
|
}
|
|
if ((bool)fish)
|
|
{
|
|
fish.stateIndicator.gameObject.SetActive(false);
|
|
fish.modelNormal.SetActive(false);
|
|
if ((bool)fish.waterInteractive)
|
|
{
|
|
fish.waterInteractive.gameObject.SetActive(false);
|
|
}
|
|
fish.GetComponent<FishAnimationController>().fishAnimSwim.enabled = true;
|
|
fish.GetComponent<FishAnimationController>().StartWatchFish(false);
|
|
}
|
|
else if ((bool)fishAnimSwim)
|
|
{
|
|
fishAnimSwim.enabled = true;
|
|
}
|
|
else if ((bool)reel)
|
|
{
|
|
reel.line.gameObject.SetActive(false);
|
|
reel.shortLine.gameObject.SetActive(false);
|
|
}
|
|
else if ((bool)rod)
|
|
{
|
|
if ((bool)rod.lineStatic)
|
|
{
|
|
rod.lineStatic.gameObject.SetActive(false);
|
|
}
|
|
if ((bool)rod.lineStaticTop)
|
|
{
|
|
rod.lineStaticTop.gameObject.SetActive(false);
|
|
}
|
|
if ((bool)rod.rodEndPosition)
|
|
{
|
|
rod.rodEndPosition.gameObject.SetActive(false);
|
|
}
|
|
if ((bool)rod.rodPhysics)
|
|
{
|
|
rod.rodPhysics.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
else if ((bool)bait)
|
|
{
|
|
base.transform.localScale = Vector3.one * Mathf.Lerp(0.4f, 1.1f, Utilities.GetAverage(modelViewerManager.equipmentObject.sizes) / 16f);
|
|
bait.Initialize();
|
|
bait.baitAnimation.ResetMovingParts(true);
|
|
bait.FixHooksPosition();
|
|
}
|
|
else if ((bool)fishingLine)
|
|
{
|
|
fishingLine.model.SetActive(true);
|
|
fishingLine.UpdateModelViewer();
|
|
}
|
|
base.enabled = true;
|
|
}
|
|
|
|
public void LateInitialize()
|
|
{
|
|
if (!bait)
|
|
{
|
|
}
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
base.transform.localPosition = offsetPosition;
|
|
base.transform.localEulerAngles = offsetRotation;
|
|
base.transform.parent.localPosition = Vector3.zero;
|
|
Vector3 normalized = (modelViewerManager.modelCamera.transform.position - base.transform.parent.position).normalized;
|
|
base.transform.parent.localPosition = Vector3.zero + normalized * zoom;
|
|
if ((bool)bait)
|
|
{
|
|
bait.baitAnimation.ResetMovingParts(true);
|
|
bait.FixHooksPosition();
|
|
if (bait.sizeScaleFactor < 0f)
|
|
{
|
|
base.transform.localPosition = offsetPosition * (0f - bait.sizeScaleFactor);
|
|
}
|
|
}
|
|
}
|
|
}
|