static GameObject Create(string itemName, string icon, string holderName, bool unique = false) { if (unique) { GameObject o = MapComponents.FindFixed(itemName); if (o != null) { Debug.LogError(itemName + " already exists!"); Selection.activeGameObject = o; return(null); } } GameObject obj = new GameObject(itemName); obj.transform.position = GetSpawnPos(); SetIcon(obj, icon); if (holderName != null && holderName.Length > 0) { GameObject holder = GameObject.Find(holderName); if (holder == null) { holder = new GameObject(holderName); } obj.transform.SetParent(holder.transform); } Selection.activeGameObject = obj; return(obj); }
void CoreUI() { GUILayout.Space(5); if (MapComponents.FindFixed("StartPad") == null) { if (FoldoutButton("Start Pad", 1)) { CreateStartPad(); } } else { FoldoutLabel("<color=green>Start Pad in Scene.</color>", 1); } if (MapComponents.FindFixed("EndPad") == null) { if (FoldoutButton("End Pad", 1)) { CreateEndPad(); } } else { FoldoutLabel("<color=green>End Pad in Scene.</color>", 1); } if (MapComponents.FindFixed("LevelBounds") == null) { if (FoldoutButton("Level Bounds", 1)) { CreateLvlBounds(); } } else { if (FoldoutButton("Recalculate Level Bounds", 1)) { UpdateLevelBounds(); } } if (FindObjectOfType <LevelTiming>() == null) { if (FoldoutButton("Level Timing", 1)) { CreateTimingObj(); } } else { FoldoutLabel("<color=green>Level Timing in Scene.</color>", 1); } GUILayout.Space(5); }
static void UpdateLevelBounds() { BoxCollider bc = null; GameObject bounds = MapComponents.FindFixed("LevelBounds"); if (bounds != null) { bc = bounds.GetComponent <BoxCollider>(); } if (bc != null) { Bounds b = new Bounds(Vector3.zero, Vector3.zero); foreach (Collider r in FindObjectsOfType <MeshCollider>()) { b.Encapsulate(r.bounds); } bounds.transform.position = b.center + (Vector3.up * 10); bc.center = Vector3.zero; bc.size = b.size + new Vector3(10, 20, 10); } }
public static void BakeScene() { hasResult = false; var assembly = Assembly.GetAssembly(typeof(SceneView)); var type = assembly.GetType("UnityEditor.LogEntries"); var method = type.GetMethod("Clear"); method.Invoke(new object(), null); LevelSerializer.failCause = ""; Debug.Log("Starting Level Export"); if (MapComponents.GetNumOf("SpawnPoint") == 0) { if (MapComponents.GetNumOf("StartPad") != 1) { LevelSerializer.failCause = "Singleplayer Level needs one StartPad!"; } if (MapComponents.GetNumOf("EndPad") != 1) { LevelSerializer.failCause = "Singleplayer Level needs one EndPad!"; } if (FindObjectsOfType <LevelTiming>().Length != 1) { LevelSerializer.failCause = "Singleplayer Level needs one Level Times object!"; } } else { if (MapComponents.GetNumOf("StartPad") > 0) { LevelSerializer.failCause = "Multiplayer Maps can't have StartPads."; } if (MapComponents.GetNumOf("EndPad") > 0) { LevelSerializer.failCause = "Multiplayer Maps can't have EndPads."; } if (FindObjectsOfType <LevelTiming>().Length > 0) { LevelSerializer.failCause = "Multiplayer Maps can't have timers."; } } if (MapComponents.GetNumOf("LevelBounds") != 1) { LevelSerializer.failCause = "Level needs one Level Bounds!"; } else { GameObject bounds = MapComponents.FindFixed("LevelBounds"); BoxCollider box = bounds.GetComponent <BoxCollider>(); if (box.size.x > 4096 || box.size.y > 4096 || box.size.z > 4096) { LevelSerializer.failCause = "Map is too large! Ensure leve bounds dimensions are under 4096."; } } var serializer = new LevelSerializer(); ByteStream levelBits = new ByteStream(); if (LevelSerializer.failCause.Length == 0) { serializer.Serialize(ref levelBits); } if (LevelSerializer.failCause.Length == 0) { string filePath = "Assets/" + LevelSerializer.GetCurrentSceneLevelId() + ".level"; FileStream file; if (!File.Exists(filePath)) { file = File.Create(filePath); } else { file = File.Open(filePath, FileMode.Truncate, FileAccess.Write); } file.Write(levelBits.Buffer, 0, levelBits.Position); file.Close(); Debug.Log("<color=green>Level Exported:</color> " + filePath); } else { Debug.Log("<color=#ff3232>Export Failed:</color> " + LevelSerializer.failCause); } hasResult = true; }