Beispiel #1
0
    void Update()
    {
        //Tag the terrain to be used as a navmesh source
        //When these tagged terrains overlap with the LocalNavMeshBuilder (child object of player) the navmesh is updated
        foreach (Transform tile in mapMagicContainer.transform)
        {
            var mainTerrain       = tile.Find("Main Terrain");
            var navMeshSourceTags = mainTerrain.GetComponentsInChildren(typeof(NavMeshSourceTag));
            if (navMeshSourceTags.Length == 0)
            {
                NavMeshSourceTag navMeshSourceTag =
                    mainTerrain.gameObject.AddComponent(typeof(NavMeshSourceTag)) as NavMeshSourceTag;
            }
        }

        if (transform.childCount < 20 && Random.value < 0.1)
        {
            //The size (diameter) of LocalNavMeshBuilder has to be at least twice the spawnDistanceMax (radius) in each dimension
            float spawnDistanceMin = 40;
            float spawnDistanceMax = spawnDistanceMin * 2;
            var   enemyToSpawn     = enemyList[Random.Range(0, enemyList.Length)];
            var   playerPos        = Camera.main.transform.position;
            var   spawnPos         = GetRandomPoint(playerPos, spawnDistanceMax);
            var   spawnDistance    = (spawnPos - playerPos).magnitude;

            if (spawnDistance > spawnDistanceMin && spawnDistance < Mathf.Infinity)
            {
                Instantiate(enemyToSpawn, spawnPos, Quaternion.identity, transform);
            }
        }
    }
Beispiel #2
0
    public AsyncOperation ResetNavMesh(AI_TYPE InType)
    {
        NavMeshDataInstance dataInstance;

        if (Map_MeshInstance.TryGetValue(InType, out dataInstance))
        {
            NavMesh.RemoveNavMeshData(dataInstance);
            Map_MeshInstance.Remove(InType);
        }

        NavMeshData meshData = new NavMeshData();

        dataInstance = NavMesh.AddNavMeshData(meshData);
        Map_MeshInstance.Add(InType, dataInstance);

        int agentIndex = (int)InType;

        List <NavMeshBuildSource> sources = new List <NavMeshBuildSource>();

        NavMeshSourceTag.Collect(ref sources, GetArea(agentIndex), InType);

        NavMeshBuildSettings defaultBuildSettings = NavMesh.GetSettingsByIndex(agentIndex);

        //print(agentIndex + "," + defaultBuildSettings.agentRadius);

        var bounds = QuantizedBounds();

        return(NavMeshBuilder.UpdateNavMeshDataAsync(meshData, defaultBuildSettings, sources, bounds));
    }
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        NavMeshSourceTag.CollectMeshes(ref m_Sources);
        NavMeshSourceTag.CollectModifierVolumes(LayerMask.GetMask("Default"), ref m_Sources);

        var defaultBuildSettings = NavMesh.GetSettingsByID(AgentID);
        var bounds = QuantizedBounds();

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }

        /*
         * NavMeshSourceTag.Collect(ref m_Sources);
         * var defaultBuildSettings = NavMesh.GetSettingsByID(0);
         * var bounds = QuantizedBounds();
         *
         * if (asyncUpdate)
         * m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
         * else
         * NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
         */
    }
Beispiel #4
0
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        //Don't do anything if the target area hasn't changed
        if (asyncUpdate && center == (m_Tracked ? m_Tracked.position : transform.position))
        {
            return;
        }

        NavMeshSourceTag.Collect(ref m_Sources);
        var defaultBuildSettings = NavMesh.GetSettingsByIndex(0);

        defaultBuildSettings.overrideVoxelSize = true;
        defaultBuildSettings.voxelSize         = 0.4f;
        defaultBuildSettings.overrideTileSize  = true;
        defaultBuildSettings.tileSize          = 16;

        var bounds = QuantizedBounds();

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
    }
