-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin.cs
182 lines (157 loc) · 7.78 KB
/
Plugin.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BepInEx;
using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;
using UnityEngine.Rendering;
using HarmonyLib;
using BepInEx.Configuration;
using RealAirplaneTag;
using Random = System.Random;
namespace RealAirplaneTag
{
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
public const string GUID = MyPluginInfo.PLUGIN_GUID;
public const string PluginName = MyPluginInfo.PLUGIN_NAME;
public const string Version = MyPluginInfo.PLUGIN_VERSION;
public ConfigEntry<bool> Enabled;
ConfigFile config = new ConfigFile(Path.Combine(Paths.ConfigPath, $"{MyPluginInfo.PLUGIN_GUID}.cfg"), true);
private void Awake()
{
// Plugin startup logic
Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!");
Enabled = config.Bind("PluginSetting",
"Enabled",
true,
"Enabled");
Logger.LogInfo("Enabled.Value:"+ Enabled.Value);
Logger.LogInfo("GlobalSettings.AllMaps.Count:"+ GlobalSettings.AllMaps.Count);
Logger.LogInfo("GlobalSettings.FlightNo.Count:"+ GlobalSettings.FlightNo.Count);
if (Enabled.Value == false)
{
return;
}
SceneManager.sceneLoaded += OnSceneLoaded;
Harmony harmony = new Harmony(MyPluginInfo.PLUGIN_GUID);
harmony.PatchAll();
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
Logger.LogInfo($"Scene loaded: {scene.name}");
Logger.LogInfo("scene.path: "+scene.path);
if ((scene.name == "MapPlayer" || scene.name == "London" ||scene.name == "CreatorPlayer" ) &&
AircraftManager.Instance != null && Enabled.Value)
{
Logger.LogInfo("MapManager.mapName: "+MapManager.mapName);
Logger.LogInfo("Hooking AircraftManager");
AircraftManager.Instance.AircraftCreateEvent.AddListener(HookAircraft);
}
}
private void HookAircraft(Vector2 pos, Aircraft aircraft)
{
Logger.LogInfo("Aircraft created: " + aircraft.name);
Logger.LogInfo("Aircraft ID: " + aircraft.GetInstanceID());
AircraftStatHelper cp = aircraft.gameObject.AddComponent<AircraftStatHelper>();
cp.m_Aircraft = aircraft;
}
}
public class AircraftStatHelper : MonoBehaviour
{
private Vector3 _apScale;
private Vector3 _plScale;
private Dictionary<int, PlaneTag> planeID= new Dictionary<int, PlaneTag> { };
private TMP_Text m_Text;
public Aircraft m_Aircraft;
bool inited = false;
private PlaneTag info= new PlaneTag("", "", 0);
void Start()
{
_apScale= m_Aircraft.AP.gameObject.transform.localScale;
_plScale= m_Aircraft.AP.gameObject.transform.localScale;
GameObject obj = Instantiate(new GameObject("Text"), m_Aircraft.transform, true);
m_Text = obj.AddComponent<TextMeshPro>();
m_Text.fontSize = 2;
m_Text.horizontalAlignment = HorizontalAlignmentOptions.Left;
m_Text.verticalAlignment = VerticalAlignmentOptions.Top;
m_Text.rectTransform.sizeDelta = new Vector2(3, 1);
obj.transform.localPosition = new Vector3(1, -3f, 5);
// make sorting layer of obj "Text"
SortingGroup sg = obj.AddComponent<SortingGroup>();
sg.sortingLayerName = "Text";
sg.sortingOrder = 1;
planeID.Add(m_Aircraft.GetInstanceID(), GetRandomTags());
info = planeID[m_Aircraft.GetInstanceID()];
inited = true;
m_Text.text = $"{info.CallSign} | {info.AirType} | {LevelToName(info.SizeOfPlane)} \n";
}
private PlaneTag GetRandomTags()
{
Random random = new Random();
int callNumber = random.Next(1, 10000);
string randomcall="MU9191";
switch (m_Aircraft.direction)
{
case Aircraft.Direction.Inbound:
randomcall = GlobalSettings.AllMaps[MapManager.mapName].Departures.ToList()[random.Next(GlobalSettings.AllMaps[MapManager.mapName].Departures.ToList().Count-1)];
break;
case Aircraft.Direction.Outbound:
randomcall = GlobalSettings.AllMaps[MapManager.mapName].Arrivals.ToList()[random.Next(GlobalSettings.AllMaps[MapManager.mapName].Arrivals.ToList().Count-1)];
break;
}
var airtype = GlobalSettings.FlightNo[randomcall];
var pf = new planeFunc(GlobalSettings.PlaneTypes[airtype]);
return new PlaneTag(randomcall, GlobalSettings.PlaneTypes[airtype].Name,pf.WtCtoLevel());
}
void Update()
{
if (!m_Aircraft) {
planeID.Remove(m_Aircraft.GetInstanceID());
Destroy(gameObject);
}
if (!inited || !m_Text)
{
return;
}
}
private string LevelToName(int i)
{
switch (i)
{
case 1:
m_Aircraft.AP.gameObject.transform.localScale = new Vector3(_apScale.x*0.7f, _apScale.y*0.7f, _apScale.z*0.7f);
m_Aircraft.Panel.gameObject.transform.localScale = new Vector3(_plScale.x * 0.7f, _plScale.y * 0.7f, _plScale.z * 0.7f);
return "超轻型";
case 2:
m_Aircraft.AP.gameObject.transform.localScale = new Vector3(_apScale.x*0.9f, _apScale.y*0.9f, _apScale.z*0.9f);
m_Aircraft.Panel.gameObject.transform.localScale = new Vector3(_plScale.x * 0.9f, _plScale.y * 0.9f, _plScale.z * 0.9f);
return "轻型";
case 3:
m_Aircraft.AP.gameObject.transform.localScale = new Vector3(_apScale.x*1.0f, _apScale.y*1.0f, _apScale.z*1.0f);
m_Aircraft.Panel.gameObject.transform.localScale = new Vector3(_plScale.x *1.0f, _plScale.y * 1.0f, _plScale.z * 1.0f);
return "中型";
case 4:
m_Aircraft.AP.gameObject.transform.localScale = new Vector3(_apScale.x*1.4f, _apScale.y*1.4f, _apScale.z*1.4f);
m_Aircraft.Panel.gameObject.transform.localScale = new Vector3(_plScale.x * 1.4f, _plScale.y * 1.4f, _plScale.z * 1.4f);
return "大型";
case 5:
m_Aircraft.AP.gameObject.transform.localScale = new Vector3(_apScale.x*1.6f, _apScale.y*1.6f, _apScale.z*1.6f);
m_Aircraft.Panel.gameObject.transform.localScale = new Vector3(_plScale.x * 1.6f, _plScale.y * 1.6f, _plScale.z * 1.6f);
return "超大型";
default:
m_Aircraft.AP.gameObject.transform.localScale = new Vector3(_apScale.x*1.0f, _apScale.y*1.0f, _apScale.z*1.0f);
m_Aircraft.Panel.gameObject.transform.localScale = new Vector3(_plScale.x *1.0f, _plScale.y * 1.0f, _plScale.z * 1.0f);
return "中型";
}
}
}
}
public class GlobalSettings
{
public static readonly Dictionary<string, Map> AllMaps = Map.FromJson(GetRes.GetFromRes(".res.map.json"));
public static readonly Dictionary<string, string> FlightNo = JsonHelper.ConvertJsonToDictionaryFlightNo(GetRes.GetFromRes(".res.FlightNo.json"));
public static readonly Dictionary<string, PlaneType> PlaneTypes = PlaneType.FromJson(GetRes.GetFromRes(".res.plane.json"));
}