Ejemplo n.º 1
0
 private void AppendModifierVolumes(ref List <NavMeshBuildSource> sources)
 {
     using (List <NavMeshModifierVolume> .Enumerator enumerator = NavMeshModifierVolume.get_activeModifiers().GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             NavMeshModifierVolume current = enumerator.Current;
             if ((LayerMask.op_Implicit(this.LayerMask) & 1 << ((Component)current).get_gameObject().get_layer()) != 0 && current.AffectsAgentType(this.agentTypeId))
             {
                 Vector3 vector3_1 = ((Component)current).get_transform().TransformPoint(current.get_center());
                 if (((Bounds) ref this.Bounds).Contains(vector3_1))
                 {
                     Vector3 lossyScale = ((Component)current).get_transform().get_lossyScale();
                     Vector3 vector3_2;
                     ((Vector3) ref vector3_2).\u002Ector((float)current.get_size().x *Mathf.Abs((float)lossyScale.x), (float)current.get_size().y *Mathf.Abs((float)lossyScale.y), (float)current.get_size().z *Mathf.Abs((float)lossyScale.z));
                     NavMeshBuildSource navMeshBuildSource = (NavMeshBuildSource)null;
                     ((NavMeshBuildSource) ref navMeshBuildSource).set_shape((NavMeshBuildSourceShape)5);
                     ((NavMeshBuildSource) ref navMeshBuildSource).set_transform(Matrix4x4.TRS(vector3_1, ((Component)current).get_transform().get_rotation(), Vector3.get_one()));
                     ((NavMeshBuildSource) ref navMeshBuildSource).set_size(vector3_2);
                     ((NavMeshBuildSource) ref navMeshBuildSource).set_area(current.get_area());
                     sources.Add(navMeshBuildSource);
                 }
             }
         }
     }
 }
        static void RenderBoxGizmo(NavMeshModifierVolume navModifier, GizmoType gizmoType)
        {
            var color = s_HandleColor;

            if (!navModifier.enabled)
            {
                color = s_HandleColorDisabled;
            }
            var colorTrans = new Color(color.r * 0.75f, color.g * 0.75f, color.b * 0.75f, color.a * 0.15f);

            var oldColor  = Gizmos.color;
            var oldMatrix = Gizmos.matrix;

            Gizmos.matrix = navModifier.transform.localToWorldMatrix;

            Gizmos.color = colorTrans;
            Gizmos.DrawCube(navModifier.center, navModifier.size);

            Gizmos.color = color;
            Gizmos.DrawWireCube(navModifier.center, navModifier.size);

            Gizmos.matrix = oldMatrix;
            Gizmos.color  = oldColor;

            Gizmos.DrawIcon(navModifier.transform.position, "NavMeshModifierVolume Icon", true);
        }
    public void CreatePlaneAndModifierVolume()
    {
        var go = GameObject.CreatePrimitive(PrimitiveType.Plane);

        surface = go.AddComponent <NavMeshSurface>();

        modifier = new GameObject().AddComponent <NavMeshModifierVolume>();
    }
Ejemplo n.º 4
0
 private void Awake()
 {
     foreach (NavMeshSurface surface in GetComponentsInChildren <NavMeshSurface>())
     {
         surfaces.Add(surface);
     }
     modifier = GetComponentInChildren <NavMeshModifierVolume>();
 }
