forked from Blightbuster/The-Forest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AfsBillboardBoundingBox_180.cs
90 lines (65 loc) · 2.15 KB
/
AfsBillboardBoundingBox_180.cs
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
86
87
88
89
90
using System;
using UnityEngine;
[ExecuteInEditMode]
public class AfsBillboardBoundingBox_180 : MonoBehaviour
{
private void Awake()
{
this.SetBounds();
this.SetStippling();
}
private void CheckInstance()
{
if (!this.instatiated)
{
Mesh sharedMesh = base.GetComponent<MeshFilter>().sharedMesh;
Mesh sharedMesh2 = UnityEngine.Object.Instantiate<Mesh>(sharedMesh);
base.GetComponent<MeshFilter>().sharedMesh = sharedMesh2;
this.instatiated = true;
}
}
private void SetBounds()
{
Mesh sharedMesh = base.GetComponent<MeshFilter>().sharedMesh;
Material sharedMaterial = base.GetComponent<MeshRenderer>().sharedMaterial;
if (sharedMaterial.HasProperty("_TreeHeight"))
{
this.TreeHeight = sharedMaterial.GetFloat("_TreeHeight");
this.TreeScale = sharedMaterial.GetFloat("_TreeScale");
Bounds bounds = new Bounds(new Vector3(0f, this.TreeScale * this.TreeHeight * 0.5f, 0f), new Vector3(this.TreeScale, this.TreeScale * this.TreeHeight, this.TreeScale));
sharedMesh.bounds = bounds;
}
}
private void SetRotation()
{
Mesh sharedMesh = base.GetComponent<MeshFilter>().sharedMesh;
Vector3[] vertices = sharedMesh.vertices;
Color[] array = sharedMesh.colors;
if (array.Length == 0)
{
Debug.Log("Vertex Colors added.");
array = new Color[vertices.Length];
}
Quaternion rotation = Quaternion.AngleAxis(this.Rotation, Vector3.up);
Vector3 vector = rotation * Vector3.forward;
float num = Mathf.Atan2(vector.x, vector.z);
num = (num + 3.14159274f) / 6.28318548f;
for (int i = 0; i < vertices.Length; i++)
{
array[i] = new Color(0f, 0f, num, 0f);
}
sharedMesh.colors = array;
}
private void SetStippling()
{
base.GetComponent<Renderer>().sharedMaterial.SetVector("_StippleRangeSq", new Vector4(this.FadeNearDistance * this.FadeNearDistance, this.FadeFarDistance * this.FadeFarDistance, 0f, this.FarKillDistance * this.FarKillDistance));
}
public bool instatiated;
private float TreeHeight;
private float TreeScale;
public float FadeNearDistance = 20f;
public float FadeFarDistance = 21f;
public float FarKillDistance = 16384f;
[Range(0f, 179.9f)]
public float Rotation;
}