Ejemplo n.º 1
0
 // Token: 0x06000B3A RID: 2874 RVA: 0x00050BE4 File Offset: 0x0004EDE4
 private void SetupAgents()
 {
     this.ClearAgentSettings();
     Pathfinding.AgentSettings agentSettings = this.AddAgent(Pathfinding.AgentType.Humanoid, null);
     agentSettings.m_build.agentHeight = 1.8f;
     agentSettings.m_build.agentClimb  = 0.3f;
     agentSettings.m_build.agentRadius = 0.4f;
     agentSettings.m_build.agentSlope  = 85f;
     this.AddAgent(Pathfinding.AgentType.Wolf, agentSettings).m_build.agentSlope  = 85f;
     this.AddAgent(Pathfinding.AgentType.HumanoidNoSwim, agentSettings).m_canSwim = false;
     Pathfinding.AgentSettings agentSettings2 = this.AddAgent(Pathfinding.AgentType.HumanoidBigNoSwim, null);
     agentSettings2.m_build.agentHeight = 2.5f;
     agentSettings2.m_build.agentClimb  = 0.3f;
     agentSettings2.m_build.agentRadius = 0.5f;
     agentSettings2.m_build.agentSlope  = 85f;
     agentSettings2.m_canSwim           = false;
     this.AddAgent(Pathfinding.AgentType.HumanoidAvoidWater, agentSettings).m_avoidWater = true;
     Pathfinding.AgentSettings agentSettings3 = this.AddAgent(Pathfinding.AgentType.TrollSize, null);
     agentSettings3.m_build.agentHeight = 7f;
     agentSettings3.m_build.agentClimb  = 0.6f;
     agentSettings3.m_build.agentRadius = 1f;
     agentSettings3.m_build.agentSlope  = 85f;
     Pathfinding.AgentSettings agentSettings4 = this.AddAgent(Pathfinding.AgentType.GoblinBruteSize, null);
     agentSettings4.m_build.agentHeight = 3.5f;
     agentSettings4.m_build.agentClimb  = 0.3f;
     agentSettings4.m_build.agentRadius = 0.8f;
     agentSettings4.m_build.agentSlope  = 85f;
     Pathfinding.AgentSettings agentSettings5 = this.AddAgent(Pathfinding.AgentType.HugeSize, null);
     agentSettings5.m_build.agentHeight = 10f;
     agentSettings5.m_build.agentClimb  = 0.6f;
     agentSettings5.m_build.agentRadius = 2f;
     agentSettings5.m_build.agentSlope  = 85f;
     Pathfinding.AgentSettings agentSettings6 = this.AddAgent(Pathfinding.AgentType.HorseSize, null);
     agentSettings6.m_build.agentHeight = 2.5f;
     agentSettings6.m_build.agentClimb  = 0.3f;
     agentSettings6.m_build.agentRadius = 0.8f;
     agentSettings6.m_build.agentSlope  = 85f;
     Pathfinding.AgentSettings agentSettings7 = this.AddAgent(Pathfinding.AgentType.Fish, null);
     agentSettings7.m_build.agentHeight = 0.5f;
     agentSettings7.m_build.agentClimb  = 1f;
     agentSettings7.m_build.agentRadius = 0.5f;
     agentSettings7.m_build.agentSlope  = 90f;
     agentSettings7.m_canSwim           = true;
     agentSettings7.m_canWalk           = false;
     agentSettings7.m_swimDepth         = 0.4f;
     agentSettings7.m_areaMask          = 12;
     Pathfinding.AgentSettings agentSettings8 = this.AddAgent(Pathfinding.AgentType.BigFish, null);
     agentSettings8.m_build.agentHeight = 1.5f;
     agentSettings8.m_build.agentClimb  = 1f;
     agentSettings8.m_build.agentRadius = 1f;
     agentSettings8.m_build.agentSlope  = 90f;
     agentSettings8.m_canSwim           = true;
     agentSettings8.m_canWalk           = false;
     agentSettings8.m_swimDepth         = 1.5f;
     agentSettings8.m_areaMask          = 12;
     NavMesh.SetAreaCost(0, this.m_defaultCost);
     NavMesh.SetAreaCost(3, this.m_waterCost);
 }
