Exemplo n.º 1
0
    public void ShowSubtitle(string text, float duration = 5.0f, string audioPath = "")
    {
        if (Subtitles.Count > 0)
        {
            Debug.Log("[RPGAIO] Skipped showing a single subtitle line as a longer list is already showing.");
        }

        timeShown    = 0;
        showDuration = duration + Rm_RPGHandler.Instance.Customise.SubtitleDelayBetweenLines;

        SubtitleText.text = text;
        SubtitleTextObject.SetActive(true);


        if (!string.IsNullOrEmpty(audioPath))
        {
            var soundclip = (AudioClip)Resources.Load(audioPath);

            if (soundclip != null)
            {
                AudioPlayer.Instance.Play(soundclip, AudioType.SoundFX, Vector3.zero);
            }
        }

        hLayout.GetComponent <ContentSizeFitter>().enabled = false;
        Canvas.ForceUpdateCanvases();
        hLayout.SetLayoutHorizontal();
        hLayout.GetComponent <ContentSizeFitter>().enabled = true;
    }
Exemplo n.º 2
0
    protected override Vector2 GetItemSize()
    {
        RectTransform content   = horizontalLayoutGroup.GetComponent <RectTransform>();
        RectTransform child0    = content.GetChild(0) as RectTransform;
        RectTransform child1    = content.GetChild(1) as RectTransform;
        float         childSize = abs(child1.anchoredPosition.x - child0.anchoredPosition.x) - horizontalLayoutGroup.spacing;

        return(new Vector2(childSize, 0));
    }
Exemplo n.º 3
0
        public void PanResearch(bool left)
        {
            int numLevels = researchList.transform.childCount;

            researchPannedAmount         += left? 1:-1;
            researchPanRight.interactable = researchPannedAmount > 0;
            researchPanLeft.interactable  = researchPannedAmount < numLevels - 1;
            IEnumerator Pan()
            {
                float xDelta = 100 + researchList.spacing;

                var   rt       = researchList.GetComponent <RectTransform>();
                float x0       = rt.anchoredPosition.x;
                float x1       = -researchPannedAmount * xDelta;
                float duration = .2f;

                float tStart = Time.time;

                while (Time.time < tStart + duration)
                {
                    float x = Mathf.Lerp(x0, x1, Tweens.QuadraticInOut((Time.time - tStart) / duration));
                    rt.anchoredPosition = new Vector2(x, rt.anchoredPosition.y);
                    yield return(null);
                }
                rt.anchoredPosition = new Vector2(x1, rt.anchoredPosition.y);
                researchPanRoutine  = null;
            }

            if (researchPanRoutine != null)
            {
                StopCoroutine(researchPanRoutine);
            }
            StartCoroutine(researchPanRoutine = Pan());
            SetCurrentResearchLeaderboard();
        }
    public void RefreshParent2()
    {
        HorizontalLayoutGroup parent = transform.GetComponentInParent <HorizontalLayoutGroup>();

        parent.childControlHeight = false;
        LayoutRebuilder.ForceRebuildLayoutImmediate(parent.GetComponent <RectTransform>());
    }
Exemplo n.º 5
0
    public void InitializeScrollView()
    {
        GameObject tournamentElement;

        for (int i = 0; i < ((TournamentModel)model).tournamentMatchList.Count; i++)
        {
            tournamentElement = Instantiate(Resources.Load("Prefabs/TournamentElement", typeof(GameObject))) as GameObject;
            tournamentElement.GetComponent <TournamentElementController>().SetStageData(((TournamentModel)model).tournamentMatchList[((TournamentModel)model).tournamentMatchList.Count - (i + 1)]);
            tournamentElement.GetComponent <TournamentElementController>().CheckIfStageIsUnlocked();

            elementsList.Add(tournamentElement);
        }

        tournamentElement = Instantiate(Resources.Load("Prefabs/TournamentElement_Self", typeof(GameObject))) as GameObject;
        elementsList.Insert(((TournamentModel)model).tournamentMatchList.Count - GameData.instance.playerData.tournamentProgress, tournamentElement);

        for (int i = elementsList.Count - 1; i >= 0; i--)
        {
            elementsList[i].transform.SetParent(content.transform, false);
            elementsList[i].GetComponent <TournamentElementController>().SetRankValue(i + 1);
        }

        // Resize scrollable background based on number of elements
        elementWidth = tournamentElement.GetComponent <LayoutElement>().minWidth + content.spacing;
        RectTransform rt = content.GetComponent <RectTransform>();

        rt.sizeDelta = new Vector2(elementWidth * (((TournamentModel)model).tournamentMatchList.Count + 1) + content.padding.right + content.padding.bottom, rt.rect.height);

        GetComponentInChildren <ScrollRect>().horizontalScrollbar.value = 0;
        //StartCoroutine(ScrolldownCoroutine());
    }
