// Use this for initialization void Start() { navMeshLink = transform.GetComponent <NavMeshLink>(); InvokeRepeating("ForcePosUpdate", 0.5f, 0.5f); }
// Start is called before the first frame update void Start() { agent = GetComponent <NavMeshAgent>(); link = null; }
// Start is called before the first frame update void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } for (int ring = 1; ring <= numberOfRings; ring++) { GameObject currentRing = new GameObject(); float circumference = (float)(Mathf.PI * 2 * radius * ring); int numberOfBlocks = Mathf.CeilToInt(circumference / lengthOfBlock); float currentRadius = (float)(radius * ring); List <GameObject> blocksOnCurrentRing = new List <GameObject>(); Bounds? lastBounds = null; for (int block = 1; block <= numberOfBlocks; block++) { if (Random.Range(0, 100) <= randomCapProb * 100) { continue; } float currentAngle = (360f / numberOfBlocks) * block; Vector3 position = PointOnCircle(currentRadius + Random.Range(-offsetRadius, offsetRadius), currentAngle + Random.Range(-offsetRotation, offsetRotation)); //Debug.Log("currentAngle: " + currentAngle + " numberOfBlocks: " + numberOfBlocks + " block: " + block + " xPos: " + position.x + " yPos: " + position.y); GameObject currentBlock = Instantiate(wallPrefab, position, Quaternion.Euler(0, 360 - currentAngle + Random.Range(-offsetAngle, offsetAngle), 0)); currentBlock.transform.SetParent(currentRing.transform); blocksOnCurrentRing.Add(currentBlock); } currentRing.AddComponent <NavMeshSurface>(); currentRing.layer = 19; currentRing.GetComponent <NavMeshSurface>().collectObjects = CollectObjects.Children; currentRing.GetComponent <NavMeshSurface>().BuildNavMesh(); foreach (GameObject block in blocksOnCurrentRing) { Bounds currentBlockBounds = block.GetComponent <BoxCollider>().bounds; currentBlockBounds.Expand(-1.5f); if (lastBounds != null) { Bounds old = lastBounds ?? new Bounds(); if (!currentBlockBounds.Intersects(old)) { Vector3 closestPointOld = old.ClosestPoint(block.transform.position); closestPointOld.y += old.extents.y; Vector3 closestPointNew = currentBlockBounds.ClosestPoint(closestPointOld); closestPointNew.y += currentBlockBounds.extents.y; if (maxLinkDistance >= Vector3.Distance(closestPointOld, closestPointNew)) { NavMeshHit hit; NavMeshLink newLink = block.AddComponent <NavMeshLink>(); NavMesh.SamplePosition(closestPointNew, out hit, maxLinkDistance, NavMesh.AllAreas); newLink.startPoint = block.transform.InverseTransformPoint(hit.position); NavMesh.SamplePosition(closestPointOld, out hit, maxLinkDistance, NavMesh.AllAreas); newLink.endPoint = block.transform.InverseTransformPoint(hit.position); newLink.bidirectional = true; newLink.autoUpdate = true; } } } lastBounds = currentBlockBounds; } Rings.Add(currentRing); } }
static Vector3 CalcLinkRight(NavMeshLink navLink) { Vector3 dir = navLink.endPoint - navLink.startPoint; return((new Vector3(-dir.z, 0.0f, dir.x)).normalized); }
void Start() { navLink = GetComponent <NavMeshLink>(); UpdatePositions(); }
void Start() { //*** Init from Json m_nbColor_min = OptionsManager.m_options.lvl2_nbColors; m_random_steps_max = OptionsManager.m_options.lvl2_randomSteps; m_rate_side = OptionsManager.m_options.lvl2_sideSteps; m_steps_min = OptionsManager.m_options.lvl2_steps; m_random_color_max = OptionsManager.m_options.lvl2_random_color_max; m_nbColor = m_nbColor_min + Random.Range(0, m_random_color_max); //size of the ground where the player start m_ground.transform.localScale = new Vector3(m_ground.transform.localScale.x, m_ground.transform.localScale.y, 4f * m_nbColor); m_ground.transform.position = new Vector3(m_ground.transform.position.x, m_ground.transform.position.y, (4f * m_nbColor) / 2); //Randomly improve number of steps m_steps = m_steps_min + Random.Range(0, m_random_steps_max); m_list = new GameObject[m_steps, m_nbColor]; Queue <Material> shuffleColor = new Queue <Material>(); for (int i = 0; i < m_steps; i++) { //reload color Shuffle(m_color, m_nbColor); for (int r = 0; r < m_nbColor; r++) { shuffleColor.Enqueue(m_color[r]); } for (int j = 0; j < m_nbColor; j++) { GameObject cgenerated = Instantiate(m_shape); cgenerated.transform.parent = this.transform; //inside this game object cgenerated.transform.position = m_shape.transform.position + new Vector3(i * m_gape, 0, j * m_gape); cgenerated.GetComponent <Renderer>().material = shuffleColor.Dequeue(); NavMeshLink north = cgenerated.AddComponent <NavMeshLink>(); north.startPoint = new Vector3(-m_gape, 1, 0); north.endPoint = new Vector3(0, 1, 0); NavMeshLink east = cgenerated.AddComponent <NavMeshLink>(); east.startPoint = new Vector3(0, 1, 0); east.endPoint = new Vector3(0, 1, m_gape); NavMeshLink ne = cgenerated.AddComponent <NavMeshLink>(); ne.startPoint = new Vector3(0, 1, 0); ne.endPoint = new Vector3(m_gape, 1, m_gape); NavMeshLink nw = cgenerated.AddComponent <NavMeshLink>(); nw.startPoint = new Vector3(0, 1, 0); nw.endPoint = new Vector3(m_gape, 1, -m_gape); m_list[i, j] = cgenerated; } } Destroy(m_shape); m_surfaces.BuildNavMesh(); m_path = new List <GameObject>(); makePath(m_path); updateColorIcons(); //Show all the cube map from the cam m_cam.orthographicSize += m_path.Count * 1.4f; //Sounds FindObjectOfType <OptionsManager>().PlaySound("bgm_action_4"); }
void Start() { link = GetComponent <NavMeshLink>(); AlighPoints(); }
public override void ServerInit() { base.ServerInit(); if (Door.nonWalkableArea < 0) { Door.nonWalkableArea = NavMesh.GetAreaFromName("Not Walkable"); } if (Door.animalAgentTypeId < 0) { NavMeshBuildSettings settingsByIndex = NavMesh.GetSettingsByIndex(1); Door.animalAgentTypeId = ((NavMeshBuildSettings) ref settingsByIndex).get_agentTypeID(); } if (Object.op_Equality((Object)this.NavMeshVolumeAnimals, (Object)null)) { this.NavMeshVolumeAnimals = (NavMeshModifierVolume)((Component)this).get_gameObject().AddComponent <NavMeshModifierVolume>(); this.NavMeshVolumeAnimals.set_area(Door.nonWalkableArea); this.NavMeshVolumeAnimals.AddAgentType(Door.animalAgentTypeId); this.NavMeshVolumeAnimals.set_center(Vector3.get_zero()); this.NavMeshVolumeAnimals.set_size(Vector3.get_one()); } if (this.HasSlot(BaseEntity.Slot.Lock)) { this.canNpcOpen = false; } if (!this.canNpcOpen) { if (Door.humanoidAgentTypeId < 0) { NavMeshBuildSettings settingsByIndex = NavMesh.GetSettingsByIndex(0); Door.humanoidAgentTypeId = ((NavMeshBuildSettings) ref settingsByIndex).get_agentTypeID(); } if (Object.op_Equality((Object)this.NavMeshVolumeHumanoids, (Object)null)) { this.NavMeshVolumeHumanoids = (NavMeshModifierVolume)((Component)this).get_gameObject().AddComponent <NavMeshModifierVolume>(); this.NavMeshVolumeHumanoids.set_area(Door.nonWalkableArea); this.NavMeshVolumeHumanoids.AddAgentType(Door.humanoidAgentTypeId); this.NavMeshVolumeHumanoids.set_center(Vector3.get_zero()); this.NavMeshVolumeHumanoids.set_size(Vector3.op_Addition(Vector3.op_Addition(Vector3.get_one(), Vector3.get_up()), Vector3.get_forward())); } } else if (Object.op_Equality((Object)this.NpcTriggerBox, (Object)null)) { if (this.isSecurityDoor) { M0 m0 = ((Component)this).get_gameObject().AddComponent <NavMeshObstacle>(); ((NavMeshObstacle)m0).set_carving(true); ((NavMeshObstacle)m0).set_center(Vector3.get_zero()); ((NavMeshObstacle)m0).set_size(Vector3.get_one()); ((NavMeshObstacle)m0).set_shape((NavMeshObstacleShape)1); } this.NpcTriggerBox = (NPCDoorTriggerBox) new GameObject("NpcTriggerBox").AddComponent <NPCDoorTriggerBox>(); this.NpcTriggerBox.Setup(this); } AIInformationZone forPoint = AIInformationZone.GetForPoint(((Component)this).get_transform().get_position(), (BaseEntity)null); if (!Object.op_Inequality((Object)forPoint, (Object)null) || !Object.op_Equality((Object)this.NavMeshLink, (Object)null)) { return; } this.NavMeshLink = forPoint.GetClosestNavMeshLink(((Component)this).get_transform().get_position()); }
/// <summary> /// Initializer /// </summary> private void Awake() { this.soundLink = GetComponent <NavMeshLink>(); }