Exemple #1
0
    void Start()
    {
        pickPanel        = FindObjectOfType <EmojiPickPanelScript>();
        pickContentPanel = pickPanel.GetComponentInChildren <EmojiPickPanelContentScript>();
        emojiButtonGroup = transform.parent.GetComponent <EmojiSlotButtonGroupScript>();
        rectTransform    = GetComponent <RectTransform>();
        img = transform.GetChild(0).GetComponent <Image>();

        // Set current image
        img.sprite = PreferencesScript.Instance.GetEmojiSpriteInSlot(slot);

        // Subscribe to choose event
        pickContentPanel.OnEmojiChosen += SetImageTo;

        // On click event
        EventTrigger.Entry entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerUp;
        entry.callback.AddListener((BaseEventData bed) => {
            // On click
            DOTween.Sequence()
            .Append(rectTransform.DOScale(0.7f, animationTime))
            .Append(rectTransform.DOScale(1f, animationTime))
            .OnComplete(new TweenCallback(() => {
                // (toggled) means   if this button has been pressed and because of this the pickpanel has been opened
                if (toggled)
                {
                    pickPanel.Close();
                    ToggleToFalse();
                    emojiButtonGroup.MakeEveryButtonNormal();
                }
                else             // Not toggled
                // First set every button to untoggled, because only one can be and we want this button to be
                {
                    emojiButtonGroup.SetEveryButtonToggleFalse();
                    ToggleToTrue();
                    // Set every button small but this one
                    emojiButtonGroup.MakeUntoggledButtonsSmall();

                    if (pickPanel.IsOpen)
                    {
                        // We don't want to open it again just simply change which is selected
                        pickContentPanel.SetNumberEnabled(slot);
                    }
                    else
                    {
                        // panel is not open so we first want to open it then set which is selected
                        pickPanel.Open();
                        pickContentPanel.SetNumberEnabled(slot);
                    }
                }
            }));
        });
        GetComponent <EventTrigger>().triggers.Add(entry);
    }
Exemple #2
0
 void Start()
 {
     panelContentScript = transform.parent.GetComponent <EmojiPickPanelContentScript>();
 }