Esempio n. 1
0
 public static void RebuildNavmesh()
 {
     if (navMesh.navMeshData != null)
     {
         navMesh.UpdateNavMesh(navMesh.navMeshData);
     }
 }
Esempio n. 2
0
    private void Start()
    {
        //surface.BuildNavMesh();
        NavMeshData navData = new NavMeshData();

        surface.UpdateNavMesh(navData);
    }
        IEnumerator AsyncBake()
        {
            if (surface == null)
            {
                yield break;
            }

            data      = InitializeBakeData(surface);
            operation = surface.UpdateNavMesh(data);

            if (operation == null)
            {
                yield break;
            }

            while (!operation.isDone)
            {
                yield return(null);
            }

            surface.RemoveData();
            surface.navMeshData = data;
            if (surface.isActiveAndEnabled)
            {
                surface.AddData();
            }

            operation = null;
        }
Esempio n. 4
0
    public void set_Map_and_Destinations(string currentMap_name)
    {
        // 이전의 인스턴스는 삭제
        if (GameObject.FindGameObjectWithTag("Map"))
        {
            Destroy(GameObject.FindGameObjectWithTag("Map"));
        }
        if (GameObject.FindGameObjectWithTag("Destinations"))
        {
            Destroy(GameObject.FindGameObjectWithTag("Destinations"));
        }

        // 해당 층의 프리팹으로 map이랑 dest 인스턴스화
        map = Instantiate(Resources.Load("Map/" + currentMap_name)) as GameObject;
        calibrationLocations = Instantiate(Resources.Load("Destinations/" + currentMap_name + "_Destinations")) as GameObject;

        // navmesh 생성
        if (surface.navMeshData != null)
        {
            surface.UpdateNavMesh(surface.navMeshData);
        }
        else
        {
            surface.BuildNavMesh();
        }

        // dest 오브젝트들 안 보이게 설정
        MeshRenderer[] allChildren = calibrationLocations.GetComponentsInChildren <MeshRenderer>();
        foreach (MeshRenderer child in allChildren)
        {
            child.enabled = false;
        }
    }
Esempio n. 5
0
    // called by startcoroutine whenever you want to build the navmesh
    IEnumerator BuildNavmesh(NavMeshSurface surface)
    {
        // wait until everything has rendered
        yield return(new WaitForEndOfFrame());

        // get the data for the surface
        var data = InitializeBakeData(surface);

        // start building the navmesh
        var async = surface.UpdateNavMesh(data);

        // wait until the navmesh has finished baking
        yield return(async);

        Debug.Log("Finished updating NavMeshSurface.");

        // you need to save the baked data back into the surface
        surface.navMeshData = data;

        // save the nav mesh data
        SaveNavMeshData(data);

        // call AddData() to finalize it
        surface.AddData();
    }
Esempio n. 6
0
    public static void nuevaSala(Puerta puerta)
    {
        Sala salaActual = salaActiva.GetComponent <Sala>();

        GameObject prefab;

        System.Random rnd = new System.Random();

        //al principio siempre vamos a crear un pasillo
        if (salaActual.CompareTag("Respawn"))
        {
            prefab = pasillos[rnd.Next(pasillos.Count)];
            CrearPrefab(prefab, puerta);
        }
        else if (salaActual.CompareTag("Pasillo"))
        {
            prefab = salasCombate[rnd.Next(salasCombate.Count)];
            CrearPrefab(prefab, puerta);
            ColocarEvento(rnd.Next());
        }
        else
        {
            prefab = pasillos[rnd.Next(pasillos.Count)];
            CrearPrefab(prefab, puerta);
        }
        navegacion.UpdateNavMesh(navegacion.navMeshData);
        salasMazmorra.Add(prefab);
        DesactivarPuerta(puerta);
    }
