public void DecisionButtonTriggered(DecisionButton button)
    {
        string correct_text  = GetEntryText(current_character.ChineseEntry, current_character.CharType);
        bool   correct_guess = button.GetText() == correct_text;

        if (correct_guess)
        {
            Destroy(current_character.gameObject);
            correct_choices++;
        }
        else
        {
            current_character.IncorrectGuess();
            incorrect_choices++;
        }

        my_characters.RecordGuess(current_character.chinese_character, correct_guess, current_character.CharType);
        ClearDecisionButtons();
        TrigStep();

        if (my_characters.AllScoresReached())
        {
            status_text.SetText("YOU WIN!");
        }
    }
Ejemplo n.º 2
0
    public IEnumerator ProcessPLY(string input, string output)
    {
        string pinput  = Path.GetFullPath(input);
        string poutput = Path.GetFullPath(output);

        Debug.Log("converting " + pinput + " into " + poutput);
        if (File.Exists(input))
        {
            string parameters = " \"" + pinput + "\" -o \"" + poutput + "\" -t " + this.siteData.custom.modelType;

            StatusText.SetText("Converting " + input + "into octree format and caching");

            var stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();
            var proc = System.Diagnostics.Process.Start(Path.GetFullPath(GameManager.pathToPotreeExecutable), parameters);
            while (!proc.HasExited)
            {
                yield return(null);
            }
            // proc.WaitForExit();
            // proc.CloseMainWindow();
            StatusText.Hide();
            stopwatch.Stop();
            Debug.Log("Done in " + stopwatch.Elapsed.Seconds + " seconds");
        }
        yield return(null);
    }
Ejemplo n.º 3
0
 public static void NextTurn()
 {
     if (!IsGameStarted())
     {
         return;
     }
     if (m_currentPlayer == m_player0)
     {
         m_currentPlayer = m_player1;
         m_anotherPlayer = m_player0;
     }
     else
     {
         m_currentPlayer = m_player0;
         m_anotherPlayer = m_player1;
     }
     if (m_currentPlayer.GetRole() == PlayerRole.Cross)
     {
         StatusText.SetText(Constant.STATUS_TEXT.CROSS_TURN);
     }
     else
     {
         StatusText.SetText(Constant.STATUS_TEXT.ROUND_TURN);
     }
     if (m_currentPlayer.IsAI())
     {
         instance.StartCoroutine(CurrentPlayerDoTurnAfterSeconds(Constant.AI_THINKING_SECONDS));
     }
 }
Ejemplo n.º 4
0
    public IEnumerator CacheTextures(List <Texture2D> textures, string imagePath)
    {
        string cacheDirectory = GetCacheDirectory(imagePath);

        if (Directory.Exists(cacheDirectory))
        {
            foreach (string file in Directory.GetFiles(cacheDirectory))
            {
                File.Delete(file);
            }

            Directory.Delete(cacheDirectory);
        }

        Directory.CreateDirectory(cacheDirectory);

        string fileName = Path.GetFileNameWithoutExtension(imagePath);

        string cachedPathFormat = cacheDirectory + "/" + fileName + "_{0}.png";

        for (int i = 0; i < textures.Count; i++)
        {
            string finalpath = "";

            switch (i)
            {
            case FRONT_INDEX:
                finalpath = string.Format(cachedPathFormat, "front");
                break;

            case BACK_INDEX:
                finalpath = string.Format(cachedPathFormat, "back");
                break;

            case LEFT_INDEX:
                finalpath = string.Format(cachedPathFormat, "left");
                break;

            case RIGHT_INDEX:
                finalpath = string.Format(cachedPathFormat, "right");
                break;

            case UP_INDEX:
                finalpath = string.Format(cachedPathFormat, "up");
                break;

            case DOWN_INDEX:
                finalpath = string.Format(cachedPathFormat, "down");
                break;
            }

            byte[] bytes = textures[i].EncodeToPNG();

            StatusText.SetText("Stage 4: Caching Images:\n" + (i + 1) + " of " + textures.Count);
            yield return(null);

            File.WriteAllBytes(finalpath, bytes);
        }
    }