Beispiel #5
0
    void UpdateNavMesh()
    {
        NavMeshSourceTag.Collect(ref m_Sources, transform);
        NavMeshBuildSettings defaultBuildSettings = NavMesh.GetSettingsByID(0);

        defaultBuildSettings.agentClimb       *= transform.lossyScale.x;
        defaultBuildSettings.agentHeight      *= transform.lossyScale.x;
        defaultBuildSettings.agentRadius      *= transform.lossyScale.x;
        defaultBuildSettings.minRegionArea    *= transform.lossyScale.x;
        defaultBuildSettings.overrideVoxelSize = true;
        defaultBuildSettings.voxelSize         = defaultBuildSettings.agentRadius / 3f;
        Bounds bounds = new Bounds(Vector3.zero, Vector3.Scale(new Vector3(3f, 3f, 3f), transform.lossyScale));

        NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);

        /*
         * navMeshVis.transform.SetParent(null, false);
         * NavMeshTriangulation triangulation = NavMesh.CalculateTriangulation();
         * Mesh mesh = navMeshVis.mesh;
         * mesh.Clear();
         * mesh.vertices = triangulation.vertices;
         * mesh.triangles = triangulation.indices;
         * mesh.RecalculateNormals();
         */
        for (int i = 0; i < placedInArea.Count; i++)
        {
            if (placedInArea[i].GetComponent <NavMeshSourceTag>() == null)
            {
                placedInArea[i].transform.position = PlacementManager.Instance.GetNavPos(placedInArea[i].transform.position);
                MoveInArea(placedInArea[i]);
            }
        }
    }
Beispiel #6
0
    // 3 Event handler for when a SpatialMapping mesh is updated
    private void SpatialMappingSourceSurfaceUpdated(object sender, DataEventArgs <SpatialMappingSource.SurfaceUpdate> dataEvent)
    {
        NavMeshSourceTag navMeshSourceTag = dataEvent.Data.New.Object.GetComponent <NavMeshSourceTag>();

        if (navMeshSourceTag == null)
        {
            dataEvent.Data.New.Object.AddComponent <NavMeshSourceTag>();
        }
    }
Beispiel #7
0
 public override void Initialize(int p_x, int p_y)
 {
     base.Initialize(p_x, p_y);
     FloodVelocity     = GameSettings.FLOOD_VELOCITY;
     _navMeshSourceTag = transform.GetChild(2).GetComponent <NavMeshSourceTag>();
     if (isFloodSource)
     {
         SetState(State.FLOOD_SOURCE);
     }
 }
    void BakeNavMesh()
    {
        navMeshData = new NavMeshData(0);


        NavMeshSourceTag.Collect(ref sources);
        var defaultBuildSettings = NavMesh.GetSettingsByID(0);
        var bounds = new Bounds(center, size);

        NavMeshBuilder.UpdateNavMeshData(navMeshData, defaultBuildSettings, sources, bounds);
        navMeshInstance = NavMesh.AddNavMeshData(navMeshData);
        //NavMeshBuilder.BuildNavMeshData(defaultBuildSettings, sources, bounds, this.gameObject.transform.position, this.gameObject.transform.rotation);
    }
Beispiel #9
0
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        NavMeshSourceTag.Collect(ref m_Sources); //←NavMeshSourceTagタグをセットしたオブジェクトをすべて集めてListに格納
        var defaultBuildSettings = NavMesh.GetSettingsByID(0);
        var bounds = QuantizedBounds();          //←メッシュ生成の範囲をセット

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);    //←実際のメッシュ生成を行っている部分。
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
    }
