// Update is called once per frame
    void Update()
    {
        if (type == Type.builder)
        {
            // Will load the menu if power is pressed
            if (Input.GetAxis("Power") > 0)
            {
                GoToMenu();
            }

            if (SceneManager.GetActiveScene().name == "coursebuilder")
            {
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                //
                if (Physics.Raycast(ray, out hit))
                {
                    lvlBuilder LB = hit.collider.GetComponent <lvlBuilder>();

                    //
                    if (Input.GetMouseButton(0) && LB.perim == false)
                    {
                        if (!remove)
                        {
                            if (spent == false)
                            {
                                // change these to = first in selhexx array
                                stSave = hit.transform.position;
                                S.transform.position = stSave + (Vector3.up * 2.05f);
                                stLoc = LB.id;
                                spent = true;
                            }

                            SelectHex(hit.collider.gameObject);
                        }
                        else
                        {
                            RemoveHex(hit.collider.gameObject);

                            if (selHexx.Count > 0)
                            {
                                lvlBuilder LB2 = selHexx[0].GetComponent <lvlBuilder>();
                                int        ch  = LB2.id;

                                //
                                if (ch != stLoc)
                                {
                                    S.transform.position = LB2.transform.position + (Vector3.up * 2.05f);
                                    stSave = S.transform.position;
                                }
                            }
                            else
                            {
                                spent  = false;
                                stSave = Vector3.zero;
                                S.transform.position = Vector3.one * 1000;
                            }
                        }
                    }
                    else if (Input.GetMouseButton(1))
                    {
                        RemoveHex(hit.collider.gameObject);

                        if (selHexx.Count > 0)
                        {
                            lvlBuilder LB2 = selHexx[0].GetComponent <lvlBuilder>();
                            int        ch  = LB2.id;

                            //
                            if (ch != stLoc)
                            {
                                S.transform.position = LB2.transform.position + (Vector3.up * 2.05f);
                                stSave = S.transform.position;
                            }
                        }
                        else
                        {
                            spent  = false;
                            stSave = Vector3.zero;
                            S.transform.position = Vector3.one * 1000;
                        }
                    }
                }

                //
                if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1))
                {
                    saveB.interactable = (saveIF.text != "" && selHexx.Count > 5);
                }

                if (!Input.GetMouseButton(0))
                {
                    dir = 0;
                }
                //
                if (Input.GetMouseButton(2))
                {
                    dir = (Input.GetKey(KeyCode.LeftShift)) ? -1 : 1;
                }

                S.transform.eulerAngles += Vector3.up * dir;
            }
        }
    }
    void GenHex(GameObject F)
    {
        List <int> data = new List <int>();

        int[] t = new int[saveFile.Split(',').Length - 1];

        bool loading = (t.Length > 5);

        string vectConv = saveFile.Split(',')[saveFile.Split(',').Length - 1];

        //
        if (SceneManager.GetActiveScene().name == "course")
        {
            startPt = new Vector4(float.Parse(vectConv.Split('#')[0]), float.Parse(vectConv.Split('#')[1]), float.Parse(vectConv.Split('#')[2]), float.Parse(vectConv.Split('#')[3]));
        }

        //
        if (loading)
        {
            for (int i = 0; i < t.Length; i++)
            {
                t[i] = int.Parse(saveFile.Split(',')[i]);
            }

            data.AddRange(t);
        }

        for (int i = 0; i < size.x; i++)
        {
            if (!data.Contains(id))
            {
                GameObject H = Instantiate(hex);
                H.tag = "Obstacle";
                H.AddComponent <MeshCollider>();
                H.transform.position = new Vector3(i - (size.x / 2), 0, -(size.y / 2));
                H.transform.SetParent(F.transform);

                lvlBuilder lb = H.AddComponent <lvlBuilder>();
                lb.mat   = mat;
                lb.type  = Type.block;
                lb.id    = id;
                lb.perim = true;
            }
            id++;

            for (int j = 1; j < size.y; j++)
            {
                if (!data.Contains(id))
                {
                    if (size.y > 1)
                    {
                        GameObject I = Instantiate(hex);
                        I.tag = "Obstacle";
                        I.AddComponent <MeshCollider>();
                        I.transform.position = new Vector3(i - (size.x / 2) - ((j % 2 == 1) ? .5f : 0), 0, (j * .87f) - (size.y / 2));
                        I.transform.SetParent(F.transform);

                        lvlBuilder lb2 = I.AddComponent <lvlBuilder>();
                        lb2.mat  = mat;
                        lb2.type = Type.block;
                        lb2.id   = id;

                        if (i == 0 || i == size.x - 1 || j == size.y - 1)
                        {
                            lb2.perim = true;
                        }
                    }
                }
                id++;
            }
        }
    }