Ejemplo n.º 5
0
    public TerrainChunk(Vector2 coord, HeightMapSettings heightMapSettings, MeshSettings meshSettings, LODInfo[] detailLevels, int colliderLODindex, Transform parent, Transform viewer, Material meshMaterial, ObjectCreator objectCreator, float collisionGenerationThreshold)
    {
        this.coord            = coord;
        this.detailLevels     = detailLevels;
        this.colliderLODindex = colliderLODindex;
        this.objectCreator    = objectCreator;

        this.heightMapSettings = heightMapSettings;
        this.meshSettings      = meshSettings;
        this.viewer            = viewer;
        this.meshMaterial      = meshMaterial;

        // max view distance should be last detail level
        maxViewDst    = detailLevels[detailLevels.Length - 1].visibleDstThreshold;
        sampleCenter  = coord * meshSettings.meshWorldSize / meshSettings.terrainScale;
        chunkPosition = coord * meshSettings.meshWorldSize;
        bounds        = new Bounds(chunkPosition, Vector2.one * meshSettings.meshWorldSize);

        colliderGenrationThreshold = collisionGenerationThreshold;

        // Create plane
        meshObject     = new GameObject(GameConstants.TerrainChunkPrefix + coord.x + ":" + coord.y);
        meshObject.tag = GameConstants.TerrainChunkTag;
        meshObject.transform.parent   = parent;
        meshObject.transform.position = new Vector3(chunkPosition.x, 0, chunkPosition.y);

        meshFilter   = meshObject.AddComponent <MeshFilter>();
        meshRenderer = meshObject.AddComponent <MeshRenderer>();
        meshCollider = meshObject.AddComponent <MeshCollider>();

        navMeshModifier = meshObject.AddComponent <NavMeshModifierVolume>();
        //navMeshSurface.collectObjects = CollectObjects.Volume;
        //navMeshSurface.useGeometry = NavMeshCollectGeometry.PhysicsColliders;
        navMeshModifier.center = Vector3.zero;
        navMeshModifier.size   = new Vector3(meshSettings.meshWorldSize * 1.1f, heightMapSettings.maxHeight * 2, meshSettings.meshWorldSize * 1.1f);
        SetVisible(false);

        // Create LOD meshes for all levels of detail
        lodMeshes = new LODMesh[detailLevels.Length];
        for (int i = 0; i < detailLevels.Length; i++)
        {
            lodMeshes[i] = new LODMesh(detailLevels[i].lod);
            if (i == colliderLODindex)
            {
                lodMeshes[i].updateCallback += UpdateCollisionMesh;
                lodMeshes[i].updateCallback += UpdateTreeVisibility;
            }
            lodMeshes[i].updateCallback += UpdateTerrainChunk;
        }
    }
Ejemplo n.º 6
0
 public override void ServerInit()
 {
     base.ServerInit();
     if (Barricade.nonWalkableArea < 0)
     {
         Barricade.nonWalkableArea = NavMesh.GetAreaFromName("Not Walkable");
     }
     if (Barricade.animalAgentTypeId < 0)
     {
         NavMeshBuildSettings settingsByIndex = NavMesh.GetSettingsByIndex(1);
         Barricade.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(Barricade.nonWalkableArea);
         this.NavMeshVolumeAnimals.AddAgentType(Barricade.animalAgentTypeId);
         this.NavMeshVolumeAnimals.set_center(Vector3.get_zero());
         this.NavMeshVolumeAnimals.set_size(Vector3.get_one());
     }
     if (!this.canNpcSmash)
     {
         if (Barricade.humanoidAgentTypeId < 0)
         {
             NavMeshBuildSettings settingsByIndex = NavMesh.GetSettingsByIndex(0);
             Barricade.humanoidAgentTypeId = ((NavMeshBuildSettings) ref settingsByIndex).get_agentTypeID();
         }
         if (!Object.op_Equality((Object)this.NavMeshVolumeHumanoids, (Object)null))
         {
             return;
         }
         this.NavMeshVolumeHumanoids = (NavMeshModifierVolume)((Component)this).get_gameObject().AddComponent <NavMeshModifierVolume>();
         this.NavMeshVolumeHumanoids.set_area(Barricade.nonWalkableArea);
         this.NavMeshVolumeHumanoids.AddAgentType(Barricade.humanoidAgentTypeId);
         this.NavMeshVolumeHumanoids.set_center(Vector3.get_zero());
         this.NavMeshVolumeHumanoids.set_size(Vector3.get_one());
     }
     else
     {
         if (!Object.op_Equality((Object)this.NpcTriggerBox, (Object)null))
         {
             return;
         }
         this.NpcTriggerBox = (NPCBarricadeTriggerBox) new GameObject("NpcTriggerBox").AddComponent <NPCBarricadeTriggerBox>();
         this.NpcTriggerBox.Setup(this);
     }
 }
