-
Notifications
You must be signed in to change notification settings - Fork 2
/
CamGun.cs
166 lines (123 loc) · 3.92 KB
/
CamGun.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using CrashUtils.WeaponManager.WeaponSetup;
using HarmonyLib;
using System.Collections.Generic;
using UnityEngine;
namespace CoolCamUtils
{
public class CamGun : Gun
{
public static GameObject Asset;
public static GameObject weaponPrefab;
public static GameObject V1MDL;
public GameObject CamObj;
public GameObject PlayerObj;
public Camera Cam;
public Camera PlayerCam;
public bool LookAt;
public bool ShootAlt;
public static void LoadAssets()
{
weaponPrefab = CamGunLoader.Assets.LoadAsset<GameObject>("CamGunPrefab");
V1MDL = CamGunLoader.Assets.LoadAsset<GameObject>("v1_combined");
}
public override GameObject Create(Transform parent)
{
base.Create(parent);
Asset = GameObject.Instantiate(weaponPrefab, parent);
CamGunLoader.CamGn = Asset.AddComponent<CameraGun>();
PlayerObj = GameObject.Instantiate(V1MDL, CameraController.Instance.GetComponent<Camera>().transform);
PlayerObj.transform.localPosition = new Vector3(0, -3, -1);
PlayerObj.transform.localScale = new Vector3(2, 2, 2);
return Asset;
}
public override int Slot()
{
return 0;
}
public override int WheelOrder()
{
return 6;
}
public override string Pref()
{
return "camgun0";
}
}
public class CameraGun : MonoBehaviour
{
public static AssetBundle Assets;
public GameObject CamObj;
public Camera Cam;
public Camera PlayerCam;
public bool LookAt;
public bool ShootAlt;
private float cooldown = 0.25f;
private void Start()
{
PlayerCam = CameraController.Instance.GetComponent<Camera>();
CamObj = new GameObject("Cool Cam");
Cam = CamObj.AddComponent<Camera>();
Cam.Render();
Cam.cullingMask = 8192 | 198369047;
Cam.gameObject.transform.SetParent(null);
Cam.enabled = false;
}
private void OnEnable()
{
}
private void OnDisable()
{
cooldown = 0;
}
private void OnDestroy()
{
}
private void Update()
{
cooldown -= Time.deltaTime;
if (!MonoSingleton<ColorBlindSettings>.Instance)
{
return;
}
if (MonoSingleton<InputManager>.Instance.InputSource.Fire2.WasPerformedThisFrame && !GameStateManager.Instance.PlayerInputLocked)
{
if (LookAt)
{
LookAt = false;
}
else
{
LookAt = true;
}
}
else if (MonoSingleton<InputManager>.Instance.InputSource.Fire1.IsPressed && MonoSingleton<GunControl>.Instance.activated && !GameStateManager.Instance.PlayerInputLocked && cooldown <= 0)
{
if (!ShootAlt)
{
Cam.enabled = true;
this.Shoot();
cooldown = 0.25f;
}
else
{
DisableCams();
cooldown = 0.25f;
}
}
}
public void Shoot()
{
Cam.transform.position = PlayerCam.transform.position;
Cam.transform.rotation = PlayerCam.transform.rotation;
Cam.enabled = true;
Cam.depth = 10;
Cam.pixelRect = new Rect(Screen.width * 0.625f, 100, Screen.width * 0.25f, Screen.height * 0.25f);
ShootAlt = true;
}
public void DisableCams()
{
Cam.enabled = false;
ShootAlt = false;
}
}
}