/// 搜索掉落物的目标(超出distance距离以外的最近的道具目标); public Pick SearchPickTarget(ObjectBase startObj, float distance) { Pick nearestObj = null; float minDis = float.MaxValue; PoolSlot slot = mObjPool.UsedList(); while (slot != null) { Pick unit = slot.Content as Pick; if (unit == null || unit == startObj || (unit.GetCurPickTableItem().resID != ZombiesStageModule.PickId && unit.GetCurPickTableItem().resID != 26)) { slot = slot.NextSlot; continue; } float dis = Vector3.Distance(unit.GetPosition(), startObj.GetPosition()); //大于最小距离 if (dis >= distance) { if (dis < minDis) { minDis = dis; nearestObj = unit; } } slot = slot.NextSlot; } return(nearestObj); }
public override void OnPick(ObjectBase pick, ObjectBase picker) { base.OnPick (pick, picker); if (pick == null || picker == null) return; Pick obj = pick as Pick; if (obj == null) return; PickTableItem pti = obj.GetCurPickTableItem(); if (pti == null) return; if (!ObjectType.IsPlayer(picker.Type)) return; if (pti.resID == mGoldId1 || pti.resID == mGoldId2 || pti.resID == mGoldId3) { if (mCurPickCount >= mMaxPickCount) return; mCurPickCount++; MaoStageUpdateGoldEvent eUI = new MaoStageUpdateGoldEvent(); eUI.CurrentGold = mCurPickCount; eUI.TotalGold = mMaxPickCount; eUI.PickPos = obj.GetPosition(); EventSystem.Instance.PushEvent(eUI); if (mCurPickCount >= mMaxPickCount) { EventSystem.Instance.PushEvent(new MaoStageSucceedEvent()); } } else { FindPickEvent e = new FindPickEvent(); e.OwnerId = (int)picker.InstanceID; e.PickResId = pti.resID; e.Position = obj.GetPosition(); EventSystem.Instance.PushEvent(e); } }
/// <summary> /// 指引道具的方位; /// </summary> /// <returns><c>true</c>, if pick target dir was gotten, <c>false</c> otherwise.</returns> /// <param name="dir">Dir.</param> public bool GetPickTargetDir(ref Vector3 dir) { ObjectBase owner = GetOwner(); if (owner == null) { return(false); } if (mPickTarget == null) { return(false); } dir = mPickTarget.GetPosition() - owner.GetPosition(); dir.y = 0.0f; dir.Normalize(); return(true); }