Exemplo n.º 1
0
    /// <summary>
    /// Gets the user's current location and places a marker.
    /// </summary>
    void GPSLocation()
    {
        string stringer = "";

        // First, check if user has location service enabled
        if (!Input.location.isEnabledByUser)
        {
            return;
        }

        // Start service before querying location
        Input.location.Start();

        // Wait until service initializes
        int maxWait = 3000;

        while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
        {
            maxWait--;
        }

        // Service didn't initialize in 20 seconds
        if (maxWait < 1)
        {
            stringer = ("Timed out");
            controller.GetComponent <ControllerScript>().miniGPSDatabase[GameObject.Find("Sticker").GetComponent <ScannedStickersScript>().type] = stringer;
            Input.location.Stop();
        }

        // Connection has failed
        if (Input.location.status == LocationServiceStatus.Failed)
        {
            stringer = ("Unable to determine device location");
            controller.GetComponent <ControllerScript>().miniGPSDatabase[GameObject.Find("Sticker").GetComponent <ScannedStickersScript>().type] = stringer;
            Input.location.Stop();
        }
        else
        {
            // Access granted and location value could be retrieved
            stringer = (Input.location.lastData.latitude + " " + Input.location.lastData.longitude);
            controller.GetComponent <ControllerScript>().miniGPSDatabase[GameObject.Find("Sticker").GetComponent <ScannedStickersScript>().type] = stringer;
            PlaceMarker(stringer);
            Input.location.Stop();
        }

        // Stop service if there is no need to query location updates continuously
        Input.location.Stop();
    }
