Created
July 11, 2014 22:14
-
-
Save ashblue/026242094ad93f4c19a6 to your computer and use it in GitHub Desktop.
Unity loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
// @TODO While this is great for debug purposes, all of this data should be loaded a level higher in the actual game | |
public class SceneLoader : MonoBehaviour { | |
GameObject map; | |
void Awake () { | |
// Check if the MapData prefab already exists from DontDestroyOnLoad | |
// If it does keep on going, if it doesn't create a new one | |
map = GetInstance("Map"); | |
if (!map) map = (GameObject)Instantiate(Resources.Load("Map")); | |
// Health and mana should always be present | |
// @TODO At some point this should all be moved into a HUD object at some point | |
if (!GetInstance("HealthBar")) Instantiate(Resources.Load("HealthBar")); | |
if (!GetInstance("ManaBar")) Instantiate(Resources.Load("ManaBar")); | |
// Check if the player already exists, if so don't load him | |
// Otherwise load him off the prefab | |
GameObject player = GetInstance("Player"); | |
if (player) { | |
// Check the map API to see if we have a previous position | |
// If not exit now | |
} else { | |
// Generate | |
} | |
// If the camera isn't created it will need to have its target set to the player | |
if (!GetInstance("MainCamera")) { | |
GameObject camera = (GameObject)Instantiate(Resources.Load("MainCamera")); | |
camera.SendMessage("SetTarget", player.transform); | |
} | |
} | |
void PosPlayer () { | |
// Figure out which doorway to place the character at | |
// Apply previous position on the character relative to Doorway coords | |
// Apply physics on character | |
} | |
GameObject GetInstance (string name) { | |
// Check for a clone | |
GameObject result = GameObject.Find(name + "(Clone)"); | |
// Check for a regular instance if nothing was found | |
if (result) return result; | |
else result = GameObject.Find(name); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment