コード例 #1
0
ファイル: InsideCheck.cs プロジェクト: DevZhav/The-Forest
        private static void AddRoof(InsideCheck.GridPosition position, IRoof roof)
        {
            List <IRoof> list = InsideCheck.AffirmRoofList(position);

            list.Add(roof);
            InsideCheck.ForceRefresh(position);
        }
コード例 #2
0
 private void OnDisable()
 {
     if (this._gridToken >= 0)
     {
         InsideCheck.RemoveWallChunk(this._gridToken);
     }
 }
コード例 #3
0
ファイル: InsideCheck.cs プロジェクト: DevZhav/The-Forest
        private static void AddWallChunk(InsideCheck.GridPosition position, InsideCheck.WallChunk chunk)
        {
            List <InsideCheck.WallChunk> list = InsideCheck.AffirmWallList(position);

            list.Add(chunk);
            InsideCheck.ForceRefresh(position);
        }
コード例 #4
0
        private IEnumerator UpdateInsideRoutine()
        {
            for (;;)
            {
                Transform listener = this.GetListener();
                if (listener == null)
                {
                    yield return(YieldPresets.WaitForFixedUpdate);

                    yield return(0);
                }
                else
                {
                    InsideCheck.GridPosition position = InsideCheck.ToGridPosition(listener.position);
                    if (this._forceRefresh || position != this._currentGridPosition)
                    {
                        this._forceRefresh        = false;
                        this._currentGridPosition = position;
                        this._currentGridCells.Clear();
                        for (int i = -1; i <= 1; i++)
                        {
                            for (int j = -1; j <= 1; j++)
                            {
                                InsideCheck.GridCell gridCell = InsideCheck.GetGridCell(position + new InsideCheck.GridPosition(i, j));
                                if (gridCell != null)
                                {
                                    this._currentGridCells.Add(gridCell);
                                }
                            }
                        }
                    }
                    for (int k = 0; k < this._occlusion.Count; k++)
                    {
                        this._occlusion[k] = false;
                    }
                    this._roofDetected = InsideCheck.IsAnyRoofAbove(listener.position);
                    if (this._roofDetected)
                    {
                        for (int l = 0; l < this._currentGridCells.Count; l++)
                        {
                            InsideCheck.RenderWallsToOcclusion(this._currentGridCells[l], listener.position, this._occlusion);
                        }
                    }
                    float occlusionPercent = 0f;
                    for (int m = 0; m < this._occlusion.Count; m++)
                    {
                        if (this._occlusion[m])
                        {
                            occlusionPercent += 1f;
                        }
                    }
                    occlusionPercent *= 100f / (float)this._occlusion.Count;
                    this.SetInside(occlusionPercent >= this.OCCLUSION_THRESHOLD);
                    yield return(YieldPresets.WaitPointOneSeconds);
                }
            }
            yield break;
        }
コード例 #5
0
ファイル: InsideCheck.cs プロジェクト: DevZhav/The-Forest
 private static List <IRoof> AffirmRoofList(InsideCheck.GridPosition position)
 {
     InsideCheck.GridCell gridCell = InsideCheck.AffirmGridCell(position);
     if (gridCell.roofs == null)
     {
         gridCell.roofs = new List <IRoof>();
     }
     return(gridCell.roofs);
 }
コード例 #6
0
        private void OnEnable()
        {
            Vector3 start;
            Vector3 end;
            Vector3 vector;

            this.CalculatePoints(out start, out end, out vector);
            this._gridToken = InsideCheck.AddWallChunk(start, end, vector.y - start.y);
        }
コード例 #7
0
ファイル: InsideCheck.cs プロジェクト: DevZhav/The-Forest
 private static List <InsideCheck.WallChunk> AffirmWallList(InsideCheck.GridPosition position)
 {
     InsideCheck.GridCell gridCell = InsideCheck.AffirmGridCell(position);
     if (gridCell.walls == null)
     {
         gridCell.walls = new List <InsideCheck.WallChunk>();
     }
     return(gridCell.walls);
 }
