UIManager.cs 2.23 KB
Newer Older
BlackAngle233's avatar
BlackAngle233 committed
1
2
3
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
BlackAngle233's avatar
BlackAngle233 committed
4
using UnityEngine.UI;
BlackAngle233's avatar
BlackAngle233 committed
5
6
7

public class UIManager : MonoBehaviour
{
BlackAngle233's avatar
BlackAngle233 committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    List<GameObject> points;
    List<GameObject> lines;

    public Transform pointsParent;
    public Transform linesParent;
    public GameObject button;
    public GameObject line;

    string chosen1 = "";
    string chosen2 = "";

    public CanvasManager3D CM;

    enum UIState
    {
        none,
        createLine
    }

    UIState state = UIState.none;
    
BlackAngle233's avatar
BlackAngle233 committed
29
30
31
    // Start is called before the first frame update
    void Start()
    {
BlackAngle233's avatar
BlackAngle233 committed
32
33
        points = new List<GameObject>();
        lines = new List<GameObject>();
BlackAngle233's avatar
BlackAngle233 committed
34
35
36
37
38
    }

    // Update is called once per frame
    void Update()
    {
BlackAngle233's avatar
BlackAngle233 committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
        switch (state)
        {
            case UIState.none:
                break;
            case UIState.createLine:
                if(!chosen1.Equals("") && !chosen2.Equals(""))
                {
                    createLine();
                }
                break;
        }
    }

    public void createPoint()
    {
        string n = CM.createPoint();
        GameObject tmp = Instantiate(button);
        tmp.transform.SetParent(pointsParent);
        points.Add(tmp);
        tmp.transform.localPosition = new Vector3(50 + 40 * (points.Count - 1), 0, 0);
        tmp.GetComponentInChildren<Text>().text = n;
        tmp.GetComponent<Button>().onClick.AddListener(delegate(){ chooseObject(n); });
    }

    public void createLineButton()
    {
        state = UIState.createLine;
    }

    void createLine()
    {
        string n = CM.createLine(chosen1, chosen2);
        chosen1 = "";
        chosen2 = "";
        GameObject tmp = Instantiate(line);
        tmp.transform.SetParent(linesParent);
        lines.Add(tmp);
        tmp.transform.localPosition = new Vector3(50 + 40 * (lines.Count - 1), 0, 0);
        tmp.GetComponentInChildren<Text>().text = n;
        state = UIState.none;
    }

    public void chooseObject(string obj)
    {
        if (chosen1.Equals(""))
            chosen1 = obj;
        if (!chosen1.Equals("") && !chosen1.Equals(obj) && chosen2.Equals(""))
            chosen2 = obj;
    }

    public void LineButton()
    {
        if(state == UIState.none)
        {

        }
BlackAngle233's avatar
BlackAngle233 committed
95
96
    }
}