void Awake() { mycam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>(); mytransform = transform; //Check if the SetGeolocation script is being used try { setLocation = gameObject.GetComponent <SetGeolocation>(); } catch (System.Exception e) { Debug.Log(e); } //Use SetGeolocation scale values as size reference if (setLocation != null) { initScale = new Vector3(setLocation.scaleX, setLocation.scaleY, setLocation.scaleZ); } else { initScale = transform.localScale; } }
public void AddQuest(float lat, float lon) { //Create new quest Quest newQuest = new Quest(); newQuest.id = quests.Count + 1; newQuest.portal = "Plasma_02"; newQuest.pre = ""; newQuest.answer = ""; newQuest.post = ""; //Add previous as precedence if (quests.Count > 0) { newQuest.precedences.Add(quests.Count); } quests.Add(newQuest); //Create item in list UnityEngine.Object res = Resources.Load("QuestTemplate"); GameObject newElement = (GameObject)GameObject.Instantiate(res); newElement.transform.SetParent(questList); newElement.transform.localScale = Vector3.one; newQuest.questElement = newElement; //Asign OnClick Button btn = newElement.GetComponent <Button> (); btn.onClick.AddListener(delegate { ShowQuestDetails(newQuest.id); }); //Put object on map UnityEngine.Object resource = Resources.Load("MapObject"); GameObject mapObject = (GameObject)GameObject.Instantiate(resource); SetGeolocation loc = mapObject.GetComponent <SetGeolocation> (); loc.lat = lat; loc.lon = lon; loc.height = playerLocation.height - 100; loc.scaleX = 1f; loc.scaleY = 1f; loc.scaleZ = 1f; GetGeolocation realLoc = mapObject.GetComponent <GetGeolocation> (); newQuest.location = realLoc; QuestObject script = mapObject.AddComponent <QuestObject> (); script.id = newQuest.id; newQuest.mapObject = mapObject; }
private void MoveCursor(float lat, float lon) { SetGeolocation oldScript = playerLocation.gameObject.GetComponent <SetGeolocation> (); if (oldScript != null) { Destroy(oldScript); } SetGeolocation script = playerLocation.gameObject.AddComponent <SetGeolocation> (); script.lat = lat; script.lon = lon; script.height = playerLocation.height; script.scaleX = playerLocation.scaleX; script.scaleY = playerLocation.scaleY; script.scaleZ = playerLocation.scaleZ; }
private IEnumerator LoadQuestDataCoroutine(int questId) { Debug.Log("Gathering database data..."); SetLoadingBar(0f); WWW www = new WWW(baseUrl + "quest.php?id=" + questId); Debug.Log(baseUrl + "quest.php?id=" + questId); while (!www.isDone) { SetLoadingBar(www.progress); } yield return(www.progress); Debug.Log(www.text); SetLoadingBar(1f); if (www.error != null) { Debug.Log("No connection available!!"); } else { if (www.text != "") { JSONNode objectsDatabase = JSON.Parse(www.text); for (int i = 0; i < objectsDatabase["elements"].AsInt; i++) { Quest newQuest = new Quest(); JSONNode obj = objectsDatabase["objects"][i]; newQuest.id = obj["id"].AsInt; newQuest.name = obj["name"].Value; newQuest.lat = obj["lat"].AsFloat; newQuest.lon = obj["lon"].AsFloat; newQuest.portal = obj["object"].Value; newQuest.pre = obj["pre"].Value; newQuest.post = obj["post"].Value; newQuest.answer = obj["answer"].Value; newQuest.type = obj["type"].AsInt; newQuest.media = obj["media"].Value; quests.Add(newQuest); //Create item in list UnityEngine.Object res = Resources.Load("QuestTemplate"); GameObject newElement = (GameObject)GameObject.Instantiate(res); newElement.transform.SetParent(questList); newElement.transform.localScale = Vector3.one; newQuest.questElement = newElement; Text questName = newElement.GetComponentInChildren <Text>(); questName.text = newQuest.name; //Asign OnClick Button btn = newElement.GetComponent <Button> (); AddClickListener(btn, newQuest.id); //Put object on map UnityEngine.Object resource = Resources.Load("MapObject"); GameObject mapObject = (GameObject)GameObject.Instantiate(resource); SetGeolocation loc = mapObject.GetComponent <SetGeolocation> (); loc.lat = newQuest.lat; loc.lon = newQuest.lon; loc.height = playerLocation.height - 100; loc.scaleX = 1f; loc.scaleY = 1f; loc.scaleZ = 1f; GetGeolocation realLoc = mapObject.GetComponent <GetGeolocation> (); newQuest.location = realLoc; QuestObject script = mapObject.AddComponent <QuestObject> (); script.id = newQuest.id; newQuest.mapObject = mapObject; if (newQuest.id == 1) { MoveCursor(newQuest.lat, newQuest.lon); } } } } }