private void CreateNavSearchAgent() { if (!this.actor.isMovable) { return; } Seeker seeker = base.gameObject.GetComponent <Seeker>(); if (!seeker) { seeker = base.gameObject.AddComponent <Seeker>(); } FunnelModifier funnelModifier = base.gameObject.GetComponent <FunnelModifier>(); if (!funnelModifier) { funnelModifier = base.gameObject.AddComponent <FunnelModifier>(); } seeker.startEndModifier.Priority = 3; funnelModifier.Priority = 2; if (this.actor.TheActorMeta.ActorType == ActorTypeDef.Actor_Type_Monster || this.actor.TheActorMeta.ActorType == ActorTypeDef.Actor_Type_Hero) { RVOController rVOController = base.gameObject.GetComponent <RVOController>(); if (!rVOController) { rVOController = base.gameObject.AddComponent <RVOController>(); } rVOController.maxSpeed = this.maxSpeed; rVOController.enabled = true; rVOController.EnsureActorAndSimulator(); } }
private void CreateNavSearchAgent() { if (base.actor.isMovable) { Seeker component = base.gameObject.GetComponent <Seeker>(); if (component == null) { component = base.gameObject.AddComponent <Seeker>(); } FunnelModifier modifier = base.gameObject.GetComponent <FunnelModifier>(); if (modifier == null) { modifier = base.gameObject.AddComponent <FunnelModifier>(); } component.startEndModifier.Priority = 3; modifier.Priority = 2; if ((base.actor.TheActorMeta.ActorType == ActorTypeDef.Actor_Type_Monster) || (base.actor.TheActorMeta.ActorType == ActorTypeDef.Actor_Type_Hero)) { RVOController controller = base.gameObject.GetComponent <RVOController>(); if (controller == null) { controller = base.gameObject.AddComponent <RVOController>(); } controller.maxSpeed = this.maxSpeed; controller.enabled = true; controller.EnsureActorAndSimulator(); } } }
public void Start() { target = transform.position; seeker = GetComponent <Seeker>(); funnel = GetComponent <FunnelModifier>(); //StartCoroutine(findfindfind()); }
void CreateNavAgent() { var actorShowObj = ActorTransform.gameObject; seeker = actorShowObj.getOrAddComponent <Seeker>(); fmodifier = actorShowObj.getOrAddComponent <FunnelModifier>(); controller = actorShowObj.getOrAddComponent <RVOController>(); controller.center = new Int3(0, 1600, 0); Position = (Int3) new Vector3(0, 13, -41); controller.EnsureActorAndSimulator(); }
void InitAStar() { aStarSeeker = gameObject.AddComponent <Seeker>(); aStarSeeker.startEndModifier.exactStartPoint = StartEndModifier.Exactness.Exact; aStarSeeker.startEndModifier.exactEndPoint = StartEndModifier.Exactness.Exact; aStarSeeker.startEndModifier.mask = soldierGeneralInfo.pathFindObstacleMask; aStarFunnelModifier = gameObject.AddComponent <FunnelModifier>(); aStarSimpleSmoothModifier = gameObject.AddComponent <SimpleSmoothModifier>(); aStarSeeker.startEndModifier.priority = 3; aStarFunnelModifier.priority = 2; aStarSimpleSmoothModifier.priority = 1; }
private void Start() { for (var i = 0; i < System.Enum.GetNames(typeof(actions_enum)).Length; i++) { action_ratings.Add(0); } for (var i = 0; i < System.Enum.GetNames(typeof(contexts_enum)).Length; i++) { context_ratings.Add(0); } UpdateActiveActionsContexts(); //get character components seeker = gameObject.GetComponent <Seeker>(); controller = gameObject.AddComponent <Rigidbody>(); movementController = gameObject.AddComponent <AIPath>(); anim = gameObject.GetComponent <Animator>(); rend = gameObject.GetComponentsInChildren <SkinnedMeshRenderer>(); movementController.slowdownDistance = 1; movementController.pickNextWaypointDist = 1f; movementController.endReachedDistance = 1f; movementController.slowWhenNotFacingTarget = true; movementController.repathRate = 1; //movementController.gravity = new Vector3(0,0,0); controller.mass = 5; controller.freezeRotation = true; positionPrevious = transform.position; //add a smoothing modifier modifier = gameObject.AddComponent <FunnelModifier>(); targetLocation = transform.position; //find all mesh renderers for (var i = 0; i < rend.Length; i++) { Material[] mats = rend[i].materials; transparentMaterials.Add(mats[0]); mats[0] = rend[i].materials[1]; mats[1] = rend[i].materials[1]; rend[i].materials = mats; } }
void Start() { //Get a reference to the Seeker component we added earlier _seeker = GetComponent <Seeker>(); if (_seeker == null) { _seeker = gameObject.AddComponent <Seeker> (); } if (_fm == null) { _fm = gameObject.AddComponent <FunnelModifier> (); } _controller = GetComponent <CharacterController>(); //InvokeRepeating("AdjustPosition", 0, 1); SetAngularSpeed(100000); }
public ServerNPC Load(int num, CAMP camp, GameObject WarPoint) { if (NpcModel == null) { NpcModel = Core.Data.getIModelConfig <NPCModel>(); } NPCConfigData configData = NpcModel.get(num); #if DEBUG Utils.Assert(configData == null, "Virtual Npc load can't find npc configure. NPC id = " + num); #endif if (cached == null) { string path = SPath.Combine(ResourceSetting.PACKROOT, NPC); path = SPath.Combine(path, VIRTUAL); cached = URes.Load(path); } GameObject go = GameObject.Instantiate(cached) as GameObject; UnityUtils.AddChild_Reverse(go, WarPoint); if (configData.type == LifeNPCType.Build) { go.layer = LayerMask.NameToLayer(Consts.LAYER_BUILD); } else { go.layer = LayerMask.NameToLayer(Consts.LAYER_NPC); } ServerNPC npc = null; if (configData.healthpoint > 0) { npc = go.AddComponent <ServerLifeNpc>(); } else { npc = go.AddComponent <ServerNPC>(); } //如果是可以移动的,添加寻路脚本 if (configData.moveable == Moveable.Movable) { Seeker seek = go.AddComponent <Seeker>(); seek.drawGizmos = false; AIPath pathFinding = go.AddComponent <AIPath>(); pathFinding.speed = configData.speed; pathFinding.slowdownDistance = 0.0f; pathFinding.pickNextWaypointDist = 2; pathFinding.forwardLook = 1f; FunnelModifier modifer = go.AddComponent <FunnelModifier>(); modifer.Priority = 2; CharacterController box = go.AddComponent <CharacterController>(); box.radius = configData.radius; box.height = 2; if (box.radius >= box.height) { box.center = Vector3.up * box.radius; } else { box.center = Vector3.up * box.height / 2; } } else if (configData.radius > 0) { CapsuleCollider cap = go.AddComponent <CapsuleCollider>(); cap.radius = configData.radius; cap.height = 2; if (cap.radius >= cap.height) { cap.center = Vector3.up * cap.radius; } else { cap.center = Vector3.up * cap.height / 2; } NavmeshCut cut = go.AddComponent <NavmeshCut>(); cut.type = NavmeshCut.MeshType.Circle; cut.circleRadius = configData.radius; cut.height = 10; cut.center = Vector3.up * 5; } DynamicDataInit(npc, configData, camp); go.name = "NPC_" + configData.ID + "_" + npc.UniqueID; return(npc); }
/// <summary> /// Loads the bullet. /// </summary> /// <returns>The bullet.</returns> /// <param name="num">Number.</param> /// <param name="camp">Camp.</param> /// <param name="pos">Position.</param> /// <param name="rot">Rot.</param> public GameObject LoadNpcObj(int num, CAMP camp, Vector3 pos, Quaternion rot) { if (NpcModel == null) { NpcModel = Core.Data.getIModelConfig <NPCModel>(); } NPCConfigData configData = NpcModel.get(num); #if DEBUG Utils.Assert(configData == null, "Virtual Npc load can't find npc configure. NPC id = " + num); #endif string path = SPath.Combine(ResourceSetting.PACKROOT, NPC); if (configData.healthpoint > 0) { path = SPath.Combine(path, "LifeSummonNpc"); } else { path = SPath.Combine(path, "NoneLifeSummonNpc"); } UObj obj = URes.Load(path); GameObject go = GameObject.Instantiate(obj) as GameObject; go.transform.position = pos; go.transform.rotation = rot; if (configData.moveable == Moveable.Movable) { Seeker seek = go.AddComponent <Seeker>(); seek.drawGizmos = false; AIPath pathFinding = go.AddComponent <AIPath>(); pathFinding.speed = configData.speed; pathFinding.slowdownDistance = 0.0f; pathFinding.pickNextWaypointDist = 2; pathFinding.forwardLook = 1f; FunnelModifier modifer = go.AddComponent <FunnelModifier>(); modifer.Priority = 2; CharacterController box = go.AddComponent <CharacterController>(); box.radius = configData.radius; box.height = 2; if (box.radius >= box.height) { box.center = Vector3.up * box.radius; } else { box.center = Vector3.up * box.height / 2; } } else if (configData.radius > 0) { CapsuleCollider cap = go.AddComponent <CapsuleCollider>(); cap.radius = configData.radius; cap.height = 2; if (cap.radius >= cap.height) { cap.center = Vector3.up * cap.radius; } else { cap.center = Vector3.up * cap.height / 2; } NavmeshCut cut = go.AddComponent <NavmeshCut>(); cut.type = NavmeshCut.MeshType.Circle; cut.circleRadius = configData.radius; cut.height = 10; cut.center = Vector3.up * 5; } ServerNPC npc = go.GetComponent <ServerNPC>(); if (npc != null) { DynamicDataInit(npc, configData, camp); } return(go); }
public static void ShowModifiers() { Seeker seeker = m_AI.GetComponent <Seeker>(); AlternativePath altPath = m_AI.GetComponent <AlternativePath>(); FunnelModifier funnel = m_AI.GetComponent <FunnelModifier>(); SimpleSmoothModifier simpleSmooth = m_AI.GetComponent <SimpleSmoothModifier>(); GUILayout.BeginHorizontal(); GUILayout.Space(25); // seeker if (seeker == null) { if (GUILayout.Button("Add Seeker", GUILayout.Height(25), GUILayout.MinWidth(150))) { seeker = m_AI.gameObject.AddComponent <Seeker>(); } } else if (GUILayout.Button("Remove Seeker", GUILayout.Height(25), GUILayout.MinWidth(150))) { DestroyImmediate(seeker); } // funnel modifier if (funnel == null) { if (GUILayout.Button("Add Funnel", GUILayout.Height(25), GUILayout.MinWidth(150))) { funnel = m_AI.gameObject.AddComponent <FunnelModifier>(); } } else if (GUILayout.Button("Remove Funnel", GUILayout.Height(25), GUILayout.MinWidth(150))) { DestroyImmediate(funnel); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(25); // simple smooth if (simpleSmooth == null) { if (GUILayout.Button("Add Simple Smooth", GUILayout.Height(25), GUILayout.MinWidth(150))) { simpleSmooth = m_AI.gameObject.AddComponent <SimpleSmoothModifier>(); } } else if (GUILayout.Button("Remove Simple Smooth", GUILayout.Height(25), GUILayout.MinWidth(150))) { DestroyImmediate(simpleSmooth); } // alternative path if (altPath == null) { if (GUILayout.Button("Add Alternative Path", GUILayout.Height(25), GUILayout.MinWidth(150))) { altPath = m_AI.gameObject.AddComponent <AlternativePath>(); } } else if (GUILayout.Button("Remove Alternative Path", GUILayout.Height(25), GUILayout.MinWidth(150))) { DestroyImmediate(altPath); } GUILayout.EndHorizontal(); GUILayout.Space(5); if (m_AI.AStarAutoPrioritize) { int priority = 1; if (simpleSmooth != null) { simpleSmooth.priority = priority++; } if (funnel != null) { funnel.priority = priority++; } if (altPath != null) { altPath.priority = priority++; } } }