forked from solidDoWant/Planetbase-Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseModuleType.cs
More file actions
56 lines (46 loc) · 2.22 KB
/
BaseModuleType.cs
File metadata and controls
56 lines (46 loc) · 2.22 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
using Planetbase;
using UnityEngine;
namespace PlanetbaseFramework
{
public class BaseModuleType : ModuleType
{
public GameObject[] ModuleObjects { get; protected set; }
public string ModuleName { get; protected set; }
public BaseModuleType(Texture2D icon, GameObject[] moduleObjects)
{
//These settings are designed to keep the game from crashing, not to provide any functionality.
ModuleObjects = moduleObjects;
mIcon = icon;
mMinSize = 0;
mMaxSize = 0;
mDefaultSize = 0;
initStrings();
mCost = new ResourceAmounts();
}
public override GameObject loadPrefab(int sizeIndex)
{
int adjustedSizeIndex = sizeIndex - mMinSize; //Takes into account the edge case where mMinSize != 0
ModuleObjects[adjustedSizeIndex].calculateSmoothMeshRecursive(mMeshes);
//Add collider to object for raycasting
foreach (Transform transform in ModuleObjects[adjustedSizeIndex].transform)
{
//Make the collider for the GameObject the same size/shape as the mesh
if (transform.gameObject.GetComponent<MeshFilter>() != null)
{
transform.gameObject.AddComponent<MeshCollider>().sharedMesh = transform.gameObject.GetComponent<MeshFilter>().sharedMesh;
}
//This is copied directly from PB code. Not really sure that it's needed, but I'll leave it in place in case somebody else is comparing this to
//PB code
if (transform.gameObject.name.IsValidTag())
{
transform.gameObject.tag = transform.gameObject.name;
}
}
//This is more or less copied from PB code. Not entirely sure the effect of GroupNames on PB. TODO review this
GameObject moduleObject2 = GameObject.Find(GroupName) ?? new GameObject { name = GroupName };
ModuleObjects[adjustedSizeIndex].transform.SetParent(moduleObject2.transform, false);
ModuleObjects[adjustedSizeIndex].SetActive(false);
return ModuleObjects[adjustedSizeIndex];
}
}
}