Ejemplo n.º 5
0
    public IEnumerator CreateCubemapFromTextures(List <Texture2D> textures, Cubemap newCubemap)
    {
        Texture2D frontFace = textures[FRONT_INDEX];
        Texture2D backFace  = textures[BACK_INDEX];

        Texture2D upFace   = textures[UP_INDEX];
        Texture2D downFace = textures[DOWN_INDEX];

        Texture2D leftFace  = textures[LEFT_INDEX];
        Texture2D rightFace = textures[RIGHT_INDEX];

        Debug.LogFormat("Setting Cubemap Faces from {0} textures", textures.Count);


        StatusText.SetText("Final Stage: Setting cubemap faces:\n1 of 6");
        yield return(null);

        newCubemap.SetPixels(frontFace.GetPixels(), CubemapFace.PositiveZ);

        StatusText.SetText("Final Stage: Setting cubemap faces:\n 2 of 6");
        yield return(null);

        newCubemap.SetPixels(upFace.GetPixels(), CubemapFace.PositiveY);

        StatusText.SetText("Final Stage: Setting cubemap faces:\n 3 of 6");
        yield return(null);

        newCubemap.SetPixels(leftFace.GetPixels(), CubemapFace.NegativeX);

        StatusText.SetText("Final Stage: Setting cubemap faces:\n 4 of 6");
        yield return(null);

        newCubemap.SetPixels(rightFace.GetPixels(), CubemapFace.PositiveX);

        StatusText.SetText("Final Stage: Setting cubemap faces:\n 5 of 6");
        yield return(null);

        newCubemap.SetPixels(backFace.GetPixels(), CubemapFace.NegativeZ);

        StatusText.SetText("Final Stage: Setting cubemap faces:\n 6 of 6");
        yield return(null);

        newCubemap.SetPixels(downFace.GetPixels(), CubemapFace.NegativeY);


        frontFace = null;
        backFace  = null;
        upFace    = null;
        downFace  = null;
        leftFace  = null;
        rightFace = null;
        yield return(null);
    }
Ejemplo n.º 6
0
    public IEnumerator LoadAndSaveCubemapMaterials(string path, bool isRightEye)
    {
        List <Texture2D> textures = new List <Texture2D>();

        if (Directory.Exists(GetCacheDirectory(path)))
        {
            StatusText.SetText("Loading textures from cache");


            yield return(StartCoroutine(GetTexturesFromCache(path, textures)));
        }
        else
        {
            StatusText.SetText("Loading textures from tif");

            yield return(StartCoroutine(GetTexturesFromTif(path, textures)));
        }

        int           texSize = textures[0].width;
        TextureFormat format  = textures[0].format;

        StatusText.SetText("Creating cubemap");

        yield return(null);

        Cubemap cubemap = new Cubemap(texSize, format, false);

        yield return(StartCoroutine(CreateCubemapFromTextures(textures, cubemap)));

        cubemap.Apply();

        Material eyeMat = new Material(Shader.Find("Skybox/Cubemap"));

        eyeMat.SetTexture(Shader.PropertyToID("_Tex"), cubemap);

        if (isRightEye)
        {
            rightEye = eyeMat;
        }
        else
        {
            leftEye = eyeMat;
        }

        loaded = true;
        for (int i = 0; i < textures.Count; ++i)
        {
            Destroy(textures[i]);
        }
        textures.Clear();
        textures = null;
    }