Esempio n. 7
0
    private void Update()
    {
        // zorgt dat currentLevel geupdate wordt naar de build index van het huidige level
        // hier kan ook iets gedaan worden dat alleen de eerste keer moet gebeuren dat een bepaald level geladen wordt
        if (currentLevel != null && SceneManager.GetActiveScene().buildIndex >= 1)
        {
            if (currentLevel != SceneManager.GetActiveScene().buildIndex)
            {
                currentLevel   = SceneManager.GetActiveScene().buildIndex;
                levelGameOvers = 0;
                //if (currentLevel % 3 == 0) playerLives++; //player lives
            }
        }

        //zorgt dat het geluid de goede snelheid heeft
        if (Time.timeScale != currentTimeScale)
        {
            currentTimeScale = Time.timeScale;
            SoundAssets.Instance.Master.audioMixer.SetFloat("masterPitch", Time.timeScale);
        }

        //zorgt dat de navmesh word geupdate als er een mine meer of minder in het spel komt
        if (currentLayedMines != minesInGame.Count)
        {
            currentLayedMines = minesInGame.Count;
            navMeshSurface.UpdateNavMesh(navMeshSurface.navMeshData);
        }
    }
Esempio n. 8
0
        private IEnumerator BuildNavMeshes()
        {
            botSurface.UpdateNavMesh(botSurface.navMeshData);
            yield return(null);

            creatureSurface.UpdateNavMesh(creatureSurface.navMeshData);
        }
Esempio n. 9
0
 public override void UpdateNavMesh()
 {
     if (surface != null)
     {
         surface.UpdateNavMesh(surface.navMeshData);
     }
 }
Esempio n. 10
0
 /// <summary>
 /// NavMeshのデータを更新する関数
 /// </summary>
 private void UpdateNavMesh()
 {
     if (playerNav == null)
     {
         return;
     }
     playerNav.layerMask = navLayerMask;
     playerNav.UpdateNavMesh(playerNav.navMeshData);
 }
Esempio n. 11
0
    IEnumerator Regen()
    {
        WaitForSeconds wait = new WaitForSeconds(regenEverySec);

        while (true)
        {
            surface.UpdateNavMesh(surface.navMeshData);
            yield return(wait);
        }
    }
Esempio n. 12
0
        public void Build(System.Action <AsyncOperation> callback = null)
        {
            IsBuilt = false;
            surface = GetComponent <NavMeshSurface> ();
            var operation = surface.UpdateNavMesh(surface.navMeshData);

            operation.completed += BuildComplete;
            if (callback != null)
            {
                operation.completed += callback;
            }
        }
Esempio n. 13
0
 public void BuildMesh(Vector2 chunkCoord, Mesh mesh)
 {
     if (navMeshBuilt)
     {
         navMeshSurface.UpdateNavMesh(navMeshSurface.navMeshData);
     }
     else
     {
         navMeshSurface.BuildNavMesh();
         navMeshBuilt = true;
     }
 }
Esempio n. 14
0
    public void OnDestroy()
    {
        GameObject ground = GameObject.FindGameObjectWithTag("Ground");

        if (ground != null)
        {
            NavMeshSurface surface = ground.GetComponent <NavMeshSurface>();
            if (surface != null)
            {
                surface.UpdateNavMesh(surface.navMeshData);
            }
        }
    }
        void RebuildNavMesh()
        {
            var navMeshData = m_NavMeshSurface.navMeshData;

            if (navMeshData == null)
            {
                m_NavMeshSurface.BuildNavMesh();
            }
            else
            {
                navMeshData.position = m_Transform.position;
                navMeshData.rotation = m_Transform.rotation;
                m_NavMeshSurface.UpdateNavMesh(navMeshData);
            }
        }
