-
Notifications
You must be signed in to change notification settings - Fork 115
/
ModularScatter.cs
executable file
·89 lines (81 loc) · 3.21 KB
/
ModularScatter.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
85
86
87
88
89
/**
* Kopernicus Planetary System Modifier
* -------------------------------------------------------------
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* This library is intended to be used as a plugin for Kerbal Space Program
* which is copyright 2011-2017 Squad. Your usage of Kerbal Space Program
* itself is governed by the terms of its EULA, not the license above.
*
* https://kerbalspaceprogram.com
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace Kopernicus
{
namespace Components
{
/// <summary>
/// Component to add other Components to Scatter objects easily
/// </summary>
public class ModularScatter : MonoBehaviour, IComponentSystem<ModularScatter>
{
/// <summary>
/// Components that can be added to the Ring
/// </summary>
public List<IComponent<ModularScatter>> Components { get; set; }
/// <summary>
/// The mod we are attached to
/// </summary>
public PQSLandControl landControl;
/// <summary>
/// The scatter instance we are attached to
/// </summary>
public PQSLandControl.LandClassScatter scatter;
/// <summary>
/// Create a new ScatterExtension
/// </summary>
public ModularScatter()
{
Components = new List<IComponent<ModularScatter>>();
}
/// <summary>
/// Create colliders for the scatter
/// </summary>
void Start()
{
// Register us as the parental object for the scatter
landControl = transform.parent.GetComponent<PQSLandControl>();
transform.parent = landControl.sphere.transform;
transform.localPosition = Vector3.zero;
transform.localRotation = Quaternion.identity;
transform.localScale = Vector3.one;
typeof(PQSLandControl.LandClassScatter).GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
.FirstOrDefault(f => f.FieldType == typeof(GameObject))?.SetValue(scatter, gameObject);
// Call the modules
Components.ForEach(c => c.Apply(this));
Components.ForEach(c => c.PostApply(this));
}
void Update()
{
Components.ForEach(c => c.Update(this));
}
}
}
}