Exemple #1
0
    private void DrawGrid(Vector3 center, float sizeX, float sizeY)
    {
        Vector3 vector3  = base.transform.right * (sizeX / 2f);
        Vector3 vector31 = base.transform.forward * (sizeY / 2f);

        CullGrid.DrawQuadRayCastDown((center + vector3) + vector31, (center + vector3) - vector31, (center - vector3) - vector31, (center - vector3) + vector31);
    }
Exemple #2
0
    private void DrawGrid(Vector3 center)
    {
        Vector3 vector3  = base.transform.right * ((float)this.setup.cellSquareDimension / 2f);
        Vector3 vector31 = base.transform.forward * ((float)this.setup.cellSquareDimension / 2f);

        CullGrid.DrawQuadRayCastDown((center + vector3) + vector31, (center + vector3) - vector31, (center - vector3) - vector31, (center - vector3) + vector31);
    }
Exemple #3
0
 private static void RegisterGrid(CullGrid grid)
 {
     if (grid != null)
     {
         CullGrid.grid = new CullGridRuntime(grid);
         has_grid      = true;
     }
 }
Exemple #4
0
    public static ushort CellFromGroupID(int groupID, out ushort x, out ushort y)
    {
        ushort num = CullGrid.CellFromGroupID(groupID);

        x = (ushort)(num % CullGrid.grid.cellsWide);
        y = (ushort)(num / CullGrid.grid.cellsWide);
        return(num);
    }
Exemple #5
0
 private static void DrawQuadRayCastDown(Vector3 a, Vector3 b, Vector3 c, Vector3 d)
 {
     CullGrid.RaycastDownVect(ref a);
     CullGrid.RaycastDownVect(ref b);
     CullGrid.RaycastDownVect(ref c);
     CullGrid.RaycastDownVect(ref d);
     Gizmos.DrawLine(a, b);
     Gizmos.DrawLine(b, c);
     Gizmos.DrawLine(c, d);
     Gizmos.DrawLine(d, a);
     if (a.y > c.y)
     {
         if (b.y > d.y)
         {
             if (b.y - d.y <= a.y - c.y)
             {
                 Gizmos.DrawLine(a, c);
             }
             else
             {
                 Gizmos.DrawLine(b, d);
             }
         }
         else if (d.y - b.y <= a.y - c.y)
         {
             Gizmos.DrawLine(a, c);
         }
         else
         {
             Gizmos.DrawLine(d, b);
         }
     }
     else if (b.y > d.y)
     {
         if (b.y - d.y <= c.y - a.y)
         {
             Gizmos.DrawLine(c, a);
         }
         else
         {
             Gizmos.DrawLine(b, d);
         }
     }
     else if (d.y - b.y <= c.y - a.y)
     {
         Gizmos.DrawLine(c, a);
     }
     else
     {
         Gizmos.DrawLine(d, b);
     }
 }
