示例#1
0
        public static void RegisterJoyStick(MenuCommand menuCommand)
        {
            GameObject joyStick = CreateJoyStick(UIMenuTools.GetStandardResources());

            UIMenuTools.PlaceUIElementRoot(joyStick, menuCommand);

            // 以下三行必须在此执行,若放在CreateJoyStick中会因为新建对象层级未绑定以至canvas为null
            UIDragable dragable = joyStick.GetComponentInChildren <UIDragable>();
            Canvas     canvas   = dragable.GetComponentInParent <Canvas>();

            dragable.rect = canvas.GetComponent <RectTransform>();
        }
示例#2
0
        static GameObject CreateArcView(UIResources resources)
        {
            GameObject arc = DefaultControls.CreateImage(UIDefaultControls.ConvertToDefaultResources(resources));

            arc.name = "ArcView";
            Image background = arc.GetComponent <Image>();

            background.enabled       = false;
            background.raycastTarget = false;

            GameObject content = new GameObject("Content", typeof(RectTransform));

            content.transform.SetParent(arc.transform);

            GameObject btnSwitch = DefaultControls.CreateButton(UIDefaultControls.ConvertToDefaultResources(resources));

            btnSwitch.name = "BtnSwitch";
            btnSwitch.transform.SetParent(arc.transform);

            GameObject hotSpot = DefaultControls.CreateImage(UIDefaultControls.ConvertToDefaultResources(resources));

            hotSpot.name = "HotSpot";
            hotSpot.GetComponent <Image>().color = new Vector4(255, 255, 255, 0);
            UIDragable uiDragable = hotSpot.AddComponent <UIDragable>();

            uiDragable.rect = hotSpot.GetComponent <RectTransform>();
            hotSpot.transform.SetParent(arc.transform);
            PassPointerEvent passEvent = hotSpot.AddComponent <PassPointerEvent>();

            passEvent.passPointerClick = true;

            ArcView arcView = arc.AddComponent <ArcView>();

            arcView.panel     = arc.transform as RectTransform;
            arcView.content   = content.transform as RectTransform;
            arcView.hotSpot   = uiDragable;
            arcView.btnSwitch = btnSwitch.GetComponent <Button>();

            return(arc);
        }