Tanoda
pb_ObjectUtility.cs
Go to the documentation of this file.
1using UnityEngine;
2using System.Collections;
3
4namespace GILES
5{
6 public static class pb_ObjectUtility
7 {
11 public static GameObject AddChild(this GameObject go)
12 {
13 GameObject child = new GameObject();
14 child.transform.SetParent(go.transform);
15 return child;
16 }
17
21 public static Transform AddChild(this Transform trs)
22 {
23 Transform go = new GameObject().GetComponent<Transform>();
24 go.SetParent(trs);
25 return go;
26 }
27
28 public static float CalcMinDistanceToBounds(Camera cam, Bounds bounds, float scale = 1.0f)
29 {
30 float frustumHeight = Mathf.Max(Mathf.Max(bounds.size.x, bounds.size.y), bounds.size.z) * scale;
31 float distance = frustumHeight * .5f / Mathf.Tan(cam.fieldOfView * .5f * Mathf.Deg2Rad);
32
33 if (/*frustumHeight > 10 &&*/ distance < frustumHeight/2)
34 {
35 distance = frustumHeight * Mathf.Sqrt(2) / Mathf.Tan(cam.fieldOfView * .5f * Mathf.Deg2Rad);
36 }
37
38 return distance;
39 }
40
41 public static void Destroy<T>(T obj) where T : UnityEngine.Object
42 {
43 GameObject.Destroy(obj);
44 }
45
46 public static void Destroy<T>(T[] array) where T : UnityEngine.Object
47 {
48 foreach (var gameObject in array)
49 {
50 Destroy(gameObject);
51 }
52 }
53 }
54}