Beispiel #1
0
        // todo: remove from here
        private bool TryGetButton(IMouseEvent mouseEvent, out MovieButton button)
        {
            button = MovieButton.Start; // Default
            var globalRay  = mouseEvent.Viewport.GetGlobalRayForPixelPos(mouseEvent.State.Position);
            var cPlacement = Node.PresentationInfra().Placement;

            if (!cPlacement.PlacementSurface2D.TryFindPoint2D(globalRay, out var plainPoint))
            {
                return(false);
            }
            var rect = Rectangle;

            if (plainPoint.Y > rect.MinY)
            {
                return(false);
            }
            if (((plainPoint.X - rect.MinX) %
                 ((rect.Width - 2 * ButtonHalfWidth) / (AllMovieButtons.Length - 1))) >=
                2 * ButtonHalfWidth)
            {
                return(false);
            }
            button = (MovieButton)(int)((plainPoint.X - rect.MinX) /
                                        ((rect.Width - 2 * ButtonHalfWidth) / (AllMovieButtons.Length - 1)));
            return(true);
        }
    private void OnButtonClick(MovieButton button)
    {
        var movieInfo = button.MovieInfo;

        buttonClickingHistory.Push(beforeMovieInfo);
        ChangeMovieDetailInfo(movieInfo, button.GetTexture);
        beforeMovieInfo = movieInfo;
    }
    public void openPopup(MovieButton button)
    {
        var movieInfo = button.MovieInfo;

        movieDetailPanel.SetActive(true);
        ChangeMovieDetailInfo(movieInfo, button.GetTexture);

        beforeMovieInfo = movieInfo;
    }
    public void GenerateButtons()
    {
        while (panel.childCount > 0)
        {
            DestroyImmediate(panel.GetChild(0).gameObject);
        }

        int   row     = buttonRowCount;
        int   column  = buttonColumnCount;
        float spacing = 10;

        var panelRectTransform = panel.GetComponent <RectTransform>();
        var panelWidth         = panelRectTransform.rect.width;
        var panelHeight        = panelRectTransform.rect.height;

        var buttonWidth  = (panelWidth - (spacing * (column - 1))) / column;
        var buttonHeight = (panelHeight - (spacing * (row - 1))) / row;

        var buttonSize     = buttonWidth < buttonHeight ? buttonWidth : buttonHeight;
        var buttonHalfSize = buttonSize * 0.5f;

        var spacingWidth  = (panelWidth - (buttonSize * column)) / (column - 1);
        var spacingHeight = (panelHeight - (buttonSize * row)) / (row - 1);

        int buttonCount = 0;

        for (int k = 0; k < 2; ++k)
        {
            for (int i = 0; i < row; ++i)
            {
                for (int j = 0; j < column; ++j)
                {
                    MovieButton button = Instantiate(prefab, panel);
                    button.name = buttonCount++.ToString();
                    var buttonTransForm = button.GetComponent <RectTransform>();
                    buttonTransForm.sizeDelta        = new Vector2(buttonSize, buttonSize);
                    buttonTransForm.anchoredPosition = new Vector2(j * (buttonSize + spacingWidth) + buttonHalfSize, -(i * (buttonSize + spacingHeight) + buttonHalfSize));
                }
            }
        }
    }
