Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
 private static InsideCheck.GridCell GetGridCell(InsideCheck.GridPosition position)
 {
     InsideCheck.GridCell result = null;
     if (InsideCheck._grid != null)
     {
         InsideCheck._grid.TryGetValue(position, out result);
     }
     return(result);
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 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);
         }
     }
 }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
0
 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);
 }
Ejemplo n.º 8
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;
            }
        }
Ejemplo n.º 9
0
 public static void RemoveRoof(IRoof roof)
 {
     if (InsideCheck._grid != null)
     {
         foreach (KeyValuePair <InsideCheck.GridPosition, InsideCheck.GridCell> keyValuePair in InsideCheck._grid)
         {
             InsideCheck.GridCell value = keyValuePair.Value;
             if (value.roofs != null)
             {
                 for (int i = value.roofs.Count - 1; i >= 0; i--)
                 {
                     if (value.roofs[i] == roof)
                     {
                         value.roofs.RemoveAt(i);
                     }
                 }
                 if (value.roofs.Count == 0)
                 {
                     value.roofs = null;
                 }
             }
         }
     }
 }
Ejemplo n.º 10
0
 public static void RemoveWallChunk(int token)
 {
     if (InsideCheck._grid != null)
     {
         foreach (KeyValuePair <InsideCheck.GridPosition, InsideCheck.GridCell> keyValuePair in InsideCheck._grid)
         {
             InsideCheck.GridCell value = keyValuePair.Value;
             if (value.walls != null)
             {
                 for (int i = value.walls.Count - 1; i >= 0; i--)
                 {
                     if (value.walls[i].token == token)
                     {
                         value.walls.RemoveAt(i);
                     }
                 }
                 if (value.walls.Count == 0)
                 {
                     value.walls = null;
                 }
             }
         }
     }
 }