/// <summary> /// 移动到父亲目标指定范围内的随机位置 /// </summary> /// <returns></returns> public BehaviourReturnCode ActionWalkToParentActorRangeRandomPosition(float nearRadius, float farRadius) { if (RunningProperty.AI.Machine.CurrentStateType == BehaviourMachine.State.WALK) { return(BehaviourReturnCode.Failure); } if (RunningProperty.SelfActor.ParentActor == null) { return(BehaviourReturnCode.Failure); } Vector3 pos = AIHelper.GetActorRangeRandomPosition(RunningProperty.SelfActor.ParentActor, nearRadius, farRadius); if (AIHelper.RoughlyEqual(pos, RunningProperty.SelfActorPos)) { RunningProperty.AI.Machine.SwitchToState(BehaviourMachine.State.EMPTY); return(BehaviourReturnCode.Success); } RunningProperty.TargetActor = null; RunningProperty.AI.PathWalker.WalkTo(pos); RunningProperty.AI.Machine.SwitchToState(BehaviourMachine.State.WALK); return(BehaviourReturnCode.Failure); }
public UnitID CreateNPC(Neptune.NPC npcInfo, Actor parent = null) { if (npcInfo == null) { GameDebug.LogError("Error in create npc, npc info is null!!!"); return(null); } Vector3 bornPos = npcInfo.Position; NpcDefine npcDefine = NpcHelper.MakeNpcDefine((uint)npcInfo.ExcelId); if (npcDefine == null) { GameDebug.LogError("Error in create npc, npc define is null!!!"); return(null); } // 护送任务NPC可以创建多个 if (GetNpcByNpcId((uint)npcInfo.Id) != null && npcDefine.Function != NpcDefine.EFunction.ESCORT) { return(null); } uint uuid = GetAvailableUUId(npcInfo, npcDefine); DBActor dbActor = DBManager.GetInstance().GetDB <DBActor>(); DBActor.ActorData actorData = dbActor.GetData((uint)npcDefine.ActorId); bornPos = RoleHelp.GetPositionInScene((uint)npcDefine.ActorId, npcInfo.Position.x, npcInfo.Position.z); if (npcInfo.Id >= 300) { GameDebug.LogError("npcInfo.Id is too large! " + npcInfo.Id); } xc.UnitCacheInfo initData = new xc.UnitCacheInfo(EUnitType.UNITTYPE_NPC, uuid); initData.ClientNpc = npcInfo; initData.ClientNpcDefine = NpcHelper.MakeNpcDefine((uint)(npcInfo.ExcelId)); initData.CacheType = xc.UnitCacheInfo.EType.ET_Create; initData.PosBorn = bornPos; initData.ParentActor = parent; // 如果有父角色,则出生在父角色附近的一个随机位置 if (parent != null) { Vector3 pos = AIHelper.GetActorRangeRandomPosition(parent, 1f, 2f); bool result = false; initData.PosBorn = InstanceHelper.ClampInWalkableRange(pos, pos, out result); } mCreatings.Add(initData.UnitID.obj_idx); ActorManager.Instance.PushUnitCacheData(initData); return(initData.UnitID); }