Exemple #6
0
    private void uLink_OnNetworkInstantiate(uLink.NetworkMessageInfo info)
    {
        ushort num;
        ushort num2;

        uLink.NetworkView networkView = info.networkView;
        this.groupID = (int)info.networkView.group;
        this.center  = CullGrid.Flat(networkView.position);
        this.size    = networkView.position.y;
        this.extent  = this.size / 2f;
        CullGrid.CellFromGroupID(this.groupID, out num, out num2);
        base.name = string.Format("GRID-CELL:{0:00000}-[{1},{2}]", this.groupID, num, num2);
        this.y_mc = HeightCast(this.center);
        this.y_xy = HeightCast(new Vector2(this.center.x - this.extent, this.center.y - this.extent));
        this.y_XY = HeightCast(new Vector2(this.center.x + this.extent, this.center.y + this.extent));
        this.y_Xy = HeightCast(new Vector2(this.center.x + this.extent, this.center.y - this.extent));
        this.y_xY = HeightCast(new Vector2(this.center.x - this.extent, this.center.y + this.extent));
        this.y_xc = HeightCast(new Vector2(this.center.x - this.extent, this.center.y));
        this.y_Xc = HeightCast(new Vector2(this.center.x + this.extent, this.center.y));
        this.y_my = HeightCast(new Vector2(this.center.x, this.center.y - this.extent));
        this.y_mY = HeightCast(new Vector2(this.center.x, this.center.y + this.extent));
        base.transform.position = new Vector3(this.center.x, this.y_mc, this.center.y);
        float[] values = new float[] { this.y_xy, this.y_XY, this.y_Xy, this.y_xY, this.y_xc, this.y_Xc, this.y_my, this.y_mY, this.y_mc };
        float   num3   = Mathf.Min(values);

        float[] singleArray2 = new float[] { this.y_xy, this.y_XY, this.y_Xy, this.y_xY, this.y_xc, this.y_Xc, this.y_my, this.y_mY, this.y_mc };
        float   y            = Mathf.Max(singleArray2) - num3;

        this.bounds = new Bounds(new Vector3(this.center.x, num3 + (y * 0.5f), this.center.y), new Vector3(this.size, y, this.size));
        Transform transform = base.transform;

        this.t_xy          = transform.FindChild("BL");
        this.t_XY          = transform.FindChild("FR");
        this.t_Xy          = transform.FindChild("BR");
        this.t_xY          = transform.FindChild("FL");
        this.t_xc          = transform.FindChild("ML");
        this.t_Xc          = transform.FindChild("MR");
        this.t_my          = transform.FindChild("BC");
        this.t_mY          = transform.FindChild("FC");
        this.t_mc          = transform.FindChild("MC");
        this.t_xy.position = new Vector3(this.center.x - this.extent, this.y_xy, this.center.y - this.extent);
        this.t_XY.position = new Vector3(this.center.x + this.extent, this.y_XY, this.center.y + this.extent);
        this.t_Xy.position = new Vector3(this.center.x + this.extent, this.y_Xy, this.center.y - this.extent);
        this.t_xY.position = new Vector3(this.center.x - this.extent, this.y_xY, this.center.y + this.extent);
        this.t_xc.position = new Vector3(this.center.x - this.extent, this.y_xc, this.center.y);
        this.t_Xc.position = new Vector3(this.center.x + this.extent, this.y_Xc, this.center.y);
        this.t_my.position = new Vector3(this.center.x, this.y_my, this.center.y - this.extent);
        this.t_mY.position = new Vector3(this.center.x, this.y_mY, this.center.y + this.extent);
        this.t_mc.position = new Vector3(this.center.x, this.y_mc, this.center.y);
        transform.gameObject.GetComponentInChildren <SkinnedMeshRenderer>().localBounds = new Bounds(new Vector3(0f, this.y_mc - (num3 + (y * 0.5f)), 0f), new Vector3(this.size, y, this.size));
    }
Exemple #7
0
        public CullGridRuntime(CullGrid cullGrid) : base(cullGrid.setup)
        {
            this.cullGrid            = cullGrid;
            this.transform           = cullGrid.transform;
            this.halfCellTall        = (double)this.cellsTall / 2;
            this.halfCellWide        = (double)this.cellsWide / 2;
            this.twoMinusOddTall     = 2 - (this.cellsTall & 1);
            this.twoMinusOddWide     = 2 - (this.cellsWide & 1);
            this.halfTwoMinusOddTall = (double)this.twoMinusOddTall / 2;
            this.halfTwoMinusOddWide = this.halfTwoMinusOddWide / 2;
            this.halfCellTallMinusHalfTwoMinusOddTall = this.halfCellTall - this.halfTwoMinusOddTall;
            this.halfCellWideMinusHalfTwoMinusOddWide = this.halfCellWide - this.halfTwoMinusOddWide;
            Vector3 vector3  = this.transform.forward;
            Vector3 vector31 = this.transform.right;
            Vector3 vector32 = this.transform.position;

            this.fx = (double)vector3.x;
            this.fy = (double)vector3.y;
            this.fz = (double)vector3.z;
            double num = Math.Sqrt(this.fx * this.fx + this.fy * this.fy + this.fz * this.fz);

            CullGrid.CullGridRuntime cullGridRuntime = this;
            cullGridRuntime.fx = cullGridRuntime.fx / num;
            CullGrid.CullGridRuntime cullGridRuntime1 = this;
            cullGridRuntime1.fy = cullGridRuntime1.fy / num;
            CullGrid.CullGridRuntime cullGridRuntime2 = this;
            cullGridRuntime2.fz = cullGridRuntime2.fz / num;
            this.rx             = (double)vector31.x;
            this.ry             = (double)vector31.y;
            this.rz             = (double)vector31.z;
            num = Math.Sqrt(this.rx * this.rx + this.ry * this.ry + this.rz * this.rz);
            CullGrid.CullGridRuntime cullGridRuntime3 = this;
            cullGridRuntime3.rx = cullGridRuntime3.rx / num;
            CullGrid.CullGridRuntime cullGridRuntime4 = this;
            cullGridRuntime4.ry = cullGridRuntime4.ry / num;
            CullGrid.CullGridRuntime cullGridRuntime5 = this;
            cullGridRuntime5.rz = cullGridRuntime5.rz / num;
            this.px             = (double)vector32.x;
            this.py             = (double)vector32.y;
            this.pz             = (double)vector32.z;
            this.flat_wide_ofs  = (double)this.cellSquareDimension * (this.halfCellWide - (double)(1 - (this.cellsWide & 1)) / 2);
            this.flat_tall_ofs  = (double)this.cellSquareDimension * (this.halfCellTall - (double)(1 - (this.cellsTall & 1)) / 2);
            this.cellTallLast   = (ushort)(this.cellsTall - 1);
            this.cellWideLast   = (ushort)(this.cellsWide - 1);
            this.cellTallLastTimesSquareDimension = (double)this.cellTallLast * (double)this.cellSquareDimension;
            this.cellWideLastTimesSquareDimension = (double)this.cellWideLast * (double)this.cellSquareDimension;
            this.numCells = this.cellsTall * this.cellsWide;
            this.groupEnd = this.groupBegin + this.numCells;
        }
