forked from Blightbuster/The-Forest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnimationLoadManager.cs
129 lines (106 loc) · 3.62 KB
/
AnimationLoadManager.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections;
using TheForest.Utils;
using UnityEngine;
public class AnimationLoadManager : MonoBehaviour
{
private void Start()
{
this.animator = base.GetComponent<Animator>();
this.overrideController = (this.animator.runtimeAnimatorController as AnimatorOverrideController);
}
private IEnumerator LoadAnimClip(string clipName, string boolName)
{
LocalPlayer.AnimControl.loadingAnimation = true;
ResourceRequest request = Resources.LoadAsync("CutScene/" + clipName);
yield return request;
AnimationClip animClip = request.asset as AnimationClip;
this.overrideController[clipName + " Empty"] = animClip;
this.animator.Update(0f);
for (int i = 0; i < this.animator.layerCount; i++)
{
this.animator.CrossFade(this.layerInfo[i].nameHash, 0f, i, this.layerInfo[i].normalizedTime);
this.animator.SetLayerWeight(i, this.layerWeights[i]);
}
if (this.flashLightHeld)
{
this.animator.SetBool("flashLightHeld", true);
}
if (this.lighterHeld)
{
this.animator.SetBool("lighterHeld", true);
}
if (this.pedHeld)
{
this.animator.SetBool("pedHeld", true);
}
this.animator.Update(0f);
LocalPlayer.AnimControl.loadingAnimation = false;
yield break;
}
public void LoadAnimation(string animationName, string animationBoolName)
{
this.animator = base.GetComponent<Animator>();
this.layerInfo = new AnimatorStateInfo[this.animator.layerCount];
this.layerWeights = new float[this.animator.layerCount];
for (int i = 0; i < this.animator.layerCount; i++)
{
this.layerInfo[i] = this.animator.GetCurrentAnimatorStateInfo(i);
this.layerWeights[i] = this.animator.GetLayerWeight(i);
}
this.flashLightHeld = this.animator.GetBool("flashLightHeld");
this.lighterHeld = this.animator.GetBool("lighterHeld");
this.pedHeld = this.animator.GetBool("pedHeld");
base.StartCoroutine(this.LoadAnimClip(animationName, animationBoolName));
}
public IEnumerator UnloadAnimation(string clipName, bool refreshAssets)
{
this.animator = base.GetComponent<Animator>();
LocalPlayer.AnimControl.loadingAnimation = true;
this.layerInfo = new AnimatorStateInfo[this.animator.layerCount];
this.layerWeights = new float[this.animator.layerCount];
this.flashLightHeld = this.animator.GetBool("flashLightHeld");
this.lighterHeld = this.animator.GetBool("lighterHeld");
this.pedHeld = this.animator.GetBool("pedHeld");
for (int i = 0; i < this.animator.layerCount; i++)
{
this.layerInfo[i] = this.animator.GetCurrentAnimatorStateInfo(i);
this.layerWeights[i] = this.animator.GetLayerWeight(i);
}
ResourceRequest request = Resources.LoadAsync("CutScene/" + clipName + " Empty");
yield return request;
AnimationClip animClip = request.asset as AnimationClip;
this.overrideController[clipName + " Empty"] = animClip;
for (int j = 0; j < this.animator.layerCount; j++)
{
this.animator.CrossFade(this.layerInfo[j].nameHash, 0f, j, this.layerInfo[j].normalizedTime);
this.animator.SetLayerWeight(j, this.layerWeights[j]);
}
if (refreshAssets)
{
Resources.UnloadUnusedAssets();
}
if (this.flashLightHeld)
{
this.animator.SetBool("flashLightHeld", true);
}
if (this.lighterHeld)
{
this.animator.SetBool("lighterHeld", true);
}
if (this.pedHeld)
{
this.animator.SetBool("pedHeld", true);
}
this.animator.Update(0f);
LocalPlayer.AnimControl.loadingAnimation = false;
yield break;
}
private AnimatorOverrideController overrideController;
private Animator animator;
private AnimatorStateInfo[] layerInfo;
private float[] layerWeights;
private bool flashLightHeld;
private bool lighterHeld;
private bool pedHeld;
}