/// <summary> /// 根据centerAndSize添加包围盒 /// </summary> public static BoxCollider AddBoxCollider(GameObject obj) { Vector3 pos = obj.transform.position; obj.transform.position = Vector3.zero; BoxCollider boxCollider = obj.GetComponent <BoxCollider>(); if (boxCollider == null) { boxCollider = obj.AddComponent <BoxCollider>(); CenterAndSize cs = CenterAndSizeUtil.Get(obj.transform); boxCollider.center = cs.Center; boxCollider.size = cs.Size; Debug.Log(obj.name + "-" + boxCollider.center + "-" + boxCollider.size); } obj.transform.position = pos; return(boxCollider); }
public void Catch(Transform t) { Debug.Log("Catch"); Vector3 euler = transform.localEulerAngles; transform.localEulerAngles = Vector3.zero; ClearTarget(); t.SetParent(target); t.localPosition = Vector3.zero; t.localEulerAngles = Vector3.zero; target.localPosition = Vector3.zero; CenterAndSize targetCS = CenterAndSizeUtil.Get(target); CenterAndSize modelCS = CenterAndSizeUtil.Get(model); float offsetZ = (targetCS.Size.z + modelCS.Size.z) / 2; t.localPosition += Vector3.forward * offsetZ; float offsetY = targetCS.Size.y / 2 - targetCS.Center.y; t.localPosition += Vector3.up * offsetY; transform.localEulerAngles = euler; }