Ejemplo n.º 7
0
 public void Init()
 {
     m_isGameStarted = false;
     StatusText.SetText(Constant.STATUS_TEXT.WAIT_FOR_CHOICE);
     PlayerChooseRole.Init();
     Field.Init();
     m_player0.ClearScore();
     m_player1.ClearScore();
     buttonNextRound.SetActive(false);
     roundResult.SetActive(false);
     buttonUndoOnce.SetActive(true);
     dropdownGameMode.GetComponent <Dropdown>().interactable = true;
 }
Ejemplo n.º 8
0
    // Loads every single site and it's data.
    // Warning: This can take a LONG time! Best when scheduled when nobody will be using the application.
    public IEnumerator LoadAllSites()
    {
        // Set the status text so the user knows to wait.
        StatusText.SetText("Loading All Sites. Please Wait.");

        // Lock all input.
        GamepadInput.LockInput(true);

        // Check one more time to make sure we're supposed to be doing this.
        if (GameManager.instance.caveSettings.loadAllDataOnStart)
        {
            // Iterate through every single site.
            for (int i = 0; i < sites.Count; i++)
            {
                // Store the site at this array index.
                Site site = sites[i];

                // Iterate through all data sets that are part of this site.
                for (int j = 0; j < site.dataSets.Count; j++)
                {
                    // Store the data set.
                    SiteElementSet dataSet = site.dataSets[j];

                    // Iterate through all data elements that are part of this data set.
                    for (int k = 0; k < dataSet.siteElements.Count; k++)
                    {
                        // Store this data element.
                        SiteElement dataElement = dataSet.siteElements[k];

                        // Set the status text to a helpful message.
                        string statusString = string.Format("Loading element {0} of {1} from set {2} of {3} from site {4} of {5}",
                                                            k, dataSet.siteElements.Count, j, site.dataSets.Count, i, sites.Count);

                        StatusText.SetText(statusString);
                        Debug.Log(statusString);

                        // Wait for this data element to load before proceeding.
                        yield return(dataElement.Load());
                    }
                }
            }
        }

        // Unlock input.
        GamepadInput.LockInput(false);
    }
Ejemplo n.º 9
0
    public IEnumerator GetTexturesFromTif(string tifPath, List <Texture2D> textures)
    {
        List <Image> images = new List <Image>();


        yield return(StartCoroutine(LoadTifPages(tifPath, images)));

        StatusText.SetText("Loaded Tif Images");

        yield return(StartCoroutine(LoadImagesAsTextures(images, textures)));

        yield return(StartCoroutine(CacheTextures(textures, tifPath)));

        for (int i = 0; i < images.Count; ++i)
        {
            images[i].Dispose();
        }
        images.Clear();
        images = null;

        System.GC.Collect();
    }
Ejemplo n.º 10
0
 public static void StartGame()
 {
     m_isGameStarted = true;
     dropdownGameModeStatic.GetComponent <Dropdown>().interactable = false;
     StatusText.SetText(Constant.STATUS_TEXT.CROSS_TURN);
     m_player0.SetRole(PlayerChooseRole.GetChoice());
     m_player1.SetRole(PlayerChooseRole.GetAnotherChoice());
     if (m_gameMode == GameMode.PlayerVsAI)
     {
         m_player0.SetAI(false);
         m_player1.SetAI(true);
     }
     else if (m_gameMode == GameMode.PlayerVsPlayer)
     {
         m_player0.SetAI(false);
         m_player1.SetAI(false);
     }
     else if (m_gameMode == GameMode.AIVsAI)
     {
         m_player0.SetAI(true);
         m_player1.SetAI(true);
     }
     if (m_player0.GetRole() == PlayerRole.Cross)
     {
         m_currentPlayer = m_player0;
         m_anotherPlayer = m_player1;
     }
     else
     {
         m_currentPlayer = m_player1;
         m_anotherPlayer = m_player0;
     }
     PlayerChooseRole.SetEnableChooseRoleButtons(false);
     if (m_currentPlayer.IsAI())
     {
         instance.StartCoroutine(CurrentPlayerDoTurnAfterSeconds(Constant.AI_THINKING_SECONDS));
     }
 }
