Exemple #1
0
    public void GenerateSingleMap()
    {
        Tile[,] map = GenerateLevel();         //GetComponent<DrunkardWalkGenerator>().GenerateLevel();

        // RenderMapWithGameObjects(map);
        RenderMapWithSprite(map);

        // GameObject.Find("DAN").GetComponent<LevelAnalyser>()
        float densMetric = LevelAnalyser.CalculateDensity(map);
        float openMetric = LevelAnalyser.CalculateOpenness(map);

        GameObject.Find("MetricValues").GetComponent <UnityEngine.UI.Text>().text = "" + densMetric.ToString("0.000") + "\n" + openMetric.ToString("0.000");
    }
Exemple #2
0
    // Use this for initialization
    void Start()
    {
        AutoTuneButton = GameObject.Find("AutoTuneButton").GetComponent <UnityEngine.UI.Button>();
        // TargetOpenness = GameObject.Find("TargetOpenness").GetComponent<UnityEngine.UI.InputField>();
        // TargetDensity = GameObject.Find("TargetDensity").GetComponent<UnityEngine.UI.InputField>();

        tuner    = DAN.Instance.tuner;
        analyser = DAN.Instance.analyser;

        MetricReportPanel     = GameObject.Find("MetricReportPanel");
        TargetMetricPanel     = GameObject.Find("MetricListPanel");
        TunableParameterPanel = GameObject.Find("ParameterListPanel");

        SetupTuningUI(DAN.Instance.GetGeneratorMB());
    }
Exemple #3
0
    public void AnalyseLargeSet(int amount = 100)
    {
        float oTotal = 0;
        float dTotal = 0;

        for (int i = 0; i < amount; i++)
        {
            Tile[,] map = GenerateLevel();
            dTotal     += LevelAnalyser.CalculateDensity(map);
            oTotal     += LevelAnalyser.CalculateOpenness(map);
        }
        float densMetric = dTotal / 100f;
        float openMetric = oTotal / 100f;

        GameObject.Find("CMetricValues").GetComponent <UnityEngine.UI.Text>().text = "" + densMetric.ToString("0.000") + "\n" + openMetric.ToString("0.000");
    }
Exemple #4
0
    // Use this for initialization
    void Start()
    {
        // GameObject gen = GameObject.Find("Generator");
        // CellularAutomataGenerator ca = gen.GetComponent<CellularAutomataGenerator>();

        LevelAnalyser la = DAN.Instance.analyser;

        // //Set up the target metrics
        targets = new List <TargetSetting>();
        // targets.Add(new TargetSetting(la.CalculateOpenness, 0.2f));
        // targets.Add(new TargetSetting(la.CalculateDensity, 0.6f));

        // //Set the parameter settings
        settings = new List <ParSetting>();
        // settings.Add(new ParSetting(typeof(CellularAutomataGenerator).GetField("ChanceTileWillSpawnAlive"), ca, 0.2f, 0.6f));
        // settings.Add(new ParSetting(typeof(CellularAutomataGenerator).GetField("NumberOfIterations"), ca, (int)1, (int)6));

        //Give AutoTuner the generation method
        // generator = ca.GenerateLevel;

        OnTuningComplete = DoNothing;
    }
Exemple #5
0
    void Awake()
    {
        Instance  = this;
        tuner     = GetComponent <AutoTuner>();
        analyser  = GetComponent <LevelAnalyser>();
        mapSprite = GameObject.Find("MapSprite");

        foreach (MonoBehaviour b in generator.GetComponents <MonoBehaviour>())
        {
            foreach (MethodInfo method in b.GetType().GetMethods())
            {
                foreach (Attribute attr in method.GetCustomAttributes(false))
                {
                    if (attr is Generator)
                    {
                        Debug.Log(generator.name + "." + method.Name);
                        generateMapMethod = method;
                        targetBehaviour   = b;
                    }
                }
            }
        }
    }