Ejemplo n.º 2
0
    // Token: 0x06000B51 RID: 2897 RVA: 0x00051A08 File Offset: 0x0004FC08
    private void RebuildLinks(Pathfinding.NavMeshTile tile)
    {
        Pathfinding.AgentType     z        = (Pathfinding.AgentType)tile.m_tile.z;
        Pathfinding.AgentSettings settings = this.GetSettings(z);
        float num = this.m_tileSize / 2f;

        this.ConnectAlongEdge(tile.m_links1, tile.m_center + new Vector3(num, 0f, num), tile.m_center + new Vector3(num, 0f, -num), this.m_linkWidth, settings);
        this.ConnectAlongEdge(tile.m_links2, tile.m_center + new Vector3(-num, 0f, num), tile.m_center + new Vector3(num, 0f, num), this.m_linkWidth, settings);
    }
Ejemplo n.º 3
0
    // Token: 0x06000B4C RID: 2892 RVA: 0x000516E0 File Offset: 0x0004F8E0
    private void BuildTile(Pathfinding.NavMeshTile tile)
    {
        DateTime now = DateTime.Now;
        List <NavMeshBuildSource> list    = new List <NavMeshBuildSource>();
        List <NavMeshBuildMarkup> markups = new List <NavMeshBuildMarkup>();

        Pathfinding.AgentType     z        = (Pathfinding.AgentType)tile.m_tile.z;
        Pathfinding.AgentSettings settings = this.GetSettings(z);
        Bounds includedWorldBounds         = new Bounds(tile.m_center, new Vector3(this.m_tileSize, 6000f, this.m_tileSize));
        Bounds localBounds = new Bounds(Vector3.zero, new Vector3(this.m_tileSize, 6000f, this.m_tileSize));
        int    defaultArea = settings.m_canWalk ? 0 : 1;

        NavMeshBuilder.CollectSources(includedWorldBounds, this.m_layers.value, NavMeshCollectGeometry.PhysicsColliders, defaultArea, markups, list);
        if (settings.m_avoidWater)
        {
            List <NavMeshBuildSource> list2 = new List <NavMeshBuildSource>();
            NavMeshBuilder.CollectSources(includedWorldBounds, this.m_waterLayers.value, NavMeshCollectGeometry.PhysicsColliders, 1, markups, list2);
            using (List <NavMeshBuildSource> .Enumerator enumerator = list2.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    NavMeshBuildSource item = enumerator.Current;
                    item.transform *= Matrix4x4.Translate(Vector3.down * 0.2f);
                    list.Add(item);
                }
                goto IL_1AE;
            }
        }
        if (settings.m_canSwim)
        {
            List <NavMeshBuildSource> list3 = new List <NavMeshBuildSource>();
            NavMeshBuilder.CollectSources(includedWorldBounds, this.m_waterLayers.value, NavMeshCollectGeometry.PhysicsColliders, 3, markups, list3);
            if (settings.m_swimDepth != 0f)
            {
                using (List <NavMeshBuildSource> .Enumerator enumerator = list3.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        NavMeshBuildSource item2 = enumerator.Current;
                        item2.transform *= Matrix4x4.Translate(Vector3.down * settings.m_swimDepth);
                        list.Add(item2);
                    }
                    goto IL_1AE;
                }
            }
            list.AddRange(list3);
        }
IL_1AE:
        if (tile.m_data == null)
        {
            tile.m_data          = new NavMeshData();
            tile.m_data.position = tile.m_center;
        }
        this.m_buildOperation = NavMeshBuilder.UpdateNavMeshDataAsync(tile.m_data, settings.m_build, list, localBounds);
        this.m_buildTile      = tile;
    }
