Ejemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        _wg = target as WordSetGenerator;


        if (GUILayout.Button("Generate"))
        {
            MgsCoroutine.GetTime = GetTime;
            MgsCoroutine.Start(
                _wg.MakeWordSet(),
                () => EditorUtility.DisplayCancelableProgressBar(MgsCoroutine.Title, MgsCoroutine.Info, MgsCoroutine.Percentage),
                0.1);

            EditorUtility.ClearProgressBar();

            _wg.EditorInstantiate = EditorInstantiate;

            _wg.SpawnWordSet();
        }

        if (GUILayout.Button("Partition"))
        {
            if (_partitioner == null)
            {
                _partitioner = new NewPartitioner();
            }

            MgsCoroutine.GetTime = GetTime;
            MgsCoroutine.Start(
                _partitioner.Portion(),
                () => EditorUtility.DisplayCancelableProgressBar(MgsCoroutine.Title, "Partitioning..", MgsCoroutine.Percentage),
                0.1);

            EditorUtility.ClearProgressBar();
        }

        if (GUILayout.Button("Shuffle"))
        {
            if (_shuffler == null)
            {
                _shuffler = new Shuffler();
            }

            Undo.RecordObjects(FindObjectsOfType <Letter>().Select(l => (Object)(l.transform)).ToArray(), "Shuffle");

            _shuffler.ShuffleEditor();
        }

        DrawDefaultInspector();
    }
    public IEnumerator Generate()
    {
        // Setup generator
        string allWords = WordsWindow.WordsText.text.Replace(' ', '\n');

        Generator.AllWords = allWords;
        Generator.Clue     = ClueWindow.ClueInputField.text;
        Generator.Initialize();
        Generator.UsedWordCount = 0;
        Generator.MaxResults    = allWords.Length;

        // Generate Word set
        yield return(Generator.MakeWordSet());

        // fail to generate word sets
        if (!Generator.Successful)
        {
            FollowMachine.SetOutput("Fail");
            yield break;
        }

        // Spawn words
        var bestWordSet = Generator.GetBestWordSet();

        Singleton.Instance.WordSpawner.SpawnPartByPart = false;
        GameController.Instance.SpawnWordSet(bestWordSet);
        Singleton.Instance.WordSpawner.SpawnPartByPart = true;

        // Run partitioner
        if (_partitioner == null)
        {
            _partitioner = new NewPartitioner();
        }
        yield return(_partitioner.Portion(5 * allWords.Length));

        FollowMachine.SetOutput("Success");
    }
Ejemplo n.º 3
0
    private static List <LetterBound> ComputeLetterBounds()
    {
        List <List <Letter> > paritions = NewPartitioner.GetPartitions();

        #region Shuffle partions

        for (int i = 0; i < paritions.Count * 2; i++)
        {
            int p1 = UnityEngine.Random.Range(0, paritions.Count);
            int p2 = Random.Range(0, paritions.Count);

            var tp = paritions[p1];
            paritions[p1] = paritions[p2];
            paritions[p2] = tp;
        }

        #endregion

        #region Get bounds

        List <LetterBound> letterBounds = new List <LetterBound>();

        foreach (List <Letter> letters in paritions)
        {
            letterBounds.Add(new LetterBound(letters));
        }

        #endregion

        #region Place as a grid

        int columns = Mathf.RoundToInt(Mathf.Sqrt(letterBounds.Count));

        int x = 0, y = 0;

        for (int i = 0; i <= columns; i++)
        {
            int width  = 0;
            int height = 0;

            for (int j = 0; j < columns; j++)
            {
                int index = i * columns + j;

                if (index >= paritions.Count)
                {
                    break;
                }

                width += letterBounds[index].Width;

                if (height < letterBounds[index].Height)
                {
                    height = letterBounds[index].Height;
                }
            }

            x = -width / 2;

            for (int j = 0; j < columns; j++)
            {
                int index = i * columns + j;

                if (index >= paritions.Count)
                {
                    break;
                }

                var bounds = letterBounds[index];

                bounds.SetTarget(x, y + (height - bounds.Height) / 2);

                x += bounds.Width;
            }

            y += height;
        }

        #endregion

        #region Move to center

        foreach (var letterBound in letterBounds)
        {
            letterBound.TargetY += -y / 2 - 2;
        }

        #endregion

        return(letterBounds);
    }