Exemplo n.º 6
0
        private void UpdateMagic()
        {
            foreach (var gizmo in _magicGizmos)
            {
                Destroy(gizmo.gameObject);
            }
            _magicGizmos.Clear();

            float totalItemWidth = 0f;

            foreach (var item in Data.MagicOverrides)
            {
                var itemGizmo = DomEdit.I.Ui.Create <MagicGizmo>(magicGroup.transform);
                itemGizmo.Initialize(this, item);
                totalItemWidth += itemGizmo.RectTrans.sizeDelta.x;

                _magicGizmos.Add(itemGizmo);
            }

            float groupWidth = magicGroup.GetComponent <RectTransform>().sizeDelta.x;

            if (totalItemWidth > groupWidth && Data.MagicOverrides.Count > 1)
            {
                float widthNeeded   = totalItemWidth - groupWidth;
                float spacingNeeded = widthNeeded / (Data.MagicOverrides.Count - 1);
                magicGroup.spacing = -spacingNeeded;
            }
        }
Exemplo n.º 7
0
    public static void ResizeForContent(this HorizontalLayoutGroup _this)
    {
        RectTransform t = _this.GetComponent <RectTransform>();
        float         h = ComputeContentWidth(_this);

        t.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, h);
    }
Exemplo n.º 8
0
    private void SetInitialReferences()
    {
        rectTransform = GetComponent <RectTransform>();

        //Debug.Log("THIS SLIDER IS BAD", this);

        minSlider      = rectTransform.Find("Min Slider").GetComponent <RangeMinSlider>();
        maxSlider      = rectTransform.Find("Max Slider").GetComponent <RangeMaxSlider>();
        minSliderLabel = rectTransform.Find("FirstLabel").GetComponent <TextMeshProUGUI>();
        maxSliderLabel = rectTransform.Find("LastLabel").GetComponent <TextMeshProUGUI>();

        rangeTickLayoutGroup   = rectTransform.Find("RangeTicks").GetComponent <HorizontalLayoutGroup>();
        rangeTickRectTransform = rangeTickLayoutGroup.GetComponent <RectTransform>();
        rangeTickGameObject    = rangeTickLayoutGroup.gameObject;

        bufferedRangeTicks = new BufferedArray <BufferedRangeTick>(InstantiateRangeTickBuffer, BufferRangeTick);

        List <BufferedRangeTick> bufferedRangeTicksInChildren = new List <BufferedRangeTick>();

        foreach (Transform obj in rangeTickRectTransform)
        {
            bufferedRangeTicksInChildren.Add(new BufferedRangeTick(obj.gameObject));
        }

        bufferedRangeTicks.AddRange(bufferedRangeTicksInChildren);

        bufferedRangeTicks.bufferedCount = bufferedRangeTicksInChildren.Count;

        bufferedRangeTicks.UpdatePooledObjects(0);

        minSlider.label        = minSliderLabel;
        minSlider.numberFormat = "n" + 0; //DecimalPlaces;
        maxSlider.label        = maxSliderLabel;
        maxSlider.numberFormat = "n" + 0; //DecimalPlaces;
    }
Exemplo n.º 9
0
    private void AddLife()
    {
        RectTransform parent = livesGroup.GetComponent <RectTransform>();
        GameObject    l      = Instantiate(lifePrefab);

        l.GetComponent <RectTransform>().SetParent(parent);
        livesList.Add(l);
    }
Exemplo n.º 10
0
 private void SetupSlot()
 {
     Slot.cam           = Camera.main;
     Slot.layoutGroup   = layoutGroup;
     Slot.offset        = itemDropOffset;
     Slot.player        = player;
     Slot.rectTransform = layoutGroup.GetComponent <RectTransform>();
 }
Exemplo n.º 11
0
    private void OnMouseUp()
    {
        cardToAttach = this.GetComponent <ClickOn>();

        Debug.Log("Mouse up over panel");

        LayoutRebuilder.ForceRebuildLayoutImmediate(hlg.GetComponent <RectTransform>());
    }