Ejemplo n.º 4
0
    // Token: 0x06000B44 RID: 2884 RVA: 0x00051120 File Offset: 0x0004F320
    private void CleanPath(List <Vector3> basePath, Pathfinding.AgentSettings settings)
    {
        if (basePath.Count <= 2)
        {
            return;
        }
        NavMeshQueryFilter filter = default(NavMeshQueryFilter);

        filter.agentTypeID = settings.m_build.agentTypeID;
        filter.areaMask    = settings.m_areaMask;
        int num = 0;

        this.optPath.Clear();
        this.optPath.Add(basePath[num]);
        do
        {
            num = this.FindNextNode(basePath, filter, num);
            this.optPath.Add(basePath[num]);
        }while (num < basePath.Count - 1);
        this.tempPath.Clear();
        this.tempPath.Add(this.optPath[0]);
        for (int i = 1; i < this.optPath.Count - 1; i++)
        {
            Vector3 vector      = this.optPath[i - 1];
            Vector3 vector2     = this.optPath[i];
            Vector3 vector3     = this.optPath[i + 1];
            Vector3 normalized  = (vector3 - vector2).normalized;
            Vector3 normalized2 = (vector2 - vector).normalized;
            Vector3 vector4     = vector2 - (normalized + normalized2).normalized * Vector3.Distance(vector2, vector) * 0.33f;
            vector4.y = (vector2.y + vector.y) * 0.5f;
            Vector3    normalized3 = (vector4 - vector2).normalized;
            NavMeshHit navMeshHit;
            if (!NavMesh.Raycast(vector2 + normalized3 * 0.1f, vector4, out navMeshHit, filter) && !NavMesh.Raycast(vector4, vector, out navMeshHit, filter))
            {
                this.tempPath.Add(vector4);
            }
            this.tempPath.Add(vector2);
            Vector3 vector5 = vector2 + (normalized + normalized2).normalized * Vector3.Distance(vector2, vector3) * 0.33f;
            vector5.y = (vector2.y + vector3.y) * 0.5f;
            Vector3 normalized4 = (vector5 - vector2).normalized;
            if (!NavMesh.Raycast(vector2 + normalized4 * 0.1f, vector5, out navMeshHit, filter) && !NavMesh.Raycast(vector5, vector3, out navMeshHit, filter))
            {
                this.tempPath.Add(vector5);
            }
        }
        this.tempPath.Add(this.optPath[this.optPath.Count - 1]);
        basePath.Clear();
        basePath.AddRange(this.tempPath);
    }
Ejemplo n.º 5
0
 // Token: 0x06000B39 RID: 2873 RVA: 0x00050B44 File Offset: 0x0004ED44
 private Pathfinding.AgentSettings AddAgent(Pathfinding.AgentType type, Pathfinding.AgentSettings copy = null)
 {
     while (type + 1 > (Pathfinding.AgentType) this.m_agentSettings.Count)
     {
         this.m_agentSettings.Add(null);
     }
     Pathfinding.AgentSettings agentSettings = new Pathfinding.AgentSettings(type);
     if (copy != null)
     {
         agentSettings.m_build.agentHeight = copy.m_build.agentHeight;
         agentSettings.m_build.agentClimb  = copy.m_build.agentClimb;
         agentSettings.m_build.agentRadius = copy.m_build.agentRadius;
         agentSettings.m_build.agentSlope  = copy.m_build.agentSlope;
     }
     this.m_agentSettings[(int)type] = agentSettings;
     return(agentSettings);
 }
Ejemplo n.º 6
0
    // Token: 0x06000B42 RID: 2882 RVA: 0x00051000 File Offset: 0x0004F200
    public bool FindValidPoint(out Vector3 point, Vector3 center, float range, Pathfinding.AgentType agentType)
    {
        this.PokePoint(center, agentType);
        Pathfinding.AgentSettings settings = this.GetSettings(agentType);
        NavMeshHit navMeshHit;

        if (NavMesh.SamplePosition(center, out navMeshHit, range, new NavMeshQueryFilter
        {
            agentTypeID = (int)settings.m_agentType,
            areaMask = settings.m_areaMask
        }))
        {
            point = navMeshHit.position;
            return(true);
        }
        point = center;
        return(false);
    }
Ejemplo n.º 7
0
    // Token: 0x06000B43 RID: 2883 RVA: 0x00051064 File Offset: 0x0004F264
    public bool GetPath(Vector3 from, Vector3 to, List <Vector3> path, Pathfinding.AgentType agentType, bool requireFullPath = false, bool cleanup = true)
    {
        if (path != null)
        {
            path.Clear();
        }
        this.PokeArea(from, agentType);
        this.PokeArea(to, agentType);
        Pathfinding.AgentSettings settings = this.GetSettings(agentType);
        if (!this.SnapToNavMesh(ref from, settings))
        {
            return(false);
        }
        if (!this.SnapToNavMesh(ref to, settings))
        {
            return(false);
        }
        NavMeshQueryFilter filter = new NavMeshQueryFilter
        {
            agentTypeID = settings.m_build.agentTypeID,
            areaMask    = settings.m_areaMask
        };

        if (!NavMesh.CalculatePath(from, to, filter, this.m_path))
        {
            return(false);
        }
        if (this.m_path.status == NavMeshPathStatus.PathPartial && requireFullPath)
        {
            return(false);
        }
        if (path != null)
        {
            path.AddRange(this.m_path.corners);
            if (cleanup)
            {
                this.CleanPath(path, settings);
            }
        }
        return(true);
    }
