public bool InitializeLevelEditor(LevelToLoad lvl) { try { if (parent != null) { foreach (Transform child in parent) { GameObject.Destroy(child.gameObject); } } Debug.Log("Initialize level..."); foreach (var elm in lvl.elements) { Debug.Log(elm.toInstantiate().transform.localScale); var obj = elm.toInstantiate(); obj.transform.localScale = new Vector3(1, 1, 1); var tmp = GameObject.Instantiate(obj); tmp.transform.SetParent(parent, false); } return(true); } catch (Exception e) { Debug.LogError(e.ToString()); return(false); } }
public bool InitializeLevel(LevelToLoad lvl) { try { if (parent != null) { foreach (Transform child in parent) { GameObject.Destroy(child.gameObject); } } Debug.Log("Initialize level..."); float highestY = 0; List <GameObject> instanciated = new List <GameObject>(); foreach (var elm in lvl.elements) { if (elm.Position.y > highestY) { highestY = elm.Position.y; } instanciated.Add(instanciate(elm)); } foreach (var grp in lvl.groups) { Debug.Log(JsonUtility.ToJson(grp)); createGroup(grp, instanciated); } foreach (var inte in lvl.interactables) { Debug.Log(JsonUtility.ToJson(inte)); applyChannel(inte, instanciated); } if (lightManager != null) { lightManager.SetDistance(highestY); lightManager.setPlanetary(); } if (target != null) { parent.SetParent(target); } return(true); } catch (Exception e) { Debug.LogError(e.ToString()); return(false); } }
//void Update () // { // if (Input.GetMouseButtonDown(0)) // { // FadeToLevel(1); // } //} void Start() { f = Fader.GetComponent <LevelToLoad>(); }
public LevelToLoad ReadLevelJSON() { try { string filePath = Path.Combine(Application.persistentDataPath, "Levels/" + levelName); //string filePath = Path.Combine(Application.dataPath, "Levels/level.json"); Debug.Log(filePath); if (File.Exists(filePath)) { string dataAsJson = File.ReadAllText(filePath); JsonLevel loadedData = JsonUtility.FromJson <JsonLevel>(dataAsJson); //Debug.Log(dataAsJson); List <Element> Elements = new List <Element>(); List <Group> Groups = new List <Group>(); List <Interactable> Interactables = new List <Interactable>(); //Debug.Log(JsonUtility.ToJson(loadedData)); foreach (var element in loadedData.elements) { Element elm = new Element(idToGameObject(element.id)); elm.Position = new Vector3(element.position.x - 20.5f, element.position.y, element.position.z - 20.5f); elm.Rotation = new Quaternion(element.rotation.x, element.rotation.y, element.rotation.z, element.rotation.w); //Debug.Log(elm.Rotation); Elements.Add(elm); } foreach (var group in loadedData.groups) { Group grp = new Group(); grp.component = new Component(); grp.component.channel = group.component.channel; grp.component.id = group.component.id; grp.component.position = new Vector3(group.component.position.x - 20.5f, group.component.position.y, group.component.position.z - 20.5f); grp.component.speed = group.component.speed; grp.pA = new Vector3((group.pA.x * 2) - 20.5f, group.pA.y * 2, (group.pA.z * 2) - 20.5f); grp.pB = new Vector3((group.pB.x * 2) - 20.5f, group.pB.y * 2, (group.pB.z * 2) - 20.5f); //Debug.Log(elm.Rotation); Groups.Add(grp); } foreach (var interactable in loadedData.interactables) { Interactable inte = new Interactable(); inte.position = new Vector3(interactable.pos.x - 20.5f, interactable.pos.y, interactable.pos.z - 20.5f); inte.channel = interactable.channel; //Debug.Log(elm.Rotation); Interactables.Add(inte); } LevelToLoad lvl = new LevelToLoad(); lvl.groups = Groups; lvl.elements = Elements; lvl.interactables = Interactables; return(lvl); } else { Debug.Log("Can't find file !"); } } catch (Exception e) { Debug.LogException(e, this); Debug.Log("Can't find designed level"); return(null); } return(null); }