Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author: Tomoya
- * @created_at: 1/9
- **/
- using UnityEditor;
- using UnityEngine;
- using System.Collections;
- namespace warpPlaces{
- public class SetWarpPlaces : ScriptableWizard{
- [SerializeField] private GameObject plain;
- [SerializeField] private GameObject obj;
- [SerializeField] private string parentName = "WarpPlaces";
- [SerializeField] private string objectName = "warpPlace";
- [SerializeField] private float objectOffset = 0.0f;
- [SerializeField] private float space = 10.0f;
- [SerializeField] private float x1 = -50;
- [SerializeField] private float z1 = -50;
- [SerializeField] private float x2 = 50;
- [SerializeField] private float z2 = 50;
- [SerializeField] private float groundY = 0.0f;
- [SerializeField] private float laserHeight = 20;
- private const float EXPECTED_DOWN = 10.0f;
- private Vector3 coodinate;
- private Vector3 maxCoodinate;
- private Vector3 offsetVec;
- private Vector3 spaceX;
- private Vector3 spaceZ;
- private int incX;
- private int incZ;
- private int loopCntX;
- private int loopCntZ;
- private Quaternion rot;
- private GameObject parentObj;
- private int setCnt = 0;
- [MenuItem("WarpSetter/Launch Wizard!")]
- static void CreateWizard(){
- ScriptableWizard.DisplayWizard<SetWarpPlaces> ("WarpPlaceSetter", "close", "Set warp places!!");
- }
- void OnWizardCreate(){
- Debug.Log ("close");
- }
- void OnWizardUpdate(){
- Debug.Log ("Updated Data!");
- }
- void OnWizardOtherButton(){
- Debug.Log ("Setting objects!");
- init ();
- createParentObj ();
- explore ();
- }
- void init(){
- if (space == 0)
- space = 10;
- incX = (int)((x2 - x1) / System.Math.Abs (x2 - x1));
- incZ = (int)((z2 - z1) / System.Math.Abs (z2 - z1));
- spaceX = new Vector3 (space, 0, 0);
- spaceZ = new Vector3 (0, 0, space);
- offsetVec = new Vector3 (0, objectOffset, 0);
- maxCoodinate = new Vector3 (x2, 0, z2);
- coodinate = new Vector3 (x1, groundY, z1);
- loopCntX = calcLoopCnt (x1, x2);
- loopCntZ = calcLoopCnt (z1, z2);
- Debug.Log (x1 + " " + z1);
- }
- int calcLoopCnt(float start, float end){
- if (System.Math.Abs(start - end) == 0.0f){
- return 0;
- }
- return (int)(System.Math.Floor(System.Math.Abs(start - end))/ space)+ 1;
- }
- void setObj(Vector3 xyz){
- GameObject ins = GameObject.Instantiate (obj, xyz+offsetVec, rot) as GameObject;
- ins.name = objectName + setCnt.ToString ("D7");
- ins.transform.SetParent (parentObj.transform);
- setCnt ++;
- }
- RaycastHit shootRay(Vector3 origin){
- Vector3 direction = new Vector3 (0, -1, 0);
- origin += new Vector3 (0, laserHeight, 0);
- Ray ray = new Ray (origin, direction);
- RaycastHit hit;
- Debug.DrawRay(ray.origin, ray.direction*laserHeight, Color.green, 1);
- if (!Physics.Raycast (ray, out hit, laserHeight + EXPECTED_DOWN)) {
- return hit;
- }
- return hit;
- }
- void createParentObj(){
- parentObj = new GameObject ();
- if (parentName == ""){
- parentName = "WarpPlaces";
- }
- parentObj.name = parentName;
- Undo.RegisterCreatedObjectUndo (parentObj, "Create " + parentObj.name);
- }
- void explore(){
- Debug.Log("Explore!");
- Debug.Log ("coodinate: " + coodinate.x + " " + coodinate.z);
- Debug.Log("target: " + x2 + ", " + z2);
- Vector3 spaceAdderX = new Vector3(0,0,0);
- Vector3 spaceAdderZ = new Vector3 (0, 0, 0);
- for (int idxX=0; idxX < loopCntX; idxX ++) {
- for (int idxZ=0; idxZ < loopCntZ; idxZ ++) {
- RaycastHit hit = shootRay (coodinate + spaceAdderX + spaceAdderZ);
- //TODO: set object
- if (hit.collider.gameObject != null){
- setObj (hit.point);
- }
- //Debug.Log(hit.point.x + " : " + hit.point.z);
- spaceAdderZ += spaceZ*incZ;
- }
- spaceAdderZ *= 0;
- spaceAdderX += spaceX*incX;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment