Example #1
0
        private GameObject CreateExpernalDeviceCanvas(Util.Device device, GameObject panel)
        {
            var canvas = Instantiate(DeviceCanvas);

            canvas.name = device.Name + "_canvas";
            canvas.transform.Find("HiddenName").gameObject.GetComponent <Text>().text = device.Name;
            var content = canvas.transform.Find("Content");

            content.GetComponent <RectTransform>().sizeDelta      = new Vector2(content.GetComponent <RectTransform>().sizeDelta.x, panel.GetComponent <RectTransform>().sizeDelta.y + 10);
            panel.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, -5);
            panel.transform.Find("MoveBack").gameObject.GetComponent <Button>().interactable = true;
            panel.transform.Find("MoveBack").gameObject.GetComponent <Button>().onClick.AddListener(delegate
            {
                device.SetRotation(false);
                panel.SetActive(false);
                panel.transform.SetParent(Content.transform, false);
                _panelsList.Add(panel);
                panel.transform.Find("MoveBack").gameObject.GetComponent <Button>().onClick.RemoveAllListeners();
                panel.transform.Find("MoveBack").gameObject.GetComponent <Button>().interactable = false;
                device.IsPlaced = false;
                PanelBackClick(canvas);
            });
            panel.transform.Find("TapToPlaceButton").gameObject.GetComponent <Button>().onClick.RemoveAllListeners();
            panel.transform.Find("TapToPlaceButton").gameObject.GetComponent <Button>().onClick.AddListener(delegate
            {
                if (!device.IsPlaced)
                {
                    EventManager.Instance.RemoveDevice(device.GObject, device.Name);
                    device.SetRotation(true);
                    device.IsPlaced = true;
                    _panelsList.Remove(panel);
                    var newCanvas = CreateExpernalDeviceCanvas(device, panel);
                    PanelPlaceClick(newCanvas);
                }
                else
                {
                    PanelPlaceClick(canvas);
                }
            });
            panel.transform.SetParent(content.transform, false);
            //resize content
            var height = panel.GetComponent <RectTransform>().sizeDelta.y;
            var size   = canvas.GetComponent <RectTransform>().sizeDelta;

            canvas.GetComponent <RectTransform>().sizeDelta = new Vector2(size.x, height + 10);
            canvas.GetComponent <BoxCollider>().size        = new Vector2(size.x, height);
            canvas.transform.parent = transform.Find("/Objects");
            canvas.SetActive(true);
            return(canvas);
        }
Example #2
0
        private GameObject AddPanel(Util.Device device, string name)
        {
            var panel = CreatePanel(device, name);

            panel.transform.Find("TapToPlaceButton").gameObject.GetComponent <Button>().onClick.RemoveAllListeners();
            panel.transform.Find("TapToPlaceButton").gameObject.GetComponent <Button>().onClick.AddListener(delegate
            {
                if (!device.IsPlaced)
                {
                    EventManager.Instance.RemoveDevice(device.GObject, device.Name);
                    device.SetRotation(true);
                    device.IsPlaced = true;
                    _panelsList.Remove(panel);
                    var canvas = CreateExpernalDeviceCanvas(device, panel);
                    PanelPlaceClick(canvas);
                }
            });
            panel.transform.Find("MoveBack").gameObject.GetComponent <Button>().interactable = false;
            panel.transform.SetParent(Content.transform, false);
            _panelsList.Add(panel);
            return(panel);
        }