Ejemplo n.º 8
0
    // Token: 0x06000B55 RID: 2901 RVA: 0x00051D20 File Offset: 0x0004FF20
    private void FindGround(Vector3 p, bool testWater, List <Vector3> hits, Pathfinding.AgentSettings settings)
    {
        p.y = 6000f;
        int   layerMask   = testWater ? (this.m_layers.value | this.m_waterLayers.value) : this.m_layers.value;
        float agentHeight = settings.m_build.agentHeight;
        float y           = p.y;
        int   num         = Physics.RaycastNonAlloc(p, Vector3.down, this.tempHitArray, 10000f, layerMask);

        for (int i = 0; i < num; i++)
        {
            Vector3 point = this.tempHitArray[i].point;
            if (Mathf.Abs(point.y - y) >= agentHeight)
            {
                y = point.y;
                if ((1 << this.tempHitArray[i].collider.gameObject.layer & this.m_waterLayers) != 0)
                {
                    point.y -= settings.m_swimDepth;
                }
                hits.Add(point);
            }
        }
    }
Ejemplo n.º 9
0
    // Token: 0x06000B46 RID: 2886 RVA: 0x000513FC File Offset: 0x0004F5FC
    private bool SnapToNavMesh(ref Vector3 point, Pathfinding.AgentSettings settings)
    {
        if (ZoneSystem.instance)
        {
            float num;
            if (ZoneSystem.instance.GetGroundHeight(point, out num) && point.y < num)
            {
                point.y = num;
            }
            if (settings.m_canSwim)
            {
                point.y = Mathf.Max(ZoneSystem.instance.m_waterLevel - settings.m_swimDepth, point.y);
            }
        }
        NavMeshQueryFilter filter = default(NavMeshQueryFilter);

        filter.agentTypeID = settings.m_build.agentTypeID;
        filter.areaMask    = settings.m_areaMask;
        NavMeshHit navMeshHit;

        if (NavMesh.SamplePosition(point, out navMeshHit, 1.5f, filter))
        {
            point = navMeshHit.position;
            return(true);
        }
        if (NavMesh.SamplePosition(point, out navMeshHit, 10f, filter))
        {
            point = navMeshHit.position;
            return(true);
        }
        if (NavMesh.SamplePosition(point, out navMeshHit, 20f, filter))
        {
            point = navMeshHit.position;
            return(true);
        }
        return(false);
    }
Ejemplo n.º 10
0
    // Token: 0x06000B52 RID: 2898 RVA: 0x00051ABC File Offset: 0x0004FCBC
    private void ConnectAlongEdge(List <KeyValuePair <Vector3, NavMeshLinkInstance> > links, Vector3 p0, Vector3 p1, float step, Pathfinding.AgentSettings settings)
    {
        Vector3 normalized = (p1 - p0).normalized;
        Vector3 a          = Vector3.Cross(Vector3.up, normalized);
        float   num        = Vector3.Distance(p0, p1);
        bool    canSwim    = settings.m_canSwim;

        this.tempStitchPoints.Clear();
        for (float num2 = step / 2f; num2 <= num; num2 += step)
        {
            Vector3 p2 = p0 + normalized * num2;
            this.FindGround(p2, canSwim, this.tempStitchPoints, settings);
        }
        if (this.CompareLinks(this.tempStitchPoints, links))
        {
            return;
        }
        this.ClearLinks(links);
        foreach (Vector3 vector in this.tempStitchPoints)
        {
            NavMeshLinkInstance value = NavMesh.AddLink(new NavMeshLinkData
            {
                startPosition = vector - a * 0.1f,
                endPosition   = vector + a * 0.1f,
                width         = step,
                costModifier  = this.m_linkCost,
                bidirectional = true,
                agentTypeID   = settings.m_build.agentTypeID,
                area          = 2
            });
            if (value.valid)
            {
                links.Add(new KeyValuePair <Vector3, NavMeshLinkInstance>(vector, value));
            }
        }
    }