Esempio n. 16
0
    private void OnMouseDown()
    {
        if (turret != null)
        {
            Debug.Log("Can't build there! = TODO: Display on Screen.");
            return;
        }
        //Build a Turret
        GameObject turretToBuild = BuildManager.instance.GetTurretToBuild();

        turret = (GameObject)Instantiate(turretToBuild, transform.position + positionOffset, transform.rotation);
        NavMeshSurface nm = GameObject.FindObjectOfType <NavMeshSurface>();

        nm.UpdateNavMesh(nm.navMeshData);

        surface.BuildNavMesh();
    }
    public IEnumerator UpdatingAndAddingNavMesh()
    {
        var navmeshData = new NavMeshData();
        var oper        = surface.UpdateNavMesh(navmeshData);

        Assert.IsFalse(HasNavMeshAtOrigin());

        do
        {
            yield return(null);
        } while (!oper.isDone);
        surface.RemoveData();
        surface.navMeshData = navmeshData;
        surface.AddData();

        Assert.IsTrue(HasNavMeshAtOrigin());
    }
Esempio n. 18
0
    public static AsyncOperation BuildNavMeshAsync(this NavMeshSurface surface)
    {
        surface.RemoveData();
        surface.navMeshData = new NavMeshData(surface.agentTypeID)
        {
            name     = surface.gameObject.name,
            position = surface.transform.position,
            rotation = surface.transform.rotation
        };

        if (surface.isActiveAndEnabled)
        {
            surface.AddData();
        }

        return(surface.UpdateNavMesh(surface.navMeshData));
    }
Esempio n. 19
0
 void Update()
 {
     if (!player)
     {
         player = GameObject.FindGameObjectWithTag("Player");
         return;
     }
     if (op != null && !op.isDone)
     {
         return;
     }
     op = null;
     if (updateDelay++ % 120 != 13)
     {
         return;
     }
     surface.center = player.transform.position;
     op             = surface.UpdateNavMesh(surface.navMeshData);
 }
Esempio n. 20
0
    private void Update()
    {
        if (!charController.isGrounded && !beingPushed)
        {
            charController.Move(new Vector3(0, gravity * Time.deltaTime, 0));
        }

        if (charController.isGrounded && inHole && !gameObject.isStatic && !stop)
        {
            AudioSource ac = GetComponents <AudioSource>()[1];
            ac.Play();
            gameObject.isStatic = true;
            childCube.isStatic  = true;
            gameObject.layer    = 11;
            childCube.layer     = 11;
            navMeshSurface.UpdateNavMesh(navMeshSurface.navMeshData);
            stop = true;
        }
    }
Esempio n. 21
0
    // called by startcoroutine whenever you want to build the navmesh
    IEnumerator BuildNavmesh(NavMeshSurface surface)
    {
        Debug.Log("building navmesh");

        foreach (NPC_Navigation npc in NPCs)
        {
            npc.gameObject.SetActive(false);
        }


        // get the data for the surface
        var data = InitializeBakeData(surface);

        surface.RemoveData();
        surface.navMeshData = null;

        Application.backgroundLoadingPriority = ThreadPriority.Low;

        // start building the navmesh
        asyncop = surface.UpdateNavMesh(data);

        // wait until the navmesh has finished baking
        yield return(asyncop);

        //Debug.Log("finished");

        // you need to save the baked data back into the surface
        surface.navMeshData = data;

        // call AddData() to finalize it
        surface.AddData();

        foreach (NPC_Navigation npc in NPCs)
        {
            npc.gameObject.SetActive(true);
            npc.AdjustPosition();
            if (Application.isPlaying)
            {
                npc.SetNewRandomTarget();
            }
        }
    }
Esempio n. 22
0
        public IEnumerator BuildNavMesh()
        {
            Debug.Log("[Level] Building nav mesh...");

            // https://github.com/Unity-Technologies/NavMeshComponents/issues/97
            _navMeshSurface.RemoveData();
            _navMeshSurface.navMeshData = new NavMeshData(_navMeshSurface.agentTypeID)
            {
                name     = _navMeshSurface.gameObject.name,
                position = _navMeshSurface.transform.position,
                rotation = _navMeshSurface.transform.rotation
            };
            _navMeshSurface.AddData();

            AsyncOperation asyncOp = _navMeshSurface.UpdateNavMesh(_navMeshSurface.navMeshData);

            while (!asyncOp.isDone)
            {
                yield return(null);
            }
        }
