Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1.         float count = _board.Reinforcements.Count + 1;
  2.         int i = 1;
  3.         float scale = 2;
  4.         foreach (Piece ri in _board.Reinforcements)
  5.         {
  6.             // create new reinforcements
  7.             GameObject s = PieceView.CreatePiece((dynamic)ri);
  8.  
  9.             // place in Reinforcment panel
  10.             Vector3[] v = new Vector3[4];
  11.             ReinforcementsPanel.GetWorldCorners(v);
  12.             Vector3 bottomLeft = Camera.main.ScreenToWorldPoint(v[0]);
  13.             Vector3 topRight = Camera.main.ScreenToWorldPoint(v[2]);
  14.             float x0 = bottomLeft.x;
  15.             float x1 = topRight.x;
  16.             float y0 = bottomLeft.y;
  17.             float y1 = topRight.y;
  18.             float panelWidth = x1 - x0;
  19.             float panelHeight = y1 - y0;
  20.             Vector3 rect = s.GetComponent<SpriteRenderer>().bounds.size;
  21.             float shipWidth = rect.x*scale;
  22.             float shipHeight = rect.y*scale;
  23.             float x = bottomLeft.x;
  24.             switch (ri.ReinforcementDelay)
  25.             {
  26.                 case 0:
  27.                     x += shipWidth / 2.0f;
  28.                     break;
  29.                 case 1:
  30.                     x += panelWidth / 2.0f;
  31.                     break;
  32.                 case 2:
  33.                     x += panelWidth - shipWidth / 2.0f;
  34.                     break;
  35.             }
  36.             float y = panelHeight * ((float)(i++)) / count + bottomLeft.y;
  37.             s.transform.localPosition = new Vector3(x, y, 0);
  38.             s.transform.localScale = new Vector3(scale, scale, 1);
  39.             s.transform.parent = ReinforcementsPanel.transform;
  40.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement