public void HideAllGizmos() { aGizmo G = gameObject.GetComponentInChildren <aGizmo>(); if (G == null) { return; } G.OnGizmoMoved -= G_OnGizmoMoved; G.transform.SetParent(null); GameObject.Destroy(G.gameObject); }
public void ShowGizmo(string Gz) { HideAllGizmos(); if (PlayerManager.Type != "BuilderPlayer") { return; } UnityEngine.Object objGizmo = Resources.Load("Prefabs/Gizmos/Gizmo" + Gz); GameObject Gizmo = (GameObject)Object.Instantiate(objGizmo, Vector3.zero, Quaternion.identity); Gizmo.name = "Gizmo" + Gz; Gizmo.transform.SetParent(gameObject.transform); if (Gz == "Rotate" || Gz == "Scale") { Gizmo.transform.rotation = gameObject.transform.rotation; } if (Gz == "Scale") { Gizmo.transform.localScale = VectGeom.Reciprocal(gameObject.transform.localScale); } aGizmo G = Gizmo.GetComponent <aGizmo>(); G.OnGizmoMoved += G_OnGizmoMoved; G.AttachedTransform = gameObject.transform; G.AttachedObject = this; //this version puts the gizmo wherever you clicked on the collider RaycastHit Hit; FPCam = GameObject.Find("BuilderCamera").GetComponent <Camera>(); Ray R = FPCam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(R, out Hit) && Hit.collider.transform.parent == gameObject.transform) //if clicked on this object { //put the gizmo where you clicked Gizmo.transform.position = Hit.point; } else { Collider TopC = gameObject.GetComponentsInChildren <Collider>().OrderBy(c => c.enabled == false ? -1000 : c.transform.position.y + c.bounds.max.y).LastOrDefault(); Gizmo.transform.position = TopC.transform.position + new Vector3(0, TopC.bounds.extents.y, 0); } if (Gz == "Move" || Gz == "Scale") { Gizmo.transform.position += Vector3.up * 2; } G.SetHoverPos(Gizmo.transform.position - gameObject.transform.position); }