备份CatanBuilding瘦身独立工程
This commit is contained in:
222
Assets/Scripts/GampPlay/Fishing/Fish.cs
Normal file
222
Assets/Scripts/GampPlay/Fishing/Fish.cs
Normal file
@@ -0,0 +1,222 @@
|
||||
using asap.core;
|
||||
using DG.Tweening;
|
||||
using Game;
|
||||
using GameCore;
|
||||
using System.Collections;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
public struct FishRotateEvent
|
||||
{
|
||||
public float rotate;
|
||||
public int state;// 0:停止自转, 1:开始自转, 2:旋转,3:固定角度, 4:隐藏, 5:显示
|
||||
public int rodType;
|
||||
public FishRotateEvent(float rotate, int state, int rodType)
|
||||
{
|
||||
this.rotate = rotate;
|
||||
this.state = state;
|
||||
this.rodType = rodType;
|
||||
}
|
||||
}
|
||||
public class Fish : MonoBehaviour
|
||||
{
|
||||
//鱼嘴位置
|
||||
public Transform mouthPos;
|
||||
public Transform Head;
|
||||
public Transform LeftEye;
|
||||
public Transform RightEye;
|
||||
public Transform Fin;
|
||||
public Transform Tail;
|
||||
public Transform Neck;
|
||||
public Transform Root;
|
||||
public Animator animator;
|
||||
//public FishingFlyingFish fishingFlyingFish;
|
||||
BoxCollider boxCollider;
|
||||
bool isCollider = false;
|
||||
[HideInInspector]
|
||||
public GameObject modeGo;
|
||||
//旋转速度
|
||||
public int rotateSpeed = 10;
|
||||
System.IDisposable disposable;
|
||||
float _fishAnimSpeed;
|
||||
bool Pulling01;
|
||||
public float FishAnimSpeed
|
||||
{
|
||||
set
|
||||
{
|
||||
_fishAnimSpeed = value;
|
||||
animator.speed = _fishAnimSpeed;
|
||||
}
|
||||
get { return _fishAnimSpeed; }
|
||||
}
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
boxCollider = GetComponent<BoxCollider>();
|
||||
if (boxCollider)
|
||||
{
|
||||
boxCollider.enabled = isCollider;
|
||||
}
|
||||
}
|
||||
public Transform Find(string name)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case "Fin":
|
||||
return Fin;
|
||||
case "Tail":
|
||||
return Tail;
|
||||
case "Neck":
|
||||
return Neck;
|
||||
case "Head":
|
||||
return Head;
|
||||
case "LeftEye":
|
||||
return LeftEye;
|
||||
case "RightEye":
|
||||
return RightEye;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
Pulling01 = false;
|
||||
transform.DOKill();
|
||||
disposable = GContext.OnEvent<FishRotateEvent>().Subscribe(OnFishingRotate);
|
||||
GameEventMgr.Instance.AddListener(GameEvents.EventFishingPlay, PlayerClick);
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
disposable.Dispose();
|
||||
disposable = null;
|
||||
GameEventMgr.Instance.RemoveListener(GameEvents.EventFishingPlay, PlayerClick);
|
||||
}
|
||||
public void EnableCollider()
|
||||
{
|
||||
isCollider = true;
|
||||
if (boxCollider)
|
||||
{
|
||||
boxCollider.enabled = true;
|
||||
}
|
||||
}
|
||||
public float GetColliderSize(float size)
|
||||
{
|
||||
if (boxCollider)
|
||||
{
|
||||
boxCollider.isTrigger = true;
|
||||
boxCollider.size *= size;
|
||||
return boxCollider.size.magnitude / 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
private void PlayerClick()
|
||||
{
|
||||
if (animator != null)
|
||||
{
|
||||
var clicp = animator.GetCurrentAnimatorClipInfo(0);
|
||||
if (clicp[0].clip.name == "Idle01")
|
||||
{
|
||||
StartCoroutine(PlayClickSound());
|
||||
animator.SetTrigger("Click01");
|
||||
}
|
||||
}
|
||||
}
|
||||
public void PlayBite()
|
||||
{
|
||||
animator.SetTrigger("Bite01");
|
||||
}
|
||||
public void PlayJump()
|
||||
{
|
||||
animator.SetTrigger("Jump01");
|
||||
}
|
||||
public void SetTrigger(string triggerName)
|
||||
{
|
||||
animator.SetBool("Swim01", false);
|
||||
animator.speed = 1;
|
||||
animator.SetTrigger(triggerName);
|
||||
}
|
||||
public void PlaySwim01()
|
||||
{
|
||||
animator.speed = _fishAnimSpeed;
|
||||
if (!Pulling01)
|
||||
{
|
||||
animator.SetTrigger("Swim01");
|
||||
}
|
||||
}
|
||||
public void SetSkillInt(int inValue)
|
||||
{
|
||||
animator.SetInteger("SkillIndex", inValue);
|
||||
}
|
||||
public void SetSkillType(int inValue)
|
||||
{
|
||||
animator.SetInteger("SkillType", inValue);
|
||||
}
|
||||
IEnumerator PlayClickSound()
|
||||
{
|
||||
FishingData fishingData = GContext.container.Resolve<FishingData>();
|
||||
yield return new WaitForSeconds(fishingData.curFishData.DelaySplashClick);
|
||||
var audios = fishingData.curFishData.AudioSplashClick;
|
||||
if (audios.Count > 0)
|
||||
{
|
||||
string pullingOutSound = audios[Random.Range(0, audios.Count)];
|
||||
|
||||
GContext.Publish(new EventFishingSound(pullingOutSound));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(fishingData.curFishData.FxWaterSplash))
|
||||
GContext.Publish(new PlayerRaindropEvent() { FxWaterSplash = fishingData.curFishData.FxWaterSplash });
|
||||
}
|
||||
public void Pulling()
|
||||
{
|
||||
if (animator != null)
|
||||
{
|
||||
animator.SetBool("Swim01", false);
|
||||
Pulling01 = true;
|
||||
animator.SetTrigger("Pulling01");
|
||||
}
|
||||
}
|
||||
void OnFishingRotate(FishRotateEvent fishRotateEvent)
|
||||
{
|
||||
OnFishingRotate(fishRotateEvent.rotate, fishRotateEvent.state, fishRotateEvent.rodType);
|
||||
}
|
||||
private void OnFishingRotate(float rotate, int state, int rodType)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case 0:
|
||||
//停止自转
|
||||
transform.DOKill();
|
||||
break;
|
||||
case 1:
|
||||
DOLocalRotate(rodType);
|
||||
break;
|
||||
case 2:
|
||||
transform.Rotate(Vector3.forward * rotate);
|
||||
break;
|
||||
case 3:
|
||||
transform.DOKill();
|
||||
transform.localEulerAngles = Vector3.back * rotate;
|
||||
break;
|
||||
case 4:
|
||||
animator.gameObject.SetActive(false);
|
||||
break;
|
||||
case 5:
|
||||
animator.gameObject.SetActive(true);
|
||||
animator.Play("Idle01");
|
||||
DOLocalRotate(rodType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DOLocalRotate(int rodType)
|
||||
{
|
||||
transform.DOKill();
|
||||
//开始自转
|
||||
Vector3 vector3 = Vector3.back * 360;
|
||||
if (rodType == 2)
|
||||
{
|
||||
vector3 = Vector3.forward * 360;
|
||||
}
|
||||
transform.DOLocalRotate(vector3, rotateSpeed, RotateMode.LocalAxisAdd).SetEase(Ease.Linear).SetLoops(-1);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user