Ejemplo n.º 7
0
    public override void ServerInit()
    {
        NavMeshBuildSettings settingsByIndex;

        base.ServerInit();
        if (Barricade.nonWalkableArea < 0)
        {
            Barricade.nonWalkableArea = NavMesh.GetAreaFromName("Not Walkable");
        }
        if (Barricade.animalAgentTypeId < 0)
        {
            settingsByIndex             = NavMesh.GetSettingsByIndex(1);
            Barricade.animalAgentTypeId = settingsByIndex.agentTypeID;
        }
        if (this.NavMeshVolumeAnimals == null)
        {
            this.NavMeshVolumeAnimals      = base.gameObject.AddComponent <NavMeshModifierVolume>();
            this.NavMeshVolumeAnimals.area = Barricade.nonWalkableArea;
            this.NavMeshVolumeAnimals.AddAgentType(Barricade.animalAgentTypeId);
            this.NavMeshVolumeAnimals.center = Vector3.zero;
            this.NavMeshVolumeAnimals.size   = Vector3.one;
        }
        if (!this.canNpcSmash)
        {
            if (Barricade.humanoidAgentTypeId < 0)
            {
                settingsByIndex = NavMesh.GetSettingsByIndex(0);
                Barricade.humanoidAgentTypeId = settingsByIndex.agentTypeID;
            }
            if (this.NavMeshVolumeHumanoids == null)
            {
                this.NavMeshVolumeHumanoids      = base.gameObject.AddComponent <NavMeshModifierVolume>();
                this.NavMeshVolumeHumanoids.area = Barricade.nonWalkableArea;
                this.NavMeshVolumeHumanoids.AddAgentType(Barricade.humanoidAgentTypeId);
                this.NavMeshVolumeHumanoids.center = Vector3.zero;
                this.NavMeshVolumeHumanoids.size   = Vector3.one;
                return;
            }
        }
        else if (this.NpcTriggerBox == null)
        {
            this.NpcTriggerBox = (new GameObject("NpcTriggerBox")).AddComponent <NPCBarricadeTriggerBox>();
            this.NpcTriggerBox.Setup(this);
        }
    }
Ejemplo n.º 8
0
        static void RenderBoxGizmoNotSelected(NavMeshModifierVolume navModifier, GizmoType gizmoType)
        {
            if (NavMeshVisualizationSettings.showNavigation > 0)
            {
                var color     = navModifier.enabled ? s_HandleColor : s_HandleColorDisabled;
                var oldColor  = Gizmos.color;
                var oldMatrix = Gizmos.matrix;

                Gizmos.matrix = navModifier.transform.localToWorldMatrix;

                Gizmos.color = color;
                Gizmos.DrawWireCube(navModifier.center, navModifier.size);

                Gizmos.matrix = oldMatrix;
                Gizmos.color  = oldColor;
            }

            Gizmos.DrawIcon(navModifier.transform.position, "NavMeshModifierVolume Icon", true);
        }
Ejemplo n.º 9
0
 public override void ServerInit()
 {
     base.ServerInit();
     if (nonWalkableArea < 0)
     {
         nonWalkableArea = NavMesh.GetAreaFromName("Not Walkable");
     }
     if (animalAgentTypeId < 0)
     {
         animalAgentTypeId = NavMesh.GetSettingsByIndex(1).agentTypeID;
     }
     if (NavMeshVolumeAnimals == null)
     {
         NavMeshVolumeAnimals      = base.gameObject.AddComponent <NavMeshModifierVolume>();
         NavMeshVolumeAnimals.area = nonWalkableArea;
         NavMeshVolumeAnimals.AddAgentType(animalAgentTypeId);
         NavMeshVolumeAnimals.center = Vector3.zero;
         NavMeshVolumeAnimals.size   = Vector3.one;
     }
     if (!canNpcSmash)
     {
         if (humanoidAgentTypeId < 0)
         {
             humanoidAgentTypeId = NavMesh.GetSettingsByIndex(0).agentTypeID;
         }
         if (NavMeshVolumeHumanoids == null)
         {
             NavMeshVolumeHumanoids      = base.gameObject.AddComponent <NavMeshModifierVolume>();
             NavMeshVolumeHumanoids.area = nonWalkableArea;
             NavMeshVolumeHumanoids.AddAgentType(humanoidAgentTypeId);
             NavMeshVolumeHumanoids.center = Vector3.zero;
             NavMeshVolumeHumanoids.size   = Vector3.one;
         }
     }
     else if (NpcTriggerBox == null)
     {
         NpcTriggerBox = new GameObject("NpcTriggerBox").AddComponent <NPCBarricadeTriggerBox>();
         NpcTriggerBox.Setup(this);
     }
 }
