-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClothesManager.cs
More file actions
88 lines (74 loc) · 2.89 KB
/
ClothesManager.cs
File metadata and controls
88 lines (74 loc) · 2.89 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
using MSCLoader;
using System.Linq;
using UnityEngine;
namespace Expanded_Clothes
{
public enum ClothesKind { None, Jacket, Coverall }
public class ClothesManager
{
public static ClothesManager Instance;
private Mod modInstance;
public GameObject jacketItem;
public GameObject coverallItem;
public string jacketLocation = "None";
public string coverallLocation = "None";
public ClothesManager(Mod mod)
{
Instance = this;
modInstance = mod;
LoadData();
FindItems();
}
public void FindItems()
{
jacketItem = Resources.FindObjectsOfTypeAll<GameObject>().FirstOrDefault(g => g.name == "winter jacket(itemx)");
coverallItem = Resources.FindObjectsOfTypeAll<GameObject>().FirstOrDefault(g => g.name == "winter coverall(itemx)");
}
public bool IsItemOnShelf(string shelfID, ClothesKind kind)
{
if (kind == ClothesKind.Jacket) return jacketLocation == shelfID;
if (kind == ClothesKind.Coverall) return coverallLocation == shelfID;
return false;
}
public void SetItemLocation(string shelfID, ClothesKind kind)
{
if (kind == ClothesKind.Jacket) jacketLocation = shelfID;
if (kind == ClothesKind.Coverall) coverallLocation = shelfID;
}
public void DisablePhysicalItem(GameObject item)
{
var mesh = item.GetComponentInChildren<MeshRenderer>();
if (mesh) mesh.enabled = false;
var col = item.GetComponent<Collider>();
if (col) col.enabled = false;
var rb = item.GetComponent<Rigidbody>();
if (rb) { rb.isKinematic = true; rb.useGravity = false; }
}
public void EnablePhysicalItem(GameObject item)
{
var mesh = item.GetComponentInChildren<MeshRenderer>();
if (mesh) mesh.enabled = true;
var col = item.GetComponent<Collider>();
if (col) col.enabled = true;
var rb = item.GetComponent<Rigidbody>();
if (rb)
{
rb.isKinematic = false;
rb.useGravity = true;
rb.WakeUp();
}
}
public void Save()
{
SaveLoad.WriteValue(modInstance, "EC_JacketLocation", jacketLocation);
SaveLoad.WriteValue(modInstance, "EC_CoverallLocation", coverallLocation);
}
private void LoadData()
{
if (SaveLoad.ValueExists(modInstance, "EC_JacketLocation"))
jacketLocation = SaveLoad.ReadValue<string>(modInstance, "EC_JacketLocation");
if (SaveLoad.ValueExists(modInstance, "EC_CoverallLocation"))
coverallLocation = SaveLoad.ReadValue<string>(modInstance, "EC_CoverallLocation");
}
}
}