Exemplo n.º 2
0
    public WorldData(ControllerScript controller)
    {
        time = controller.time;
        ambientTemperature = controller.ambientTemperature;
        playerTemperature  = controller.playerTemperature;
        currentSeason      = controller.currentSeason;
        currentDay         = controller.currentDay;
        currentDayInSeason = controller.currentDayInSeason;
        health             = controller.playerInventoryScript.GetComponent <PlayerScript> ().health;
        hunger             = controller.playerInventoryScript.GetComponent <PlayerScript> ().hunger;
        happiness          = controller.playerInventoryScript.GetComponent <PlayerScript> ().happiness;

        droppedItems   = new SaveSystem.MyDroppedItem[controller.GetComponent <SaveSystemScript>().items.Length];
        terrains       = new SaveSystem.MyTerrain[controller.GetComponent <SaveSystemScript> ().terrains.Length];
        buildings      = new SaveSystem.Buildings.BasicBuildingSaveProperties[controller.GetComponent <SaveSystemScript>().buildings.Length];
        mobs           = new SaveSystem.Mobs.BasicMobAttributes[controller.GetComponent <SaveSystemScript>().mobs.Length];
        playerPosition = new MyVector3(controller.playerInventoryScript.transform.position);

        playerInventory = new SerializedInventoryItem[controller.playerInventoryScript.playerInventory.Length];
        for (int i = 0; i < playerInventory.Length; i++)
        {
            playerInventory [i] = controller.playerInventoryScript.playerInventory [i].convertToSave();
        }
        for (int i = 0; i < droppedItems.Length; i++)
        {
            if (controller.GetComponent <SaveSystemScript> ().items [i] != null)
            {
                droppedItems [i] = new SaveSystem.MyDroppedItem(controller.GetComponent <SaveSystemScript> ().items [i].transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue.name, controller.GetComponent <SaveSystemScript> ().items [i].transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue.quantity, new MyVector3(controller.GetComponent <SaveSystemScript> ().items [i].transform.position));
            }
        }

        for (int i = 0; i < terrains.Length; i++)
        {
            if (controller.GetComponent <SaveSystemScript> ().terrains [i] != null)
            {
                GameObject terrain = controller.GetComponent <SaveSystemScript> ().terrains [i];
                terrains [i] = new SaveSystem.MyTerrain(terrain.GetComponent <TerrainScript> ().terrainName, terrain.transform.position);
            }
        }
        for (int i = 0; i < mobs.Length; i++)
        {
            if (controller.GetComponent <SaveSystemScript> ().mobs [i] != null)
            {
                GameObject mob = controller.GetComponent <SaveSystemScript> ().mobs [i];
                if (mob.GetComponent <PassiveFourLegs> () != null)
                {
                    mobs [i] = new SaveSystem.Mobs.BasicMobAttributes(mob.GetComponent <PassiveFourLegs>().mobName, mob.GetComponent <PassiveFourLegs> ().health, mob.GetComponent <PassiveFourLegs> ().maxHealth, mob.transform.position, mob.transform.eulerAngles);
                }
                else if (mob.GetComponent <Sheep> () != null)
                {
                    mobs [i] = new SaveSystem.Mobs.Sheep(mob.GetComponent <Sheep>().mobName, mob.GetComponent <Sheep> ().health, mob.GetComponent <Sheep> ().maxHealth, mob.transform.position, mob.transform.eulerAngles);
                }
            }
        }
        for (int i = 0; i < buildings.Length; i++)
        {
            if (controller.GetComponent <SaveSystemScript> ().buildings [i] != null)
            {
                GameObject building = controller.GetComponent <SaveSystemScript> ().buildings [i];

                TreeScript       treeScript        = null;
                BoulderScript    boulderScript     = null;
                GrassScript      grassScript       = null;
                BushScript       bushScript        = null;
                BerryBushScript  berryBushScript   = null;
                FireScript       fireScript        = null;
                GroundFoodScript naturalFoodScript = null;

                if (building.GetComponent <TreeScript> () != null)
                {
                    treeScript = building.GetComponent <TreeScript> ();
                }
                if (building.GetComponent <BoulderScript> () != null)
                {
                    boulderScript = building.GetComponent <BoulderScript> ();
                }
                if (building.GetComponent <GrassScript> () != null)
                {
                    grassScript = building.GetComponent <GrassScript> ();
                }
                if (building.GetComponent <BushScript> () != null)
                {
                    bushScript = building.GetComponent <BushScript> ();
                }
                if (building.GetComponent <BerryBushScript> () != null)
                {
                    berryBushScript = building.GetComponent <BerryBushScript> ();
                }
                if (building.GetComponent <FireScript> () != null)
                {
                    fireScript = building.GetComponent <FireScript> ();
                }
                if (building.GetComponent <GroundFoodScript> () != null)
                {
                    naturalFoodScript = building.GetComponent <GroundFoodScript> ();
                }

                if (treeScript != null || boulderScript != null)
                {
                    //natural barriers
                    if (treeScript != null)
                    {
                        buildings [i] = new SaveSystem.Buildings.NaturalBarriers("tree", treeScript.transform.position, treeScript.transform.eulerAngles, treeScript.health);
                    }
                    else if (boulderScript != null)
                    {
                        buildings [i] = new SaveSystem.Buildings.NaturalBarriers("boulder", boulderScript.transform.position, boulderScript.transform.eulerAngles, boulderScript.health);
                    }
                }
                else if (grassScript != null || bushScript != null || berryBushScript != null)
                {
                    if (grassScript != null)
                    {
                        buildings [i] = new SaveSystem.Buildings.NaturalCrops("grassPatch", grassScript.transform.position, grassScript.transform.eulerAngles, grassScript.cut, grassScript.growTimer);
                    }
                    if (bushScript != null)
                    {
                        buildings [i] = new SaveSystem.Buildings.NaturalCrops("bush", bushScript.transform.position, bushScript.transform.eulerAngles, bushScript.cut, bushScript.growTimer);
                    }
                    else if (berryBushScript != null)
                    {
                        buildings [i] = new SaveSystem.Buildings.NaturalCrops("berryBush", berryBushScript.transform.position, berryBushScript.transform.eulerAngles, berryBushScript.cut, berryBushScript.growTimer);
                    }
                }
                else if (fireScript != null)
                {
                    buildings [i] = new SaveSystem.Buildings.Campfire("campfire", fireScript.transform.position, fireScript.transform.eulerAngles, fireScript.fuel);
                }
                else if (naturalFoodScript != null)
                {
                    buildings [i] = new SaveSystem.Buildings.BasicBuildingSaveProperties(naturalFoodScript.buildingIDName, naturalFoodScript.transform.position, naturalFoodScript.transform.eulerAngles);
                }
            }
        }
    }
 //reference here everytime building is placed, item is dropped or crop is planted
 //complete here
 public void addGameObjectToSaves(GameObject building)
 {
     masterControllerScript.GetComponent <SaveSystemScript> ().addObjectToBuildingsArray(building);
 }