Exemple #8
0
    private void uLink_OnNetworkInstantiate(uLink.NetworkMessageInfo info)
    {
        ushort num;
        ushort num1;

        uLink.NetworkView networkView = info.networkView;
        this.groupID = info.networkView.@group;
        this.center  = CullGrid.Flat(networkView.position);
        this.size    = networkView.position.y;
        this.extent  = this.size / 2f;
        CullGrid.CellFromGroupID(this.groupID, out num, out num1);
        base.name = string.Format("GRID-CELL:{0:00000}-[{1},{2}]", this.groupID, num, num1);
        this.y_mc = CullCell.HeightCast(this.center);
        this.y_xy = CullCell.HeightCast(new Vector2(this.center.x - this.extent, this.center.y - this.extent));
        this.y_XY = CullCell.HeightCast(new Vector2(this.center.x + this.extent, this.center.y + this.extent));
        this.y_Xy = CullCell.HeightCast(new Vector2(this.center.x + this.extent, this.center.y - this.extent));
        this.y_xY = CullCell.HeightCast(new Vector2(this.center.x - this.extent, this.center.y + this.extent));
        this.y_xc = CullCell.HeightCast(new Vector2(this.center.x - this.extent, this.center.y));
        this.y_Xc = CullCell.HeightCast(new Vector2(this.center.x + this.extent, this.center.y));
        this.y_my = CullCell.HeightCast(new Vector2(this.center.x, this.center.y - this.extent));
        this.y_mY = CullCell.HeightCast(new Vector2(this.center.x, this.center.y + this.extent));
        base.transform.position = new Vector3(this.center.x, this.y_mc, this.center.y);
        float single  = Mathf.Min(new float[] { this.y_xy, this.y_XY, this.y_Xy, this.y_xY, this.y_xc, this.y_Xc, this.y_my, this.y_mY, this.y_mc });
        float single1 = Mathf.Max(new float[] { this.y_xy, this.y_XY, this.y_Xy, this.y_xY, this.y_xc, this.y_Xc, this.y_my, this.y_mY, this.y_mc }) - single;

        this.bounds = new Bounds(new Vector3(this.center.x, single + single1 * 0.5f, this.center.y), new Vector3(this.size, single1, this.size));
        Transform bound = base.transform;

        this.t_xy          = bound.FindChild("BL");
        this.t_XY          = bound.FindChild("FR");
        this.t_Xy          = bound.FindChild("BR");
        this.t_xY          = bound.FindChild("FL");
        this.t_xc          = bound.FindChild("ML");
        this.t_Xc          = bound.FindChild("MR");
        this.t_my          = bound.FindChild("BC");
        this.t_mY          = bound.FindChild("FC");
        this.t_mc          = bound.FindChild("MC");
        this.t_xy.position = new Vector3(this.center.x - this.extent, this.y_xy, this.center.y - this.extent);
        this.t_XY.position = new Vector3(this.center.x + this.extent, this.y_XY, this.center.y + this.extent);
        this.t_Xy.position = new Vector3(this.center.x + this.extent, this.y_Xy, this.center.y - this.extent);
        this.t_xY.position = new Vector3(this.center.x - this.extent, this.y_xY, this.center.y + this.extent);
        this.t_xc.position = new Vector3(this.center.x - this.extent, this.y_xc, this.center.y);
        this.t_Xc.position = new Vector3(this.center.x + this.extent, this.y_Xc, this.center.y);
        this.t_my.position = new Vector3(this.center.x, this.y_my, this.center.y - this.extent);
        this.t_mY.position = new Vector3(this.center.x, this.y_mY, this.center.y + this.extent);
        this.t_mc.position = new Vector3(this.center.x, this.y_mc, this.center.y);
        bound.gameObject.GetComponentInChildren <SkinnedMeshRenderer>().localBounds = new Bounds(new Vector3(0f, this.y_mc - (single + single1 * 0.5f), 0f), new Vector3(this.size, single1, this.size));
    }