Beispiel #5
0
        private ButtonTextureName GetButtonTextureName(MovieButton button)
        {
            switch (button)
            {
            case MovieButton.Start: return(ButtonTextureName.Start);

            case MovieButton.FBwrd: return(ButtonTextureName.FBwrd);

            case MovieButton.Bwrd: return(ButtonTextureName.Bwrd);

            case MovieButton.Play:
                return(moviePlayback.State == MoviePlaybackState.Playing
                        ? ButtonTextureName.Pause
                        : ButtonTextureName.Frwd);

            case MovieButton.FFrwd: return(ButtonTextureName.FFrwd);

            case MovieButton.End: return(ButtonTextureName.End);

            default:
                throw new ArgumentOutOfRangeException(nameof(button), button, null);
            }
        }
    public void OnButtonClick(MovieButton button)
    {
        Debug.LogFormat("button.name = {0}", button.name);

        movieDetailManager.openPopup(button);
    }
    private void UpdateButtons()
    {
        // move to left
        for (int i = 0; i < buttonsOnField.Count; i++)
        {
            var button = buttonsOnField[i];
            if (button.CurrentIndex > button.TargetIndex || (i > 0 && button.CurrentIndex - buttonsOnField[i - 1].CurrentIndex > 1))
            {
                Sequence seqInner = DOTween.Sequence();
                button.CurrentIndex -= 1;
                var newPosition = buttons[button.CurrentIndex].OriginPosition;
                if (button.CurrentIndex % buttonColumnCount == buttonColumnCount - 1)
                {
                    seqInner.AppendCallback(() =>
                    {
                        var clone               = Instantiate(button.RectTransform, button.transform.parent);
                        var clonePosition       = button.AnchoredPosition;
                        clonePosition.x        -= button.ButtonSize;
                        newPosition.x          += button.ButtonSize;
                        button.AnchoredPosition = newPosition;
                        newPosition.x          -= button.ButtonSize;
                        clone.DOAnchorPosX(clonePosition.x, duration).OnComplete(() => { Destroy(clone.gameObject); });
                    });
                }
                seqInner.Join(button.RectTransform.DOAnchorPosX(newPosition.x, duration));
                return;
            }
        }

        if (!isAnimating && buttonActionQueue.Count > 0)
        {
            MovieButton newButton = buttonActionQueue.Peek();
            if (!newButton.IsTexture)
            {
                return;
            }
            else
            {
                buttonActionQueue.Dequeue();
            }

            isAnimating = true;
            Sequence seq = DOTween.Sequence();

            int targetIndex  = newButton.TargetIndex;
            int currentIndex = targetIndex;

            var foundButton = buttonsOnField.Find(button => button != newButton && (button.CurrentIndex == currentIndex || button.TargetIndex > targetIndex));
            if (foundButton != null)
            {
                // push all buttons to right(button.CurrentIndex == currentIndex)
                int foundButtonCurrentIndex = foundButton.CurrentIndex;
                for (int i = foundButton.CurrentIndex; i < buttonsOnField.Count; ++i)
                {
                    var button = buttonsOnField[i];
                    button.CurrentIndex += 1;
                    var toMovePosition = buttons[button.CurrentIndex].OriginPosition;
                    if (button.CurrentIndex % buttonColumnCount == 0)
                    {
                        var clone           = Instantiate(button.RectTransform, panel);
                        var cloneToPosition = button.AnchoredPosition.x + button.ButtonSize;
                        seq.Join(clone.DOAnchorPosX(cloneToPosition, duration).OnComplete(() => { Destroy(clone.gameObject); }));

                        toMovePosition.x       -= button.ButtonSize;
                        button.AnchoredPosition = toMovePosition;
                        toMovePosition.x       += button.ButtonSize;
                    }
                    seq.Join(button.RectTransform.DOAnchorPosX(toMovePosition.x, duration));
                }

                if (foundButton.TargetIndex > targetIndex)
                {
                    currentIndex = foundButtonCurrentIndex;
                }
            }
            else
            {
                currentIndex = buttonsOnField.Count;
            }

            newButton.CurrentIndex = currentIndex;

            if (!buttonsOnField.Contains(newButton))
            {
                if (buttonsOnField.Count > currentIndex)
                {
                    buttonsOnField.Insert(currentIndex, newButton);
                }
                else
                {
                    buttonsOnField.Add(newButton);
                }
                newButton.AnchoredPosition = buttons[currentIndex].OriginPosition;
                seq.Append(newButton.RectTransform.DOScale(1, duration));
            }

            //seq.OnComplete(() => { isAnimating = false; });
            seq.OnKill(() => { isAnimating = false; });
        }

        //int count = 0;
        //foreach (var item in buttonsOnField)
        //{
        //    Debug.LogFormat("item index = {0}, currentIndex = {1}", count++, item.CurrentIndex);
        //}
    }