Ejemplo n.º 1
0
    void OnGUI()
    {
        if (currentState == EditorState.Creation) {

            GUI.BeginGroup (new Rect (Screen.width / 2 - 100, Screen.height / 2 - 100, 200, 200));

            GUI.Box (new Rect (0, 0, 200, 200), "Options");
            GUI.Label (new Rect (10, 10, 180, 20), "Width");
            width = GUI.TextField (new Rect (10, 40, 180, 20), width);
            GUI.Label (new Rect (10, 60, 180, 20), "Height");
            height = GUI.TextField (new Rect (10, 90, 180, 20), height);

            GUI.Label (new Rect (10, 110, 180, 20), "Export To");
            fileName = GUI.TextField (new Rect(10, 130, 180, 20), fileName);

            float testW = 0;
            float testH = 0;

            if (float.TryParse (width, out testW) && float.TryParse (height, out testH) && fileName != "") {
                if (GUI.Button (new Rect (40, 160, 120, 30), "Create Map")) {
                    canvas = new GameObject ("Canvas");
                    MeshFilter newFilter = canvas.AddComponent<MeshFilter> ();
                    newFilter.mesh = new Mesh ();
                    float widthNum = float.Parse (width) / 2;
                    float heightNum = float.Parse (height) / 2;

                    newFilter.mesh.vertices = new Vector3[4] {
                        new Vector3 (-widthNum, -heightNum, 0),
                        new Vector3 (widthNum, -heightNum, 0),
                        new Vector3 (widthNum, heightNum, 0),
                        new Vector3 (-widthNum, heightNum, 0)
                    };
                    newFilter.mesh.triangles = new int[6]{0,2,1,0,3,2};
                    newFilter.mesh.RecalculateNormals ();

                    MeshRenderer newRenderer = canvas.AddComponent<MeshRenderer> ();

                    newRenderer.material.shader = Shader.Find ("Sprites/Default");
                    newRenderer.material.color = Color.grey;

                    canvas.AddComponent<MeshCollider> ();

                    CanvasClick newClick = new CanvasClick();
                    newClick.parentCC = this;
                    currentClick = newClick;

                    CameraMove cameraMove = Camera.main.GetComponent<CameraMove>();
                    cameraMove.xBound = widthNum;
                    cameraMove.yBound = heightNum;

                    currentState = EditorState.Editing;
                }
            }

            GUI.EndGroup ();

        } else if (currentState == EditorState.Editing) {

            GUI.BeginGroup (new Rect (0, 0, 200, 150));

            GUI.Box (new Rect (0, 0, 200, 150), "Options");
            GUI.Label (new Rect (20, 30, 160, 20), "Node count: " + nodes.Count.ToString ());
            GUI.Label (new Rect (20, 50, 160, 20), "Link count: " + links.Count.ToString ());

            if (nodes.Count == 0) {
                if (GUI.Button (new Rect (40, 70, 120, 30), "Delete Canvas")) {
                    GameObject.Destroy (canvas);
                }
            } else {
                if (GUI.Button (new Rect (40, 110, 120, 30), "Convert Countries")) {
                    if(ConvertCountries ()) {
                        foreach(CNode node in nodes) {
                            Destroy (node.gameObject);
                        }

                        Destroy(canvas);
                        currentClick = new CountryClick();
                        currentState = EditorState.Finalising;
                    }
                }
            }

            GUI.EndGroup ();

        } else if (currentState == EditorState.Finalising) {

            int groupWidth = 100;

            GUI.BeginGroup(new Rect(0, 0, groupWidth*factions.Count + 50, 180));

            for(int factionCount = 0; factionCount < factions.Count; factionCount++) {
                Faction faction = factions[factionCount];

                GUI.Box( new Rect(groupWidth*factionCount, 0, groupWidth, 180), faction.factionName);

                if(factionCount != 0) {
                    faction.factionName = GUI.TextField(new Rect(groupWidth*factionCount + 10, 20, groupWidth-20, 30), faction.factionName);
                } else {
                    GUI.Label(new Rect(groupWidth*factionCount + 10, 20, groupWidth-20, 30), faction.factionName);
                }

                GUI.Label (new Rect(groupWidth*factionCount + 10, 60, groupWidth-20, 20), "Countries: " + faction.countries.Count.ToString());

                faction.colorString = GUI.TextField(new Rect(groupWidth*factionCount + 10, 80, groupWidth-20, 20), faction.colorString);

                if(faction.colorString.Length == 6) {
                    bool canParse = true;

                    for(int i = 0; i < faction.colorString.Length; i += 2) {
                        byte outByte;
                        if(!byte.TryParse(faction.colorString.Substring(0,2), System.Globalization.NumberStyles.HexNumber, null, out outByte)) {
                            canParse = false;
                        }
                    }

                    if(canParse) {
                        if(GUI.Button (new Rect(groupWidth*factionCount + 10, 110, groupWidth-20, 20), "Colour")) {
                            faction.factionColor = MeshMaker.HexToColor(faction.colorString);
                            faction.ColorCountries();
                        }
                    }
                }

                if(factionCount != 0) {
                    if(GUI.Button (new Rect(groupWidth*factionCount + 10, 140, groupWidth-20, 20), "Delete")) {
                        factions.Remove (faction);
                        while(faction.countries.Count != 0) {
                            factions[0].AddCountry(faction.countries[0]);
                        }
                        factionCount--;
                    }
                }
            }

            GUI.Box (new Rect(groupWidth*factions.Count, 50, 50, 50), "");
            if(GUI.Button (new Rect(groupWidth*factions.Count, 50, 50, 50), "+")) {
                factions.Add (new Faction());
            }
            GUI.EndGroup();

            GUI.BeginGroup (new Rect(0, Screen.height - 90, 100, 90));

            GUI.Box (new Rect(0, 0, 100, 90), "Final Conversion");
            if(GUI.Button(new Rect(10, 30, 90, 30), "Convert")) {
                warningLabel = CanExportMap();
                if(warningLabel == "") {
                    ExportMap();
                }
            }

            GUI.Label (new Rect(10, 70, 90, 20), warningLabel);

            GUI.EndGroup();
        }
    }