Exemple #9
0
    public static bool GroupIDContainsPoint(int groupID, ref Vector3 worldPoint, out int groupID_point)
    {
        ushort num;

        if (groupID < CullGrid.grid.groupBegin || groupID >= CullGrid.grid.groupEnd)
        {
            groupID_point = NetworkGroup.unassigned.id;
            return(false);
        }
        if (CullGrid.CellContainsPoint(CullGrid.CellFromGroupID(groupID), ref worldPoint, out num))
        {
            groupID_point = groupID;
            return(true);
        }
        groupID_point = CullGrid.GroupIDFromCell(num);
        return(false);
    }
Exemple #10
0
    public static bool GroupIDContainsPoint(int groupID, ref Vector2 flatPoint, out int groupID_point)
    {
        ushort num;

        if (groupID < CullGrid.grid.groupBegin || groupID >= CullGrid.grid.groupEnd)
        {
            groupID_point = NetworkGroup.unassigned.id;
            return(false);
        }
        if (CullGrid.CellContainsPoint((ushort)(groupID - CullGrid.grid.groupBegin), ref flatPoint, out num))
        {
            groupID_point = groupID;
            return(true);
        }
        groupID_point = num + CullGrid.grid.groupBegin;
        return(false);
    }
Exemple #11
0
        public CullGridRuntime(CullGrid cullGrid) : base(cullGrid.setup)
        {
            this.cullGrid             = cullGrid;
            this.transform            = cullGrid.transform;
            this.halfCellTall         = ((double)base.cellsTall) / 2.0;
            this.halfCellWide         = ((double)base.cellsWide) / 2.0;
            this.twoMinusOddTall      = 2 - (base.cellsTall & 1);
            this.twoMinusOddWide      = 2 - (base.cellsWide & 1);
            this.halfTwoMinusOddTall  = ((double)this.twoMinusOddTall) / 2.0;
            this.halfTwoMinusOddWide /= 2.0;
            this.halfCellTallMinusHalfTwoMinusOddTall = this.halfCellTall - this.halfTwoMinusOddTall;
            this.halfCellWideMinusHalfTwoMinusOddWide = this.halfCellWide - this.halfTwoMinusOddWide;
            Vector3 forward  = this.transform.forward;
            Vector3 right    = this.transform.right;
            Vector3 position = this.transform.position;

            this.fx = forward.x;
            this.fy = forward.y;
            this.fz = forward.z;
            double num = Math.Sqrt(((this.fx * this.fx) + (this.fy * this.fy)) + (this.fz * this.fz));

            this.fx           /= num;
            this.fy           /= num;
            this.fz           /= num;
            this.rx            = right.x;
            this.ry            = right.y;
            this.rz            = right.z;
            num                = Math.Sqrt(((this.rx * this.rx) + (this.ry * this.ry)) + (this.rz * this.rz));
            this.rx           /= num;
            this.ry           /= num;
            this.rz           /= num;
            this.px            = position.x;
            this.py            = position.y;
            this.pz            = position.z;
            this.flat_wide_ofs = base.cellSquareDimension * (this.halfCellWide - (((double)(1 - (base.cellsWide & 1))) / 2.0));
            this.flat_tall_ofs = base.cellSquareDimension * (this.halfCellTall - (((double)(1 - (base.cellsTall & 1))) / 2.0));
            this.cellTallLast  = (ushort)(base.cellsTall - 1);
            this.cellWideLast  = (ushort)(base.cellsWide - 1);
            this.cellTallLastTimesSquareDimension = this.cellTallLast * base.cellSquareDimension;
            this.cellWideLastTimesSquareDimension = this.cellWideLast * base.cellSquareDimension;
            this.numCells = base.cellsTall * base.cellsWide;
            this.groupEnd = base.groupBegin + this.numCells;
        }
