156 lines
4.2 KiB
C#
156 lines
4.2 KiB
C#
using System;
|
|
using BitStrap;
|
|
using UltimateWater;
|
|
using UnityEngine;
|
|
|
|
public class Boilie : MonoBehaviour
|
|
{
|
|
public GameObject ballModel;
|
|
|
|
public GameObject dissolveModel;
|
|
|
|
public float amount = 10f;
|
|
|
|
[ReadOnly]
|
|
public float currentAmount = 10f;
|
|
|
|
public float disappearSpeed = 1f;
|
|
|
|
public float waterDrag = 20f;
|
|
|
|
public MeshRenderer onWaterMesh;
|
|
|
|
private LTDescr tweenOnWaterMesh;
|
|
|
|
public int maxFishes = 3;
|
|
|
|
public int fishCounter;
|
|
|
|
[HideInInspector]
|
|
public bool hitWater;
|
|
|
|
public Vector2 rippleForce = new Vector2(20f, 1f);
|
|
|
|
[HideInInspector]
|
|
public Rigidbody rigidbody;
|
|
|
|
public BoxCollider attractCollider;
|
|
|
|
[ReadOnly]
|
|
public bool canHitWater;
|
|
|
|
public FishLikesParams fishLikesParams;
|
|
|
|
public void Awake()
|
|
{
|
|
currentAmount = amount;
|
|
rigidbody = GetComponent<Rigidbody>();
|
|
if (attractCollider == null)
|
|
{
|
|
attractCollider = GetComponentInChildren<BoxCollider>();
|
|
}
|
|
attractCollider.transform.localScale = new Vector3(1f, 1f, 1f);
|
|
attractCollider.gameObject.SetActive(false);
|
|
if ((bool)onWaterMesh)
|
|
{
|
|
onWaterMesh.gameObject.SetActive(false);
|
|
onWaterMesh.material.color = new Color(onWaterMesh.material.color.r, onWaterMesh.material.color.g, onWaterMesh.material.color.b, 0f);
|
|
}
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (ballModel == null)
|
|
{
|
|
return;
|
|
}
|
|
if (!hitWater && base.transform.position.y <= 0f && canHitWater)
|
|
{
|
|
HitWater();
|
|
}
|
|
if (!hitWater)
|
|
{
|
|
return;
|
|
}
|
|
attractCollider.gameObject.SetActive(true);
|
|
attractCollider.transform.eulerAngles = new Vector3(-180f, 0f, 0f);
|
|
attractCollider.size = new Vector3(attractCollider.size.x, Mathf.Abs(base.transform.position.y), attractCollider.size.z);
|
|
attractCollider.center = new Vector3(0f, (0f - attractCollider.size.y) * 0.5f, 0f);
|
|
ballModel.transform.localScale = Vector3.one * (currentAmount / amount);
|
|
if ((bool)onWaterMesh)
|
|
{
|
|
onWaterMesh.transform.rotation = Quaternion.identity;
|
|
}
|
|
if (tweenOnWaterMesh == null || tweenOnWaterMesh.direction == 0f)
|
|
{
|
|
if ((bool)onWaterMesh)
|
|
{
|
|
onWaterMesh.material.color = new Color(onWaterMesh.material.color.r, onWaterMesh.material.color.g, onWaterMesh.material.color.b, currentAmount / amount);
|
|
}
|
|
Eat(disappearSpeed * Time.deltaTime);
|
|
}
|
|
}
|
|
|
|
public void Throw()
|
|
{
|
|
rigidbody.isKinematic = false;
|
|
rigidbody.useGravity = true;
|
|
LeanTween.delayedCall(0.5f, (Action)delegate
|
|
{
|
|
canHitWater = true;
|
|
});
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.currentPlatform != GlobalSettings.Platform.ARCADE && !GlobalSettings.Instance.playerSettings.IsSandbox())
|
|
{
|
|
EquipmentObject currentEquipment = GlobalSettings.Instance.equipmentManager.GetCurrentEquipment(EquipmentObject.EquipmentType.BOILIE);
|
|
if (currentEquipment.amount <= 0)
|
|
{
|
|
currentEquipment.amount = 0;
|
|
GlobalSettings.Instance.equipmentManager.UnequipObject(EquipmentObject.EquipmentType.BOILIE);
|
|
HUDManager.Instance.UpdateControls();
|
|
}
|
|
else
|
|
{
|
|
currentEquipment.amount--;
|
|
}
|
|
GlobalSettings.Instance.equipmentManager.Save();
|
|
}
|
|
}
|
|
|
|
public void Eat(float eatAmount)
|
|
{
|
|
if (!(ballModel == null))
|
|
{
|
|
currentAmount -= eatAmount;
|
|
if (currentAmount <= 0f)
|
|
{
|
|
currentAmount = 0f;
|
|
UnityEngine.Object.Destroy(base.gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void HitWater()
|
|
{
|
|
AudioController.Play("SplashBoilie_01", base.transform.position, base.transform, 1f);
|
|
rigidbody.drag = waterDrag;
|
|
rigidbody.freezeRotation = true;
|
|
GameController.Instance.waterEffectsManager.PlaySplashParticle((!GameController.Instance.iceLevel) ? WaterEffectsManager.SplashSize.MEDIUM : WaterEffectsManager.SplashSize.VERY_SMALL, new Vector3(base.transform.position.x, (!GameController.Instance.iceLevel) ? 0.2f : 0.2f, base.transform.position.z), new Vector3(-90f, 0f, 0f));
|
|
GameController.Instance.PlayWaterRipple(base.transform.position, rippleForce.x, rippleForce.y);
|
|
if ((bool)onWaterMesh)
|
|
{
|
|
onWaterMesh.gameObject.SetActive(true);
|
|
onWaterMesh.GetComponent<WaterFloat>().enabled = true;
|
|
tweenOnWaterMesh = LeanTween.alpha(onWaterMesh.gameObject, 1f, 6f).setOnComplete((Action)delegate
|
|
{
|
|
tweenOnWaterMesh.setDirection(0f);
|
|
}).setDelay(2f);
|
|
}
|
|
hitWater = true;
|
|
}
|
|
|
|
public float GetFishInterest(Fish.Species species)
|
|
{
|
|
return fishLikesParams.GetFishInterest(species);
|
|
}
|
|
}
|