Esempio n. 23
0
 //构造函数,只有第一个房子用得到,后面用CreateNextRoom就行了
 public Room(int id, GameObject roomprefab, Vector3 p, MobGroup mobgroup)
 {
     if (StaticRoompPefab == null)
     {
         StaticRoompPefab = roomprefab;
     }
     this.mg = mobgroup;
     roomid = id;
     this.roomgo = GameObject.Instantiate(StaticRoompPefab, p, Quaternion.identity);  //第一次调用的时候,nextroomposition为Vector3.Zero,后面的房间才需要计算
     roomgo.name += " - " + roomid.ToString();
     rc = roomgo.GetComponent<RoomController>();
     nms = rc.Floor.GetComponent<NavMeshSurface>();
     bc = roomgo.GetComponent<BoxCollider>();
     bc.enabled = true;
     rc.thisroomid = id;
     this.CloseAll();
     nms.BuildNavMesh();
     nms.UpdateNavMesh(nms.navMeshData);
     this.directionToNextRoom = CalculateNextRoomDirection();
     this.nextroomposition = CalculateNextRoomPosition();
     roomdic.Add(this.roomid, this);
 }
Esempio n. 24
0
        /// <summary>
        /// Builds the NavMesh based on current active chunks that have colliders active.
        /// </summary>
        private IEnumerator BuildNavMeshAsync()
        {
            if (currentNavmeshBuilderId != int.MaxValue)
            {
                currentNavmeshBuilderId++;
            }
            else
            {
                currentNavmeshBuilderId = 0;
            }

            int navMeshBuilderId = currentNavmeshBuilderId;

            IsBuildingNavmesh = true;

            // Get the data for the surface
            NavMeshData data = InitializeBakeData();

            // Start building the navmesh
            AsyncOperation async = navMeshSurface.UpdateNavMesh(data);

            // Wait until the navmesh has finished baking
            yield return(async);

            if (currentNavmeshBuilderId == navMeshBuilderId)
            {
                // Remove current data
                navMeshSurface.RemoveData();

                // Save the new data into the surface
                navMeshSurface.navMeshData = data;

                // Finalize / Apply
                navMeshSurface.AddData();

                IsBuildingNavmesh = false;
            }
        }
Esempio n. 25
0
    // called by startcoroutine whenever you want to build the navmesh
    IEnumerator BuildNavmesh(NavMeshSurface surface)
    {
        // get the data for the surface
        var data = InitializeBakeData(surface);

        // start building the navmesh
        ao      = surface.UpdateNavMesh(data);
        loading = true;
        // wait until the navmesh has finished baking
        yield return(ao);

        Debug.Log("finished");

        // you need to save the baked data back into the surface
        surface.navMeshData = data;

        // call AddData() to finalize it
        surface.AddData();
        loading      = false;
        i.fillAmount = 0;
        text.SetActive(false);
        OnNavBake.Invoke();
    }
Esempio n. 26
0
 private void UpdateNavMesh()
 {
     navMeshSurface.UpdateNavMesh(navMeshSurface.navMeshData);
 }
Esempio n. 27
0
 public void RebakeNavMesh()
 {
     uhul.UpdateNavMesh(uhul.navMeshData);
 }
 private void AsyncBuildStart()
 {
     data      = InitializeBakeData(surface);
     operation = surface.UpdateNavMesh(data);
 }
Esempio n. 29
0
 public void UpdateMesh()
 {
     _navMeshSurface.UpdateNavMesh(_navMeshSurface.navMeshData);
 }
Esempio n. 30
0
 public void RebakeNavMesh()
 {
     mainNavMesh.UpdateNavMesh(mainNavMesh.navMeshData);
 }