Ejemplo n.º 10
0
        public List <WG_LocationController> GenerateLocationSegments(WG_TerrainBuilder builder, float segmentSize, float meshSquareSize, int meshSquaresCount, int segmentMinX, int segmentMaxX, int segmentMinY, int segmenMaxY, GameObject rootObject, Material floorMaterial, Material heightMaterial, Material wallsMaterial, bool[,] map, float height, bool bakeNavMesh, NavMeshModifierVolume navMeshCutter, float uvPadding)
        {
            List <WG_LocationController> locations = new List <WG_LocationController>();

            for (int u = segmentMinX; u < segmentMaxX + 1; u++)
            {
                for (int v = segmentMinY; v < segmenMaxY + 1; v++)
                {
                    bool[,] segmentMap = new bool[meshSquaresCount + 1, meshSquaresCount + 1];
                    //fill data for one segment
                    for (int x = 0; x < meshSquaresCount + 1; x++)
                    {
                        for (int y = 0; y < meshSquaresCount + 1; y++)
                        {
                            segmentMap[x, y] = map[(u - segmentMinX) * (meshSquaresCount) + x, (v - segmentMinY) * (meshSquaresCount) + y];
                        }
                    }
                    locations.Add(EmitSegment(u, v, segmentSize, meshSquareSize, rootObject.transform, segmentMap, floorMaterial, wallsMaterial, height, uvPadding));
                }
            }

            navMeshCutter.center = new Vector3((segmentMinX + segmentMaxX) * segmentSize / 2.0f, height, (segmentMinY + segmenMaxY) * segmentSize / 2.0f);
            navMeshCutter.size   = new Vector3((segmentMaxX - segmentMinX + 1) * segmentSize, 1, (segmenMaxY - segmentMinY + 1) * segmentSize);
            BuilNavMesh(builder, locations, bakeNavMesh);

            return(locations);
        }
Ejemplo n.º 11
0
    public override void ServerInit()
    {
        NavMeshBuildSettings settingsByIndex;

        base.ServerInit();
        if (Door.nonWalkableArea < 0)
        {
            Door.nonWalkableArea = NavMesh.GetAreaFromName("Not Walkable");
        }
        if (Door.animalAgentTypeId < 0)
        {
            settingsByIndex        = NavMesh.GetSettingsByIndex(1);
            Door.animalAgentTypeId = settingsByIndex.agentTypeID;
        }
        if (this.NavMeshVolumeAnimals == null)
        {
            this.NavMeshVolumeAnimals      = base.gameObject.AddComponent <NavMeshModifierVolume>();
            this.NavMeshVolumeAnimals.area = Door.nonWalkableArea;
            this.NavMeshVolumeAnimals.AddAgentType(Door.animalAgentTypeId);
            this.NavMeshVolumeAnimals.center = Vector3.zero;
            this.NavMeshVolumeAnimals.size   = Vector3.one;
        }
        if (this.HasSlot(BaseEntity.Slot.Lock))
        {
            this.canNpcOpen = false;
        }
        if (!this.canNpcOpen)
        {
            if (Door.humanoidAgentTypeId < 0)
            {
                settingsByIndex          = NavMesh.GetSettingsByIndex(0);
                Door.humanoidAgentTypeId = settingsByIndex.agentTypeID;
            }
            if (this.NavMeshVolumeHumanoids == null)
            {
                this.NavMeshVolumeHumanoids      = base.gameObject.AddComponent <NavMeshModifierVolume>();
                this.NavMeshVolumeHumanoids.area = Door.nonWalkableArea;
                this.NavMeshVolumeHumanoids.AddAgentType(Door.humanoidAgentTypeId);
                this.NavMeshVolumeHumanoids.center = Vector3.zero;
                this.NavMeshVolumeHumanoids.size   = (Vector3.one + Vector3.up) + Vector3.forward;
            }
        }
        else if (this.NpcTriggerBox == null)
        {
            if (this.isSecurityDoor)
            {
                NavMeshObstacle navMeshObstacle = base.gameObject.AddComponent <NavMeshObstacle>();
                navMeshObstacle.carving = true;
                navMeshObstacle.center  = Vector3.zero;
                navMeshObstacle.size    = Vector3.one;
                navMeshObstacle.shape   = NavMeshObstacleShape.Box;
            }
            this.NpcTriggerBox = (new GameObject("NpcTriggerBox")).AddComponent <NPCDoorTriggerBox>();
            this.NpcTriggerBox.Setup(this);
        }
        AIInformationZone forPoint = AIInformationZone.GetForPoint(base.transform.position, null);

        if (forPoint != null && this.NavMeshLink == null)
        {
            this.NavMeshLink = forPoint.GetClosestNavMeshLink(base.transform.position);
        }
    }
 public void CreatePlaneAndModifierVolume()
 {
     this.surface  = (NavMeshSurface)GameObject.CreatePrimitive((PrimitiveType)4).AddComponent <NavMeshSurface>();
     this.modifier = (NavMeshModifierVolume) new GameObject().AddComponent <NavMeshModifierVolume>();
 }
Ejemplo n.º 13
0
    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());
    }