Exemplo 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();
    }
Exemplo n.º 2
0
    void OnGUI()
    {
        #region Get clue and category

        GUILayout.Label("Generator", EditorStyles.boldLabel);

        _clue = EditorGUILayout.TextField("Clue", _clue);



        _puzzle = (PuzzleComponent)EditorGUILayout.ObjectField(_puzzle, typeof(PuzzleComponent), true);

        #endregion

        #region Spawn wordSet

        if (GUILayout.Button("Spawn"))
        {
            _clue = _puzzle.Clue;
            var Wordspawner = FindObjectOfType <WordSpawner>();

            if (Wordspawner == null)
            {
                EditorUtility.DisplayDialog("Error", "Can't find word spawner", "Ok");
                return;
            }



            Wordspawner.EditorInstatiate = EditorInstantiate;

            WordSet wSet = new WordSet();
            JsonUtility.FromJsonOverwrite(StringCompressor.DecompressString(_puzzle.Content), wSet);
            Wordspawner.WordSet = wSet;
            _wordSet            = wSet;
            Wordspawner.SpawnWords();
        }

        #endregion


        #region Regenerate wordSet

        if (GUILayout.Button("Regenerate"))
        {
            var wordGenerator = FindObjectOfType <WordSetGenerator>();
            if (wordGenerator == null)
            {
                EditorUtility.DisplayDialog("Error", "Can't find word spawner", "Ok");
                return;
            }

            wordGenerator.AllWords = "";
            foreach (var word in _wordSet.Words)
            {
                wordGenerator.AllWords += word.Name + " ";
            }
            wordGenerator.UsedWordCount = _wordSet.Words.Count;
            MgsCoroutine.GetTime        = GetTime;
            MgsCoroutine.Start(
                wordGenerator.MakeWordSet(),
                () => EditorUtility.DisplayCancelableProgressBar(MgsCoroutine.Title, MgsCoroutine.Info, MgsCoroutine.Percentage),
                0.1);

            EditorUtility.ClearProgressBar();

            wordGenerator.EditorInstantiate = EditorInstantiate;

            wordGenerator.SpawnWordSet();

            Selection.activeObject = wordGenerator.gameObject;
        }

        #endregion


        if (GUILayout.Button("Save"))
        {
            #region Get word manager

            var wordManagers = FindObjectsOfType <WordManager>();

            if (wordManagers.Length == 0)
            {
                EditorUtility.DisplayDialog("Error", "Word manager not found!", "OK");
                return;
            }

            if (wordManagers.Length > 1)
            {
                EditorUtility.DisplayDialog("Error", "More than one Word manager!", "OK");
                return;
            }

            var wordManager = wordManagers[0];

            #endregion

            #region Create New wordSet

            WordSet wordSet = new WordSet();

            wordSet.Clue  = _clue;
            wordSet.Words = new List <SWord>();

            foreach (var word in wordManager.GetComponentsInChildren <Word>())
            {
                wordSet.Words.Add(new SWord(word));
            }

            #endregion

            #region Replace Puzzle TO Server
            // create category in database
            var puzzle = new Puzzle
            {
                ID         = _puzzle.PuzzleData.ID,
                CategoryID = _puzzle.PuzzleData.CategoryID,
                Clue       = _clue,
                Row        = _puzzle.PuzzleData.Row,
                Content    = StringCompressor.CompressString(JsonUtility.ToJson(wordSet)),
                LastUpdate = DateTime.Now
            };

            _puzzle.Content = puzzle.Content;
            _puzzle.Clue    = puzzle.Clue;
            _puzzle.Dirty   = true;
            _puzzle.UpdateData();

            ServerEditor.Post(@"Puzzles/Update/" + _puzzle.PuzzleData.ID, puzzle, "Update puzzle",
                              "Update");

            #endregion
        }
    }