forked from Katalyst6/CSL.NetworkExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMod.Loading.cs
78 lines (65 loc) · 1.98 KB
/
Mod.Loading.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 ICities;
using NetworkExtensions.Framework;
using UnityEngine;
using Object = UnityEngine.Object;
namespace NetworkExtensions
{
public partial class Mod : LoadingExtensionBase
{
private bool _isReleased = true;
private GameObject _container = null;
private NetCollection _newRoads = null;
private ModInitializer _initalizer = null;
public override void OnCreated(ILoading loading)
{
base.OnCreated(loading);
if (_isReleased)
{
_container = new GameObject(NEXT_OBJECT_NAME);
_newRoads = _container.AddComponent<NetCollection>();
_newRoads.name = NEWROADS_NETCOLLECTION;
_initalizer = _container.AddComponent<ModInitializer>();
_initalizer.NewRoads = _newRoads;
_initalizer.InitializationCompleted += InitializationCompleted;
_isReleased = false;
}
}
private void InitializationCompleted(object sender, EventArgs e)
{
Loading.QueueAction(() =>
{
if (_initalizer != null)
{
_initalizer.NewRoads = null;
Object.Destroy(_initalizer);
_initalizer = null;
}
});
}
public override void OnReleased()
{
base.OnReleased();
if (_isReleased)
{
return;
}
if (_initalizer != null)
{
Object.Destroy(_initalizer);
_initalizer = null;
}
if (_newRoads != null)
{
Object.Destroy(_newRoads);
_newRoads = null;
}
if (_container != null)
{
Object.Destroy(_container);
_container = null;
}
_isReleased = true;
}
}
}