예제 #1
0
    public void BindData <T>(string templatedName, List <T> dataList, System.Action <GameObject, T> bindEvent, bool itemCanClick = true, bool showSelectedItem = false)
    {
        ShowSelectedItem = showSelectedItem;
        int childCount = Content.transform.childCount;

        for (int i = childCount - 1; i >= 0; i--)
        {
            MultiObjectManager.Despawn(Content.transform.GetChild(i));
        }
        float totalHeight = 0;

        foreach (T t in dataList)
        {
            Transform item = MultiObjectManager.Spawn(templatedName);
            item.GetComponent <RectTransform>().SetParent(Content.transform);
            if (itemCanClick)
            {
                Button btnCtr = item.GetComponent <Button>();
                if (btnCtr != null && item.GetComponent <ButtonClickListener>() == null)
                {
                    ButtonClickListener btnListener = item.gameObject.AddComponent <ButtonClickListener>();
                    btnListener.OnClick = MenuItem_OnClicked;
                    btnCtr.transition   = Selectable.Transition.None;
                    btnCtr.onClick.RemoveAllListeners();
                    btnCtr.onClick.AddListener(() => { btnListener.OnClicked(); });
                }
            }
            bindEvent(item.gameObject, t);
            if (item.GetComponent <LayoutElement>() != null)
            {
                totalHeight += item.GetComponent <LayoutElement>().preferredHeight;
            }
        }
    }
예제 #2
0
 void Awake()
 {
     panelname = "MainLobbyPanel";
     LeftBtn   = this.transform.FindChild("Drag/LeftBtn").gameObject;
     if (LeftBtn != null)
     {
         ButtonClickListener listener = ButtonClickListener.AddEventListener(LeftBtn);
         listener.onClick = Down;
     }
     RightBtn = this.transform.FindChild("Drag/RightBtn").gameObject;
     if (RightBtn != null)
     {
         ButtonClickListener listener = ButtonClickListener.AddEventListener(RightBtn);
         listener.onClick = Down;
     }
     DragArea = this.transform.FindChild("Drag/DragArea").gameObject;
     CarTypeControler.CarRoot.position = new Vector3(DragArea.transform.position.x, DragArea.transform.position.y - 1.0f, 0.0f);
     if (DragArea != null)
     {
         EventTriggerListener listener = EventTriggerListener.AddEventListener(DragArea);
         listener.onDown = DragCar;
         listener.onDrag = CarOnDrag;
         listener.onUp   = DragUp;
     }
 }
예제 #3
0
    private void Start()
    {
        trayInputButton = GetComponentInParent <TrayInputButton>();
        if (trayInputButton != null)
        {
            clickListener = trayInputButton.GetComponent <ButtonClickListener>();
            clickListener.OnClick.AddListener(OnClicked);
        }
        else
        {
            Log.LogError(this, "TrayInputButton not found");
        }
        dispatcher = Service.Get <EventDispatcher>();
        GameObject localPlayerGameObject = ClubPenguin.SceneRefs.ZoneLocalPlayerManager.LocalPlayerGameObject;

        if (localPlayerGameObject != null)
        {
            locomotionEventBroadcaster = localPlayerGameObject.GetComponent <LocomotionEventBroadcaster>();
            SlideController component = localPlayerGameObject.GetComponent <SlideController>();
            if (component != null && component.enabled)
            {
                changeState(isSliding: true);
            }
        }
        if (locomotionEventBroadcaster != null)
        {
            locomotionEventBroadcaster.OnControllerChangedEvent += onControllerChanged;
        }
        else
        {
            Log.LogError(this, "LocomotionEventBroadcaster was not found in the scene");
        }
    }
예제 #4
0
 private void Start()
 {
     clickListener = GetComponentInParent <ButtonClickListener>();
     if (clickListener == null)
     {
     }
     addListener();
 }
 public void Initialize(ButtonClickListener accept, ButtonClickListener cancel)
 {
     btnAccept = ((accept != null) ? accept.GetComponent <InputMappedButton>() : null);
     btnCancel = ((cancel != null) ? cancel.GetComponent <InputMappedButton>() : null);
     if (btnAccept == null || btnCancel == null)
     {
         btnAccept = ((btnAccept != null) ? btnAccept : btnCancel);
         btnCancel = ((btnCancel != null) ? btnCancel : btnAccept);
     }
 }
예제 #6
0
    private void Awake()
    {
        panelname = "ChatPanel";
        transform.localPosition = new Vector3(500, 0, 0);
        panel     = transform.Find("Panel").gameObject;
        ChatEnter = this.transform.Find("ChatEnter").gameObject;
        if (ChatEnter != null)
        {
            ButtonClickListener listener = ButtonClickListener.AddEventListener(ChatEnter);
            listener.onClick = OnClick;
        }

        ShowChat = false;
        if (panel != null)
        {
            r = panel.GetComponent <References>();
            if (r != null)
            {
                ChatTips = r.Object[0].GetComponent <Text>();
                FaceIcon = r.Object[3];
                if (FaceIcon != null)
                {
                    FaceIcon.AddComponent <ButtonClickListener>().onClick = FacePanelOpen;
                }
                SendBtn = r.Object[4];
                if (SendBtn != null)
                {
                    SendBtn.AddComponent <ButtonClickListener>().onClick = SendMsg;
                }
                SendText = r.Object[2].GetComponent <InputField>();
                ChatRoot = r.Object[1];
                if (ChatRoot != null)
                {
                    ScrollGrid = ChatRoot.GetComponent <GridLayoutGroup>();
                    CellHeight = ScrollGrid.spacing.y + ScrollGrid.cellSize.y;
                    GridRect   = ChatRoot.GetComponent <RectTransform>();
                }
                Scroll     = r.Object[5].GetComponent <ScrollRect>();
                ScrollRect = r.Object[5].GetComponent <RectTransform>();
                EmojiBg    = r.Object[6];
                if (!EmojiBg.activeInHierarchy)
                {
                    EmojiBg.SetActive(true);
                }
                EmojiItemRoot = r.Object[7];
                if (EmojiBg != null)
                {
                    EmojiBg.AddComponent <ButtonClickListener>().onClick = CloseEmojiPanel;
                }
            }
        }
        TcpNet.Instance.RegisterServiceHandler((int)Stype.TalkRoom, TalkRoomServiceEventHandler);
        RegisterTalkRoomServiceCmdHandler();
    }
예제 #7
0
        public void Awake()
        {
            buttonClickListener = GetComponent <ButtonClickListener>();
            Transform transform = GetComponentInParent <MainNavStateHandler>().transform;

            mainNavButtons = transform.GetComponentsInChildren <MainNavButton>(includeInactive: true);
            CPDataEntityCollection cPDataEntityCollection = Service.Get <CPDataEntityCollection>();
            DataEntityHandle       entityByType           = cPDataEntityCollection.GetEntityByType <MainNavData>();

            mainNavData = cPDataEntityCollection.GetComponent <MainNavData>(entityByType);
            mainNavData.OnCurrentStateChanged += onCurrentStateChanged;
        }
예제 #8
0
    private void AddEmojiToRoot()
    {
        string resname = null;

        for (int index = 1; index < (GameData.EmojiCount + 1); index++)
        {
            resname = EmojiName + index.ToString();
            EmojiItem item = UIManager.AddItem <EmojiItem>("EmojiItem", EmojiItemRoot.transform);
            item.SetEmoji(resname);
            item.Emoji_Id = index;
            ButtonClickListener listener = item.gameObject.AddComponent <ButtonClickListener>();
            listener.onClick = SendEmoji;
        }
    }
예제 #9
0
    private void CreateItem(int index, ref float totalHeight)
    {
        Transform     item     = MultiObjectManager.Spawn(TemplatedName, Content.transform);
        RectTransform itemRect = item.GetComponent <RectTransform>();

        //itemRect.SetParent(Content.transform);
        if (item.GetComponent <DataItemControl>() == null)
        {
            item.gameObject.AddComponent <DataItemControl>();
        }
        item.GetComponent <DataItemControl>().DataIndex = index;

        BindEvent(item.gameObject, DataList[index]);

        float offsetMinY = -totalHeight - itemRect.GetComponent <LayoutElement>().preferredHeight - Spacing;
        float offsetMaxY = -totalHeight - Spacing;

        if (!ItemList.ContainsKey(index))
        {
            ItemList.Add(index, new ItemLayoutInfo()
            {
                MinOffsetY = offsetMinY, MaxOffsetY = offsetMaxY
            });
        }
        //设置item的位置
        itemRect.anchoredPosition3D = new Vector3(0, 1, 0);
        itemRect.offsetMax          = new Vector2(0, offsetMaxY);
        itemRect.offsetMin          = new Vector2(0, offsetMinY);
        totalHeight += itemRect.GetComponent <LayoutElement>().preferredHeight + Spacing;

        if (ItemCanClick)
        {
            Button btnCtr = item.GetComponent <Button>();
            if (btnCtr != null && item.GetComponent <ButtonClickListener>() == null)
            {
                ButtonClickListener btnListener = item.gameObject.AddComponent <ButtonClickListener>();
                btnListener.OnClick = MenuItem_OnClicked;
                btnCtr.transition   = Selectable.Transition.None;
                btnCtr.onClick.RemoveAllListeners();
                btnCtr.onClick.AddListener(() => { btnListener.OnClicked(); });
            }
        }
    }
예제 #10
0
        public void ShowPrompt(DPrompt data, Action <DPrompt.ButtonFlags> callback)
        {
            localizer = Service.Get <Localizer>();
            GameObject gameObject = GameObject.FindGameObjectWithTag(UIConstants.Tags.UI_Tray_Root);

            if (gameObject != null)
            {
                stateMachineContext = gameObject.GetComponent <StateMachineContext>();
                if (stateMachineContext != null && stateMachineContext.ContainsStateMachine("Root"))
                {
                    stateMachineContext.SendEvent(new ExternalEvent("Root", "popup_open"));
                }
            }
            updateTextFields(data);
            updateImages(data);
            ModalBackground component = GetComponent <ModalBackground>();

            component.enabled = data.IsModal;
            if (data.UseCloseButton)
            {
                if (CloseButton != null)
                {
                    CloseButton.SetActive(value: true);
                    ButtonClickListener component2 = CloseButton.GetComponent <ButtonClickListener>();
                    component2.OnClick.AddListener(onButtonClicked);
                }
                else
                {
                    Log.LogError(this, "CloseButton is null, cannot activate it");
                }
            }
            ButtonClickListener btnAccept = null;
            ButtonClickListener btnCancel = null;

            for (int i = 0; i < Buttons.Length; i++)
            {
                createButton(data, i, callback, ref btnAccept, ref btnCancel);
            }
            inputHandler.Initialize(btnAccept, btnCancel);
            playAccessibilityText();
        }
예제 #11
0
        protected virtual void createButton(DPrompt data, int buttonIndex, Action <DPrompt.ButtonFlags> callback, ref ButtonClickListener btnAccept, ref ButtonClickListener btnCancel)
        {
            DPrompt.ButtonFlags flag = (DPrompt.ButtonFlags)(1 << buttonIndex);
            if ((data.Buttons & flag) != flag)
            {
                return;
            }
            string     i18nText   = Buttons[buttonIndex].i18nText;
            GameObject gameObject = createButtonObject(data, buttonIndex, flag, ref i18nText);

            if (!string.IsNullOrEmpty(i18nText))
            {
                Text componentInChildren = gameObject.GetComponentInChildren <Text>();
                if (componentInChildren != null)
                {
                    componentInChildren.text = localizer.GetTokenTranslation(i18nText);
                }
            }
            ButtonClickListener component = gameObject.GetComponent <ButtonClickListener>();

            if (!(component != null))
            {
                return;
            }
            if (isBackButton(flag))
            {
                btnCancel = component;
            }
            else
            {
                btnAccept = component;
            }
            if (callback != null)
            {
                component.OnClick.AddListener(delegate
                {
                    callback(flag);
                });
            }
            component.OnClick.AddListener(onButtonClicked);
        }
예제 #12
0
    public void BindData <T>(GameObject templated, List <T> dataList, System.Action <GameObject, T> bindEvent, bool itemCanClick = true, bool showSelectedItem = false)
    {
        ShowSelectedItem = showSelectedItem;
        int childCount = Content.transform.childCount;

        for (int i = childCount - 1; i >= 0; i--)
        {
            GameObject item = Content.transform.GetChild(i).gameObject;
            if (item.name != "template")
            {
                GameObject.Destroy(item);
            }
        }
        float totalHeight = 0;

        foreach (T t in dataList)
        {
            Transform item = GameObject.Instantiate <GameObject>(templated).transform;
            item.gameObject.SetActive(true);
            item.GetComponent <RectTransform>().SetParent(Content.transform);
            item.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
            if (itemCanClick)
            {
                Button btnCtr = item.GetComponent <Button>();
                if (btnCtr != null && item.GetComponent <ButtonClickListener>() == null)
                {
                    ButtonClickListener btnListener = item.gameObject.AddComponent <ButtonClickListener>();
                    btnListener.OnClick = MenuItem_OnClicked;
                    btnCtr.transition   = Selectable.Transition.None;
                    btnCtr.onClick.RemoveAllListeners();
                    btnCtr.onClick.AddListener(() => { btnListener.OnClicked(); });
                }
            }
            bindEvent(item.gameObject, t);
            if (item.GetComponent <LayoutElement>() != null)
            {
                totalHeight += item.GetComponent <LayoutElement>().preferredHeight;
            }
        }
    }
예제 #13
0
        public override void OnEnter()
        {
            GameObject gameObject = (string.IsNullOrEmpty(ButtonName) ? ButtonObject.Value : GameObject.Find(ButtonName));

            if (gameObject != null)
            {
                button = gameObject.GetComponent <Button>();
                buttonClickListener = gameObject.GetComponent <ButtonClickListener>();
            }
            if (buttonClickListener != null)
            {
                buttonClickListener.OnClick.AddListener(onClickListener);
                return;
            }
            if (button != null)
            {
                button.onClick.AddListener(onPressed);
                return;
            }
            Disney.LaunchPadFramework.Log.LogError(this, "Unable to find button of name : " + ButtonName);
            Finish();
        }
예제 #14
0
 private void Awake()
 {
     clickListener = GetComponent <ButtonClickListener>();
 }
 private void Awake()
 {
     this.clickListener = base.GetComponent <ButtonClickListener>();
 }
예제 #16
0
    public static ButtonClickListener AddEventListener(GameObject go)
    {
        ButtonClickListener listener = go.AddComponent <ButtonClickListener>();

        return(listener);
    }