Guest User

Untitled

a guest
Jan 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. /**
  2. * @author: Tomoya
  3. * @created_at: 1/9
  4. **/
  5.  
  6. using UnityEditor;
  7. using UnityEngine;
  8. using System.Collections;
  9.  
  10. namespace warpPlaces{
  11. public class SetWarpPlaces : ScriptableWizard{
  12. [SerializeField] private GameObject plain;
  13. [SerializeField] private GameObject obj;
  14. [SerializeField] private string parentName = "WarpPlaces";
  15. [SerializeField] private string objectName = "warpPlace";
  16. [SerializeField] private float objectOffset = 0.0f;
  17. [SerializeField] private float space = 10.0f;
  18. [SerializeField] private float x1 = -50;
  19. [SerializeField] private float z1 = -50;
  20. [SerializeField] private float x2 = 50;
  21. [SerializeField] private float z2 = 50;
  22. [SerializeField] private float groundY = 0.0f;
  23. [SerializeField] private float laserHeight = 20;
  24.  
  25. private const float EXPECTED_DOWN = 10.0f;
  26. private Vector3 coodinate;
  27. private Vector3 maxCoodinate;
  28. private Vector3 offsetVec;
  29. private Vector3 spaceX;
  30. private Vector3 spaceZ;
  31. private int incX;
  32. private int incZ;
  33. private int loopCntX;
  34. private int loopCntZ;
  35. private Quaternion rot;
  36. private GameObject parentObj;
  37. private int setCnt = 0;
  38.  
  39. [MenuItem("WarpSetter/Launch Wizard!")]
  40. static void CreateWizard(){
  41. ScriptableWizard.DisplayWizard<SetWarpPlaces> ("WarpPlaceSetter", "close", "Set warp places!!");
  42. }
  43.  
  44. void OnWizardCreate(){
  45. Debug.Log ("close");
  46. }
  47.  
  48. void OnWizardUpdate(){
  49. Debug.Log ("Updated Data!");
  50. }
  51.  
  52. void OnWizardOtherButton(){
  53. Debug.Log ("Setting objects!");
  54. init ();
  55. createParentObj ();
  56. explore ();
  57. }
  58.  
  59. void init(){
  60. if (space == 0)
  61. space = 10;
  62. incX = (int)((x2 - x1) / System.Math.Abs (x2 - x1));
  63. incZ = (int)((z2 - z1) / System.Math.Abs (z2 - z1));
  64. spaceX = new Vector3 (space, 0, 0);
  65. spaceZ = new Vector3 (0, 0, space);
  66. offsetVec = new Vector3 (0, objectOffset, 0);
  67. maxCoodinate = new Vector3 (x2, 0, z2);
  68. coodinate = new Vector3 (x1, groundY, z1);
  69. loopCntX = calcLoopCnt (x1, x2);
  70. loopCntZ = calcLoopCnt (z1, z2);
  71. Debug.Log (x1 + " " + z1);
  72. }
  73.  
  74. int calcLoopCnt(float start, float end){
  75. if (System.Math.Abs(start - end) == 0.0f){
  76. return 0;
  77. }
  78. return (int)(System.Math.Floor(System.Math.Abs(start - end))/ space)+ 1;
  79. }
  80.  
  81. void setObj(Vector3 xyz){
  82. GameObject ins = GameObject.Instantiate (obj, xyz+offsetVec, rot) as GameObject;
  83. ins.name = objectName + setCnt.ToString ("D7");
  84. ins.transform.SetParent (parentObj.transform);
  85. setCnt ++;
  86. }
  87.  
  88. RaycastHit shootRay(Vector3 origin){
  89. Vector3 direction = new Vector3 (0, -1, 0);
  90. origin += new Vector3 (0, laserHeight, 0);
  91. Ray ray = new Ray (origin, direction);
  92. RaycastHit hit;
  93. Debug.DrawRay(ray.origin, ray.direction*laserHeight, Color.green, 1);
  94. if (!Physics.Raycast (ray, out hit, laserHeight + EXPECTED_DOWN)) {
  95. return hit;
  96. }
  97. return hit;
  98. }
  99.  
  100. void createParentObj(){
  101. parentObj = new GameObject ();
  102. if (parentName == ""){
  103. parentName = "WarpPlaces";
  104. }
  105. parentObj.name = parentName;
  106. Undo.RegisterCreatedObjectUndo (parentObj, "Create " + parentObj.name);
  107. }
  108.  
  109. void explore(){
  110. Debug.Log("Explore!");
  111. Debug.Log ("coodinate: " + coodinate.x + " " + coodinate.z);
  112. Debug.Log("target: " + x2 + ", " + z2);
  113. Vector3 spaceAdderX = new Vector3(0,0,0);
  114. Vector3 spaceAdderZ = new Vector3 (0, 0, 0);
  115.  
  116. for (int idxX=0; idxX < loopCntX; idxX ++) {
  117. for (int idxZ=0; idxZ < loopCntZ; idxZ ++) {
  118. RaycastHit hit = shootRay (coodinate + spaceAdderX + spaceAdderZ);
  119. //TODO: set object
  120. if (hit.collider.gameObject != null){
  121. setObj (hit.point);
  122. }
  123. //Debug.Log(hit.point.x + " : " + hit.point.z);
  124. spaceAdderZ += spaceZ*incZ;
  125. }
  126. spaceAdderZ *= 0;
  127. spaceAdderX += spaceX*incX;
  128. }
  129.  
  130. }
  131.  
  132. }
  133. }
Add Comment
Please, Sign In to add comment