Exemple #6
0
    public void SetupTuningUI(MonoBehaviour generator)
    {
        this.generator = generator;

        TunableParameterInputList = new List <TunableParameter>();

        //Find all the fields with tunable attributes and add them to the UI
        foreach (FieldInfo field in generator.GetType().GetFields())
        {
            foreach (Attribute attr in field.GetCustomAttributes(false))
            {
                if (attr is TunableAttribute)
                {
                    TunableAttribute t = (TunableAttribute)attr;

                    TunableParameter tpi;
                    if (t.MinValue is bool)
                    {
                        GameObject tpp = Instantiate(TunableBoolUIPrefab);
                        tpp.transform.parent = TunableParameterPanel.transform;
                        tpi = tpp.GetComponent <TunableParameterToggleField>();
                    }
                    else
                    {
                        GameObject tpp = Instantiate(TunableParameterUIPrefab);
                        tpp.transform.parent = TunableParameterPanel.transform;
                        tpi = tpp.GetComponent <TunableParameterInput>();
                    }

                    tpi.Setup(this);
                    //Set the field's name up
                    tpi.targetParameter = field;
                    tpi.tuneMin         = t.MinValue;
                    tpi.tuneMax         = t.MaxValue;
                    tpi.SetValue(field.GetValue(generator));
                    if (t.Name == "")
                    {
                        tpi.label.text = field.Name;
                    }
                    else
                    {
                        tpi.label.text = t.Name;
                    }
                    //Add the TPIs to the corresponding list
                    TunableParameterInputList.Add(tpi);

                    //Also add them to the ERAnalyser as parameter setting objects
                    ParSetting p = new ParSetting(field, generator, t.MinValue, t.MaxValue);
                    tuner.AddParameter(p);
                }
            }
        }

        MetricReportTexts    = new List <Text>();
        MetricDelegateList   = new List <TargetSetting.MetricDelegate>();
        MetricInputFieldList = new List <InputField>();

        List <string> metricNames = new List <string>();

        foreach (MonoBehaviour b in generator.GetComponents <MonoBehaviour>())
        {
            foreach (MethodInfo method in b.GetType().GetMethods())
            {
                foreach (Attribute attr in method.GetCustomAttributes(false))
                {
                    if (attr is Metric)
                    {
                        GameObject metricPanel = Instantiate(TargetMetricPanelUIPrefab);
                        metricPanel.transform.parent = TargetMetricPanel.transform;
                        metricPanel.transform.Find("TargetLabel").GetComponent <Text>().text = "Calculate " + ((Metric)attr).Name;

                        //This line creates a MetricDelegate from the MethodInfo object.
                        //MetricDelegates take a Tile[,] and return a float.
                        //Note that we pass in the MonoBehaviour because it needs an object to invoke the delegate on.
                        MetricDelegateList.Add((TargetSetting.MetricDelegate)Delegate.CreateDelegate(typeof(TargetSetting.MetricDelegate), b, method));
                        MetricInputFieldList.Add(metricPanel.transform.Find("TargetInput").GetComponent <InputField>());

                        //We also create a report in the top left
                        GameObject metricReport = Instantiate(MetricReportUIPrefab);
                        metricReport.transform.parent = MetricReportPanel.transform;
                        metricReport.name             = "MetricReport" + ((Metric)attr).Name;
                        metricReport.transform.Find("MetricName").GetComponent <Text>().text = "" + ((Metric)attr).Name;
                        MetricReportTexts.Add(metricReport.transform.Find("MetricValue").GetComponent <Text>());

                        metricNames.Add(method.Name);
                    }
                }
            }
        }

        if (MetricInputFieldList.Count == 0 || DAN.Instance.AddDefaultMetrics)
        {
            LevelAnalyser la = DAN.Instance.analyser;
            foreach (MethodInfo method in la.GetType().GetMethods())
            {
                foreach (Attribute attr in method.GetCustomAttributes(false))
                {
                    if (attr is Metric)
                    {
                        GameObject metricPanel = Instantiate(TargetMetricPanelUIPrefab);
                        metricPanel.transform.parent = TargetMetricPanel.transform;
                        metricPanel.transform.Find("TargetLabel").GetComponent <Text>().text = ((Metric)attr).Name;

                        //This line creates a MetricDelegate from the MethodInfo object.
                        //MetricDelegates take a Tile[,] and return a float.
                        //Note that we pass in the MonoBehaviour because it needs an object to invoke the delegate on.
                        MetricDelegateList.Add((TargetSetting.MetricDelegate)Delegate.CreateDelegate(typeof(TargetSetting.MetricDelegate), la, method));
                        MetricInputFieldList.Add(metricPanel.transform.Find("TargetInput").GetComponent <InputField>());

                        //We also create a report in the top left
                        GameObject metricReport = Instantiate(MetricReportUIPrefab);
                        metricReport.transform.parent = MetricReportPanel.transform;
                        metricReport.name             = "MetricReport" + ((Metric)attr).Name;
                        metricReport.transform.Find("MetricName").GetComponent <Text>().text = "" + ((Metric)attr).Name;
                        MetricReportTexts.Add(metricReport.transform.Find("MetricValue").GetComponent <Text>());

                        metricNames.Add(method.Name);
                    }
                }
            }
        }

        //Update the ERA Buttons with the first two metrics
        GameObject.Find("MetricName1").GetComponent <InputField>().text = metricNames[0];
        GameObject.Find("MetricName2").GetComponent <InputField>().text = metricNames[1];
    }