Exemplo n.º 12
0
 private void Awake()
 {
     parentCategoryName = "Catalogue";
     titleText.text     = "Catalogue";
     catRect            = catGroup.GetComponent <RectTransform>();
     subCatRect         = subCatGroup.GetComponent <RectTransform> ();   //test
     furRect            = furGroup.GetComponent <RectTransform>();
     originPosY         = contentRect.anchoredPosition.y;
 }
Exemplo n.º 13
0
        public ServerBox Box(IServer server)
        {
            var serverObject = new GameObject(server.Zone.Name);
            var box          = new ServerBox(serverObject, server, parts);

            serverObject.transform.SetParent(gameObject.transform, false);
            LayoutRebuilder.ForceRebuildLayoutImmediate(layout.GetComponent <RectTransform>());
            boxesPerServer[server] = box;
            return(box);
        }
Exemplo n.º 14
0
        public void InitHpUI(int maxHp, int startingHp, bool withAnimation = false)
        {
            hearts.Clear();
            DestroyChildGameObject(container_heart);
            if (maxHp > 14)
            {
                maxHp = 14;
            }
            int heartCount = maxHp % 2 == 1 ? (maxHp + 1) / 2 : maxHp / 2;

            grid.constraintCount = Mathf.Clamp(heartCount, 1, 7);
            // Debug.Log("maxHp: " + maxHp.ToString());
            // Debug.Log("heartCount: " + heartCount.ToString());
            for (int i = 0; i < heartCount; i++)
            {
                Transform heartTransform = Instantiate(heartSlotPrefab) as Transform;
                heartTransform.SetParent(container_heart);
                heartTransform.localScale = Vector3.one;
                heartTransform.position   = Vector2.zero;
                HeartSlot heartSlot = heartTransform.GetComponent <HeartSlot>();
                hearts.Add(heartSlot);
                int         bgColorIndex    = (maxHp - 1) / 8;
                int         heartColorIndex = bgColorIndex + 1;
                HeartStatus heartStatus     = HeartStatus.empty;

                // int remainHp = currentHp % 8;
                // Debug.Log("i: " + i.ToString());
                // Debug.Log("remainHp: " + remainHp.ToString());

                if (i < startingHp / 2)
                {
                    heartStatus = HeartStatus.full;
                }
                else if ((i == startingHp / 2) && (startingHp % 2 == 1))
                {
                    heartStatus = HeartStatus.half;
                }
                else
                {
                    heartStatus = HeartStatus.empty;
                }

                heartSlot.SetHeartSlot(heartStatus);
            }
            LayoutRebuilder.ForceRebuildLayoutImmediate(container_heart.GetComponent <RectTransform>());
            LayoutRebuilder.ForceRebuildLayoutImmediate(layoutgroup_heart.GetComponent <RectTransform>());
            // Canvas.ForceUpdateCanvases();
            // layoutgroup_heart.SetLayoutHorizontal();
            if (withAnimation)
            {
                animator_heart.SetTrigger("update");
            }
        }
Exemplo n.º 15
0
    public void LoadSelectList(List <BaseMember> selectList)
    {
        currentSelectItems = selectListLayout.GetComponentsInChildren <SelectItem>();
        foreach (SelectItem item in currentSelectItems)
        {
            item.DestroySelf();
        }
        int count = selectList.Count;

        for (int i = 0; i < count; i++)
        {
            GameObject selectObject = GameObject.Instantiate(selectItemsPanel);
            selectObject.transform.SetParent(selectListLayout.transform);
            selectObject.GetComponent <SelectItem>().SetSelectInfo(selectList[i]);
        }
        Vector2 size      = selectListLayout.GetComponent <RectTransform>().sizeDelta;
        float   sizeWidth = count * (selectItemsPanel.GetComponent <RectTransform>().sizeDelta.x + selectListLayout.spacing);

        selectListLayout.GetComponent <RectTransform>().sizeDelta     = new Vector2(sizeWidth, size.y);
        selectListLayout.GetComponent <RectTransform>().localPosition = new Vector3(sizeWidth / 2, 0); //TODO可以更简单的恢复到顶部

        currentSelectItems = selectListLayout.GetComponentsInChildren <SelectItem>();
    }
