Пример #1
0
    public void LoadScreenshots(int lSystemIndex)
    {
        RatingSystem.StartGeneratingScreenshots(lSystemIndex);
        ABLevelSelector sel = gameObject.AddComponent <ABLevelSelector>();

        sel.LevelIndex = lSystemIndex * RatingSystem.MAX_LEVELS;

        LoadNextScene("GameWorld", true, sel.UpdateLevelList);
    }
Пример #2
0
    public void UpdatePreviews(int lSystemIndex)
    {
        for (int i = 0; i < RatingSystem.levelData[lSystemIndex].Count; ++i)
        {
            previews[i].sprite =
                RatingSystem.levelData[lSystemIndex][i].levelSprite;

            ABLevelSelector sel = previews[i].gameObject.GetComponent <ABLevelSelector>();
            sel.LevelIndex = lSystemIndex * RatingSystem.MAX_LEVELS + i;
        }
        marker.transform.position = new Vector2(lSystemButtons[lSystemIndex].transform.position.x + 40, lSystemButtons[lSystemIndex].transform.position.y);
    }
Пример #3
0
    // Use this for initialization
    void Start()
    {
        // Load levels in the resources folder
        TextAsset [] levelsData = Resources.LoadAll <TextAsset>(ABConstants.DEFAULT_LEVELS_FOLDER);

        string[] resourcesXml = new string[levelsData.Length];
        for (int i = 0; i < levelsData.Length; i++)
        {
            resourcesXml [i] = levelsData[i].text;
        }


#if UNITY_WEBGL && !UNITY_EDITOR
        // WebGL builds does not load local files
        string[] streamingXml = new string[0];
#else
        // Load levels in the streaming folder
        string   levelsPath = Application.dataPath + ABConstants.CUSTOM_LEVELS_FOLDER;
        string[] levelFiles = Directory.GetFiles(levelsPath, "*.xml");

        string[] streamingXml = new string[levelFiles.Length];
        for (int i = 0; i < levelFiles.Length; i++)
        {
            streamingXml [i] = File.ReadAllText(levelFiles [i]);
        }
#endif

        // Combine the two sources of levels
        string[] allXmlFiles = new string[resourcesXml.Length + streamingXml.Length];
        resourcesXml.CopyTo(allXmlFiles, 0);
        streamingXml.CopyTo(allXmlFiles, resourcesXml.Length);

        _startPos.x = Mathf.Clamp(_startPos.x, 0, 1f) * Screen.width;
        _startPos.y = Mathf.Clamp(_startPos.y, 0, 1f) * Screen.height;

        LevelList.Instance.LoadLevelsFromSource(allXmlFiles);

        int j = 0;

        for (int i = 0; i < allXmlFiles.Length; i++)
        {
            Vector2 pos = _startPos + new Vector2((i % _lines) * _buttonSize.x, j * _buttonSize.y);

            GameObject obj = Instantiate(_levelSelector, pos, Quaternion.identity) as GameObject;
            obj.transform.SetParent(_canvas.transform);

            ABLevelSelector sel = obj.AddComponent <ABLevelSelector> ();
            sel.LevelIndex = i;

            Button selectButton = obj.GetComponent <Button> ();

            selectButton.onClick.AddListener(delegate {
                preparaEditor(allXmlFiles[sel.LevelIndex]);
                LoadNextScene("GameWorld", true, sel.UpdateLevelList);
            });

            Text selectText = selectButton.GetComponentInChildren <Text> ();
            selectText.text = "" + (i + 1);

            if ((i + 1) % _lines == 0)
            {
                j--;
            }
        }
    }