Exemple #7
0
    void DrawRandomERGraph()
    {
        //Hide any levels
        // generator.GetComponent<CellularAutomataGenerator>().HideMapSprite();

        int[,] data = new int[100, 100];
        LevelAnalyser la = DAN.Instance.analyser;

        // CellularAutomataGenerator gen = generator.GetComponent<CellularAutomataGenerator>();

        // System.Type t1 = la.GetType();
        // MethodInfo metric1 = t1.GetMethod(firstMetricName);
        // System.Type t2 = la.GetType();
        // MethodInfo metric2 = t2.GetMethod(secondMetricName);

        // AutoTuner at = DAN.Instance.tuner;
        // at.Push();

        for (int att = 0; att < numberOfAttemptsRandom; att++)
        {
            // at.Randomise();
            object map = danesh.GenerateContent();
            int    m1  = (int)Mathf.Round((float)danesh.GetMetric(danesh.x_axis_era, new object[] { map }) * 99);
            int    m2  = (int)Mathf.Round((float)danesh.GetMetric(danesh.y_axis_era, new object[] { map }) * 99);
            Debug.Log(m1 + ", " + m2);
            if (m1 < 0)
            {
                m1 = 0;
            }
            if (m2 < 0)
            {
                m2 = 0;
            }
            data[m1, m2]++;
            // progressLabel.text = "Evaluating expressive range...\n"+(100*(float)att/(float)numberOfAttemptsRandom).ToString("F0")+" percent complete";
            // yield return 0;
        }

        // at.Pop();

        int sf = 5;

        Texture2D newTex = new Texture2D(1000, 1000, TextureFormat.ARGB32, false);

        //Render the map
        for (int i = 0; i < data.GetLength(0); i++)
        {
            for (int j = 0; j < data.GetLength(1); j++)
            {
                float amt = (float)data[i, j] / (float)numberOfAttempts * 50;
                PaintPoint(newTex, i, j, 5, new Color(amt, amt, amt, 1.0f));
            }
        }

        // progressLabel.text = "";

        //Replace texture
        newTex.Apply();

        GeneratedGraph = newTex;

        // ShowERA();
        // image.GetComponent<Image>().sprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), new Vector2(0.5f, 0.5f));
    }
Exemple #8
0
 protected void Awake()
 {
     analyser = GetComponent <LevelAnalyser>();
 }
Exemple #9
0
 protected void Awake()
 {
     analyser = GetComponent <LevelAnalyser>();
     rb       = GetComponent <Rigidbody>();
 }