Exemplo n.º 4
0
    public static void LoadPlayer(ControllerScript controller)
    {
        if (File.Exists(Application.persistentDataPath + "/wa.sav"))
        {
            BinaryFormatter bf     = new BinaryFormatter();
            FileStream      stream = new FileStream(Application.persistentDataPath + "/wa.sav", FileMode.Open);
            WorldData       data   = bf.Deserialize(stream) as WorldData;
            for (int i = 0; i < controller.playerInventoryScript.playerInventory.Length; i++)
            {
                controller.playerInventoryScript.playerInventory [i] = data.playerInventory [i].convertToNormal();
            }
            controller.playerInventoryScript.transform.position = data.playerPosition.toVec3();

            controller.currentDay         = data.currentDay - 1;
            controller.currentSeason      = data.currentSeason;
            controller.currentDayInSeason = data.currentDayInSeason - 1;
            controller.newDay();
            controller.time = data.time;
            controller.ambientTemperature = data.ambientTemperature;
            controller.playerTemperature  = data.playerTemperature;

            controller.playerInventoryScript.GetComponent <PlayerScript> ().health    = data.health;
            controller.playerInventoryScript.GetComponent <PlayerScript> ().hunger    = data.hunger;
            controller.playerInventoryScript.GetComponent <PlayerScript> ().happiness = data.happiness;

            for (int i = 0; i < data.mobs.Length; i++)
            {
                if (data.mobs [i] != null)
                {
                    GameObject prefab  = controller.playerInventoryScript.findMobPrefabWithName(data.mobs [i].name);
                    GameObject insItem = GameObject.Instantiate(prefab, data.mobs [i].position.toVec3(), data.mobs [i].rotation.toRotation()) as GameObject;
                    controller.GetComponent <SaveSystemScript> ().addObjectToMobsArray(insItem);

                    string targetName = data.mobs [i].name;

                    //for pigs
                    if (insItem.GetComponent <PassiveFourLegs> () != false)
                    {
                        insItem.GetComponent <PassiveFourLegs> ().health    = data.mobs [i].health;
                        insItem.GetComponent <PassiveFourLegs> ().maxHealth = data.mobs [i].maxHealth;
                    }
                    else if (targetName == "sheep")
                    {
                        insItem.GetComponent <Sheep> ().health    = data.mobs [i].health;
                        insItem.GetComponent <Sheep> ().maxHealth = data.mobs [i].maxHealth;
                    }
                }
            }
            for (int i = 0; i < data.buildings.Length; i++)
            {
                if (data.buildings[i] != null)
                {
                    GameObject prefab  = controller.playerInventoryScript.findBuildingPrefabWithName(data.buildings [i].name);
                    GameObject insItem = GameObject.Instantiate(prefab, data.buildings[i].position.toVec3(), data.buildings[i].rotation.toRotation()) as GameObject;
                    controller.GetComponent <SaveSystemScript> ().addObjectToBuildingsArray(insItem);

                    string targetName = data.buildings [i].name;

                    if (targetName == "campfire")
                    {
                        //float
                        insItem.GetComponent <FireScript> ().fuel = data.buildings [i].fuel;
                    }
                    else if (targetName == "berryBush" || targetName == "grassPatch" || targetName == "bush")
                    {
                        //bool, float
                        if (insItem.GetComponent <BerryBushScript> () != null)
                        {
                            insItem.GetComponent <BerryBushScript> ().cut       = data.buildings [i].cut;
                            insItem.GetComponent <BerryBushScript> ().growTimer = data.buildings [i].growthTime;
                        }
                        else if (insItem.GetComponent <BushScript> () != null)
                        {
                            insItem.GetComponent <BushScript> ().cut       = data.buildings [i].cut;
                            insItem.GetComponent <BushScript> ().growTimer = data.buildings [i].growthTime;
                        }
                        else if (insItem.GetComponent <GrassScript> () != null)
                        {
                            insItem.GetComponent <GrassScript> ().cut       = data.buildings [i].cut;
                            insItem.GetComponent <GrassScript> ().growTimer = data.buildings [i].growthTime;
                        }
                    }
                    else if (targetName == "boulder" || targetName == "tree")
                    {
                        //int
                        if (insItem.GetComponent <BoulderScript> () != null)
                        {
                            insItem.GetComponent <BoulderScript> ().health = data.buildings [i].health;
                        }
                        else if (insItem.GetComponent <TreeScript> () != null)
                        {
                            insItem.GetComponent <TreeScript> ().health = data.buildings [i].health;
                        }
                    }
                }
            }
            for (int i = 0; i < data.terrains.Length; i++)
            {
                if (data.terrains[i] != null)
                {
                    GameObject prefab  = controller.playerInventoryScript.findTerrainPrefabWithName(data.terrains [i].terrainType);
                    GameObject insItem = GameObject.Instantiate(prefab, data.terrains[i].position.toVec3(), Quaternion.identity) as GameObject;
                    controller.GetComponent <SaveSystemScript> ().addObjectToTerrainsArray(insItem);
                }
            }
            for (int i = 0; i < data.droppedItems.Length; i++)
            {
                if (data.droppedItems[i] != null)
                {
                    GameObject prefab  = controller.playerInventoryScript.droppedItemPrefab;
                    GameObject insItem = GameObject.Instantiate(prefab, data.droppedItems[i].position.toVec3(), prefab.transform.rotation);
                    insItem.transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue = new InventoryItem(data.droppedItems[i].itemQuantity, data.droppedItems[i].itemName, controller.playerInventoryScript.findItemDisplayNameWithName(data.droppedItems[i].itemName));
                    controller.GetComponent <SaveSystemScript> ().addObjectToItemsArray(insItem);
                }
            }

            stream.Close();
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// Let the GameScript do stuff when pressed, what, differs per button.
    /// </summary>
    void ButtonClick()
    {
        switch (buttonType)
        {
        case ButtonTypes.Scan:
            controller.AddPreviousScene();
            SceneManager.LoadScene("QRScanScene");
            break;

        case ButtonTypes.Find:
            controller.AddPreviousScene();
            SceneManager.LoadScene("CatalogueScene0");
            break;

        case ButtonTypes.Buy:
            controller.AddPreviousScene();
            SceneManager.LoadScene("BuyScene");
            break;

        case ButtonTypes.Info:
            controller.AddPreviousScene();
            SceneManager.LoadScene("InfoScene");
            break;

        case ButtonTypes.Map:
            controller.AddPreviousScene();
            SceneManager.LoadScene("MapScene");
            break;

        case ButtonTypes.Stats:
            SceneManager.LoadScene("StatsScene");
            break;

        case ButtonTypes.Login:
            controller.AddPreviousScene();
            if (controller.currentUser == -1)
            {
                SceneManager.LoadScene("LoginScene");
            }
            else
            {
                SceneManager.LoadScene("AccountScene");
            }
            break;

        case ButtonTypes.Home:
            controller.AddPreviousScene();
            SceneManager.LoadScene("HomeScene");
            break;

        case ButtonTypes.WhatIsBulkyWaste:
            controller.AddPreviousScene();
            SceneManager.LoadScene("FindStickerScene");
            break;

        case ButtonTypes.NeedHelp:
            controller.AddPreviousScene();
            SceneManager.LoadScene("FindStickerScene2");
            break;

        case ButtonTypes.CatalogueNormal:
            controller.catalogueElectronic = false;
            controller.AddPreviousScene();
            SceneManager.LoadScene("CatalougeScene2");
            break;

        case ButtonTypes.CatalogueElectronic:
            controller.catalogueElectronic = true;
            controller.AddPreviousScene();
            SceneManager.LoadScene("CatalougeScene2");
            break;

        case ButtonTypes.Back:
            controller.gotoPreviousScene();
            break;

        case ButtonTypes.Activate:
            controller.GetComponent <ControllerScript>().miniDateDatabase[GameObject.Find("Sticker").GetComponent <ScannedStickersScript>().type] = DateTime.Now.ToString();
            GPSLocation();
            break;

        case ButtonTypes.Deactivate:
            controller.GetComponent <ControllerScript>().miniDateDatabase[GameObject.Find("Sticker").GetComponent <ScannedStickersScript>().type] = null;
            SceneManager.LoadScene("ScannedItemScene");
            break;

        case ButtonTypes.DoneAfterScan:
            SceneManager.LoadScene("ScannedItemScene");
            break;

        case ButtonTypes.Next:
            Next();
            break;

        case ButtonTypes.Done:
            SceneManager.LoadScene("ScannedItemScene");
            break;

        case ButtonTypes.BuyNormal:
            controller.buyElectronic = false;
            controller.AddPreviousScene();
            SceneManager.LoadScene("BuyScene2");
            break;

        case ButtonTypes.BuyElectronic:
            controller.buyElectronic = true;
            controller.AddPreviousScene();
            SceneManager.LoadScene("BuyScene2");
            break;

        case ButtonTypes.StickerButton:
            controller.AddPreviousScene();
            SceneManager.LoadScene("BuyScene3");
            break;

        case ButtonTypes.BuyOnline:
            controller.AddPreviousScene();
            SceneManager.LoadScene("BuyScene4");     //How do I get to the scene where all the naked people have sex? LoadScene("ObScene");
            break;

        case ButtonTypes.LogInOnLogin:
            GetComponent <LogInScript>().Login();
            break;

        case ButtonTypes.CreateAccountConfirm:
            GetComponent <CreateAccountScript>().Create();
            break;

        case ButtonTypes.CreateAccount:
            controller.AddPreviousScene();
            SceneManager.LoadScene("CreateAccountScene");
            break;

        case ButtonTypes.Skip:
            SceneManager.LoadScene("AccountScene");
            break;

        case ButtonTypes.OK:
            GetComponent <AddDetailsScript>().AddDetails();
            break;

        case ButtonTypes.EditProfile:
            controller.AddPreviousScene();
            SceneManager.LoadScene("AddAccountDetailsScene");
            break;

        case ButtonTypes.CatalogueResult:
            controller.AddPreviousScene();
            controller.selectedSticker = (int)GetComponent <StickerScript>().type;
            SceneManager.LoadScene("BuyScene3");
            break;

        case ButtonTypes.CompleteOrder:
            SceneManager.LoadScene("BuyScene5");
            break;

        case ButtonTypes.Logout:
            controller.currentUser = -1;
            SceneManager.LoadScene("HomeScene");
            break;

        case ButtonTypes.Row1:
            controller.findStickerScene[0] = controller.catalogueElectronic;
            controller.findStickerScene[2] = false;
            SceneManager.LoadScene("CatalogueScene3");
            break;

        case ButtonTypes.Row2:
            controller.findStickerScene[0] = controller.catalogueElectronic;
            controller.findStickerScene[2] = true;
            SceneManager.LoadScene("CatalogueScene3");
            break;
        }
    }