// Use this for initialization void Start() { m_eventHandlerUIClass = m_eventHandlerUI.GetComponent <EventHandlerUI>(); ShowView(m_startView); // This is the default value for user login (not hardcoding) m_loginViewNameInputField.text = ServerDataInfo.DEFAULT_USER_NAME; m_loginViewPasswordInputField.text = ServerDataInfo.DEFAULT_PASSWORD; }
public IEnumerator LoginRequest(string name, string password, EventHandlerUI handler) { WWWForm form = new WWWForm(); form.AddField("authkey", ServerDataInfo.AUTH_KEY); form.AddField("auth", ServerDataInfo.AUTH); form.AddField("username", name); form.AddField("password", password); form.AddField("gameid", ServerDataInfo.GAME_ID); WWW www = new WWW(ServerDataInfo.URL, form); yield return(www); if (www.error == null) { m_connected = true; Debug.Log(www.text); Dictionary <string, object> json_objects_all = MiniJSON.Json.Deserialize(www.text) as Dictionary <string, object>; if (json_objects_all["success"] != null) { string result = json_objects_all["success"].ToString(); // error // success if (result == "success") { string json_data = MiniJSON.Json.Serialize(json_objects_all["data"]); Dictionary <string, object> json_objects_data = MiniJSON.Json.Deserialize(json_data) as Dictionary <string, object>; PlayerPrefs.SetString("sessionid", json_objects_data["sessionId"].ToString()); PlayerPrefs.SetString("sessionkey", json_objects_data["sessionKey"].ToString()); } handler.EventUserLoginCallback(result, name); } } else { Debug.Log("Login Error!"); } }
//increments age each cycle, which is currently 10 seconds for a year. Cycle created inside WorldController class private void AddAge() { age += 1; EventHandlerUI.AgeChanged(); }
// Update is called once per frame void Update() { //DEBUG /*if(Input.GetKeyDown(KeyCode.E)){ * ApplicationControl.sceneSwitch = true; * ApplicationControl.maxBushes = 0.3f; * ApplicationControl.maxTrees = 0.2f; * ApplicationControl.maxPlants = 0.5f; * ApplicationControl.maxPopulation = 10; * ApplicationControl.malePop = 5; * ApplicationControl.femalePop = 5; * //spawning = true; * //GetFreePosition(); * * } */ if (currentTrees == maxTrees && currentBushes == maxBushes && currentPlants == maxPlants && currentNests == maxNests && currentRabbitPopulation == maxRabbitPopulation && currentSheepPopulation == maxSheepPopulation && spawning) { EventHandlerUI.Loading(); spawning = false; } if (ApplicationControl.sceneSwitch && !spawning) { StartSpawning(); } if (respawning) { if (currentPlants == maxPlants) { respawning = false; } else { if (GetFreePlantPosition()) { Transform plant = Instantiate(Resources.Load <Transform>("Assets/EntityPlant")); plant.position = new Vector3(spawnPosition.x, 0f, spawnPosition.z); currentPlants++; } } } if (spawning) { if (currentTrees < maxTrees) { if (GetFreeTreePosition()) { Transform tree = null; if (prng.Next(0, 2) == 1) { tree = Instantiate(Resources.Load <Transform>("Assets/EntityTree2")); } else { tree = Instantiate(Resources.Load <Transform>("Assets/EntityTree")); } tree.position = new Vector3(spawnPosition.x, -0.5f, spawnPosition.z); currentTrees++; } } else if (currentBushes < maxBushes) { if (GetFreeBushPosition()) { Transform bush = Instantiate(Resources.Load <Transform>("Assets/EntityBush")); bush.position = new Vector3(spawnPosition.x, 0.5f, spawnPosition.z); currentBushes++; } } else if (currentPlants < maxPlants) { if (GetFreePlantPosition()) { Transform plant = Instantiate(Resources.Load <Transform>("Assets/EntityPlant")); plant.position = new Vector3(spawnPosition.x, 0f, spawnPosition.z); currentPlants++; } } else if (currentRabbitPopulation < maxRabbitPopulation) { if (GetFreeAnimalPosition()) { Transform rabbit = Resources.Load <Transform>("Assets/AnimalRabbit"); Instantiate(rabbit, spawnPosition, default); if (currentRabbitMales < ApplicationControl.rabbitMalePop) { rabbit.GetComponent <Rabbit>().SetGender(true); currentRabbitMales++; } else if (currentRabbitFemales < ApplicationControl.rabbitFemalePop) { rabbit.GetComponent <Rabbit>().SetGender(false); currentRabbitFemales++; } currentRabbitPopulation++; } } else if (currentSheepPopulation < maxSheepPopulation) { if (GetFreeAnimalPosition()) { Transform sheep = Resources.Load <Transform>("Assets/AnimalSheep"); Instantiate(sheep, spawnPosition, default); if (currentSheepMales < ApplicationControl.sheepMalePop) { sheep.GetComponent <Sheep>().SetGender(true); currentRabbitMales++; } else if (currentSheepFemales < ApplicationControl.sheepFemalePop) { sheep.GetComponent <Sheep>().SetGender(false); currentSheepFemales++; } currentSheepPopulation++; } } else if (currentNests < maxNests) { if (GetFreeNestPosition()) { Transform nest = Instantiate(Resources.Load <Transform>("Assets/EntityNest")); nest.position = new Vector3(spawnPosition.x, 0f, spawnPosition.z); currentNests++; } } } }
protected void Update() { thirst -= Time.deltaTime * 0.2f; hunger -= Time.deltaTime * 0.095f; if (thirst < 0f) { Die(CauseOfDeath.Thirst); } if (hunger < 0f) { Die(CauseOfDeath.Hunger); } if (age > liveSpan) { Die(CauseOfDeath.OldAge); } if (!male && pregnant) { //GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); string currentOwner = nestTransform.GetComponent <Nest>().GetOwner().GetComponent <Animal>().GetName(); Transform baby; switch (currentOwner) { case "Rabbit": baby = Instantiate(Resources.Load <Transform>("Assets/AnimalRabbit")); baby.transform.position = nestTransform.position; if (Random.Range(0, 2) == 1) { baby.GetComponent <Rabbit>().SetGender(true); } else { baby.GetComponent <Rabbit>().SetGender(false); } break; case "Sheep": baby = Instantiate(Resources.Load <Transform>("Assets/AnimalSheep")); baby.transform.position = nestTransform.position; if (Random.Range(0, 2) == 1) { baby.GetComponent <Sheep>().SetGender(true); } else { baby.GetComponent <Sheep>().SetGender(false); } break; } pregnant = false; //lastChild = Time.time; } if (Time.time - lastChild > 120f) { canMate = true; } if (moving) { MoveTo(); } else { EventHandlerUI.ActionChanged(); HandleInteraction(); float timeSinceLastAction = Time.time - lastAction; if (timeSinceLastAction > betweenActionCooldown && (currentAction != Action.Eating && currentAction != Action.Drinking && currentAction != Action.Nesting)) { betweenActionCooldown = Random.Range(2f, 2.6f); ChooseNextAction(); } } }