CMPlacedObjectTypeSO.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [CreateAssetMenu()]
  5. public class CMPlacedObjectTypeSO : ScriptableObject {
  6. public static Dir GetNextDir(Dir dir) {
  7. switch (dir) {
  8. default:
  9. case Dir.Down: return Dir.Left;
  10. case Dir.Left: return Dir.Up;
  11. case Dir.Up: return Dir.Right;
  12. case Dir.Right: return Dir.Down;
  13. }
  14. }
  15. public enum Dir {
  16. Down,
  17. Left,
  18. Up,
  19. Right,
  20. }
  21. public string nameString;
  22. public Transform prefab;
  23. public Transform visual;
  24. public int width;
  25. public int height;
  26. public int GetRotationAngle(Dir dir) {
  27. switch (dir) {
  28. default:
  29. case Dir.Down: return 0;
  30. case Dir.Left: return 90;
  31. case Dir.Up: return 180;
  32. case Dir.Right: return 270;
  33. }
  34. }
  35. public Vector2Int GetRotationOffset(Dir dir) {
  36. switch (dir) {
  37. default:
  38. case Dir.Down: return new Vector2Int(0, 0);
  39. case Dir.Left: return new Vector2Int(0, width);
  40. case Dir.Up: return new Vector2Int(width, height);
  41. case Dir.Right: return new Vector2Int(height, 0);
  42. }
  43. }
  44. public List<Vector2Int> GetGridPositionList(Vector2Int offset, Dir dir) {
  45. List<Vector2Int> gridPositionList = new List<Vector2Int>();
  46. switch (dir) {
  47. default:
  48. case Dir.Down:
  49. case Dir.Up:
  50. for (int x = 0; x < width; x++) {
  51. for (int y = 0; y < height; y++) {
  52. gridPositionList.Add(offset + new Vector2Int(x, y));
  53. }
  54. }
  55. break;
  56. case Dir.Left:
  57. case Dir.Right:
  58. for (int x = 0; x < height; x++) {
  59. for (int y = 0; y < width; y++) {
  60. gridPositionList.Add(offset + new Vector2Int(x, y));
  61. }
  62. }
  63. break;
  64. }
  65. return gridPositionList;
  66. }
  67. }