Beispiel #10
0
    private void UpdateNavMesh(bool asyncUpdate = false)
    {
        NavMeshSourceTag.Collect(ref this.m_Sources, 0);
        NavMeshBuildSettings settingsById = NavMesh.GetSettingsByID(0);
        Bounds bounds = this.QuantizedBounds();

        if (asyncUpdate)
        {
            this.m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(this.m_NavMesh, settingsById, this.m_Sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(this.m_NavMesh, settingsById, this.m_Sources, bounds);
        }
    }
Beispiel #11
0
    // ========================== [ Division ] ========================== //

    void UpdateNavMesh(bool asyncUpdate = false)
    {
        NavMeshSourceTag.Collect(ref _listSources);
        var defaultBuildSettings = NavMesh.GetSettingsByID(0);
        var bounds = QuantizedBounds();

        if (asyncUpdate)
        {
            _pOperation = NavMeshBuilder.UpdateNavMeshDataAsync(_pNavMesh, defaultBuildSettings, _listSources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(_pNavMesh, defaultBuildSettings, _listSources, bounds);
        }
    }
Beispiel #12
0
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        NavMeshSourceTag.Collect(ref m_Sources);
        var defaultBuildSettings = NavMesh.GetSettingsByID(agentTypeId);
        var bounds = QuantizedBounds();

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
    }
Beispiel #13
0
        private List <NavMeshBuildSource> CollectSources()
        {
            List <NavMeshBuildSource> sources = new List <NavMeshBuildSource>();

            NavMeshSourceTag.Collect(ref sources, this.m_DefaultArea);
            if (this.m_IgnoreNavMeshAgent)
            {
                sources.RemoveAll((Predicate <NavMeshBuildSource>)(x => Object.op_Inequality((Object)((NavMeshBuildSource) ref x).get_component(), (Object)null) && Object.op_Inequality((Object)((NavMeshBuildSource) ref x).get_component().get_gameObject().GetComponent <NavMeshAgent>(), (Object)null)));
            }
            if (this.m_IgnoreNavMeshObstacle)
            {
                sources.RemoveAll((Predicate <NavMeshBuildSource>)(x => Object.op_Inequality((Object)((NavMeshBuildSource) ref x).get_component(), (Object)null) && Object.op_Inequality((Object)((NavMeshBuildSource) ref x).get_component().get_gameObject().GetComponent <NavMeshObstacle>(), (Object)null)));
            }
            this.AppendModifierVolumes(ref sources);
            return(sources);
        }
    private void UpdateNavMesh(bool isAsync = false)
    {
        NavMeshSourceTag.Collect(ref sources);
        NavMeshBuildSettings settings;

        settings = NavMesh.GetSettingsByID(0);
        Bounds bounds = QuantizeBounds();

        if (isAsync)
        {
            operation = NavMeshBuilder.UpdateNavMeshDataAsync(navMesh, settings, sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(navMesh, settings, sources, bounds);
        }
    }
Beispiel #15
0
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        Debug.Log("Updating nav");
        NavMeshSourceTag.Collect(ref m_Sources);
        var defaultBuildSettings = NavMesh.GetSettingsByID(0);

        buildBounds = QuantizedBounds();

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, buildBounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, buildBounds);
        }
    }
Beispiel #16
0
    public void Clear(AI_TYPE InType)
    {
        NavMeshSourceTag.UnCollect(InType);

        List <TrafficLine> List_TrafficLine;

        if (!Map.TryGetValue(InType, out List_TrafficLine))
        {
            return;
        }

        foreach (var t in List_TrafficLine)
        {
            Destroy(t.gameObject);
        }
        List_TrafficLine.Clear();
    }