Ejemplo n.º 11
0
    public IEnumerator LoadTifPages(string imagePath, List <Image> tifImages)
    {
        StatusText.SetText("Stage 1: Loading Pages From Tif File");

        yield return(null);

        TiffImage loadedTiff = new TiffImage(imagePath);

        loadedTiff.LoadAllPages();

        while (!loadedTiff.allPagesLoaded)
        {
            yield return(null);
        }

        tifImages.AddRange(loadedTiff.pages);

        loadedTiff = null;

        System.GC.Collect();

        yield return(null);
    }
Ejemplo n.º 12
0
 public void OnNextRoundButtonClick()
 {
     Field.Init();
     m_isGameOver = false;
     buttonNextRound.SetActive(false);
     roundResult.SetActive(false);
     buttonUndoOnceStatic.SetActive(true);
     if (m_player0.GetRole() == PlayerRole.Cross)
     {
         m_currentPlayer = m_player0;
         m_anotherPlayer = m_player1;
     }
     else
     {
         m_currentPlayer = m_player0;
         m_anotherPlayer = m_player1;
     }
     StatusText.SetText(Constant.STATUS_TEXT.CROSS_TURN);
     if (m_currentPlayer.IsAI())
     {
         instance.StartCoroutine(m_coroutine);
     }
 }
Ejemplo n.º 13
0
    protected override IEnumerator LoadCoroutine()
    {
        if (this.idleAnimation == null)
        {
            this.idleAnimation = new SpinningIdle(0.05f);
        }

        SerializableCAVECam camData = siteData as SerializableCAVECam;

        Debug.Log("Loading " + camData.name);

        if (camData.cube4096 == null || string.IsNullOrEmpty(camData.cube4096.left) || string.IsNullOrEmpty(camData.cube4096.right))
        {
            leftEyePath  = GetAbsolutePath(camData.cube1024.left);
            rightEyePath = GetAbsolutePath(camData.cube1024.right);
        }
        else
        {
            leftEyePath  = GetAbsolutePath(camData.cube4096.left);
            rightEyePath = GetAbsolutePath(camData.cube4096.right);
        }


        if (!File.Exists(leftEyePath) || !File.Exists(rightEyePath))
        {
            StatusText.SetText("Failed to load files");
            Debug.LogErrorFormat("Could not load pano: Failed to find left pano {0} or right pano {1}", leftEyePath, rightEyePath);
        }

        else
        {
            yield return(StartCoroutine(LoadAndSaveCubemapMaterials(rightEyePath, true)));

            if (CAVECameraRig.isCAVE)
            {
                yield return(StartCoroutine(LoadAndSaveCubemapMaterials(leftEyePath, false)));
            }
            else
            {
                leftEye = rightEye;
            }

            loaded = true;

            yield return(null);
        }

        //Janky memory fix, remove and watch your ram skyrocket
        var    wait = new WaitForSeconds(0.01f);
        string name = SceneManager.GetActiveScene().name;

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);

        yield return(SceneManager.LoadSceneAsync(name));

        yield return(wait);
    }
