public void LoadTheData() { if (objectlist.Count != 0) { foreach (GameObject o in objectlist) { Destroy(o); } objectlist.Clear(); } SD = new SaveData(); if (File.Exists(PlayerPrefs.GetString("Level", "None"))) { file = PlayerPrefs.GetString("Level", "None"); } else { file = "savedata.xml"; } if (File.Exists(file)) { XmlSerializer x = new XmlSerializer(typeof(SaveData)); FileStream myFileStream = new FileStream(file, FileMode.Open); SD = (SaveData)x.Deserialize(myFileStream); myFileStream.Close(); foreach (DataStruct od in SD.DataStructList) { GameObject newGO = Instantiate(SpawnPrefab[od.number], od.Location, od.Rot); placeable nOD = newGO.GetComponent <placeable>(); nOD.codex = od.number; nOD.Location = od.Location; nOD.Rot = od.Rot; objectlist.Add(newGO); PlayerSpawn p = newGO.GetComponent <PlayerSpawn>(); if (p != null) { ps = p; if (play) { ps.Play = true; } } } foreach (GameObject od in objectlist) { if (od.transform.position.y < ps.bottom) { ps.bottom = od.transform.position.y; } } } else { Debug.Log("Failed to find file"); } }
void FixedUpdate() { RaycastHit hit; Ray ray = cam.ScreenPointToRay(gameObject.transform.position); ray.direction = gameObject.transform.forward; if (Physics.Raycast(ray, out hit)) { /* * if (last != hit.collider.gameObject && last != null) * { * Renderer rend = hit.collider.gameObject.GetComponent<Renderer>(); * current = hit.collider.gameObject; * Renderer rend2 = last.GetComponent<Renderer>(); * * if (rend2 != null && last != null) * { * rend2.material.color = Original; * } * if (rend != null) * { * Original = rend.material.color; * rend.material.color = red; * } * } */ if (last != hit.collider.gameObject && last != null) { Debug.Log("hit"); Renderer rend = hit.collider.gameObject.GetComponent <Renderer>(); current = hit.collider.gameObject; placeable p = last.GetComponent <placeable>(); if (p == null) { p = last.GetComponentInParent <placeable>(); } if (p != null) { p.ResetColor(); } rend.material.color = red; } if (Input.GetMouseButtonDown(0)) { MouseButton(); } last = hit.collider.gameObject; } }
public override void EndCommand() { if (current != null) { placeable rend = current.GetComponent <placeable>(); if (rend != null) { rend.ResetColor(); } } }
public void SaveTheData() { file = PlayerPrefs.GetString("Level", "None"); SD = new SaveData(); ml.addobjects(); foreach (GameObject o in objectlist) { placeable od = o.GetComponent <placeable>(); if (od && o.tag != "ghost") { SD.AddData(od.codex, od.Location, od.Rot); } Debug.Log(SD.DataStructList.Count); } string filename = file; XmlSerializer x = new XmlSerializer(typeof(SaveData)); TextWriter writer = new StreamWriter(filename); x.Serialize(writer, SD); writer.Close(); Debug.Log("Save Data!"); }