Exemplo n.º 16
0
    public static void GetSizeForHorizontalGroup(HorizontalLayoutGroup _group, int _elementsCount, float _elementWidth, float _deltaWidth = 0f)
    {
        var   rect  = _group.GetComponent <RectTransform>();
        float size  = 0;
        var   width = rect.sizeDelta.x * rect.localScale.x;

        size = width;
        size = _elementWidth * _elementsCount + _elementsCount * _group.spacing + _group.padding.left + _group.padding.right + _deltaWidth;
        if (size < width)
        {
            return;
        }
        rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size);
    }
Exemplo n.º 17
0
        private bool SetSelectedHeroIndexAndUpdateScrollPosition(
            int heroIndex, bool animateTransition, bool selectOverlordObject = true, bool force = false)
        {
            if (!force && heroIndex == _selectedHeroIndex)
            {
                return(false);
            }

            _selectedHeroIndex = heroIndex;

            RectTransform overlordContainerRectTransform = _overlordsContainer.GetComponent <RectTransform>();

            _heroSelectScrollSequence?.Kill();
            if (animateTransition)
            {
                _heroSelectScrollSequence = DOTween.Sequence();
                _heroSelectScrollSequence.Append(
                    DOTween.To(
                        () => overlordContainerRectTransform.anchoredPosition,
                        v => overlordContainerRectTransform.anchoredPosition = v,
                        CalculateOverlordContainerShiftForHeroIndex(_selectedHeroIndex),
                        ScrollAnimationDuration))
                .AppendCallback(() => _heroSelectScrollSequence = null);
            }
            else
            {
                overlordContainerRectTransform.anchoredPosition =
                    CalculateOverlordContainerShiftForHeroIndex(_selectedHeroIndex);
            }

            if (selectOverlordObject)
            {
                _overlordObjects[_selectedHeroIndex].Select(animateTransition);
            }

            return(true);
        }
Exemplo n.º 18
0
    public override void Setup()
    {
        if (gunSelectionItems == null)
        {
            gunSelectionItems = new List <GunSelectionItem>();
            List <ConfigGunRecord> gunRecords = ConfigurationManager.instance.gun.GetAll();
            List <int>             activeGuns = DataAPIController.instance.GetAllActiveGun();
            RectTransform          rect       = content.GetComponent <RectTransform>();
            rect.sizeDelta = new Vector2(contentWidth * gunRecords.Count, rect.sizeDelta.y);

            enquipId = DataAPIController.instance.GetCurrentEnquipId();

            foreach (var g in gunRecords)
            {
                Transform obj = Instantiate(gunSelectionItemPrefab);
                obj.SetParent(content.transform);
                obj.localScale = Vector3.one;
                GunSelectionItem item = obj.GetComponent <GunSelectionItem>();
                item.Setup(g, activeGuns.Contains(g.Id), enquipId);
                gunSelectionItems.Add(item);
            }

            root.btnDownBuy.onClick.AddListener(() =>
            {
                LevelUpFirePower();
            });

            root.btnMidBuy.onClick.AddListener(() =>
            {
                LevelUpStrength();
            });


            DataAPIController.instance.RegisterEvent(DataPath.ENQUIPS, OnChangeEnquip);
            DataAPIController.instance.RegisterEvent(DataPath.GOLD, OnGoldChangeEvent);

            OnChangeEnquip(enquipId);
        }
    }
Exemplo n.º 19
0
 public void OnScroll()
 {
     Debug.Log(content.transform.childCount * content.GetComponent <RectTransform>().sizeDelta.y);
     //this.GetComponent<ScrollRect>().StopMovement();
     //this.GetComponent<ScrollRect>().enabled = false;
 }