コード例 #8
0
ファイル: InsideCheck.cs プロジェクト: DevZhav/The-Forest
 private static void RenderWallsToOcclusion(InsideCheck.GridCell cell, Vector3 centre, List <bool> occlusion)
 {
     if (cell.walls != null)
     {
         for (int i = 0; i < cell.walls.Count; i++)
         {
             InsideCheck.RenderChunkToOcclusion(cell.walls[i], centre, occlusion);
         }
     }
 }
コード例 #9
0
ファイル: InsideCheck.cs プロジェクト: DevZhav/The-Forest
 private static InsideCheck.GridCell AffirmGridCell(InsideCheck.GridPosition position)
 {
     InsideCheck.AffirmGrid();
     InsideCheck.GridCell gridCell = null;
     if (!InsideCheck._grid.TryGetValue(position, out gridCell))
     {
         gridCell = new InsideCheck.GridCell();
         InsideCheck._grid[position] = gridCell;
     }
     return(gridCell);
 }
コード例 #10
0
ファイル: InsideCheck.cs プロジェクト: DevZhav/The-Forest
 private static bool IsAnyRoofAbove(Vector3 position)
 {
     InsideCheck.GridCell gridCell = InsideCheck.GetGridCell(InsideCheck.ToGridPosition(position));
     if (gridCell != null && gridCell.roofs != null)
     {
         for (int i = 0; i < gridCell.roofs.Count; i++)
         {
             if (InsideCheck.IsRoofAbove(gridCell.roofs[i], position))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #11
0
 private void Start()
 {
     InsideCheck.AffirmGrid();
     this._currentGridCells = new List <InsideCheck.GridCell>();
     this._occlusion        = new List <bool>(36);
     for (int i = 0; i < 36; i++)
     {
         this._occlusion.Add(false);
     }
     if (FMOD_StudioSystem.instance)
     {
         this._snapshotInstance = FMOD_StudioSystem.instance.GetEvent("snapshot:/inside_buildings");
     }
     base.StartCoroutine(this.UpdateInsideRoutine());
     FMOD_Listener.DrawInsideCheck = new Action(this.DrawDebug);
     InsideCheck._instance         = this;
 }
コード例 #12
0
        public void DrawDebug()
        {
            Transform listener = this.GetListener();

            if (listener == null)
            {
                return;
            }
            if (InsideCheck.lineTexture == null)
            {
                this.CreateDebugTextures();
            }
            if (Camera.main != null)
            {
                Vector2 vector  = new Vector2(110f, (float)(Camera.main.pixelHeight - 110));
                Vector2 vector2 = vector - new Vector2(105f, 105f);
                GUI.Box(new Rect(vector2.x, vector2.y - 35f, 210f, 245f), ((!this._inside) ? "OUTSIDE" : "INSIDE") + "\n" + ((!this._roofDetected) ? "NO ROOF" : "ROOF DETECTED"));
                List <InsideCheck.GridCell> currentGridCells = this._currentGridCells;
                for (int i = 0; i < currentGridCells.Count; i++)
                {
                    InsideCheck.GridCell gridCell = currentGridCells[i];
                    if (gridCell.walls != null)
                    {
                        float scale = 1.66666663f;
                        for (int j = 0; j < gridCell.walls.Count; j++)
                        {
                            Vector2 start = InsideCheck.ToUIPosition(LocalPlayer.Transform.InverseTransformPoint(gridCell.walls[j].start), vector, scale);
                            Vector2 end   = InsideCheck.ToUIPosition(LocalPlayer.Transform.InverseTransformPoint(gridCell.walls[j].end), vector, scale);
                            this.DrawLine(start, end, InsideCheck.lineTexture);
                        }
                    }
                }
                Color color = GUI.color;
                float num   = listener.eulerAngles.y * 0.0174532924f;
                int   num2  = 5;
                for (int k = 0; k < this._occlusion.Count; k++)
                {
                    float   num3    = (float)((!this._occlusion[k]) ? 0 : 1);
                    Vector2 vector3 = vector + 100f * new Vector2(Mathf.Cos(num), -Mathf.Sin(num));
                    GUI.color = new Color(num3, num3, num3);
                    GUI.DrawTexture(new Rect(vector3.x - (float)(num2 / 2), vector3.y - (float)(num2 / 2), (float)num2, (float)num2), InsideCheck.lineTexture);
                    num += 6.28318548f / (float)this._occlusion.Count;
                }
                GUI.color = color;
            }
        }
コード例 #13
0
ファイル: InsideCheck.cs プロジェクト: DevZhav/The-Forest
 public static int AddWallChunk(Vector3 start, Vector3 end, float height)
 {
     if (end.y < start.y)
     {
         float y = start.y;
         start.y = end.y;
         end.y   = y;
     }
     end.y += height;
     InsideCheck.WallChunk wallChunk = new InsideCheck.WallChunk(start, end, InsideCheck._nextGridToken);
     InsideCheck._nextGridToken++;
     InsideCheck.GridPosition gridPosition = InsideCheck.ToGridPosition(start);
     InsideCheck.AddWallChunk(gridPosition, wallChunk);
     InsideCheck.GridPosition gridPosition2 = InsideCheck.ToGridPosition(end);
     if (gridPosition2 != gridPosition)
     {
         InsideCheck.AddWallChunk(gridPosition2, wallChunk);
     }
     return(wallChunk.token);
 }
コード例 #14
0
ファイル: InsideCheck.cs プロジェクト: DevZhav/The-Forest
        private static void RenderChunkToOcclusion(InsideCheck.WallChunk chunk, Vector3 centre, List <bool> occlusion)
        {
            if (centre.y < chunk.start.y || chunk.end.y < centre.y)
            {
                return;
            }
            float num  = InsideCheck.CalculateAngle(InsideCheck.ToPlanarPosition(chunk.start, centre));
            float num2 = InsideCheck.CalculateAngle(InsideCheck.ToPlanarPosition(chunk.end, centre));

            if (num2 < num)
            {
                float num3 = num;
                num  = num2;
                num2 = num3;
            }
            int   num4 = InsideCheck.CalculateIndex(num, occlusion.Count);
            int   num5 = InsideCheck.CalculateIndex(num2, occlusion.Count);
            float num6 = num2 - num;

            if (num6 <= 3.14159274f)
            {
                for (int i = num4; i <= num5; i++)
                {
                    occlusion[i] = true;
                }
            }
            else
            {
                for (int j = 0; j <= num4; j++)
                {
                    occlusion[j] = true;
                }
                for (int k = num5; k < occlusion.Count; k++)
                {
                    occlusion[k] = true;
                }
            }
        }
コード例 #15
0
ファイル: InsideCheck.cs プロジェクト: DevZhav/The-Forest
        public static void AddRoof(IRoof roof)
        {
            List <Vector3> polygon = roof.GetPolygon();

            if (polygon.Count <= 0)
            {
                return;
            }
            Bounds bounds = new Bounds(polygon[0], Vector3.zero);

            for (int i = 1; i < polygon.Count; i++)
            {
                bounds.Encapsulate(polygon[i]);
            }
            InsideCheck.GridPosition gridPosition  = InsideCheck.ToGridPosition(bounds.min);
            InsideCheck.GridPosition gridPosition2 = InsideCheck.ToGridPosition(bounds.max);
            for (int j = gridPosition.x; j <= gridPosition2.x; j++)
            {
                for (int k = gridPosition.y; k <= gridPosition2.y; k++)
                {
                    InsideCheck.AddRoof(new InsideCheck.GridPosition(j, k), roof);
                }
            }
        }
コード例 #16
0
 private void OnEnable()
 {
     this._polygon = this.CalculatePolygon();
     InsideCheck.AddRoof(this);
 }
コード例 #17
0
 private void OnDisable()
 {
     InsideCheck.RemoveRoof(this);
 }