コード例 #1
0
    // Use this for initialization
    public void Start()
    {
        // Set reference to the builderScript
        builderScript    = GameObject.Find("BuildingManager").GetComponent <BuilderScript>();
        uiScript         = GameObject.Find("UIManager").GetComponent <UIManagerScript>();
        inputFieldScript = gameObject.GetComponent <InputField>();

        // Add a listener function to this object.
        // The onEndEdit listener has to have a string as its input parameter
        inputFieldScript.onEndEdit.AddListener(EnhancedOnEndEdit);
    }
コード例 #2
0
    // Use this for initialization
    void Start()
    {
        // set references to the objects to be used
        levelButtonHolder = GameObject.Find("LevelButtonHolder");

        buildingManager = GameObject.Find("BuildingManager");
        buildScript     = buildingManager.GetComponent <BuilderScript>();

        yesButton = GameObject.Find("YesButton");
        noButton  = GameObject.Find("NoButton");

        cancelButton = GameObject.Find("CancelButton");

        cubeMgr = GameObject.Find("GameManager").GetComponent <CubeManager>();

        clueEditButton = GameObject.Find("ClueEditButton");
        clueEditButton.SetActive(false);    // Initially hide the clue edit button.

        // Reference to the exit button.
        exitButton = GameObject.Find("ExitButton");

        // Initially hide the yes, no, and cancel buttons.
        yesButton.SetActive(false);
        noButton.SetActive(false);
        cancelButton.SetActive(false);

        // set menu on to initially be true
        isMenuOn = true;

        // Set the path to the folder that contains the puzzles
        folderPath = Application.streamingAssetsPath;

        // set the reference to the parent object that is holding all the help images/text
        facesHelpGroup = GameObject.Find("FacesHelpGroup");
        facesHelpGroup.SetActive(false);

        //set the reference to the help text that is visible
        // initially hide it, havingthe controls/help open
        helpText = GameObject.Find("HelpText");

        inputField          = GameObject.Find("InputField");
        puzzleSavedText     = GameObject.Find("PuzzleSavedText");
        overwriteTextObject = GameObject.Find("OverwriteText");
        overwriteTextObject.SetActive(false);

        //Initially hide the inputField and puzzleSavedText
        inputField.SetActive(false);
        puzzleSavedText.SetActive(false);

        enteringInput = false;  // Initialize this tracker as false since the game starts
                                // without showing the inputField.

        askingReplay = false;   // AskingReplay will be set to true after a puzzle is completed.
        // TODO
        // Make this work for android/web
        // Might need to include all this in an IENumerator-returning method

        /*
         * // if the streamingAssetsPath contains the start of a web address, such as when
         * // the game is built for web or android, modify the path to be read via this method
         * if (folderPath.Contains("://"))
         * {
         *  UnityEngine.Networking.UnityWebRequest www = UnityEngine.Networking.UnityWebRequest.Get(folderPath);
         *  yield return www.SendWebRequest();
         *  folderPath = www.downloadHandler.text;
         * }
         */

        // create a DirectoryInfo object that can be used to see files in directories
        DirectoryInfo info = new DirectoryInfo(folderPath);



        // Create an array of FileInfo objects based on the files read into the DirectoryInfo object.
        // Read them in using the searchPattern of "*.txt" to only get the files that end in ".txt"
        // so we don't try to use meta files for puzzle solutions.
        //FileInfo[] fileInfo = info.GetFiles("*.txt");
        FileInfo[] fileInfo = info.GetFiles("*.json");

        // set the size of the array that will contain the level names to be used to
        // create buttons for each level
        puzzleButtons = new GameObject[fileInfo.Length];

        GameObject newButton;
        Vector3    startingPoint = levelButtonHolder.transform.position;
        string     tempPuzzleName;

        for (int i = 0; i < fileInfo.Length; i++)
        {
            // TODO
            // create the UI elements here, or export these files or strings to the UI manager
            newButton = Instantiate(buttonPrefab, levelButtonHolder.transform) as GameObject;

            // set the starting point for th enext button to be one button's height below the next
            // can modify this to have some spacing between the buttons
            newButton.GetComponent <RectTransform>().localPosition -=
                new Vector3(0f, (i + 1) * buttonPrefab.GetComponent <RectTransform>().rect.height, 0f);

            // remove the ".txt" from the string that will be the puzzle name
            // The name of the puzzle that will appear on the button will be 4 units shorter than its
            // current length, aka ".txt" will be removed
            //tempPuzzleName = fileInfo[i].Name.Remove(fileInfo[i].Name.Length - 4);

            // remove the ".json" from the string that will be the puzzle name
            // The name of the puzzle that will appear on the button will be 5 units shorter than its
            // current length, aka ".json" will be removed
            tempPuzzleName = fileInfo[i].Name.Remove(fileInfo[i].Name.Length - 5);
            // Set the text on the button to be displayed
            newButton.transform.GetChild(0).GetComponent <Text>().text = tempPuzzleName;
            // Give an appropriate name to each puzzle to help see them in the editor
            newButton.name = tempPuzzleName;

            puzzleButtons[i] = newButton;   // add the new button to the list of puzzle buttons
        }
    }
