-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRCC_CameraConfig.cs
More file actions
85 lines (62 loc) · 1.78 KB
/
RCC_CameraConfig.cs
File metadata and controls
85 lines (62 loc) · 1.78 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//----------------------------------------------
// Realistic Car Controller
//
// Copyright © 2014 - 2017 BoneCracker Games
// http://www.bonecrackergames.com
// Buğra Özdoğanlar
//
//----------------------------------------------
using UnityEngine;
using System.Collections;
/// <summary>
/// Sets new camera settings to RCC Camera per vehicle.
/// </summary>
[AddComponentMenu("BoneCracker Games/Realistic Car Controller/Camera/RCC Camera Config")]
public class RCC_CameraConfig : MonoBehaviour {
public bool automatic = true;
private Bounds combinedBounds;
public float distance = 10f;
public float height = 5f;
void OnEnable(){
if(automatic){
Quaternion orgRotation = transform.rotation;
transform.rotation = Quaternion.identity;
distance = MaxBoundsExtent(transform) * 2.75f;
height = MaxBoundsExtent(transform) * .6f;
if (height < 1)
height = 1;
transform.rotation = orgRotation;
}
}
public void SetCameraSettings () {
RCC_Camera cam = RCC_SceneManager.Instance.activePlayerCamera;
if(!cam)
return;
cam.TPSDistance = distance;
cam.TPSHeight = height;
}
public static float MaxBoundsExtent(Transform obj){
// get the maximum bounds extent of object, including all child renderers,
// but excluding particles and trails, for FOV zooming effect.
var renderers = obj.GetComponentsInChildren<Renderer>();
Bounds bounds = new Bounds();
bool initBounds = false;
foreach (Renderer r in renderers)
{
if (!((r is TrailRenderer) || (r is ParticleSystemRenderer)))
{
if (!initBounds)
{
initBounds = true;
bounds = r.bounds;
}
else
{
bounds.Encapsulate(r.bounds);
}
}
}
float max = Mathf.Max(bounds.extents.x, bounds.extents.y, bounds.extents.z);
return max;
}
}