Exemple #12
0
 private void Awake()
 {
     CullGrid.RegisterGrid(this);
 }
Exemple #13
0
 public static bool IsCellGroup(NetworkGroup group)
 {
     return(CullGrid.IsCellGroupID(group.id));
 }
Exemple #14
0
 public static bool GroupIDContainsPoint(int groupID, ref Vector3 worldPoint)
 {
     return(groupID < CullGrid.grid.groupBegin || groupID >= CullGrid.grid.groupEnd ? false : CullGrid.CellContainsPoint((ushort)(groupID - CullGrid.grid.groupBegin), ref worldPoint));
 }
Exemple #15
0
 public CullGridRuntime(CullGrid cullGrid)
     : base(cullGrid.setup)
 {
     this.cullGrid = cullGrid;
     this.transform = cullGrid.transform;
     this.halfCellTall = (double)this.cellsTall / 2;
     this.halfCellWide = (double)this.cellsWide / 2;
     this.twoMinusOddTall = 2 - (this.cellsTall & 1);
     this.twoMinusOddWide = 2 - (this.cellsWide & 1);
     this.halfTwoMinusOddTall = (double)this.twoMinusOddTall / 2;
     this.halfTwoMinusOddWide = this.halfTwoMinusOddWide / 2;
     this.halfCellTallMinusHalfTwoMinusOddTall = this.halfCellTall - this.halfTwoMinusOddTall;
     this.halfCellWideMinusHalfTwoMinusOddWide = this.halfCellWide - this.halfTwoMinusOddWide;
     Vector3 vector3 = this.transform.forward;
     Vector3 vector31 = this.transform.right;
     Vector3 vector32 = this.transform.position;
     this.fx = (double)vector3.x;
     this.fy = (double)vector3.y;
     this.fz = (double)vector3.z;
     double num = Math.Sqrt(this.fx * this.fx + this.fy * this.fy + this.fz * this.fz);
     CullGrid.CullGridRuntime cullGridRuntime = this;
     cullGridRuntime.fx = cullGridRuntime.fx / num;
     CullGrid.CullGridRuntime cullGridRuntime1 = this;
     cullGridRuntime1.fy = cullGridRuntime1.fy / num;
     CullGrid.CullGridRuntime cullGridRuntime2 = this;
     cullGridRuntime2.fz = cullGridRuntime2.fz / num;
     this.rx = (double)vector31.x;
     this.ry = (double)vector31.y;
     this.rz = (double)vector31.z;
     num = Math.Sqrt(this.rx * this.rx + this.ry * this.ry + this.rz * this.rz);
     CullGrid.CullGridRuntime cullGridRuntime3 = this;
     cullGridRuntime3.rx = cullGridRuntime3.rx / num;
     CullGrid.CullGridRuntime cullGridRuntime4 = this;
     cullGridRuntime4.ry = cullGridRuntime4.ry / num;
     CullGrid.CullGridRuntime cullGridRuntime5 = this;
     cullGridRuntime5.rz = cullGridRuntime5.rz / num;
     this.px = (double)vector32.x;
     this.py = (double)vector32.y;
     this.pz = (double)vector32.z;
     this.flat_wide_ofs = (double)this.cellSquareDimension * (this.halfCellWide - (double)(1 - (this.cellsWide & 1)) / 2);
     this.flat_tall_ofs = (double)this.cellSquareDimension * (this.halfCellTall - (double)(1 - (this.cellsTall & 1)) / 2);
     this.cellTallLast = (ushort)(this.cellsTall - 1);
     this.cellWideLast = (ushort)(this.cellsWide - 1);
     this.cellTallLastTimesSquareDimension = (double)this.cellTallLast * (double)this.cellSquareDimension;
     this.cellWideLastTimesSquareDimension = (double)this.cellWideLast * (double)this.cellSquareDimension;
     this.numCells = this.cellsTall * this.cellsWide;
     this.groupEnd = this.groupBegin + this.numCells;
 }
Exemple #16
0
 private static void RegisterGrid(CullGrid grid)
 {
     if (grid)
     {
         CullGrid.grid = new CullGrid.CullGridRuntime(grid);
         CullGrid.has_grid = true;
     }
 }