Ejemplo n.º 2
0
 private void OnCanvasClick()
 {
     CanvasClick?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 3
0
    void OnGUI()
    {
        if (currentState == EditorState.Creation)
        {
            GUI.BeginGroup(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 200, 200));

            GUI.Box(new Rect(0, 0, 200, 200), "Options");
            GUI.Label(new Rect(10, 10, 180, 20), "Width");
            width = GUI.TextField(new Rect(10, 40, 180, 20), width);
            GUI.Label(new Rect(10, 60, 180, 20), "Height");
            height = GUI.TextField(new Rect(10, 90, 180, 20), height);

            GUI.Label(new Rect(10, 110, 180, 20), "Export To");
            fileName = GUI.TextField(new Rect(10, 130, 180, 20), fileName);

            float testW = 0;
            float testH = 0;

            if (float.TryParse(width, out testW) && float.TryParse(height, out testH) && fileName != "")
            {
                if (GUI.Button(new Rect(40, 160, 120, 30), "Create Map"))
                {
                    canvas = new GameObject("Canvas");
                    MeshFilter newFilter = canvas.AddComponent <MeshFilter> ();
                    newFilter.mesh = new Mesh();
                    float widthNum  = float.Parse(width) / 2;
                    float heightNum = float.Parse(height) / 2;

                    newFilter.mesh.vertices = new Vector3[4] {
                        new Vector3(-widthNum, -heightNum, 0),
                        new Vector3(widthNum, -heightNum, 0),
                        new Vector3(widthNum, heightNum, 0),
                        new Vector3(-widthNum, heightNum, 0)
                    };
                    newFilter.mesh.triangles = new int[6] {
                        0, 2, 1, 0, 3, 2
                    };
                    newFilter.mesh.RecalculateNormals();

                    MeshRenderer newRenderer = canvas.AddComponent <MeshRenderer> ();

                    newRenderer.material.shader = Shader.Find("Sprites/Default");
                    newRenderer.material.color  = Color.grey;

                    canvas.AddComponent <MeshCollider> ();


                    CanvasClick newClick = new CanvasClick();
                    newClick.parentCC = this;
                    currentClick      = newClick;

                    CameraMove cameraMove = Camera.main.GetComponent <CameraMove>();
                    cameraMove.xBound = widthNum;
                    cameraMove.yBound = heightNum;

                    currentState = EditorState.Editing;
                }
            }

            GUI.EndGroup();
        }
        else if (currentState == EditorState.Editing)
        {
            GUI.BeginGroup(new Rect(0, 0, 200, 150));

            GUI.Box(new Rect(0, 0, 200, 150), "Options");
            GUI.Label(new Rect(20, 30, 160, 20), "Node count: " + nodes.Count.ToString());
            GUI.Label(new Rect(20, 50, 160, 20), "Link count: " + links.Count.ToString());

            if (nodes.Count == 0)
            {
                if (GUI.Button(new Rect(40, 70, 120, 30), "Delete Canvas"))
                {
                    GameObject.Destroy(canvas);
                }
            }
            else
            {
                if (GUI.Button(new Rect(40, 110, 120, 30), "Convert Countries"))
                {
                    if (ConvertCountries())
                    {
                        foreach (CNode node in nodes)
                        {
                            Destroy(node.gameObject);
                        }

                        Destroy(canvas);
                        currentClick = new CountryClick();
                        currentState = EditorState.Finalising;
                    }
                }
            }

            GUI.EndGroup();
        }
        else if (currentState == EditorState.Finalising)
        {
            int groupWidth = 100;

            GUI.BeginGroup(new Rect(0, 0, groupWidth * factions.Count + 50, 180));

            for (int factionCount = 0; factionCount < factions.Count; factionCount++)
            {
                Faction faction = factions[factionCount];

                GUI.Box(new Rect(groupWidth * factionCount, 0, groupWidth, 180), faction.factionName);

                if (factionCount != 0)
                {
                    faction.factionName = GUI.TextField(new Rect(groupWidth * factionCount + 10, 20, groupWidth - 20, 30), faction.factionName);
                }
                else
                {
                    GUI.Label(new Rect(groupWidth * factionCount + 10, 20, groupWidth - 20, 30), faction.factionName);
                }

                GUI.Label(new Rect(groupWidth * factionCount + 10, 60, groupWidth - 20, 20), "Countries: " + faction.countries.Count.ToString());

                faction.colorString = GUI.TextField(new Rect(groupWidth * factionCount + 10, 80, groupWidth - 20, 20), faction.colorString);

                if (faction.colorString.Length == 6)
                {
                    bool canParse = true;

                    for (int i = 0; i < faction.colorString.Length; i += 2)
                    {
                        byte outByte;
                        if (!byte.TryParse(faction.colorString.Substring(0, 2), System.Globalization.NumberStyles.HexNumber, null, out outByte))
                        {
                            canParse = false;
                        }
                    }

                    if (canParse)
                    {
                        if (GUI.Button(new Rect(groupWidth * factionCount + 10, 110, groupWidth - 20, 20), "Colour"))
                        {
                            faction.factionColor = MeshMaker.HexToColor(faction.colorString);
                            faction.ColorCountries();
                        }
                    }
                }

                if (factionCount != 0)
                {
                    if (GUI.Button(new Rect(groupWidth * factionCount + 10, 140, groupWidth - 20, 20), "Delete"))
                    {
                        factions.Remove(faction);
                        while (faction.countries.Count != 0)
                        {
                            factions[0].AddCountry(faction.countries[0]);
                        }
                        factionCount--;
                    }
                }
            }

            GUI.Box(new Rect(groupWidth * factions.Count, 50, 50, 50), "");
            if (GUI.Button(new Rect(groupWidth * factions.Count, 50, 50, 50), "+"))
            {
                factions.Add(new Faction());
            }
            GUI.EndGroup();

            GUI.BeginGroup(new Rect(0, Screen.height - 90, 100, 90));

            GUI.Box(new Rect(0, 0, 100, 90), "Final Conversion");
            if (GUI.Button(new Rect(10, 30, 90, 30), "Convert"))
            {
                warningLabel = CanExportMap();
                if (warningLabel == "")
                {
                    ExportMap();
                }
            }

            GUI.Label(new Rect(10, 70, 90, 20), warningLabel);

            GUI.EndGroup();
        }
    }