Exemple #3
0
    // Use this for initialization
    void Start()
    {
        menuParams.Check4MenuParam();

        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        campAdd = true;

        //
        if (GameObject.Find("menuParams"))
        {
            mP = GameObject.Find("menuParams").GetComponent <menuParams>();

            if (mP.sesh)
            {
                StreamReader sr   = new StreamReader(Path.Combine(Application.dataPath, "sesh.txt"));
                string[]     load = sr.ReadToEnd().Split('\n');
                sr.Close();

                mP.seshMark.y = load.Length;

                if (mP.seshMark.x > mP.seshMark.y)
                {
                    Application.Quit();
                    if (Application.isEditor)
                    {
                        GoToMenu();
                    }
                }

                string[] load2 = load[(int)mP.seshMark.x - 1].Split(',');

                // laps, days, course, CO, Mode, attempts, ini
                mP.laps             = int.Parse(load2[0]);
                mP.maxDays          = int.Parse(load2[1]);
                mP.lvlName          = load2[2];
                mP.lvlData          = menu.ReturnLvlData(load2[2]);
                mP.CO               = (COMode)int.Parse(load2[3]);
                mP.mode             = (GameMode)int.Parse(load2[4]);
                mP.attempts         = int.Parse(load2[5]);
                mP.randomizeWeights = bool.Parse(load2[6]);
                mP.storedName       = load2[7];
            }

            mode                = mP.mode;
            CrossOver           = mP.CO;
            selMode             = mP.SEL;
            randomizeIniWeights = mP.randomizeWeights;
            attempt.y           = mP.attempts;
            mLaps               = mP.laps;
            slowMode            = mP.slowMode;

            //
            if (mode == GameMode.Test)
            {
                attempt.y = mP.brains.Count;
            }
            else if (mode == GameMode.Campaign)
            {
                attempt.y = 1;
            }
            //
            if (mP.brains.Count > 0)
            {
                //
                for (int i = 0; i < mP.brains.Count; i++)
                {
                    loadedBrains.Add(mP.brains[i].Split('\n')[1]);
                }
            }


            //
            lvlBuilder lb = gameObject.AddComponent <lvlBuilder>();

            //
            if (mode == GameMode.Test || mode == GameMode.Train)
            {
                lb.saveFile = mP.lvlData;
                lb.reverse  = mP.reverse;
            }
            else
            {
                mP.lvlName  = "Campaign Course #" + (mP.campaignProgress + 1);
                lb.saveFile = (mP.campaignProgress < 4) ? mP.campaign[(int)Mathf.Floor(mP.campaignProgress)] : "FINAL";
                lb.reverse  = (mP.campaignProgress % 1) != 0;
            }
        }

        //
        graphs[0] = GameObject.Find("FitnessGraph");
        graphs[1] = GameObject.Find("AverageGraph");

        // This will disable the UI if in race mode
        rT[0].gameObject.SetActive(mode == GameMode.Test || mode == GameMode.Campaign);
        rT[1].gameObject.SetActive(mode == GameMode.Train);

        // Set the appropriate version number on the top left of screen
        vT.text = "v" + Application.version;

        // Set all of the input texts to "?" instead of the default "New Text" :)
        for (int i = 0; i < inp.Length; i++)
        {
            inp[i].text = "?";
        }

        // This will hide the starting marker
        startSp.GetComponent <Renderer>().enabled = false;

        // This grabs a ref to the camera's starting position & rotation
        camStarts[0] = Camera.main.transform.position;
        camStarts[1] = Camera.main.transform.eulerAngles;

        // This sets the text for the control & camera mode buttons
        //ctButt.text = intelli.ToString();
        camButt.text = Camy.ToString();

        // attIniData is Attempt Initializer, we first need to define how many brains this ini will hold, it will hold our max attempt count
        attIniData = new float[(int)attempt.y][];

        //
        attIniString = new string[(int)attempt.y];

        // then every brian will hold 29 values, in our case floats, so we'll loop through every brain & set their value size to hold 29 floats, which will be a fully randomized brain
        for (int i = 0; i < attIniData.Length; i++)
        {
            attIniData[i] = new float[29];
        }

        //
        if (loadedBrains == null || loadedBrains.Count < 1)
        {
            //
            if (randomizeIniWeights)
            {
                RandomizeWholeDay();
            }
        }
        else
        {
            SetWholeDay();
        }
    }