Beispiel #17
0
    public TerrainChunk(Vector2 coord, HeightMapSettings heightMapSettings, MeshSettings meshSettings, LODInfo[] detailLevels, int colliderLODIndex, Transform parent, Transform viewer, Material material)
    {
        this.coord             = coord;
        this.detailLevels      = detailLevels;
        this.colliderLODIndex  = colliderLODIndex;
        this.heightMapSettings = heightMapSettings;
        this.meshSettings      = meshSettings;
        this.viewer            = viewer;

        sampleCentre = coord * meshSettings.meshWorldSize / meshSettings.meshScale;
        Vector2 position = coord * meshSettings.meshWorldSize;

        bounds = new Bounds(position, Vector2.one * meshSettings.meshWorldSize);


        meshObject            = new GameObject("Terrain Chunk " + position);
        navMeshSourceTag      = meshObject.AddComponent <NavMeshSourceTag>();
        meshRenderer          = meshObject.AddComponent <MeshRenderer>();
        meshFilter            = meshObject.AddComponent <MeshFilter>();
        meshCollider          = meshObject.AddComponent <MeshCollider>();
        meshRenderer.material = material;

        meshObject.transform.position = new Vector3(position.x, 0, position.y);
        meshObject.transform.parent   = parent;

        meshObject.transform.gameObject.tag = "Chunk";

        SetVisible(false);

        lodMeshes = new LODMesh[detailLevels.Length];
        for (int i = 0; i < detailLevels.Length; i++)
        {
            lodMeshes[i] = new LODMesh(detailLevels[i].lod);
            lodMeshes[i].updateCallback += UpdateTerrainChunk;
            if (i == colliderLODIndex)
            {
                lodMeshes[i].updateCallback += UpdateCollisionMesh;
            }
        }

        maxViewDst = detailLevels [detailLevels.Length - 1].visibleDstThreshold;
    }
    public void NavMeshAdder(GameObject childTransform)


    {
        // NavMeshSurface nm = childTransform.AddComponent(typeof(NavMeshSurface)) as NavMeshSurface;
        //  NavMeshLink lk = childTransform.AddComponent(typeof(NavMeshLink)) as NavMeshLink;
        NavMeshSourceTag sourceTag = childTransform.AddComponent(typeof(NavMeshSourceTag)) as NavMeshSourceTag;

        //nm.buildHeightMesh = true;
        if (childTransform.transform.childCount != 0)
        {
            if (defaultPrefabHasObsticale)
            {
                NavMeshObstacle obstacle = childTransform.AddComponent(typeof(NavMeshObstacle)) as NavMeshObstacle;
                obstacle.radius = obstacleRadius;
                obstacle.size   = new Vector3(1, 1, 1);
                if (forceCapsuleObstacleForPrefab)
                {
                    obstacle.shape = NavMeshObstacleShape.Capsule;
                }
            }
            // and for it's children
            for (int i = 0; i < childTransform.transform.childCount; i++)
            {
                if (defaultPrefabChildHasObstacle)
                {
                    var childAgain = childTransform.transform.GetChild(i);

                    NavMeshObstacle childObstacle = childAgain.gameObject.AddComponent(typeof(NavMeshObstacle)) as NavMeshObstacle;
                    childObstacle.radius = obstacleRadius;
                    if (forceCapsuleObstacleForChild)
                    {
                        childObstacle.shape = NavMeshObstacleShape.Capsule;
                    }
                    childObstacle.size = new Vector3(1, 1, 1);
                }
                //   child.
            }
        }
        //nm.BuildNavMesh();
    }
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        NavMeshSourceTag.Collect(ref m_Sources);
        var defaultBuildSettings = NavMesh.GetSettingsByID(0);

        defaultBuildSettings.agentClimb    = 0.5f;
        defaultBuildSettings.minRegionArea = 50000.0f;
        defaultBuildSettings.agentSlope    = 30;
        defaultBuildSettings.agentRadius   = 0.5f;
        defaultBuildSettings.voxelSize     = 0.75f;

        var bounds = QuantizedBounds();

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
        else
        {
            //m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
    }
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        NavMeshSourceTag.Collect(ref m_Sources);
        var defaultBuildSettings = NavMesh.GetSettingsByID(0);

        defaultBuildSettings.voxelSize   = voxelSize;
        defaultBuildSettings.tileSize    = tileSize;
        defaultBuildSettings.agentClimb  = agentClimb;
        defaultBuildSettings.agentRadius = agentRadius;
        defaultBuildSettings.agentHeight = agentHeight;



        var bounds = QuantizedBounds();

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
    }