IEnumerator _Coro_Locking(Player p) { //Fish lockedTarget = mLockedTarget[p.Idx]; //if (lockedTarget == null || !lockedTarget.Attackable) // yield break; float rotateRrangeHalf = RotateRange * 0.5f; // Fish curTargetFish = mLockedTarget[p.Idx]; Transform tsTarget = curTargetFish.transform; FishEx_LockPos loclLocal = curTargetFish.GetComponent <FishEx_LockPos>(); //while (tsTarget != null && mLockedTarget[p.Idx] != null)//第一判断用于判断鱼是否游出,第二判断用于是否解锁 while (true) { if (mLockedTarget[p.Idx] == null || tsTarget == null) { yield break; } if (curTargetFish.ID != mLockedTarget[p.Idx].ID) { curTargetFish = mLockedTarget[p.Idx]; if (curTargetFish == null || !curTargetFish.Attackable) { yield break; } loclLocal = curTargetFish.GetComponent <FishEx_LockPos>(); tsTarget = curTargetFish.transform; } Transform gunTs = p.GunInst.TsGun; Vector3 upToward = (loclLocal != null ? loclLocal.LockBulletPos : tsTarget.position) - gunTs.position; upToward.z = 0F; //Quaternion preRotation = gunTs.localRotation; gunTs.rotation = Quaternion.Slerp(gunTs.rotation, Quaternion.FromToRotation(Vector3.up, upToward), 10F * Time.deltaTime); if (gunTs.localEulerAngles.z > rotateRrangeHalf && gunTs.localEulerAngles.z < (360F - rotateRrangeHalf)) { if (gunTs.localEulerAngles.z < 180F) { gunTs.RotateAroundLocal(Vector3.forward, -1.0F * (gunTs.localEulerAngles.z - rotateRrangeHalf) * Mathf.Deg2Rad); } else { gunTs.RotateAroundLocal(Vector3.forward, (360F - rotateRrangeHalf - gunTs.localEulerAngles.z) * Mathf.Deg2Rad); } } yield return(0); } }
IEnumerator _Coro_LockProcess(Fish tarFish) { Spr_TargetMoving.GetComponent <Renderer>().enabled = true; Spr_Target.GetComponent <Renderer>().enabled = false; Transform tsTarFish = tarFish.transform; //Vector3 offsetLock; //mFishPosOffsetBuff.TryGetValue(tarFish.TypeIndex, out offsetLock); FishEx_LockPos fishLockLocal = tarFish.GetComponent <FishEx_LockPos>(); float movePercent = 1F;//vecPercent = 1 - movePercent ^ 2;//mp�������� Vector3 startPos = TsTargeter.position; startPos.z = mDepth; while (true) { if (tarFish == null || !tarFish.Attackable || !mChangeTargetArea.Contains(fishLockLocal != null?fishLockLocal.LockPos:tsTarFish.position)) { Fish f = Lock(); if (f != null) { if (EvtRelock != null) { EvtRelock(f, mPlayer); } } else { UnLock(); } yield break; } Vector3 tarVec = (fishLockLocal != null ? fishLockLocal.LockPos : tsTarFish.position) - startPos; tarVec.z = 0F; float vecPercent = 1F - movePercent * movePercent; movePercent -= MoveSpd * Time.deltaTime; TsTargeter.position = startPos + tarVec * vecPercent; if (movePercent < 0F) { Spr_TargetMoving.GetComponent <Renderer>().enabled = false; Spr_Target.GetComponent <Renderer>().enabled = true; break; } yield return(0); } //Debug.Log("_Coro_LockProcess2" + tarFish.name); Vector3 tmpVec3; if (EvtTargetOnFish != null) { EvtTargetOnFish(tarFish, mPlayer); } //Quaternion rotateOri = Quaternion.AngleAxis(180F, Vector3.forward); float processPercent = 0F; Transform tsSpr_Target = Spr_Target.transform; while (true) { if (tarFish == null || !tarFish.Attackable || !mChangeTargetArea.Contains(fishLockLocal != null ? fishLockLocal.LockPos : tsTarFish.position)) { Fish f = Lock(); if (f != null) { if (EvtTargetLeaveFish != null) { EvtTargetLeaveFish(); } if (EvtRelock != null) { EvtRelock(f, mPlayer); } } else { UnLock(); } yield break; } tmpVec3 = fishLockLocal != null ? fishLockLocal.LockPos : tsTarFish.position; tmpVec3.z = mDepth; TsTargeter.position = tmpVec3; tsSpr_Target.rotation = Quaternion.AngleAxis(Mathf.Cos(Mathf.PI * 2F * processPercent) * 25F, Vector3.forward); processPercent += Time.deltaTime * 0.5F; yield return(0); } }
/// <summary> /// ������ /// </summary> /// <returns></returns> public Fish Lock() { if (!IsLockable) { return(null); } int lockIdxStart = mCurLockIdx; Dictionary <int, Fish>[] fishMap = GameMain.Singleton.FishGenerator.FishTypeIndexMap; Fish lockFish = null; do { Dictionary <int, Fish> tmpFishDict = fishMap[Prefab_FishLockabe[mCurLockIdx].TypeIndex]; if (tmpFishDict != null && tmpFishDict.Count != 0) { foreach (KeyValuePair <int, Fish> kvp in tmpFishDict) { FishEx_LockPos lockLocal = kvp.Value.GetComponent <FishEx_LockPos>(); //�жϷ�Χ..todo if (kvp.Value != null && kvp.Value.Attackable && mStartLockArea.Contains(lockLocal != null ? lockLocal.LockPos : kvp.Value.transform.position) ) { lockFish = kvp.Value; mCurLockIdx = (mCurLockIdx + 1) % Prefab_FishLockabe.Length;//���´δӲ�ͬ���㿪ʼ�� break; } } if (lockFish != null) { break; } } mCurLockIdx = (mCurLockIdx + 1) % Prefab_FishLockabe.Length; if (lockIdxStart == mCurLockIdx) { break; } } while (true); //�Ҳ������Ļ��˳� if (lockFish == null) { return(null); } //�ƶ�����ȥĿ���㴦 StopCoroutine("_Coro_UnLockProcess"); StopCoroutine("_Coro_LockProcess"); StartCoroutine("_Coro_LockProcess", lockFish); //GameMain.Singleton.FishGenerator.FishLockable. return(lockFish); }