Exemplo n.º 1
0
 private void Update()
 {
     if (LocalPlayer.Transform)
     {
         Vector3 position = LocalPlayer.Transform.position;
         this._circlePosition.x = position.x;
         this._circlePosition.y = position.z;
         Vector2 vector    = new Vector2(this._gridWorldSize, this._gridWorldSize);
         float   magnitude = vector.magnitude;
         float   num       = this._onRadius + magnitude;
         int     num2      = Mathf.Clamp(this.WorldToGridXRounded(this._circlePosition.x - num), 0, this._gridSize);
         int     num3      = Mathf.Clamp(this.WorldToGridXRounded(this._circlePosition.x + num) + 1, 0, this._gridSize);
         int     num4      = Mathf.Clamp(this.WorldToGridYRounded(this._circlePosition.y - num), 0, this._gridSize);
         int     num5      = Mathf.Clamp(this.WorldToGridYRounded(this._circlePosition.y + num) + 1, 0, this._gridSize);
         this._frameCount++;
         for (int i = num2; i < num3; i++)
         {
             for (int j = num4; j < num5; j++)
             {
                 CullingGrid.Cell cell = this._rendererGrid[i, j];
                 cell._distance = Vector2.Distance(cell._cellCenter, this._circlePosition);
                 bool flag = cell._distance <= num;
                 if (flag)
                 {
                     cell._activeAt = this._frameCount;
                     if (!cell._enabled)
                     {
                         this._activeCells.Add(cell);
                     }
                 }
             }
         }
         foreach (CullingGrid.Cell cell2 in this._activeCells)
         {
             cell2._distance = Vector2.Distance(cell2._cellCenter, this._circlePosition);
         }
         this._activeCells.Sort((CullingGrid.Cell x, CullingGrid.Cell y) => x._distance.CompareTo(y._distance));
         foreach (CullingGrid.Cell cell3 in this._activeCells)
         {
             bool flag2 = cell3._activeAt == this._frameCount;
             if (cell3._enabled != flag2)
             {
                 List <Renderer> renderers = cell3._renderers;
                 int             count     = renderers.Count;
                 for (int k = 0; k < count; k++)
                 {
                     renderers[k].enabled = flag2;
                 }
                 cell3._enabled = flag2;
             }
         }
         this._activeCells.RemoveAll((CullingGrid.Cell c) => !c._enabled);
     }
 }
Exemplo n.º 2
0
        private int RegisterInternal(Renderer r)
        {
            Vector3 position = r.transform.position;
            int     num      = Mathf.Clamp(this.WorldToGridX(position.x), 0, this._gridSize - 1);
            int     num2     = Mathf.Clamp(this.WorldToGridY(position.z), 0, this._gridSize - 1);

            CullingGrid.Cell cell = this._rendererGrid[num, num2];
            cell._renderers.Add(r);
            r.enabled = cell._enabled;
            return(num * this._gridSize + num2);
        }
Exemplo n.º 3
0
 private void Update()
 {
     if (LocalPlayer.Transform)
     {
         float   finalRadius   = this.GetFinalRadius();
         float   circle2Radius = this._circle2Radius;
         float   x             = Mathf.Min(this._circlePosition.x - finalRadius - 1f, this._circle2Position.x - circle2Radius - 1f);
         float   num           = Mathf.Max(this._circlePosition.x + finalRadius + 1f, this._circle2Position.x + circle2Radius + 1f);
         float   y             = Mathf.Min(this._circlePosition.y - finalRadius - 1f, this._circle2Position.y - circle2Radius - 1f);
         float   num2          = Mathf.Max(this._circlePosition.y + finalRadius + 1f, this._circle2Position.y + circle2Radius + 1f);
         Vector2 a             = new Vector2(x, y);
         while (a.x < num)
         {
             a.y = y;
             while (a.y < num2)
             {
                 if (a.x >= 0f && a.x < (float)this._gridSize && a.y >= 0f && a.y < (float)this._gridSize)
                 {
                     bool             flag = Vector2.Distance(a, this._circlePosition) <= finalRadius || Vector2.Distance(a, this._circle2Position) <= circle2Radius;
                     CullingGrid.Cell cell = this._rendererGrid[Mathf.FloorToInt(a.x), Mathf.FloorToInt(a.y)];
                     if (cell._enabled != flag)
                     {
                         bool            enabled   = flag;
                         List <Renderer> renderers = cell._renderers;
                         int             count     = renderers.Count;
                         for (int i = 0; i < count; i++)
                         {
                             renderers[i].enabled = enabled;
                         }
                         cell._enabled = enabled;
                     }
                 }
                 a.y += 1f;
             }
             a.x += 1f;
         }
         this._prevCirclePosition  = this._circlePosition;
         this._prevCircle2Position = this._circle2Position;
         Vector3 from = LocalPlayer.Transform.position + LocalPlayer.Transform.forward * this._circleOffset * (float)this._gridWorldSize;
         this._circlePosition.x = (float)this.WorldToGridXRounded(from.x);
         this._circlePosition.y = (float)this.WorldToGridYRounded(from.z);
         Vector3 a2 = (!Clock.Dark) ? Scene.Atmosphere.Sun.transform.forward : Scene.Atmosphere.Moon.transform.forward;
         a2.y = 0f;
         Vector3 a3     = Vector3.Lerp(from, LocalPlayer.Transform.position, a2.magnitude);
         Vector3 vector = a3 + a2 * this._circle2Offset * (float)this._gridWorldSize;
         this._circle2Position.x = (float)this.WorldToGridXRounded(vector.x);
         this._circle2Position.y = (float)this.WorldToGridYRounded(vector.z);
     }
 }
Exemplo n.º 4
0
 private void OnEnable()
 {
     for (int i = 0; i < this._gridSize; i++)
     {
         for (int j = 0; j < this._gridSize; j++)
         {
             CullingGrid.Cell cell = this._rendererGrid[i, j];
             if (cell._enabled)
             {
                 List <Renderer> renderers = cell._renderers;
                 int             count     = renderers.Count;
                 for (int k = 0; k < count; k++)
                 {
                     renderers[k].enabled = false;
                 }
                 cell._enabled = false;
             }
         }
     }
 }
Exemplo n.º 5
0
 private void Awake()
 {
     if (CullingGrid.Instance != this)
     {
         CullingGrid.Instance = this;
         this._offset         = new Vector2((float)(-(float)this._gridSize / 2) * this._gridWorldSize, (float)(-(float)this._gridSize / 2) * this._gridWorldSize);
         this._rendererGrid   = new CullingGrid.Cell[this._gridSize, this._gridSize];
         for (int i = 0; i < this._gridSize; i++)
         {
             for (int j = 0; j < this._gridSize; j++)
             {
                 CullingGrid.Cell cell = new CullingGrid.Cell();
                 cell._cellCenter         = this.GridCenterToWorld(i, j);
                 this._rendererGrid[i, j] = cell;
             }
         }
         this._activeCells    = new List <CullingGrid.Cell>();
         this._workCells      = new List <CullingGrid.Cell>();
         this._circlePosition = Vector2.zero;
     }
 }