Ejemplo n.º 14
0
    public IEnumerator LoadImagesAsTextures(List <Image> images, List <Texture2D> textures)
    {
        int numConverterThreads = 1;
        int numThreadsPerImage  = 2;

        StatusText.SetText("Stage 2: Starting threads to convert images");

        yield return(null);

        ImageToColorArray[] converters = new ImageToColorArray[images.Count];
        int numConvertersPerThread     = images.Count / numConverterThreads;

        for (int i = 0; i < numConverterThreads; i++)
        {
            int startIndex = numConvertersPerThread * i;
            int endIndex   = numConvertersPerThread * (i + 1);

            if (i == numConverterThreads - 1)
            {
                endIndex = images.Count;
            }

            Debug.LogFormat("Creating converter that starts at index {0} and ends at index {1}", startIndex, endIndex);

            ThreadPool.QueueUserWorkItem(new WaitCallback(state => LoadImageSubsetAsTextures(images, converters, startIndex, endIndex, numThreadsPerImage)));
        }

        StatusText.SetText("Stage 2: Converting images");

        yield return(null);

        for (int i = 0; i < converters.Length; i++)
        {
            while (converters[i] == null || !converters[i].IsFinished())
            {
                yield return(null);
            }
        }

        for (int i = 0; i < converters.Length; i++)
        {
            ImageToColorArray converter = converters[i];

            StatusText.SetText("Stage 3: Saving images:\n" + (i + 1) + " of " + converters.Length);

            yield return(null);

            Texture2D           newTex = new Texture2D(converter.width, converter.height);
            UnityEngine.Color[] pixels = converter.GetFinalArray();

            Debug.Log("pixels size is: " + pixels.Length);

            newTex.SetPixels(pixels);
            textures.Add(newTex);

            pixels        = null;
            converters[i] = null;
            converter     = null;
            newTex        = null;
        }

        converters = null;
        System.GC.Collect();
    }
Ejemplo n.º 15
0
    public IEnumerator GetTexturesFromCache(string filePath, List <Texture2D> textures)
    {
        string cacheDirectory = GetCacheDirectory(filePath);
        string fileName       = Path.GetFileNameWithoutExtension(filePath);

        if (!Directory.Exists(cacheDirectory))
        {
            yield return(StartCoroutine(GetTexturesFromTif(filePath, textures)));

            yield break;
        }

        string[] facePaths = new string[6];

        string frontPath = cacheDirectory + "/" + fileName + "_front.png";
        string backPath  = cacheDirectory + "/" + fileName + "_back.png";
        string leftPath  = cacheDirectory + "/" + fileName + "_left.png";
        string rightPath = cacheDirectory + "/" + fileName + "_right.png";
        string upPath    = cacheDirectory + "/" + fileName + "_up.png";
        string downPath  = cacheDirectory + "/" + fileName + "_down.png";

        facePaths[FRONT_INDEX] = frontPath;
        facePaths[BACK_INDEX]  = backPath;
        facePaths[LEFT_INDEX]  = leftPath;
        facePaths[RIGHT_INDEX] = rightPath;
        facePaths[DOWN_INDEX]  = downPath;
        facePaths[UP_INDEX]    = upPath;

        textures.Clear();

        if (File.Exists(frontPath) && File.Exists(backPath) && File.Exists(leftPath) && File.Exists(rightPath) && File.Exists(upPath) && File.Exists(downPath))
        {
            for (int i = 0; i < 6; i++)
            {
                string statusText = string.Format("Stage 1 of 2: Loading textures: \n{0} of {1}", i + 1, 6);
                StatusText.SetText(statusText);

                string fullPath = Path.GetFullPath(facePaths[i]);

                yield return(null);

                fullPath = fullPath.Replace("\\", "/");
                string fullPathWWW = "file://" + fullPath;

                Debug.Log("Loading image into texture from " + fullPath);

                yield return(null);

                Texture2D newTex = new Texture2D(4, 4, TextureFormat.ARGB32, false);
                WWW       newWWW = new WWW(fullPathWWW);

                yield return(newWWW);

                newWWW.LoadImageIntoTexture(newTex);

                while (!newWWW.isDone)
                {
                    yield return(null);
                }

                Debug.Log("Done loading");

                //  byte[] bytes = File.ReadAllBytes(fullPath);
                // newTex.LoadImage(bytes);

                yield return(null);

                textures.Add(newTex);
                newWWW.Dispose();
                newWWW = null;
                System.GC.Collect();
            }
        }
        else
        {
            yield return(StartCoroutine(GetTexturesFromTif(filePath, textures)));

            yield break;
        }

        yield return(null);
    }