273 lines
6.4 KiB
C#
273 lines
6.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BitStrap;
|
|
using UnityEngine;
|
|
|
|
public class BiteIndicator : MonoBehaviour
|
|
{
|
|
public enum IndicatorType
|
|
{
|
|
NONE = 0,
|
|
BELL = 1,
|
|
ELECTRONIC = 2
|
|
}
|
|
|
|
public IndicatorType indicatorType;
|
|
|
|
public string indicationSound = string.Empty;
|
|
|
|
public GameObject indicationLight;
|
|
|
|
public Light indicationPointLight;
|
|
|
|
[HideInInspector]
|
|
public MeshRenderer indicationLightRenderer;
|
|
|
|
public List<Transform> bells = new List<Transform>();
|
|
|
|
[ReadOnly]
|
|
public bool isIndicating;
|
|
|
|
[ReadOnly]
|
|
public FishingRod fishingRod;
|
|
|
|
[ReadOnly]
|
|
public AudioObject indicationSoundObject;
|
|
|
|
[HideInInspector]
|
|
public LTDescr indicationLightLT;
|
|
|
|
[HideInInspector]
|
|
public LTDescr bellsTrembleLT;
|
|
|
|
[HideInInspector]
|
|
public LTDescr bendLT;
|
|
|
|
[ReadOnly]
|
|
public float bendValue;
|
|
|
|
private void Awake()
|
|
{
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if ((bool)indicationLightRenderer)
|
|
{
|
|
indicationLightRenderer.material.color = new Color(0.6f, 0f, 0f);
|
|
indicationLightRenderer.material.SetColor("_EmissionColor", Color.red);
|
|
LeanTween.cancel(base.gameObject);
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
public void Initialize()
|
|
{
|
|
if (!string.IsNullOrEmpty(indicationSound))
|
|
{
|
|
indicationSoundObject = AudioController.Play(indicationSound, base.transform);
|
|
if ((bool)indicationSoundObject)
|
|
{
|
|
indicationSoundObject.stopAfterFadeOut = false;
|
|
indicationSoundObject.Pause();
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("No indicationSoundObject");
|
|
}
|
|
}
|
|
bendLT = LeanTween.value(base.gameObject, -2f, 0f, 0.5f).setLoopPingPong().setOnUpdate(delegate(float value)
|
|
{
|
|
bendValue = 0f - value;
|
|
})
|
|
.setOnComplete((Action)delegate
|
|
{
|
|
if (bendValue < 1f)
|
|
{
|
|
float value = UnityEngine.Random.value;
|
|
float num = UnityEngine.Random.Range(0.2f, 1f);
|
|
bendLT.setFrom(0f - Mathf.Lerp(5f, 35f, value));
|
|
bendLT.setTime(num);
|
|
if ((bool)indicationSoundObject)
|
|
{
|
|
indicationSoundObject.FadeIn(num * 0.25f);
|
|
}
|
|
}
|
|
else if ((bool)indicationSoundObject)
|
|
{
|
|
indicationSoundObject.FadeOut(bendLT.time * 0.8f);
|
|
}
|
|
})
|
|
.setOnCompleteOnRepeat(true);
|
|
bendLT.pause();
|
|
if (bells.Count > 0)
|
|
{
|
|
bellsTrembleLT = LeanTween.value(base.gameObject, -7f, 7f, 0.08f).setLoopPingPong().setOnUpdate(delegate(float value)
|
|
{
|
|
for (int i = 0; i < bells.Count; i++)
|
|
{
|
|
bells[i].transform.localEulerAngles = new Vector3(value, 0f, 0f);
|
|
}
|
|
});
|
|
bellsTrembleLT.pause();
|
|
}
|
|
if ((bool)indicationLight)
|
|
{
|
|
indicationLightRenderer = indicationLight.GetComponent<MeshRenderer>();
|
|
indicationLightRenderer.material.color = new Color(0.6f, 0f, 0f);
|
|
indicationLightRenderer.material.SetColor("_EmissionColor", Color.black);
|
|
indicationLightLT = LeanTween.value(base.gameObject, 0f, 1f, 0.05f).setLoopPingPong().setEaseInOutQuad()
|
|
.setOnUpdate(delegate(float value)
|
|
{
|
|
if (!(indicationSoundObject == null) && indicationSoundObject.category != null)
|
|
{
|
|
value = ((indicationSoundObject.category.VolumeTotal != 0f) ? (indicationSoundObject.volumeTotal / indicationSoundObject.subItem.Volume / indicationSoundObject.category.VolumeTotal) : 1f);
|
|
}
|
|
else
|
|
{
|
|
indicationSoundObject = AudioController.Play(indicationSound, base.transform);
|
|
value = 1f;
|
|
Debug.LogError("indicationSoundObject == null");
|
|
}
|
|
indicationLightRenderer.material.color = new Color(Mathf.Lerp(0.6f, 1f, value), 0f, 0f);
|
|
indicationLightRenderer.material.SetColor("_EmissionColor", new Color(value, 0f, 0f));
|
|
indicationLight.transform.localScale = Vector3.one * Mathf.Lerp(1.2f, 1.3f, value);
|
|
indicationPointLight.intensity = Mathf.Lerp(0f, 8f, value);
|
|
});
|
|
indicationLightLT.pause();
|
|
indicationPointLight.enabled = false;
|
|
}
|
|
Attach();
|
|
}
|
|
|
|
[Button]
|
|
public void StartIndicating()
|
|
{
|
|
if (isIndicating)
|
|
{
|
|
Debug.LogError("BiteIndicator is already indicating");
|
|
return;
|
|
}
|
|
Debug.LogError("StartIndicating");
|
|
isIndicating = true;
|
|
if (bendLT != null)
|
|
{
|
|
bendLT.resume();
|
|
}
|
|
if (indicatorType == IndicatorType.BELL)
|
|
{
|
|
if ((bool)indicationSoundObject && indicationSoundObject.IsPaused())
|
|
{
|
|
indicationSoundObject.Unpause(0.5f);
|
|
}
|
|
if (bellsTrembleLT != null)
|
|
{
|
|
bellsTrembleLT.resume();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (indicatorType != IndicatorType.ELECTRONIC)
|
|
{
|
|
return;
|
|
}
|
|
if (indicationSoundObject == null)
|
|
{
|
|
Debug.LogError("No indicationSoundObject");
|
|
indicationSoundObject = AudioController.Play(indicationSound, base.transform);
|
|
if (indicationSoundObject == null)
|
|
{
|
|
Debug.LogError("Still No indicationSoundObject");
|
|
}
|
|
}
|
|
if ((bool)indicationSoundObject && indicationSoundObject.IsPaused())
|
|
{
|
|
indicationSoundObject.Unpause(0.5f);
|
|
}
|
|
if (indicationLightLT != null)
|
|
{
|
|
indicationLightLT.resume();
|
|
}
|
|
if ((bool)indicationPointLight)
|
|
{
|
|
indicationPointLight.intensity = 0f;
|
|
indicationPointLight.enabled = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
public void StopIndicating()
|
|
{
|
|
isIndicating = false;
|
|
if (bendLT != null)
|
|
{
|
|
bendLT.pause();
|
|
}
|
|
if (indicatorType == IndicatorType.BELL)
|
|
{
|
|
if ((bool)indicationSoundObject && !indicationSoundObject.IsPaused())
|
|
{
|
|
indicationSoundObject.Pause();
|
|
}
|
|
if (bellsTrembleLT != null)
|
|
{
|
|
bellsTrembleLT.pause();
|
|
}
|
|
}
|
|
else if (indicatorType == IndicatorType.ELECTRONIC)
|
|
{
|
|
if ((bool)indicationSoundObject && !indicationSoundObject.IsPaused())
|
|
{
|
|
indicationSoundObject.Pause();
|
|
}
|
|
if (indicationLightLT != null)
|
|
{
|
|
indicationLightLT.pause();
|
|
}
|
|
indicationLightRenderer.material.color = new Color(0.6f, 0f, 0f);
|
|
indicationLightRenderer.material.SetColor("_EmissionColor", Color.black);
|
|
indicationLight.transform.localScale = Vector3.one * 1.2f;
|
|
if ((bool)indicationPointLight)
|
|
{
|
|
indicationPointLight.enabled = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void StartFishing()
|
|
{
|
|
}
|
|
|
|
public void StopFishing()
|
|
{
|
|
}
|
|
|
|
public void SetBellPosition(bool rodEnd)
|
|
{
|
|
if (indicatorType == IndicatorType.BELL)
|
|
{
|
|
base.transform.localPosition = new Vector3(0f, 0f, (!rodEnd) ? 0.25f : 0f);
|
|
}
|
|
}
|
|
|
|
public void Attach()
|
|
{
|
|
base.transform.parent = ((!fishingRod) ? null : fishingRod.rodMegaAttachPosition.transform);
|
|
if (indicatorType == IndicatorType.BELL)
|
|
{
|
|
base.transform.localRotation = Quaternion.identity;
|
|
SetBellPosition(true);
|
|
}
|
|
else if (indicatorType == IndicatorType.ELECTRONIC && base.transform.parent != null)
|
|
{
|
|
base.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void Detach()
|
|
{
|
|
base.transform.parent = null;
|
|
}
|
|
}
|