/// <summary> /// 找最近的可以自动采集的采集物 /// </summary> /// <param name="runningProperty"></param> /// <returns></returns> public static CollectionObject GetNearstAutoCollectableCollectionObject(AIRunningProperty runningProperty) { if (runningProperty == null) { return(null); } float shortest = float.MaxValue; Vector3 selfActorPos = runningProperty.SelfActorPos; CollectionObject retCollectionObject = null; Dictionary <int, CollectionObject> collectionObjects = xc.Dungeon.CollectionObjectManager.Instance.CollectionObjects; foreach (CollectionObject collectionObject in collectionObjects.Values) { if (collectionObject == null || collectionObject.BindGameObject == null || collectionObject.BindGameObject.transform == null) { continue; } CollectionObjectBehaviour collectionObjectBehaviour = collectionObject.BindGameObject.GetComponent <CollectionObjectBehaviour>(); if (collectionObjectBehaviour == null) { continue; } // 婚宴食物是否能采集 if (collectionObjectBehaviour.Class == "wedding_foods" && MarryManager.Instance.WeddingFoodsCanBeCollected == false) { continue; } // 婚宴宝箱是否能采集 if (collectionObjectBehaviour.Class == "wedding_bos" && MarryManager.Instance.WeddingBoxCanBeCollected == false) { continue; } Vector3 pos = collectionObject.BindGameObject.transform.position; if (!TargetPositionHeightIsAbnormal(pos)) { continue; } if (!InstanceHelper.CanWalkTo(pos)) { continue; } float distanceSquare = AIHelper.DistanceSquare(selfActorPos, pos); if (distanceSquare < shortest) { shortest = distanceSquare; retCollectionObject = collectionObject; } } return(retCollectionObject); }
public BehaviourReturnCode ActionWalkToTargetCollection() { if (RunningProperty.AI.Machine.CurrentStateType == BehaviourMachine.State.WALK) { return(BehaviourReturnCode.Failure); } CollectionObject collectionObject = CollectionObjectManager.Instance.GetCollectionObject(RunningProperty.TargetCollectionId); if (collectionObject == null || collectionObject.BindGameObject == null || collectionObject.BindGameObject.transform == null) { RunningProperty.TargetCollectionId = 0; return(BehaviourReturnCode.Success); } CollectionObjectBehaviour collectionObjectBehaviour = collectionObject.BindGameObject.GetComponent <CollectionObjectBehaviour>(); if (collectionObjectBehaviour == null) { RunningProperty.TargetCollectionId = 0; return(BehaviourReturnCode.Success); } Vector3 pos = collectionObject.BindGameObject.transform.position; if (AIHelper.RoughlyEqual(pos, RunningProperty.SelfActorPos) || collectionObjectBehaviour.IsTouching == true) { RunningProperty.TargetCollectionId = 0; RunningProperty.AI.PathWalker.IsWalkingToCollectionPos = false; RunningProperty.AI.Machine.SwitchToState(BehaviourMachine.State.EMPTY); // 已经在采集物范围内,马上开始采集 collectionObjectBehaviour.StartInteract(); return(BehaviourReturnCode.Success); } RunningProperty.TargetActor = null; RunningProperty.AI.PathWalker.WalkTo(pos); RunningProperty.AI.PathWalker.IsWalkingToCollectionPos = true; RunningProperty.AI.Machine.SwitchToState(BehaviourMachine.State.WALK); // 设置IsClickedTouch为true,走到采集物范围内就可以开始采集了 collectionObjectBehaviour.IsClickedTouch = true; return(BehaviourReturnCode.Failure); }