コード例 #3
0
    public void LoadMap(string path)
    {
        /* Integration function. When file was selected, this function is called and it
         * runs all methods from project.
         */
        parser  = new Parser();
        builder = new BuilderScript();
        terrain = new TerrainFill();


        parser.loadStringFromFile(path); // Calling parser with path.
        int[]       minMaxs     = parser.myParseOmap();
        Vector3[][] appContours = parser.myTerr.getApproximatedContours(5);


        ArrayList rasterizedAL = new ArrayList();

        Vector2[] line;
        int       simplifyConstant          = 40;
        int       height                    = Mathf.Abs(minMaxs[3] - minMaxs[2]) / simplifyConstant;
        int       width                     = Mathf.Abs(minMaxs[1] - minMaxs[0]) / simplifyConstant;
        ArrayList reducedLine               = new ArrayList();
        Dictionary <string, int> usedPoints = new Dictionary <string, int>();

        int[] ret = new int[4];
        ret[0] = Int32.MaxValue;
        ret[1] = Int32.MinValue;
        ret[2] = Int32.MaxValue;
        ret[3] = Int32.MinValue;

        for (int i = 0; i < appContours.Length; i++)
        {
            usedPoints.Clear();
            for (int j = 1; j < appContours[i].Length; j++)
            {
                line = builder.bresenhamLine(appContours[i][j - 1], appContours[i][j]); // Fill gaps between aproximated points and simplify to smaller coords.
                reducedLine.Clear();

                for (int k = 0; k < line.Length; k++)
                {
                    line[k].x = Mathf.Abs((line[k].x - minMaxs[0]) / simplifyConstant);
                    line[k].y = Mathf.Abs((line[k].y - minMaxs[2]) / simplifyConstant);
                    int    x     = (int)Math.Ceiling(line[k].x);
                    int    y     = (int)Math.Ceiling(line[k].y);
                    string point = x.ToString() + "," + y.ToString();

                    ret[0] = Mathf.Min(ret[0], x);
                    ret[2] = Mathf.Min(ret[2], y);
                    ret[1] = Mathf.Max(ret[1], x);
                    ret[3] = Mathf.Max(ret[3], y);

                    if (!usedPoints.ContainsKey(point))
                    {
                        usedPoints.Add(point, 0);
                        reducedLine.Add(line[k]);
                    }
                }
                rasterizedAL.Add((Vector2[])reducedLine.ToArray(typeof(Vector2)));
            }
        }
        Vector2[][] rasterized = (Vector2[][])rasterizedAL.ToArray(typeof(Vector2[]));
        Debug.Log("min x: " + ret[0].ToString() +
                  " max x: " + ret[1].ToString() +
                  " min y: " + ret[2].ToString() +
                  " max y: " + ret[3].ToString() +
                  " height: " + height.ToString() +
                  " width: " + width.ToString());

        int[][][] drawnContours = builder.drawContours(rasterized, height, width); // Draw rasterized contours to two-dimensional array.

        int[][] scanlined = builder.scanline(drawnContours);                       // Run scanline and check height between contours.

        float[][] res = builder.sampleQuantization(scanlined, 65, 65);             // Quantize huge two-dimensional array into smaller 65x65 for terrain input

        terrain.FillTerrain(res, tData, myTerrain, xBase, yBase);                  // Fill terrain with input.
    }
