/
ShopVariationButton.cs
78 lines (73 loc) · 2.31 KB
/
ShopVariationButton.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
using System;
using UMM;
using UnityEngine;
using UnityEngine.UI;
namespace BetterWeaponColourMenu
{
public class ShopVariationButton : MonoBehaviour
{
public GameObject Activator;
public GameObject CheckBox;
public GunColorSetter GunColSetter;
public int ColorNum;
public int weapo nNum;
public bool Alt;
public bool isenabled;
public bool wasActivated;
private void Start()
{
//load the persistent mod data if it exists and use that to force the color update or someshit idk
/*if(UKMod.PersistentModDataExists("Weapon." + weaponNum + ".Alt." + Alt + ".Col1", "Tony.GunColorVariation"))
{
wasActivated = UKMod.RetrieveBooleanPersistentModData("Weapon." + weaponNum + ".Alt." + Alt + ".Col1", "Tony.GunColorVariation");
if(wasActivated)
{
OnButtonTriggered(true);
}
}
*/
}
private void Update()
{
if (Activator != null && Activator.activeSelf)
{
Activator.SetActive(false);
OnButtonTriggered();
}
}
public virtual void OnButtonTriggered(bool awakeactive = false)
{
isenabled = awakeactive ? true : !isenabled;
if(CheckBox && CheckBox.GetComponent<Image>())
CheckBox.GetComponent<Image>().fillCenter = isenabled;
GameObject GC = GameObject.FindGameObjectWithTag("GunControl");
foreach (Renderer renderer in GC.GetComponentsInChildren<Renderer>(true))
{
if (renderer.gameObject.GetComponent<VariationColorHandler>())
{
if(renderer.gameObject.GetComponent<VariationColorHandler>().weaponnum == weaponNum && renderer.gameObject.GetComponent<VariationColorHandler>().alt == Alt)
{
VariationColorHandler VCH = renderer.gameObject.GetComponent<VariationColorHandler>();
switch(ColorNum)
{
case 1:
VCH.swapColor1 = isenabled;
break;
case 2:
VCH.swapColor2 = isenabled;
break;
case 3:
VCH.swapColor3 = isenabled;
break;
default:
break;
}
//update the persistent mod data for each color bool, i only did 1 here for testing
//UKMod.SetPersistentModData("Weapon." + VCH.weaponnum + ".Alt." + VCH.alt + ".Col1", isenabled.ToString(), "Tony.GunColorVariation");
if (renderer.GetComponent<GunColorSetter>()) renderer.GetComponent<GunColorSetter>().UpdateColor();
}
}
}
}
}
}