-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathModClient.cs
More file actions
1600 lines (1492 loc) · 58.3 KB
/
ModClient.cs
File metadata and controls
1600 lines (1492 loc) · 58.3 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using HutongGames.PlayMaker;
using MSCLoader;
using TommoJProductions.ModApi.Attachable;
using TommoJProductions.ModApi.Database.GameParts;
using UnityEngine;
using static UnityEngine.GUILayout;
namespace TommoJProductions.ModApi
{
#region enums
/// <summary>
/// Represents inject types.
/// </summary>
public enum InjectEnum
{
/// <summary>
/// Rpresents inject type, append. appends an action a fsmState.
/// </summary>
append,
/// <summary>
/// Rpresents inject type, prepend. prepends an action a fsmState
/// </summary>
prepend,
/// <summary>
/// Rpresents inject type, insert. insert an action in a fsmState at an index
/// </summary>
insert,
/// <summary>
/// Rpresents inject type, replace. replace an action in a fsmState at an index.
/// </summary>
replace
}
/// <summary>
/// Represents callback types for playmaker action injection any of the action extention methods: append, prepend, replace, insert. see <see cref="InjectEnum"/>.
/// </summary>
public enum CallbackTypeEnum
{
/// <summary>
/// Represents the on enter callback.
/// </summary>
onEnter,
/// <summary>
/// Represents the on fixed update callback.
/// </summary>
onFixedUpdate,
/// <summary>
/// Represents the on update callback.
/// </summary>
onUpdate,
/// <summary>
/// Represents the on gui callback.
/// </summary>
onGui
}
/// <summary>
/// Represents all databases in game.
/// </summary>
public enum Databases
{
// Written, 04.07.2022
/// <summary>
/// Represents the motor database.
/// </summary>
motor,
/// <summary>
/// Represents the mechanics database.
/// </summary>
mechanics,
/// <summary>
/// Represents the orders database.
/// </summary>
orders,
/// <summary>
/// Represents the body database.
/// </summary>
body
}
/// <summary>
/// Represents gui interact symbols.
/// </summary>
public enum GuiInteractSymbolEnum
{
// Written, 16.03.2019
/// <summary>
/// Represents no symbol.
/// </summary>
None,
/// <summary>
/// Represents the hand symbol.
/// </summary>
Hand,
/// <summary>
/// Represents the disassemble symbol.
/// </summary>
Disassemble,
/// <summary>
/// Represents the assemble symbol.
/// </summary>
Assemble,
}
/// <summary>
/// Represents a player mode.
/// </summary>
public enum PlayerModeEnum
{
// Written, 09.08.2018
/// <summary>
/// Represents that the player is on foot.
/// </summary>
OnFoot,
/// <summary>
/// Represents that the player is driving the satsuma.
/// </summary>
InSatsuma,
/// <summary>
/// Represents the the player is driving other.
/// </summary>
InOther,
}
/// <summary>
/// Represents all layers of my summer car.
/// </summary>
public enum LayerMasksEnum
{
/// <summary>
/// Represents the default layer.
/// </summary>
Default,
/// <summary>
/// Represents the transparent fx layer.
/// </summary>
TransparentFX,
/// <summary>
/// Represents the ignore raycast layer.
/// </summary>
IgnoreRaycast,
/// <summary>
/// Represents an empty layer.
/// </summary>
Layer3,
/// <summary>
/// Represents the water layer.
/// </summary>
Water,
/// <summary>
/// Represents the user interaction layer.
/// </summary>
UI,
/// <summary>
/// Represents an empty layer.
/// </summary>
Layer6,
/// <summary>
/// Represents an empty layer.
/// </summary>
Layer7,
/// <summary>
/// Represents the road layer.
/// </summary>
Road,
/// <summary>
/// Represents the hinged objects layer.
/// </summary>
HingedObjects,
/// <summary>
/// Represents the terrian layer.
/// </summary>
Terrain,
/// <summary>
/// Represents the dont collide layer.
/// </summary>
DontCollide,
/// <summary>
/// Represents the bolts layer.
/// </summary>
Bolts,
/// <summary>
/// Represents the dashboard layer.
/// </summary>
Dashboard,
/// <summary>
/// Represents the graphical user interface layer.
/// </summary>
GUI,
/// <summary>
/// Represents the tool layer.
/// </summary>
Tools,
/// <summary>
/// Represents the wheel layer.
/// </summary>
Wheel,
/// <summary>
/// Represents the collider layer.
/// </summary>
Collider,
/// <summary>
/// Represents the datsun layer. (all cars use this layer)
/// </summary>
Datsun,
/// <summary>
/// Represents the parts layer.
/// </summary>
Parts,
/// <summary>
/// Represents the player layer.
/// </summary>
Player,
/// <summary>
/// Represents the lifter layer.
/// </summary>
Lifter,
/// <summary>
/// Represents the collider2 layer.
/// </summary>
Collider2,
/// <summary>
/// Represents the player only collider layer.
/// </summary>
PlayerOnlyColl,
/// <summary>
/// Represents the cloud layer.
/// </summary>
Cloud,
/// <summary>
/// Represents the grass layer.
/// </summary>
Glass,
/// <summary>
/// Represents the forest layer.
/// </summary>
Forest,
/// <summary>
/// Represents the no rain layer.
/// </summary>
NoRain,
/// <summary>
/// Represents the trigger-only layer.
/// </summary>
TriggerOnly,
/// <summary>
/// Represents an empty layer.
/// </summary>
Layer29,
/// <summary>
/// Represents an empty layer.
/// </summary>
Layer30,
}
#endregion
#region Excections
/// <summary>
/// reps a save data not found error
/// </summary>
public class saveDataNotFoundException : Exception
{
// Written, 15.07.2022
/// <summary>
/// reps a save data not found error with a message.
/// </summary>
/// <param name="message"></param>
public saveDataNotFoundException(string message) : base(message) { }
}
#endregion
/// <summary>
/// Represents useful properties for interacting with My Summer Car and PlayMaker.
/// </summary>
public class ModClient
{
// Written, 10.08.2018 | Modified 25.09.2021
#region Events
/// <summary>
/// Occurs when the player picks up a gameobject.
/// </summary>
///
public static event Action<GameObject> onGameObjectPickUp;
/// <summary>
/// Occurs when the player drops a gameobject.
/// </summary>
public static event Action<GameObject> onGameObjectDrop;
/// <summary>
/// Occurs when the player throws a gameobject.
/// </summary>
public static event Action<GameObject> onGameObjectThrow;
#endregion
#region Fields
#if DEBUG
internal static bool devMode = true;
#else
internal static bool devMode = false;
#endif
/// <summary>
/// Represents the complied runtime version of the api.
/// </summary>
public static readonly string VERSION = ModApi.VersionInfo.version + "Build " + VersionInfo.build;
internal static bool displayLogsInConsole = false;
internal static string log;
private static ModClient _instance;
private GameObject _masterAudioGameObject;
private GameObject _player;
private GameObject _fps;
private AudioSource _assembleAudio;
private AudioSource _disassembleAudio;
private AudioSource _screwAudio;
private Material _activeBoltMaterial;
private Camera _playerCamera;
private PlayMakerFSM _pickUp;
private FsmGameObject _pickedUpGameObject;
private FsmGameObject _raycastHitGameObject;
private FsmGameObject _POV;
private FsmBool _guiDisassemble;
private FsmBool _guiAssemble;
private FsmBool _guiUse;
private FsmBool _guiDrive;
private FsmBool _handEmpty;
private FsmBool _playerInMenu;
private FsmBool _ratchetSwitch;
private FsmBool _playerHasRatchet;
private FsmString _guiInteraction;
private FsmString _playerCurrentVehicle;
private FsmFloat _toolWrenchSize;
private string _gameDirectoryPath;
private FieldInfo _modsFolderPathFieldInfo;
private string _propertyString = "";
private int _propertyInt = 0;
private float _propertyFloat = 0;
private double _propertyDouble = 0;
private bool _propertyBool = false;
private readonly Dictionary<string, AudioSource> _masterAudioDictionary = new Dictionary<string, AudioSource>();
private BoltManager _boltManager;
private PartManager _partManager;
private static GameObject _modapiGo;
#endregion
#region Properties
/// <summary>
/// Gets the current <see cref="ModClient"/> instance.
/// </summary>
public static ModClient instance => _instance;
/// <summary>
/// Cache. Represents the assemble assemble audio source.
/// </summary>
public static AudioSource assembleAudio
{
get
{
if (_instance._assembleAudio == null)
_instance._assembleAudio = getMasterAudio("CarBuilding", "assemble");
return _instance._assembleAudio;
}
}
/// <summary>
/// Cache. Represents the disassemble audio source.
/// </summary>
public static AudioSource disassembleAudio
{
get
{
if (_instance._disassembleAudio == null)
_instance._disassembleAudio = getMasterAudio("CarBuilding", "disassemble");
return _instance._disassembleAudio;
}
}
/// <summary>
/// Represents the bolt screw audio source.
/// </summary>
public static AudioSource screwAudio
{
get
{
if (_instance._screwAudio == null)
_instance._screwAudio = getMasterAudio("CarBuilding", "bolt_screw");
return _instance._screwAudio;
}
}
/// <summary>
/// Represents whether the gui disassemble icon is shown or not. (Circle with line through it.)
/// </summary>
public static bool guiDisassemble
{
get
{
if (_instance._guiDisassemble == null)
_instance._guiDisassemble = PlayMakerGlobals.Instance.Variables.FindFsmBool("GUIdisassemble");
return _instance._guiDisassemble.Value;
}
set
{
if (_instance._guiDisassemble == null)
_instance._guiDisassemble = PlayMakerGlobals.Instance.Variables.FindFsmBool("GUIdisassemble");
_instance._guiDisassemble.Value = value;
}
}
/// <summary>
/// Represents whether the gui assemble icon is shown or not. (Tick Symbol)
/// </summary>
public static bool guiAssemble
{
get
{
if (_instance._guiAssemble == null)
_instance._guiAssemble = PlayMakerGlobals.Instance.Variables.FindFsmBool("GUIassemble");
return _instance._guiAssemble.Value;
}
set
{
if (_instance._guiAssemble == null)
_instance._guiAssemble = PlayMakerGlobals.Instance.Variables.FindFsmBool("GUIassemble");
_instance._guiAssemble.Value = value;
}
}
/// <summary>
/// Represents whether or not the gui use icon is shown. (Hand Symbol)
/// </summary>
public static bool guiUse
{
get
{
if (_instance._guiUse == null)
_instance._guiUse = PlayMakerGlobals.Instance.Variables.FindFsmBool("GUIuse");
return _instance._guiUse.Value;
}
set
{
if (_instance._guiUse == null)
_instance._guiUse = PlayMakerGlobals.Instance.Variables.FindFsmBool("GUIuse");
_instance._guiUse.Value = value;
}
}
/// <summary>
/// Represents whether or not to display gui interaction text.
/// </summary>
public static string guiInteraction
{
get
{
if (_instance._guiInteraction == null)
_instance._guiInteraction = PlayMakerGlobals.Instance.Variables.FindFsmString("GUIinteraction");
return _instance._guiInteraction.Value;
}
set
{
if (_instance._guiInteraction == null)
_instance._guiInteraction = PlayMakerGlobals.Instance.Variables.FindFsmString("GUIinteraction");
_instance._guiInteraction.Value = value;
}
}
/// <summary>
/// Represents whether or not to display gui drive icon.
/// </summary>
public static bool guiDrive
{
get
{
if (_instance._guiDrive == null)
_instance._guiDrive = PlayMakerGlobals.Instance.Variables.FindFsmBool("GUIdrive");
return _instance._guiDrive.Value;
}
set
{
if (_instance._guiDrive == null)
_instance._guiDrive = PlayMakerGlobals.Instance.Variables.FindFsmBool("GUIdrive");
_instance._guiDrive.Value = value;
}
}
/// <summary>
/// Represents whether or not to display gui drive icon.
/// </summary>
public static bool playerInMenu
{
get
{
if (_instance._playerInMenu == null)
_instance._playerInMenu = PlayMakerGlobals.Instance.Variables.FindFsmBool("PlayerInMenu");
return _instance._playerInMenu.Value;
}
set
{
if (_instance._playerInMenu == null)
_instance._playerInMenu = PlayMakerGlobals.Instance.Variables.FindFsmBool("PlayerInMenu");
_instance._playerInMenu.Value = value;
}
}
/// <summary>
/// Represents the player current vehicle state.
/// </summary>
public static FsmString playerCurrentVehicle
{
get
{
if (_instance._playerCurrentVehicle == null)
_instance._playerCurrentVehicle = PlayMakerGlobals.Instance.Variables.FindFsmString("PlayerCurrentVehicle");
return _instance._playerCurrentVehicle;
}
}
/// <summary>
/// Gets the current player mode,
/// </summary>
public static PlayerModeEnum getMode
{
get
{
PlayerModeEnum pme;
switch (playerCurrentVehicle.Value)
{
case "":
pme = PlayerModeEnum.OnFoot;
break;
case "Satsuma":
pme = PlayerModeEnum.InSatsuma;
break;
default:
pme = PlayerModeEnum.InOther;
break;
}
return pme;
}
}
/// <summary>
/// Represents all parts in the current instance of my summer car. (msc mods that use MODAPI.Attachable.Part
/// will be listed here)
/// </summary>
public static List<Part> loadedParts { get; } = new List<Part>();
/// <summary>
/// Represents all bolts in the current instance of my summer car. (Parts that use bolts will be listed here)
/// </summary>
public static List<Bolt> loadedBolts { get; } = new List<Bolt>();
/// <summary>
/// Cache. Gets the pickup playmakerfsm from the hand gameobject.
/// </summary>
public static PlayMakerFSM getHandPickUpFsm
{
get
{
if (_instance._pickUp == null)
_instance._pickUp = getFPS.transform.Find("1Hand_Assemble/Hand").GetPlayMaker("PickUp");
return _instance._pickUp;
}
}
/// <summary>
/// Cache. Gets the gameobject that the player is holding.
/// </summary>
public static FsmGameObject getPickedUpGameObject
{
get
{
if (_instance._pickedUpGameObject == null)
_instance._pickedUpGameObject = getHandPickUpFsm?.FsmVariables.GetFsmGameObject("PickedObject");
return _instance._pickedUpGameObject;
}
}
/// <summary>
/// Cache. Gets the gameobject that the player is looking at.
/// </summary>
public static FsmGameObject getRaycastHitGameObject
{
get
{
if (_instance._raycastHitGameObject == null)
_instance._raycastHitGameObject = getHandPickUpFsm?.FsmVariables.GetFsmGameObject("RaycastHitObject");
return _instance._raycastHitGameObject;
}
}
/// <summary>
/// Cache. Returns true if in hand mode. determines state by <see cref="getHandPickUpFsm"/>.Active.
/// </summary>
public static bool isInHandMode => getHandPickUpFsm.Active;
/// <summary>
/// Cache. Returns true if player is not holding anything
/// </summary>
public static bool isHandEmpty
{
get
{
if (_instance._handEmpty == null)
_instance._handEmpty = getHandPickUpFsm?.FsmVariables.FindFsmBool("HandEmpty");
return _instance._handEmpty.Value;
}
}
/// <summary>
/// Cache. Gets modloaer mods folder field info.
/// </summary>
public static FieldInfo getModsFolderFi
{
// Written, 02.07.2022
get
{
if (_instance._modsFolderPathFieldInfo == null)
_instance._modsFolderPathFieldInfo = typeof(ModLoader).GetField("ModsFolder", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField);
return _instance._modsFolderPathFieldInfo;
}
}
/// <summary>
/// Cache. Gets the currently used mods folder path.
/// </summary>
public static string getModsFolder => (string)getModsFolderFi.GetValue(null);
/// <summary>
/// Cache. gets the currently used wrench size casted to a <see cref="BoltSize"/>
/// </summary>
public static BoltSize getToolWrenchSize_boltSize
{
get => (BoltSize)(getToolWrenchSize_float * 100f);
}
/// <summary>
/// Cache. gets the currently used wrench size
/// </summary>
public static float getToolWrenchSize_float
{
get
{
if (_instance._toolWrenchSize == null)
_instance._toolWrenchSize = PlayMakerGlobals.Instance.Variables.FindFsmFloat("ToolWrenchSize");
return _instance._toolWrenchSize.Value;
}
}
/// <summary>
/// Gets the spanner bolting speed wait time.
/// </summary>
public static float getSpannerBoltingSpeed => 0.28f;
/// <summary>
/// Gets the rachet bolting speed wait time.
/// </summary>
public static float getRachetBoltingSpeed => 0.08f;
/// <summary>
/// Cache. Gets the active bolt material. (green bolt texture)
/// </summary>
public static Material getActiveBoltMaterial
{
get
{
if (_instance._activeBoltMaterial == null)
{
Material[] gameMaterials = Resources.FindObjectsOfTypeAll<Material>();
_instance._activeBoltMaterial = gameMaterials.First(m => m.name == "activebolt");
}
return _instance._activeBoltMaterial;
}
}
/// <summary>
/// Cache. gets the master audio gameobject and caches a reference.
/// </summary>
public static GameObject getMasterAudioGameObject
{
get
{
if (!_instance._masterAudioGameObject)
_instance._masterAudioGameObject = GameObject.Find("MasterAudio");
return _instance._masterAudioGameObject;
}
}
/// <summary>
/// Cache. gets and stores a reference to the player camera gameobject (parent of player camera). PATH: "PLAYER/Pivot/AnimPivot/Camera/FPSCamera/FPSCamera"
/// </summary>
public static GameObject getPOV
{
get
{
if (_instance._POV == null)
{
_instance._POV = PlayMakerGlobals.Instance.Variables.FindFsmGameObject("POV");
}
return _instance._POV.Value;
}
}
/// <summary>
/// Cache. gets and stores a reference to the player gameobject. PATH: "PLAYER"
/// </summary>
public static GameObject getPlayer
{
get
{
if (_instance._player == null)
{
_instance._player = getPOV.transform.root.gameObject;
}
return _instance._player;
}
}
/// <summary>
/// Cache. gets and stores a reference to the player fps gameobject. PATH: "PLAYER/Pivot/AnimPivot/Camera/FPSCamera"
/// </summary>
public static GameObject getFPS
{
get
{
if (_instance._fps == null)
{
_instance._fps = getPOV.transform.parent.gameObject;
}
return _instance._fps;
}
}
/// <summary>
/// cache. gets and stores a reference to the player camera.
/// </summary>
public static Camera getPlayerCamera
{
get
{
if (_instance._playerCamera == null)
{
_instance._playerCamera = getPOV.GetComponent<Camera>();
}
return _instance._playerCamera;
}
}
/// <summary>
/// Cache. Gets the full game directory path on the user system.
/// </summary>
public static string getGameFolder
{
get
{
if (_instance._gameDirectoryPath == null)
{
_instance._gameDirectoryPath = Path.GetFullPath(".");
}
return _instance._gameDirectoryPath;
}
}
/// <summary>
/// Cache. Represents if the player is using the ratchet.
/// </summary>
public static FsmBool getPlayerHasRatchet
{
get
{
if (_instance._playerHasRatchet == null)
{
_instance._playerHasRatchet = PlayMakerGlobals.Instance.Variables.GetFsmBool("PlayerHasRatchet");
}
return _instance._playerHasRatchet;
}
}
/// <summary>
/// Cache. Represents if the ratchet is switched. (direction)
/// </summary>
public static FsmBool getRatchetSwitch
{
get
{
if (_instance._ratchetSwitch == null)
{
_instance._ratchetSwitch = getFPS.transform.FindChild("2Spanner/Pivot/Ratchet").gameObject.GetPlayMaker("Switch").FsmVariables.GetFsmBool("Switch");
}
return _instance._ratchetSwitch;
}
}
/// <summary>
/// Represents the dev mode behaviour instance. null if <see cref="devMode"/> is <see langword="false"/>.
/// </summary>
public static DevMode devModeBehaviour { get; internal set; }
/// <summary>
/// Represents modapi behaviour
/// </summary>
public static LevelManager levelManager { get; internal set; }
/// <summary>
/// Cache. Gets The Bolt Manager.
/// </summary>
public static BoltManager getBoltManager
{
get
{
if (_instance._boltManager == null)
{
_instance._boltManager = new BoltManager();
}
return _instance._boltManager;
}
}
/// <summary>
/// Cache. Gets The Part Manager.
/// </summary>
public static PartManager getPartManager
{
get
{
if (_instance._partManager == null)
{
_instance._partManager = new PartManager();
}
return _instance._partManager;
}
}
/// <summary>
/// Represents the gameobject that holds the dev mode behaviour. gameobject is used to detect if game has been re-loaded/changed. used to inject mod api related stuff.
/// </summary>
public static GameObject modapiGo => _modapiGo;
/// <summary>
/// Represents if ModAPI is Loaded or not.
/// </summary>
public static bool loaded => ModApiLoader.initialized && _modapiGo != null;
#endregion
#region Methods
internal static void setModApiGo(GameObject gameObject) => _modapiGo = gameObject;
/// <summary>
/// sets <see cref="_instance"/> to null. thus next call to <see cref="instance"/> will create a new instance.
/// </summary>
internal static void refreshCache()
{
_instance = new ModClient();
loadedParts.Clear();
loadedBolts.Clear();
Trigger.loadedTriggers.Clear();
Trigger.triggerDictionary.Clear();
Database.Database.refreshCache();
}
/// <summary>
/// finds child object of name <paramref name="childName"/> and gets playmaker called, "Data".
/// </summary>
/// <param name="go"></param>
/// <param name="childName"></param>
/// <returns>"Data" playmakerFsm on child of <paramref name="go"/>.</returns>
internal static PlayMakerFSM getData(GameObject go, string childName)
{
return go.transform.FindChild(childName).GetPlayMaker("Data");
}
// [Texture]
/// <summary>
/// creates a texure with the color provided.
/// </summary>
/// <param name="width">width of texture</param>
/// <param name="height">height of texture</param>
/// <param name="col">the color of the texture</param>
/// <returns>a new texture instance of color param: <paramref name="col"/></returns>
public static Texture2D createTextureFromColor(int width, int height, Color col)
{
// Written, 21.08.2022
Color[] pix = new Color[width * height];
for (int i = 0; i < pix.Length; i++)
pix[i] = col;
Texture2D result = new Texture2D(width, height);
result.SetPixels(pix);
result.Apply();
return result;
}
// [Sound]
/// <summary>
/// Plays a sound at <paramref name="transform"/> world position. if sound is already playing, does nothing.
/// </summary>
/// <param name="transform">the world position to play sound at.</param>
/// <param name="soundType">The sound type group. eg => CarBuilding</param>
/// <param name="variantName">The sound variant in the soundType group. eg => Assemble</param>
public static void playSoundAt(Transform transform, string soundType, string variantName)
{
// Written, 16.07.2022
AudioSource source = getMasterAudio(soundType, variantName);
if (source)
{
source.transform.position = transform.position;
source.Play();
}
}
/// <summary>
/// Plays a sound at <paramref name="transform"/> world position. if sound is already playing, stops and restarts.
/// </summary>
/// <param name="transform">the world position to play sound at.</param>
/// <param name="soundType">The sound type group. eg => CarBuilding</param>
/// <param name="variantName">The sound variant in the soundType group. eg => Assemble</param>
public static void playSoundAtInterupt(Transform transform, string soundType, string variantName)
{
// Written, 16.07.2022
AudioSource source = getMasterAudio(soundType, variantName);
if (source)
{
source.transform.position = transform.position;
if (source.isPlaying)
source.Stop();
source.Play();
}
}
/// <summary>
/// Gets the audio source from the master audio gameobject (MasterAudio). path => <paramref name="soundType"/>/<paramref name="variantName"/> | eg => CarBuilding/assemble. adds it to a dictionary for for a less performat hit next time. asking for the same path.
/// </summary>
/// <param name="soundType">The sound type group. eg => CarBuilding</param>
/// <param name="variantName">The sound variant in the soundType group. eg => assemble</param>
public static AudioSource getMasterAudio(string soundType, string variantName)
{
// Written, 16.07.2022
string search = $"{soundType}/{variantName}";
AudioSource source;
if (!_instance._masterAudioDictionary.TryGetValue(search, out source))
{
source = getMasterAudioGameObject.transform.Find(search)?.gameObject.GetComponent<AudioSource>();
if (source)
_instance._masterAudioDictionary.Add(search, source);
else
print($"Error: Could not find audio path: MasterAudio/{search}.");
}
return source;
}
// [Lerp]
/// <summary>
/// Same logic as <see cref="Mathf.Lerp(float, float, float)"/>, but <paramref name="t"/> is not clamped. to 0 - 1.
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <param name="t"></param>
/// <returns></returns>
public static float unclampedLerp(float from, float to, float t)
{
// Written, 13.11.2022
return from + (to - from) * t;
}
/// <summary>
/// Same logic as <see cref="Mathf.Lerp(float, float, float)"/> but defines min and max clamp params for <paramref name="t"/>.
/// </summary>
/// <param name="from">the start or from value.</param>
/// <param name="to">the end or to value.</param>
/// <param name="t">the time value.</param>
/// <param name="min">The min value for <paramref name="t"/>.</param>
/// <param name="max">The max value for <paramref name="t"/>.</param>
/// <returns></returns>
public static float clampedLerp(float from, float to, float t, float min = 0, float max = 1)
{
// Written, 13.11.2022
return from + (to - from) * Mathf.Clamp(t, min, max);
}
/// <summary>
/// Same logic as <see cref="Mathf.Approximately(float, float)"/> but with threshold parameter.
/// </summary>
/// <param name="a">the a param to compare</param>
/// <param name="b">the b param to compare.</param>
/// <param name="threshold"></param>
/// <returns></returns>
public static bool approximately(float a, float b, float threshold)
{
return ((a - b) < 0 ? ((a - b) * -1) : (a - b)) <= threshold;
}
// [GUI]
/// <summary>
/// draws a gui of info about a game part. (use within an <see cref="AreaScope"/>).
/// </summary>
/// <param name="gp"></param>
public static void drawGamePartInfo(GamePart gp)
{
// Written, 19.07.2022
using (new VerticalScope())
{