123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using DG.Tweening;
- public class DropItemFollow : MonoBehaviour
- {
- public enum AbsorbEffType
- {
- empty = 0,
- glod = 1,
- }
- public GameObject target = null;
- public AbsorbEffType effType = AbsorbEffType.empty;
- private void Update()
- {
- if(target)
- {
- this.transform.DOMove(target.transform.position, 1.0f);
- if(Vector3.Distance( this.transform.position, target.transform.position) < 1.0f)
- {
- // 增加拾取特效
- if(effType == AbsorbEffType.glod)
- {
- ResourceHelper.Instance.LoadAssetBundle("jinbi_shouji_tishi", (ab) =>
- {
- if (ab != null)
- {
- GameObject eff = (GameObject)Instantiate(ab.LoadAsset("jinbi_shouji_tishi"));
- eff.transform.parent = target.transform.Find("FBX/Effect_000/Top").transform;
- eff.transform.localPosition = Vector3.zero;
- }
- });
- }
- GameObject.Destroy(this.gameObject);
- }
- }
- }
- }
- public class DropItemAuto : MonoBehaviour
- {
- /// <summary>
- /// 方向
- /// </summary>
- private Vector3 mDir = Vector3.zero;
- public float mSpeedX = 2;
- public float mSpeedY = 10;
- public float gravity = 20.0F;
- private Vector3 moveDirection = Vector3.zero;
- private bool mFly = false;
- private bool mUpdate = false;
- public ItemVo mItemVo = null;
- /// <summary>
- /// 自身
- /// </summary>
- private Transform mTransform = null;
- /// <summary>
- /// 目标
- /// </summary>
- private Transform mTargetTransform = null;
- private Tween mtweener = null;
- private bool tweenFly = false;
- private Role role = null;
- private GameObject eff = null;
- public void Init(Transform role, ItemVo vo)
- {
- mTargetTransform = role;
- mTransform = transform;
- mFly = false;
- mUpdate = false;
- mFly = false;
- mUpdate = false;
- mItemVo = vo;
- if ((EItemSubType)mItemVo.nMo.subType == EItemSubType.BattleItem_HP || (EItemSubType)mItemVo.nMo.subType == EItemSubType.BattleItem_MP)
- {
- // do nothing
- }
- else
- {
- Invoke("LateMove", 6.0f);
- }
- InvokeRepeating("CheckPlayer", 1.0f, 0.3f);
- Invoke("LateDestroy", 30);
- }
- public void Init(ItemVo vo)
- {
- mFly = false;
- mUpdate = false;
- mItemVo = vo;
- InvokeRepeating("CheckPlayer", 0.1f, 0.3f);
- Invoke("LateDestroy", 30);
- }
- /// <summary>
- /// 延迟销毁
- /// </summary>
- private void LateDestroy()
- {
- DropManager.Instance.RemoveDropItem(this);
- }
- private void OnDisable()
- {
- if (IsInvoking("CheckPlayer"))
- {
- CancelInvoke("CheckPlayer");
- }
- }
- /// <summary>
- /// 检测玩家
- /// </summary>
- private void CheckPlayer()
- {
- if(tweenFly)
- {
- return;
- }
- // 检测身边是否有道具
- Collider[] colliders = Physics.OverlapSphere(transform.position, 1.5f, 1 << LayerMask.NameToLayer("Player"));
- if (colliders != null && colliders.Length > 0)
- {
- for (int i = 0; i < colliders.Length; i++)
- {
- role = colliders[i].GetComponent<Role>();
- if(role == null || mItemVo == null)
- {
- continue;
- }
- if ((EItemSubType)mItemVo.nMo.subType == EItemSubType.BattleItem_HP)
- {
- role.mData.UpdateHP(mItemVo.nMo.GetPillsExt().number, true);
- role.UpdateHP(mItemVo.nMo.GetPillsExt().number);
- AudioManager.Instance.PlayUISoundEffect("捡起药水");
- }
- else if ((EItemSubType)mItemVo.nMo.subType == EItemSubType.BattleItem_MP)
- {
- role.mData.UpdateMP(mItemVo.nMo.GetPillsExt().number, true);
- AudioManager.Instance.PlayUISoundEffect("捡起药水");
- }
- else
- {
- ItemProxy.Instance.AddItem(int.Parse(mItemVo.typeId), mItemVo.count);
- if ((EItemSubType)mItemVo.nMo.subType == EItemSubType.Gold)
- {
- AudioManager.Instance.PlayUISoundEffect("捡起金币");
- }
- else if ((EItemSubType)mItemVo.nMo.subType == EItemSubType.Gem)
- {
- AudioManager.Instance.PlayUISoundEffect("捡起宝石");
- }
- else if ((EItemSubType)mItemVo.nMo.subType == EItemSubType.Weapon ||
- (EItemSubType)mItemVo.nMo.subType == EItemSubType.Segment ||
- (EItemSubType)mItemVo.nMo.subType == EItemSubType.YanlingBookSegement ||
- (EItemSubType)mItemVo.nMo.subType == EItemSubType.Hunqi ||
- (EItemSubType)mItemVo.nMo.subType == EItemSubType.YanLingAdvancedStone ||
- (EItemSubType)mItemVo.nMo.subType == EItemSubType.WuqiAdvancedStone ||
- (EItemSubType)mItemVo.nMo.subType == EItemSubType.Box)
- {
- AudioManager.Instance.PlayUISoundEffect("捡起装备");
- }
- else
- {
- AudioManager.Instance.PlayUISoundEffect("捡起材料");
- }
- }
- tweenFly = true;
- // 增加拾取特效
- ResourceHelper.Instance.LoadAssetBundle("shiqu_tuowei",(ab)=>
- {
- if (ab != null )
- {
- eff = (GameObject)Instantiate(ab.LoadAsset("shiqu_tuowei"));
- eff.transform.localPosition = this.transform.position;
- //CmptAutoDestory des = eff.AddComponent<CmptAutoDestory>();
- //des.LiveTime = 2.0f;
- var s = DOTween.Sequence();
- eff.transform.DOMove(this.transform.position + Vector3.up * 4, 0.7f).OnComplete(()=>
- {
- DropItemFollow follow = eff.AddComponent<DropItemFollow>();
- follow.target = role.gameObject;
- if ((EItemSubType)mItemVo.nMo.subType == EItemSubType.Gold)
- {
- follow.effType = DropItemFollow.AbsorbEffType.glod;
- }
- });
-
- //mtweener = eff.transform.DOMove(this.transform.position + Vector3.up * 5, 1.0f);
- //mtweener.OnComplete(()=>
- //{
- // tweenFly = true;
- //});
- DropManager.Instance.RemoveDropItem(this);
- }
- });
-
- return;
- }
- }
- }
- /// <summary>
- /// 延迟开始移动
- /// </summary>
- private void LateMove()
- {
- mFly = true;
- mUpdate = true;
- // 隐藏道具名称
- HpbarManager.Instance.HideItemName(transform);
- }
- }
|