-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathpb_ObjectUtility.cs
More file actions
43 lines (39 loc) · 1.04 KB
/
pb_ObjectUtility.cs
File metadata and controls
43 lines (39 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using UnityEngine;
using System.Collections;
namespace GILES
{
public static class pb_ObjectUtility
{
///<summary>
/// Add an empty gameObject as a child to `go`.
///</summary>
public static GameObject AddChild(this GameObject go)
{
GameObject child = new GameObject();
child.transform.SetParent(go.transform);
return child;
}
///<summary>
/// Add an empty gameObject as a child to `trs`.
///</summary>
public static Transform AddChild(this Transform trs)
{
Transform go = new GameObject().GetComponent<Transform>();
go.SetParent(trs);
return go;
}
///<summary>
///Calculates the min dist. to the bounds.
///</summary>
public static float CalcMinDistanceToBounds(Camera cam, Bounds bounds)
{
float frustumHeight = Mathf.Max(Mathf.Max(bounds.size.x, bounds.size.y), bounds.size.z);
float distance = frustumHeight * .5f / Mathf.Tan(cam.fieldOfView * .5f * Mathf.Deg2Rad);
return distance;
}
public static void Destroy<T>(T obj) where T : UnityEngine.Object
{
GameObject.Destroy(obj);
}
}
}