-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCustomPrefabs.cs
84 lines (68 loc) · 2.67 KB
/
CustomPrefabs.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
using HarmonyLib;
using UnityEngine;
namespace Seasons
{
internal class CustomPrefabs
{
private const string c_rootObjectName = "_shudnalRoot";
private const string c_rootPrefabsName = "Prefabs";
private static GameObject rootObject;
private static GameObject rootPrefabs;
public static bool prefabInit = false;
private static void InitRootObject()
{
if (rootObject == null)
rootObject = GameObject.Find(c_rootObjectName) ?? new GameObject(c_rootObjectName);
UnityEngine.Object.DontDestroyOnLoad(rootObject);
if (rootPrefabs == null)
{
rootPrefabs = rootObject.transform.Find(c_rootPrefabsName)?.gameObject;
if (rootPrefabs == null)
{
rootPrefabs = new GameObject(c_rootPrefabsName);
rootPrefabs.transform.SetParent(rootObject.transform, false);
rootPrefabs.SetActive(false);
}
}
}
internal static GameObject InitPrefabClone(GameObject prefabToClone, string prefabName)
{
InitRootObject();
prefabInit = true;
GameObject clonedPrefab = UnityEngine.Object.Instantiate(prefabToClone, rootPrefabs.transform, false);
prefabInit = false;
clonedPrefab.name = prefabName;
return clonedPrefab;
}
[HarmonyPatch(typeof(ZNetView), nameof(ZNetView.Awake))]
public static class ZNetView_Awake_AddPrefab
{
[HarmonyPriority(Priority.First)]
private static bool Prefix() => !prefabInit;
}
[HarmonyPatch(typeof(ZSyncTransform), nameof(ZSyncTransform.Awake))]
public static class ZSyncTransform_Awake_AddPrefab
{
[HarmonyPriority(Priority.First)]
private static bool Prefix() => !prefabInit;
}
[HarmonyPatch(typeof(ZSyncTransform), nameof(ZSyncTransform.OnEnable))]
public static class ZSyncTransform_OnEnable_AddPrefab
{
[HarmonyPriority(Priority.First)]
private static bool Prefix() => !prefabInit;
}
[HarmonyPatch(typeof(ItemDrop), nameof(ItemDrop.Awake))]
public static class ItemDrop_Awake_AddPrefab
{
[HarmonyPriority(Priority.First)]
private static bool Prefix() => !prefabInit;
}
[HarmonyPatch(typeof(ItemDrop), nameof(ItemDrop.Start))]
public static class ItemDrop_Start_AddPrefab
{
[HarmonyPriority(Priority.First)]
private static bool Prefix() => !prefabInit;
}
}
}