void OnMouseUp() { if (!gravity_mode && save_mode && (save_obj != null)) { Debug.Log("store data!"); StoreData(save_obj); // Delete object data from the previously mapped object if (mapped_obj != null) { DeleteData(mapped_obj); } mapped_obj = save_obj; } else if (gravity_mode && (save_obj != null)) { Debug.Log("save mode set for container"); save_mode = true; colid.isTrigger = false; colid.attachedRigidbody.useGravity = true; } dragging = false; boundbox = save_obj.GetComponentInParent <DimBoxes.BoundBox>(); if (boundbox != null) { boundbox.UnableBox(); } colid.attachedRigidbody.velocity = Vector3.zero; //Debug.Log(colid.attachedRigidbody.velocity); Debug.Log("mouse up!"); }
private void OnTriggerExit(Collider other) { Debug.Log("trigger exit"); if (other.gameObject.tag != "Container" && other.gameObject.tag != "photo_object") { Transform p = other.gameObject.transform.parent; if (p == null || p.gameObject.tag != "Container") { save_mode = false; is_colliding = false; Debug.Log("save mode exit"); if (dragging) { boundbox = other.gameObject.GetComponentInParent <DimBoxes.BoundBox>(); if (boundbox != null) { boundbox.UnableBox(); } } if (mapped_obj != null) { DeleteData(mapped_obj); } mapped_obj = null; } } if (other.gameObject.name == "gravity_field" && gravity_mode == true) { Debug.Log("gravity mode exit"); gravity_mode = false; save_mode = false; colid.isTrigger = true; colid.attachedRigidbody.useGravity = false; is_colliding = false; if (dragging) { boundbox = other.gameObject.GetComponentInParent <DimBoxes.BoundBox>(); if (boundbox != null) { boundbox.UnableBox(); } } if (mapped_obj != null) { DeleteData(mapped_obj); } mapped_obj = null; } }
private void OnMouseDrag() { if (is_colliding) { if (save_obj == null) { save_obj = mapped_obj; } boundbox = save_obj.gameObject.GetComponentInParent <DimBoxes.BoundBox>(); if (boundbox != null) { boundbox.EnableBox(); } } }
// Update is called once per frame void Update() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (dragging) { //ray = Camera.main.ScreenPointToRay(Input.mousePosition); Vector3 rayPoint = ray.GetPoint(distance); transform.position = rayPoint; } // if clicked some object if (Physics.Raycast(ray, out hit_info, layer_mask)) { distance = Vector3.Distance(transform.position, Camera.main.transform.position); dragging = true; if (is_colliding) { boundbox = save_obj.gameObject.GetComponentInParent <DimBoxes.BoundBox>(); if (boundbox != null) { boundbox.EnableBox(); } } } // follow the mapped obj (calculate the coordinates here) if (mapped_obj != null && !dragging) { Vector3 n_pos = mapped_obj.transform.position; if (n_pos != mapped_pos) { obj.transform.position = mapped_obj.transform.position + mapping_vec; } else { Vector3 n_vec = obj.transform.position - mapped_obj.transform.position; if (n_vec != mapping_vec) { Debug.Log("come in mapping distance management"); // move the object toward the mapping object mapping_vec = n_vec; //obj.transform.position = mapped_obj.transform.position + mapping_vec; } } } }
void OnMouseDown() { distance = Vector3.Distance(transform.position, Camera.main.transform.position); dragging = true; if (is_colliding) { if (save_obj == null) { save_obj = mapped_obj; } boundbox = save_obj.gameObject.GetComponentInParent <DimBoxes.BoundBox>(); if (boundbox != null) { boundbox.EnableBox(); } } }
public void Init() { persist_path = Application.persistentDataPath; directory_path = persist_path + "/mapping_data"; obj = this.gameObject; rend = this.gameObject.GetComponent <Renderer>(); colid = this.gameObject.GetComponent <Collider>(); if (!Directory.Exists(directory_path)) { //if it doesn't, create it Directory.CreateDirectory(directory_path); } // occluded by the invisible walls rend.material.renderQueue = 2002; boundbox = FindObjectOfType <DimBoxes.BoundBox>(); layer_mask = ~1 << 2; // ignore the layer 2 ("Ignore Raycast" layer - gravity field) }
// Start is called before the first frame update void Start() { boundBox = GetComponent <BoundBox>(); }