Пример #4
0
    // Use this for initialization
    void Start()
    {
        //YANG
        // Delete screenshots and turn on PWCNet
        if (ABStream.optical_flow && !ABStream.streaming)
        {
            ABStream.TurnOnPWC();
            ABStream.DeleteScreenshots(ABStream.delete_every_data);
            // if (System.IO.File.Exists("pwcDone.txt"))
            //     System.IO.File.Delete("pwcDone.txt");
            // if (System.IO.File.Exists("pwcProcessing.txt"))
            //     System.IO.File.Delete("pwcProcessing.txt");
            // if (System.IO.File.Exists("tgifDone.txt"))
            //     System.IO.File.Delete("tgifDone.txt");
            // if (System.IO.File.Exists("tgifProcessing.txt"))
            //     System.IO.File.Delete("tgifProcessing.txt");
        }
        ABStream.SetFileName();
        // Read all the actions
        if (ABStream.streaming)
        {
            ABStream.loadedActions = ABStream.ReadActions(ABStream.actionFileName);
            ABStream.loadedLevels  = ABStream.ReadLevels(ABStream.levelFileName);
        }
        if (ABStream.ver2 && ABStream.simulate)
        {
            LoadNextScene("GameWorld", false, null);
            return;
        }
        // Finished

        // Load levels in the resources folder
        TextAsset [] levelsData = Resources.LoadAll <TextAsset>(ABConstants.DEFAULT_LEVELS_FOLDER);

        string[] resourcesXml = new string[levelsData.Length];
        for (int i = 0; i < levelsData.Length; i++)
        {
            resourcesXml [i] = levelsData[i].text;
        }


#if UNITY_WEBGL && !UNITY_EDITOR
        // WebGL builds does not load local files
        string[] streamingXml = new string[0];
#else
        // Load levels in the streaming folder
        string   levelsPath = Application.dataPath + ABConstants.CUSTOM_LEVELS_FOLDER;
        string[] levelFiles = Directory.GetFiles(levelsPath, "*.xml");

        string[] streamingXml = new string[levelFiles.Length];
        for (int i = 0; i < levelFiles.Length; i++)
        {
            streamingXml [i] = File.ReadAllText(levelFiles [i]);
        }
#endif

        // Combine the two sources of levels
        string[] allXmlFiles = new string[resourcesXml.Length + streamingXml.Length];
        resourcesXml.CopyTo(allXmlFiles, 0);
        streamingXml.CopyTo(allXmlFiles, resourcesXml.Length);

        _startPos.x = Mathf.Clamp(_startPos.x, 0, 1f) * Screen.width;
        _startPos.y = Mathf.Clamp(_startPos.y, 0, 1f) * Screen.height;

        LevelList.Instance.LoadLevelsFromSource(allXmlFiles);

        int j = 0;


        for (int i = 0; i < allXmlFiles.Length; i++)
        {
            Vector2 pos = _startPos + new Vector2((i % _lines) * _buttonSize.x, j * _buttonSize.y);

            GameObject obj = Instantiate(_levelSelector, pos, Quaternion.identity) as GameObject;
            obj.transform.SetParent(_canvas.transform);

            ABLevelSelector sel = obj.AddComponent <ABLevelSelector> ();
            sel.LevelIndex = i;

            Button selectButton = obj.GetComponent <Button> ();

            selectButton.onClick.AddListener(delegate {
                LoadNextScene("GameWorld", true, sel.UpdateLevelList);
            });

            Text selectText = selectButton.GetComponentInChildren <Text> ();
            selectText.text = "" + (i + 1);

            if ((i + 1) % _lines == 0)
            {
                j--;
            }

            // Orininal Code
            // if (selectText.text == "4")

            // YANG
            // Load from start level
            if (selectText.text == ABStream.currentLevel.ToString())
            {
                UnityEngine.Debug.Log("Loaded Level : " + selectText.text);
                _autobutton = selectButton;
            }
            // Finished
        }

        if (null != _autobutton)
        {
            _autobutton.onClick.Invoke();
        }
        else
        {
            print("no level 4");
        }
    }
Пример #5
0
    // Start is called before the first frame update
    void Start()
    {
        for (int i = 0; i < RatingSystem.keptForEvolution.Count; ++i)
        {
            if (RatingSystem.keptForEvolution[i].xmls.Count <= 0)
            {
                RatingSystem.GenerateXMLsForEvolution(i, 5);
                LoadXMLs(RatingSystem.keptForEvolution[i].xmls);
                RatingSystem.StartGetFitnessForEvolution(i);
                ABLevelSelector sel = gameObject.AddComponent <ABLevelSelector>();
                sel.LevelIndex = 0;
                ABSceneManager.Instance.LoadScene("GameWorld", true, sel.UpdateLevelList);
                return;
            }
        }
        RatingSystem.EndGetFitnessForEvolution();

        // TODO: Right here is when you have all the fitnesses for each lsystem in the RatingSystem.keptForEvolution
        // You can do more evolution here or pick the best 12 lSystems to put into RatingSystem.lSystems (for now just pick 12 lsystems, I'll make it possible to do more iterations tomorrow or something)
        List <LSystem> pop = new List <LSystem>();
        List <float>   fit = new List <float>();

        //  Getting lsystem and fitness
        foreach (RatingSystem.LSystemEvolution l in RatingSystem.keptForEvolution)
        {
            pop.Add(l.lSystem);
            fit.Add(l.fitness);
        }

        //  Initialize LSystem evolver.
        LSystemEvolver evolver = new LSystemEvolver(NUM_RULES, MAX_WIDTH, MAX_HEIGHT, MUT_RATE);

        //  Evolve population and store.
        List <LSystem> evolvedLSystems = null;

        if (SqlConnection.algorithm == Algorithm.MAPElites)
        {
            evolvedLSystems = evolver.EvolvePopulationMAPElitesEdition(RatingSystem.keptForEvolution);
        }
        else
        {
            evolvedLSystems = evolver.EvolvePopulation(pop, fit, MU, LAMBDA);
        }
        Debug.Log(evolvedLSystems.Count);
        RatingSystem.keptForEvolution.Clear();
        --iterations;

        Debug.Log("finished iteration " + iterations);
        if (iterations > 0)
        {
            // do it again
            foreach (LSystem l in evolvedLSystems)
            {
                RatingSystem.keptForEvolution.Add(new RatingSystem.LSystemEvolution(l));
            }
            ABSceneManager.Instance.LoadScene("Evolution");
        }
        else
        {
            RatingSystem.lSystems = evolvedLSystems;
            // generate and load the XMLs
            for (int i = 0; i < RatingSystem.MAX_LSYSTEMS; ++i)
            {
                RatingSystem.GenerateXMLs(i, 5);
            }
            ABLevelSelect.loadXMLs();



            // if you're done, then return to levelselectmenu MAKE SURE YOU HAVE 12 LSYSTEMS IN RATINGSYSTEM.LSYSTEM
            RatingSystem.keptForEvolution.Clear(); // maybe do this?
            ABSceneManager.Instance.LoadScene("LevelSelectMenu");
        }
    }