Exemplo n.º 20
0
    //  TODO optimize
    public void Update()
    {
        float leftOffset = Left;

        foreach (var item in left)
        {
            if (item != null && item.gameObject.activeSelf)
            {
                leftOffset += item.rect.width;
            }
        }

        float rightOffset = Right;

        foreach (var item in right)
        {
            if (item != null && item.gameObject.activeSelf)
            {
                rightOffset += item.rect.width;
            }
        }

        float topOffset = Top;

        foreach (var item in top)
        {
            if (item != null && item.gameObject.activeSelf)
            {
                topOffset += item.rect.height;
            }
        }

        float bottomOffset = Bottom;

        foreach (var item in bottom)
        {
            if (item != null && item.gameObject.activeSelf)
            {
                bottomOffset += item.rect.height;
            }
        }

        VerticalLayoutGroup   vertical   = transform.parent.GetComponent <VerticalLayoutGroup>();
        HorizontalLayoutGroup horizontal = transform.parent.GetComponent <HorizontalLayoutGroup>();

        layoutElement = GetComponent <LayoutElement>();

        if (vertical != null)
        {
            var vertRT = vertical.GetComponent <RectTransform>();
            if (vertRT != null)
            {
                var newHeight = vertRT.rect.height - topOffset - bottomOffset - GetLayoutGroupOffset(vertical);

                if (layoutElement != null)
                {
                    layoutElement.minHeight = newHeight;
                }

                rt.SetHeight(newHeight);
            }
        }
        else if (horizontal != null)
        {
            var horizRT = horizontal.GetComponent <RectTransform>();
            if (horizRT != null)
            {
                var newWidth = horizRT.rect.width - leftOffset - rightOffset - GetLayoutGroupOffset(horizontal);

                if (layoutElement != null)
                {
                    layoutElement.minWidth = newWidth;
                }

                rt.SetWidth(newWidth);
            }
        }
        else
        {
            rt.anchorMin = Vector2.zero;
            rt.anchorMax = Vector2.one;
            rt.pivot     = Vector2.one / 2;

            rt.SetLeft(leftOffset);
            rt.SetRight(rightOffset);
            rt.SetTop(topOffset);
            rt.SetBottom(bottomOffset);
        }
    }
Exemplo n.º 21
0
 private void Awake()
 {
     contentRect = contentGroup.GetComponent <RectTransform>();
 }
Exemplo n.º 22
0
    void PickupDragCallback(PointerEventData ped)
    {
        var gatesRT = gatesLayout.GetComponent <RectTransform>();
        var corners = new Vector3[4];

        gatesRT.GetWorldCorners(corners);

        float xMin      = corners[0].x;
        float yMin      = corners[0].y;
        float xMax      = corners[2].x;
        float yMax      = corners[2].y;
        float xViewport = (ped.position.x - xMin) / (xMax - xMin);
        float yViewport = (ped.position.y - yMin) / (yMax - yMin);

        var pickup = ped.pointerDrag.GetComponent <Pickup>();

        float snappedPosX;

        // check if hovered
        if (xViewport < 0 || xViewport > 1 || yViewport < 0 || yViewport > 1)
        {
            snappedSectionX           = snappedSectionY = -1;
            pickup.transform.position = ped.position;
            pickup.Alpha = .7f;
            return;
        }
        if (gates.Count == 0)
        {
            snappedSectionX = 0;
            snappedPosX     = xMin + (xMax - xMin) / 2;
        }
        else // find closest insertion/replacement gate to snap to
        {
            // yes this is brute force but I am pragmatic
            var xSnaps = new float[2 * gates.Count + 1];
            xSnaps[0] = (xMin + gatesLayout.padding.left + gates[0].transform.position.x) / 2;
            xSnaps[1] = gates[0].transform.position.x;
            for (int i = 1; i < gates.Count; i++)
            {
                xSnaps[i * 2]     = (gates[i - 1].transform.position.x + gates[i].transform.position.x) / 2;
                xSnaps[i * 2 + 1] = gates[i].transform.position.x;
            }
            xSnaps[2 * gates.Count] = (gates[gates.Count - 1].transform.position.x + xMax - gatesLayout.padding.right) / 2;

            snappedSectionX = 0;
            snappedPosX     = xSnaps[0];
            float maxDist = Mathf.Abs(xSnaps[0] - ped.position.x);
            for (int i = 0; i < xSnaps.Length; i++)
            {
                float dist = Mathf.Abs(xSnaps[i] - ped.position.x);
                if (dist < maxDist)
                {
                    snappedSectionX = i;
                    maxDist         = dist;
                    snappedPosX     = xSnaps[i];
                }
            }
        }

        // hard coded for two qubits only
        int nSlotsY = (pickup.type == Gate.Type.C || pickup.type == Gate.Type.NOT)? 1 : 2;

        snappedSectionY = (int)Mathf.Round(yViewport * (nSlotsY - 1));
        float snappedPosY = nSlotsY == 1? .5f : .25f + .5f * snappedSectionY / (nSlotsY - 1);

        snappedPosY = yMin + snappedPosY * (yMax - yMin);

        pickup.transform.position = new Vector2(snappedPosX, snappedPosY);
        pickup.Alpha = .9f;
        xRange       = xMax - xMin;
    }
Exemplo n.º 23
0
 void Awake()
 {
     manager     = GameObject.Find("MainObject").GetComponent <ClashGameManager>();
     toggleGroup = unitList.GetComponent <ToggleGroup>();
 }