コード例 #4
0
    public void LoadMap(string path)
    {
        /* Integration function. When file was selected, this function is called and it
         * runs all methods from project.
         */
        parser = new Parser();
        builder = new BuilderScript();
        terrain = new TerrainFill();

        parser.loadStringFromFile(path); // Calling parser with path.
        int[] minMaxs = parser.myParseOmap();
        Vector3[][] appContours = parser.myTerr.getApproximatedContours(5);

        ArrayList rasterizedAL = new ArrayList();
        Vector2[] line;
        int simplifyConstant = 40;
        int height = Mathf.Abs(minMaxs[3] - minMaxs[2])/simplifyConstant;
        int width = Mathf.Abs(minMaxs[1] - minMaxs[0])/simplifyConstant;
        ArrayList reducedLine = new ArrayList();
        Dictionary<string, int> usedPoints = new Dictionary<string, int>();

        int[] ret = new int[4];
        ret[0] = Int32.MaxValue;
        ret[1] = Int32.MinValue;
        ret[2] = Int32.MaxValue;
        ret[3] = Int32.MinValue;

        for (int i = 0; i < appContours.Length; i++) {
            usedPoints.Clear();
            for (int j = 1; j < appContours[i].Length; j++) {
                line = builder.bresenhamLine(appContours[i][j - 1], appContours[i][j]); // Fill gaps between aproximated points and simplify to smaller coords.
                reducedLine.Clear();

                for (int k = 0; k < line.Length; k++) {
                    line[k].x = Mathf.Abs((line[k].x - minMaxs[0]) / simplifyConstant);
                    line[k].y = Mathf.Abs((line[k].y - minMaxs[2]) / simplifyConstant);
                    int x = (int)Math.Ceiling(line[k].x);
                    int y = (int)Math.Ceiling(line[k].y);
                    string point = x.ToString() + "," + y.ToString();

                    ret[0] = Mathf.Min(ret[0], x);
                    ret[2] = Mathf.Min(ret[2], y);
                    ret[1] = Mathf.Max(ret[1], x);
                    ret[3] = Mathf.Max(ret[3], y);

                    if (!usedPoints.ContainsKey(point)) {
                        usedPoints.Add(point, 0);
                        reducedLine.Add(line[k]);
                    }
                }
                rasterizedAL.Add((Vector2[])reducedLine.ToArray(typeof(Vector2)));
            }
        }
        Vector2[][] rasterized = (Vector2[][])rasterizedAL.ToArray(typeof(Vector2[]));
        Debug.Log("min x: " + ret[0].ToString() +
            " max x: " + ret[1].ToString() +
            " min y: " + ret[2].ToString() +
            " max y: " + ret[3].ToString() +
            " height: " + height.ToString() +
            " width: " + width.ToString());

        int[][][] drawnContours = builder.drawContours(rasterized, height, width); // Draw rasterized contours to two-dimensional array.

        int[][] scanlined = builder.scanline(drawnContours); // Run scanline and check height between contours.

        float[][] res = builder.sampleQuantization(scanlined, 65, 65); // Quantize huge two-dimensional array into smaller 65x65 for terrain input

        terrain.FillTerrain(res, tData, myTerrain, xBase, yBase); // Fill terrain with input.
    }
コード例 #5
0
 // Use this for initialization
 public void MyStart()
 {
     build         = this.GetComponent <BuilderScript>();
     layerMask     = 1 << 10;
     goldLayerMask = 1 << 15;
 }