/// <summary>
        /// Handle drag event.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public override void OnDrag(PointerEventData eventData)
        {
            if (eventData.button != PointerEventData.InputButton.Left)
            {
                return;
            }

            if (!IsActive())
            {
                return;
            }

            Vector2 localCursor;

            if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(viewRect, eventData.position, eventData.pressEventCamera, out localCursor))
            {
                return;
            }

            if (MaxDrag != Vector2.zero)
            {
                var pointerDelta = localCursor - CursorStartPosition;
                var delta        = Vector2.zero;

                if ((MaxDrag.x > 0f) && (Mathf.Abs(pointerDelta.x) > MaxDrag.x) && horizontal)
                {
                    delta.x = pointerDelta.x > 0 ? MaxDrag.x - pointerDelta.x : -(MaxDrag.x + pointerDelta.x);
                }

                if ((MaxDrag.y > 0f) && (Mathf.Abs(pointerDelta.y) > MaxDrag.y) && vertical)
                {
                    delta.y = pointerDelta.y > 0 ? MaxDrag.y - pointerDelta.y : -(MaxDrag.y + pointerDelta.y);
                }

                Vector3 source_point;
                RectTransformUtility.ScreenPointToWorldPointInRectangle(viewRect, eventData.position, eventData.pressEventCamera, out source_point);

                var result_point = new Vector3(source_point.x + delta.x, source_point.y + delta.y);
                eventData.position = RectTransformUtility.WorldToScreenPoint(eventData.pressEventCamera, result_point);
            }

            base.OnDrag(eventData);
        }
Example #2
0
    public void ShowConstructionTooltip(Building building)
    {
        var tooltipGO = Instantiate(ConstructionTooltipPrefab);

        tooltipGO.transform.SetParent(UICanvas.transform);

        Vector2 localPoint;
        var     screenPos = RectTransformUtility.WorldToScreenPoint(Camera.main, building.VisualPrefab.transform.position);

        RectTransformUtility.ScreenPointToLocalPointInRectangle(UICanvas.GetComponent <RectTransform>(), screenPos, null, out localPoint);
        localPoint.y += yOffset;
        localPoint.x += xOffset;
        tooltipGO.transform.localPosition = localPoint;

        var toolTipComponent = tooltipGO.GetComponent <ConstructionTooltip>();

        toolTipComponent.building = building;
        toolTipComponent.Setup();
    }
Example #3
0
    public void SetPosition()
    {
        if (m_MyShipRenderer != null)
        {
            if (m_MyShipRenderer.isVisible == true)
            {
                m_MarkerImage.enabled = true;
            }
            else
            {
                m_MarkerImage.enabled = false;
            }

            if (m_MarkerImage.enabled == true)
            {
                MyRectTransform.position = RectTransformUtility.WorldToScreenPoint(Camera.main, m_SpaceObject.GetBody().transform.position);
            }
        }
    }
Example #4
0
 void LateUpdate()
 {
     if (lander)
     {
         healthBar.SetActive(true);
         RectTransform healthBarRect = healthBar.GetComponent <RectTransform>();
         float         healthCurrent = lander.GetComponent <Health>().healthCurrent;
         float         healthMax     = lander.GetComponent <Health>().healthMax;
         int           healthPercent = Mathf.RoundToInt(healthCurrent / healthMax * 100);
         healthBarRect.sizeDelta = new Vector2(healthPercent, healthBarRect.sizeDelta.y);
         Vector2 landerScreenPosition = RectTransformUtility.WorldToScreenPoint(mainCamera, lander.transform.position);
         Vector2 healthBarPosition    = new Vector2(Mathf.Round(landerScreenPosition.x), Mathf.Round(landerScreenPosition.y + 40));
         healthBarRect.position = healthBarPosition;
     }
     else
     {
         healthBar.SetActive(false);
     }
 }
Example #5
0
        public void Init(Entity.ItemGetEntity entity, Camera targetCamera)
        {
            _text.gameObject.SetActive(true);

            _text.text = entity.GetText;

            _text.color = entity.ItemColor;

            _text.rectTransform.position = RectTransformUtility.WorldToScreenPoint(targetCamera, entity.GetPosition + new Vector3(0, 1.0f, 0));

            _seq = DOTween.Sequence();

            _seq.Append(_text.rectTransform.DOMoveY(60f, 0.7f).SetRelative(true))
            .Append(_text.rectTransform.DOMoveY(100f, 0.25f).SetRelative(true))
            .Join(_text.rectTransform.DOScaleX(0, 0.25f));

            /*
             *
             * _text.DOFade(0, 0);
             * DOTweenTMPAnimator tmpAnimator = new DOTweenTMPAnimator(_text);
             *
             * for(int i = 0;i < tmpAnimator.textInfo.characterCount; i++)
             * {
             *  tmpAnimator.DOScaleChar(i, 0.45f, 0);
             *  Vector3 currCharOffset = tmpAnimator.GetCharOffset(i);
             *
             *  _seq
             *      .Join(tmpAnimator.DOOffsetChar(i, currCharOffset + new Vector3(0, 0.8f, 0), 0.15f).SetEase(Ease.OutFlash, 2))
             *      .Join(tmpAnimator.DOFadeChar(i, 1, 0.05f))
             *      .Join(tmpAnimator.DOScaleChar(i, 1, 0.4f).SetEase(Ease.OutBack))
             *      .SetDelay(0.07f * i);
             *
             * }
             */

            _seq.Play();
            _seq.OnComplete(() =>
            {
                Destroy(gameObject);
                _seq.Kill();
            });
            //.SetDelay(0.7f);
        }
Example #6
0
        //public void SetWorldColor(Button clickedButton)
        //{
        //    width = Screen.width;
        //    height = Screen.height;
        //    Vector2 buttonPos = RectTransformUtility.WorldToScreenPoint(null, clickedButton.transform.position);
        //    Vector2 buttonPosNormalized = new Vector2(buttonPos.x / width, buttonPos.y / height);

        //    worldFillMaterial.SetVector("_Offset", new Vector4(-buttonPosNormalized.x, -buttonPosNormalized.y, 0, 1));
        //    if (currentCoroutine == null)
        //    {
        //        this.newColor = clickedButton.GetComponent<Image>().color;

        //        worldFillMaterial.SetColor("_FrontColor", newColor);
        //        finalValue = Screen.orientation == ScreenOrientation.Landscape ? Mathf.Sqrt(Mathf.Pow((float)width / height, 2) + 1)
        //            : Mathf.Sqrt(Mathf.Pow((float)height / width, 2) + 1);
        //        StopCoroutine("SetMaterialParams");
        //        currentCoroutine = StartCoroutine(SetMaterialParams(finalValue));
        //    }

        //    //valueTweener = DOTween.To(x => radius = x, 0, finalValue, easeDuration)
        //    //    .SetEase(easeType)
        //    //    .SetAutoKill(false);

        //    //valueTweener.OnUpdate(() => Debug.Log(radius));// worldFillMaterial.SetFloat("_Radius", radius));

        //}

        public void SetWorldColor(UIGradient gradient)
        {
            width  = Screen.width;
            height = Screen.height;
            Vector2 buttonPos           = RectTransformUtility.WorldToScreenPoint(null, gradient.transform.position);
            Vector2 buttonPosNormalized = new Vector2(buttonPos.x / width, buttonPos.y / height);

            foreach (Material worldFillMaterial in worldFillMaterials)
            {
                worldFillMaterial.SetVector("_Offset", new Vector4(-buttonPosNormalized.x, -buttonPosNormalized.y, 0, 1));
                worldFillMaterial.SetFloat("_Radius", 0);
                this.newColor = gradient._effectGradient.colorKeys[0].color;

                worldFillMaterial.SetColor("_FrontColor", newColor);
                finalValue = Screen.orientation == ScreenOrientation.Landscape ? Mathf.Sqrt(Mathf.Pow((float)width / height, 2) + 1)
                    : Mathf.Sqrt(Mathf.Pow((float)height / width, 2) + 1);
                worldFillMaterial.DOFloat(finalValue, "_Radius", easeDuration).SetEase(easeType).OnComplete(() => worldFillMaterial.SetColor("_BackColor", newColor));
            }
        }
Example #7
0
        public static void SetInputRange(this InputSender sender, RawImage image)
        {
            // correct pointer position
            Vector3[] corners = new Vector3[4];
            image.rectTransform.GetWorldCorners(corners);
            Camera camera  = image.canvas.worldCamera;
            var    corner0 = RectTransformUtility.WorldToScreenPoint(camera, corners[0]);
            var    corner2 = RectTransformUtility.WorldToScreenPoint(camera, corners[2]);
            var    region  = new Rect(
                corner0.x,
                corner0.y,
                corner2.x - corner0.x,
                corner2.y - corner0.y
                );

            var size = new Vector2Int(image.texture.width, image.texture.height);

            sender.SetInputRange(region, size);
        }
Example #8
0
    private void Start()
    {
        //This is my code, the rest is from the asset---------------
        //Transform the joystick manually on the screen

        float size = (Screen.width < Screen.height) ? Screen.width : Screen.height; //Get horizontal or vertical size of the screen.

        background.sizeDelta = new Vector2(size * 0.8f, size * 0.8f);               //Make the joystick 80% of the screensize.

        //set the position of the joystick
        float x = background.transform.position.x;
        float y = size / 2f;
        float z = background.transform.position.z;

        background.transform.position = new Vector3(x, y, z);
        //----------------------------------------------------------

        joystickPosition = RectTransformUtility.WorldToScreenPoint(cam, background.position);
    }
Example #9
0
    /// <summary>
    /// 頭の上にUIでダメージを表示
    /// </summary>
    /// <param name="target">頭にだすキャラ</param>
    /// <param name="damage">ダメージ</param>
    public void DamegeUIInit(GameObject target, int damage)
    {
        //ダメージUI表示
        GameObject text = Instantiate(
            Resources.Load("DamageTxt"),
            GameObject.Find("Canvas1").transform.Find("frame")) as GameObject;
        //ワールド座標をスクリーン座標に変換
        var p           = RectTransformUtility.WorldToScreenPoint(Camera.main, target.transform.position);
        var retPosition = Vector2.zero;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(
            GameObject.Find("Canvas1").GetComponent <RectTransform>(),
            p,
            Camera.main,
            out retPosition
            );
        text.transform.localPosition = retPosition;
        text.GetComponent <DamegeUI>().setDamegeTxt(damage);
    }
Example #10
0
    public void OnDrag(PointerEventData eventData)
    {
        cam = null;
        if (canvas.renderMode == RenderMode.ScreenSpaceCamera)
        {
            cam = canvas.worldCamera;
        }

        Vector2 position = RectTransformUtility.WorldToScreenPoint(cam, background.position);
        Vector2 radius   = background.sizeDelta / 2;

        input = (eventData.position - position) / (radius * canvas.scaleFactor);
        FormatInput();
        HandleInput(input.magnitude, input.normalized, radius, cam);
        handle.anchoredPosition = input * radius * handleRange;

        if (OnDragging)
        {
            OnDragging.Raise(Direction);
        }
        else
        {
            Debug.LogError("OnTouchStarted not set.");
        }

        if (OnHorizontalDrag)
        {
            OnHorizontalDrag.Raise(Horizontal);
        }
        else
        {
            Debug.LogError("OnHorizontalDrag not set.");
        }

        if (OnVerticalDrag)
        {
            OnVerticalDrag.Raise(Vertical);
        }
        else
        {
            Debug.LogError("OnVerticalDrag not set.");
        }
    }
Example #11
0
    void Update()
    {
        img.transform.position
            = RectTransformUtility.WorldToScreenPoint(Camera.main, this.transform.position);
        img.rectTransform.rotation = this.transform.rotation;

        float skill = _panelController.skillSpeed;

        this.transform.position += transform.up * speed * Time.deltaTime * 0.6f * skill;
        this.transform.rotation  = Quaternion.Euler(0, 0, rotate);

        rotate += 1f * abs;

        if (this.transform.position.y >= moveOverY || this.transform.position.y <= -moveOverY || this.transform.position.x <= -13f || this.transform.position.x >= 13f)
        {
            Destroy(this.gameObject);
            Destroy(img);
        }
    }
Example #12
0
    protected RaycastHit GetCrosshairHit(out Ray outRay)
    {
        Vector3 crosshairScreenPos = RectTransformUtility.WorldToScreenPoint(null, CrosshairManager.crosshairRect.position);
        Ray     ray = mainCamera.ScreenPointToRay(crosshairScreenPos);

        outRay = ray;
        Debug.DrawRay(ray.GetPoint(0), ray.direction, Color.yellow);

        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, maxInteractDistance))
        {
            return(hit);
        }
        else
        {
            return(new RaycastHit());
        }
    }
Example #13
0
        private bool CheckNextGraph(RGNode node)
        {
            string root   = MessageManager.Instance.RootPath;
            var    expend = layout.CheckExpend(root, node);

            if (!expend)
            {
                return(false);
            }
            if (node.Data.entity == null)
            {
                var file = Path.Combine(node.Data.fullPath);
                if (File.Exists(file))
                {
                    var json = File.ReadAllText(file);
                    var tmp  = ParseUtil.ParseEntityJson(json, root);
                    if (tmp != null)
                    {
                        tmp.uid          = node.Data.UID;
                        node.Data.entity = tmp;
                    }
                    else
                    {
                        node.Data.entity = new EntityInfo
                        {
                            uid  = node.Data.UID,
                            name = node.Data.name
                        };
                    }
                }
                else
                {
                    node.Data.entity = new EntityInfo
                    {
                        uid  = node.Data.UID,
                        name = node.Data.name
                    };
                }
            }
            node.Data.Screen = RectTransformUtility.WorldToScreenPoint(renderCamera, node.mTransform.position);
            // DFNotifyManager.SendNotify(DFNotifyType.OnNodeSelected, node.Data);
            return(true);
        }
Example #14
0
    public void ResetTransPosition(Creature c, bool isBuff = false)
    {
        Vector3 pos = c.behaviour.GetDamagePos(isBuff);

        if (!m_battleCamera)
        {
            m_battleCamera = Level.currentMainCamera;
        }
        if (m_battleCamera != null)
        {
            var screenPos = RectTransformUtility.WorldToScreenPoint(m_battleCamera, pos);
            if (m_uiCamera != null)
            {
                RectTransformUtility.ScreenPointToWorldPointInRectangle(transform.rectTransform(), screenPos, m_uiCamera, out pos);
            }
        }

        transform.position = pos;
    }
Example #15
0
        Vector2 GetScreenPointOfSelectable(IBoxSelectable selectable)
        {
            //Getting the screen point requires it's own function, because we have to take into consideration the selectables hierarchy.

            //Cast the transform as a rectTransform
            var rectTransform = selectable.transform as RectTransform;

            //If it has a rectTransform component, it must be in the hierarchy of a canvas, somewhere.
            if (rectTransform)
            {
                //And the camera used to calculate it's screen point will vary.
                Camera renderingCamera = GetScreenPointCamera(rectTransform);

                return(RectTransformUtility.WorldToScreenPoint(renderingCamera, selectable.transform.position));
            }

            //If it's no in the hierarchy of a canvas, the regular Camera.main.WorldToScreenPoint will do.
            return(Camera.main.WorldToScreenPoint(selectable.transform.position));
        }
Example #16
0
 private void Follow()
 {
     if (worldCamera == null)
     {
         return;
     }
     if (target != null)
     {
         targetPos = target.position;
     }
     if (IsTargetInFieldOfView())
     {
         IsTargetVisible = !IsLineOfSightObstructed();
         if (IsTargetVisible)
         {
             var screenPoint      = RectTransformUtility.WorldToScreenPoint(worldCamera, targetPos + offsetLocalWorld) / Canvas.scaleFactor;
             var anchoredPosition = screenPoint - canvasHalfSize + offsetScreen;
             if (restrictMovementOnScreen)
             {
                 anchoredPosition.x = Mathf.Clamp(anchoredPosition.x, -canvasHalfSize.x + elementHalfSize.x, canvasHalfSize.x - elementHalfSize.x);
                 anchoredPosition.y = Mathf.Clamp(anchoredPosition.y, -canvasHalfSize.y + elementHalfSize.y, canvasHalfSize.y - elementHalfSize.y);
             }
             rectT.anchoredPosition = anchoredPosition;
         }
     }
     else
     {
         IsTargetVisible = false;
         // Set out of the view port
         rectT.anchoredPosition = new Vector2(-Screen.width, Screen.height);
     }
     if (debug)
     {
         if (IsTargetVisible)
         {
             Debug.DrawLine(worldCamera.transform.position, targetPos, Color.green);
         }
         else
         {
             Debug.DrawLine(worldCamera.transform.position, targetPos, Color.red);
         }
     }
 }
        protected virtual void TranslateUI(float pinchScale, Vector2 pinchScreenCenter)
        {
            var camera = LeanTouch.GetCamera(Camera, gameObject);

            // Screen position of the transform
            var screenPoint = RectTransformUtility.WorldToScreenPoint(camera, transform.position);

            // Push the screen position away from the reference point based on the scale
            screenPoint.x = pinchScreenCenter.x + (screenPoint.x - pinchScreenCenter.x) * pinchScale;
            screenPoint.y = pinchScreenCenter.y + (screenPoint.y - pinchScreenCenter.y) * pinchScale;

            // Convert back to world space
            var worldPoint = default(Vector3);

            if (RectTransformUtility.ScreenPointToWorldPointInRectangle(transform.parent as RectTransform, screenPoint, camera, out worldPoint) == true)
            {
                transform.position = worldPoint;
            }
        }
Example #18
0
    public void ShowPropotion(ResultData resultData, Action OnComplete)
    {
        gameObject.SetActive(true);
        var     rectTransform = GetComponent <RectTransform>();
        Vector3 screenPos     = RectTransformUtility.WorldToScreenPoint(Camera.main, resultData.worldPos);

        rectTransform.position = screenPos;

        int propotionInt = Mathf.RoundToInt(resultData.proportion);

        count = 0;
        transform.localScale = Vector3.zero;
        sequence             = DOTween.Sequence()
                               .Append(transform.DOScale(Vector3.one / 2, 0.5f).SetEase(Ease.OutBack))
                               .Append(transform.DOScale(Vector3.one, 1f).SetEase(Ease.Linear))
                               .Join(DOTween.To(() => count, (x) => count = x, propotionInt, 1f).SetEase(Ease.Linear))
                               .AppendInterval(1f)
                               .OnComplete(() => OnComplete());
    }
Example #19
0
    public void OnDrag(PointerEventData eventData)
    {
        cam = null;
        if (canvas.renderMode == RenderMode.ScreenSpaceCamera)
        {
            cam = canvas.worldCamera;
        }

        Vector2 position = RectTransformUtility.WorldToScreenPoint(cam, background.position);
        Vector2 radius   = background.sizeDelta / 2;

        input = (eventData.position - position) / (radius * canvas.scaleFactor);
        FormatInput();
        HandleInput(input.magnitude, input.normalized, radius, cam);
        //handle.anchoredPosition = input * radius * handleRange;

        Angle           = GettingAngle(input, Vector2.zero);
        handle.rotation = Quaternion.Euler(new Vector3(0f, 0f, Angle));
    }
Example #20
0
 public void ShowName(Transform _transform, string _name)
 {
     ((Component)this.rectName).get_gameObject().SetActive(true);
     ((Transform)this.rectName).set_position(Vector2.op_Implicit(RectTransformUtility.WorldToScreenPoint(Camera.get_main(), _transform.get_position())));
     ((TMP_Text)this.textName).set_text(_name);
     if (this.disposableName != null)
     {
         this.disposableName.Dispose();
     }
     this.disposableName = new SingleAssignmentDisposable();
     this.disposableName.set_Disposable(ObservableExtensions.Subscribe <long>(Observable.TakeUntil <long, long>((IObservable <M0>)Observable.EveryUpdate(), (IObservable <M1>)Observable.Timer(TimeSpan.FromSeconds(2.0))), (Action <M0>)(_ =>
     {
         if (!Object.op_Inequality((Object)_transform, (Object)null))
         {
             return;
         }
         ((Transform)this.rectName).set_position(Vector2.op_Implicit(RectTransformUtility.WorldToScreenPoint(Camera.get_main(), _transform.get_position())));
     }), (Action)(() => ((Component)this.rectName).get_gameObject().SetActive(false))));
 }
Example #21
0
    private void GetCenterPoint()
    {
        Vector3[] corners = new Vector3[4];
        rect.GetWorldCorners(corners);

        for (int i = 0; i < 4; i++)
        {
            corners[i] = RectTransformUtility.WorldToScreenPoint(null, corners[i]);
        }

        Vector3 bottomLeft = corners[0];
        Vector3 topRight   = corners[2];
        float   width      = topRight.x - bottomLeft.x;
        float   height     = topRight.y - bottomLeft.y;

        Rect _rect = new Rect(bottomLeft.x, topRight.y, width, height);

        centerPoint = new Vector2(_rect.x + _rect.width * 0.5f, _rect.y - _rect.height * 0.5f);
    }
Example #22
0
    public void OnDrag(PointerEventData eventData)
    {
        Vector2 position = RectTransformUtility.WorldToScreenPoint(null, background.position);
        Vector2 radius   = background.sizeDelta / 2;

        input = (eventData.position - position) / radius;

        if (input.magnitude > 1)
        {
            input = input.normalized;
        }

        Move_Help.Set_Flip(player.GetComponent <SpriteRenderer>(), input.normalized);


        handle.anchoredPosition = input * radius;

        is_Panel_Control = true;
    }
Example #23
0
    /// <summary>
    /// Gets the center point of the container when the object in canvas was created relative the screen size.
    /// </summary>
    /// <param name="obj">Object.</param>
    /// <returns>The center point size.</returns>
    Vector2 GetContainerCenterPoint(Graphic obj)
    {
        Vector3[] containerCorners = new Vector3[4];
        obj.rectTransform.GetWorldCorners(containerCorners);

        for (int i = 0; i < 4; i++)
        {
            containerCorners[i] = RectTransformUtility.WorldToScreenPoint(null, containerCorners[i]);
        }

        Vector3 bottomLeft = containerCorners[0];
        Vector3 topRight   = containerCorners[2];
        float   width      = topRight.x - bottomLeft.x;
        float   height     = topRight.y - bottomLeft.y;

        Rect rect = new Rect(bottomLeft.x, topRight.y, width, height);

        return(new Vector2(rect.x + rect.width * 0.5f, rect.y - rect.height * 0.5f));
    }
Example #24
0
    public void ShowActionPanel(Vector3 worldSpacePos, Sprite[] sprites, UnityAction[] actions)
    {
        Vector2 pos = RectTransformUtility.WorldToScreenPoint(Camera.main, worldSpacePos);

        pos.y -= (actionPanel.transform.parent as RectTransform).rect.height;
        print(pos);
        (actionPanel.transform as RectTransform).anchoredPosition = new Vector2(pos.x, pos.y);
        actionPanel.gameObject.SetActive(true);

        actionPanel.GetComponent <UIList>().Clear();
        UIList list = actionPanel.GetComponent <UIList>();

        for (int i = 0; i < sprites.Length; i++)
        {
            GameObject go = list.Add(null);
            go.GetComponent <Image>().sprite = sprites[i];
            go.GetComponent <Button>().onClick.AddListener(actions[i]);
        }
    }
Example #25
0
        public static Rect GetScreenRect(this RectTransform rectTransform)
        {
            //DONT CALL FROM AWAKE!!!

            Vector3[] corners = new Vector3[4];

            rectTransform.GetWorldCorners(corners);

            float xMin = float.PositiveInfinity;
            float xMax = float.NegativeInfinity;
            float yMin = float.PositiveInfinity;
            float yMax = float.NegativeInfinity;

            for (int i = 0; i < 4; i++)
            {
                // For Canvas mode Screen Space - Overlay there is no Camera; best solution I've found
                // is to use RectTransformUtility.WorldToScreenPoint) with a null camera.

                Vector3 screenCoord = RectTransformUtility.WorldToScreenPoint(null, corners[i]);

                if (screenCoord.x < xMin)
                {
                    xMin = screenCoord.x;
                }
                if (screenCoord.x > xMax)
                {
                    xMax = screenCoord.x;
                }
                if (screenCoord.y < yMin)
                {
                    yMin = screenCoord.y;
                }
                if (screenCoord.y > yMax)
                {
                    yMax = screenCoord.y;
                }
            }

            Rect result = new Rect(xMin, yMin, xMax - xMin, yMax - yMin);

            return(result);
        }
        // Start is called before the first frame update
        void Start()
        {
            MedalImagePool pool = new MedalImagePool(this);

            UnityEngine.Camera mainCamera = UnityEngine.Camera.main;

            //事前に20個のメダルエフェクトオブジェクトを生成しておく
            pool.PreloadAsync(20, 1).Subscribe();

            //エフェクト開始トリガーがかかったらエフェクトを再生する
            winMedalChecker.Checked
            //落ちたメダルの画面上のx座標を取得
            .Select(medal => (RectTransformUtility.WorldToScreenPoint(mainCamera, medal.position).x, medal))
            //プールからImageオブジェクトを取得して出現座標を設定
            .Select(pair => (img: pool.RentAndSetPositionX(pair.x), pair.medal))
            //Tweenに乗せる
            .Select(pair => DOTween.Sequence()
                    //画面下から上がってくるTween
                    .Append(pair.img.rectTransform.DOMoveY(effectMaxHeight * Random.Range(effectHeightCoefficient.x, effectHeightCoefficient.y), riseDuration).SetEase(Ease.OutCubic))
                    //上がった後にくるっと回るTween
                    .Append(pair.img.rectTransform.DORotate(new Vector3(0, 360, 0), rotateDuration, RotateMode.FastBeyond360))
                    //透明にして、
                    .Append(pair.img.DOColor(Color.clear, disappearanceDuration).SetEase(Ease.InQuad))
                    //小さくしながら、
                    .Join(pair.img.rectTransform.DOScale(0.3f, disappearanceDuration).SetEase(Ease.InQuad))
                    //メダルインベントリのUIに吸い込まれながらフェードアウト
                    .Join(pair.img.rectTransform.DOMove(effectDestination.position, disappearanceDuration))
                    //終わったらオブジェクトをプールに返す
                    .OnComplete(() =>
            {
                effectDoneSubject.OnNext(pair.medal);                               //エフェクト完了通知を送信
                pair.img.color = Color.white;                                       //透明にした色をもとに戻す
                pair.img.rectTransform.localScale = Vector3.one;
                pool.Return(pair.img);
            }))
            //SequenceとSEを再生する
            .Subscribe(sq =>
            {
                sq.Play();
                sePlayer.Play();
            });
        }
Example #27
0
        /// <summary>
        /// Get sizes and convert to current screen size
        /// </summary>
        /// <param name="rect">RectTranform from Gameobject</param>
        /// <returns>Rect</returns>
        public static Rect GetScreenRectFromRectTransform(RectTransform rect)
        {
            Vector3[] corners = new Vector3[4];
            rect.GetWorldCorners(corners);
            float xMin = float.PositiveInfinity;
            float xMax = float.NegativeInfinity;
            float yMin = float.PositiveInfinity;
            float yMax = float.NegativeInfinity;

            for (int i = 0; i < 4; i++)
            {
                Vector3 screenCoord;
                if (rect.GetComponentInParent <Canvas> ().renderMode == RenderMode.ScreenSpaceOverlay)
                {
                    screenCoord = corners[i];
                }
                else
                {
                    screenCoord = RectTransformUtility.WorldToScreenPoint(Camera.main, corners[i]);
                }
                if (screenCoord.x < xMin)
                {
                    xMin = screenCoord.x;
                }
                if (screenCoord.x > xMax)
                {
                    xMax = screenCoord.x;
                }
                if (screenCoord.y < yMin)
                {
                    yMin = screenCoord.y;
                }
                if (screenCoord.y > yMax)
                {
                    yMax = screenCoord.y;
                }
            }
            Rect result = new Rect(xMin, Screen.height - yMax, xMax - xMin, yMax - yMin);

            //Rect result = new Rect(xMin, YouDaSdkMgr.instance.getAndroidScreenHeigth() - yMax, xMax - xMin, yMax - yMin);
            return(result);
        }
Example #28
0
    //战斗中会使用这个方法
    public void ShowMsg(string content, Vector3 position, Color color, float time = 2f, int size = 35, int offY = 80)
    {
        var tipsP = RectTransformUtility.WorldToScreenPoint(Camera.main, position);

        RectTransform tip;

        if (tipRectList.Count == 0)
        {
            tip = GameObject.Instantiate(fightTipsGo, go.transform).GetComponent <RectTransform>();
        }
        else
        {
            tip = tipRectList[tipRectList.Count - 1];

            tipRectList.Remove(tip);
        }

        tip.gameObject.SetActive(true);
        curTipRectList.Add(tip);

        Text    t       = tip.GetComponent <Text>();
        Outline outline = tip.GetComponent <Outline>();

        outline.effectColor = color;
        t.text     = content;
        t.fontSize = size;
        t.color    = Color.white;
        //time秒后颜色消失

        t.DOColor(Color.clear, time).OnComplete(
            () =>
        {
            tip.gameObject.SetActive(false);
            tipRectList.Add(tip);
            curTipRectList.Remove(tip);
        });


        tip.position = tipsP;

        t.transform.DOLocalMoveY(t.transform.localPosition.y + offY, time);
    }
    // 球がクリックされた場合に
    // Event Triggerのコンポーネントから呼び出されます
    public void OnClick()
    {
        MeshRenderer meshRenderer = GetComponent <MeshRenderer>();

        if (!meshRenderer.enabled)
        {
            // 非表示なら何もしません
            return;
        }

        GameObject plane = GameObject.Find("Plane");

        // 爆発までのクリック回数をチェックします
        switch (--count)
        {
        case 2:
        case 1:
            // 上向きの力を加えます
            GetComponent <Rigidbody>().AddForce(plane.transform.forward * 10, ForceMode.Impulse);
            return;

        default:
            break;
        }

        // 球を爆発させます

        // 球を非表示にします
        meshRenderer.enabled = false;

        // 爆発の音を鳴らします
        GetComponent <AudioSource>().Play();

        // ParticleSystemを開始します
        transform.GetChild(0).gameObject.transform.forward = plane.transform.up;
        transform.GetChild(0).gameObject.SetActive(true);

        // 何番目の数字を表示します
        Vector3 position = RectTransformUtility.WorldToScreenPoint(Camera.main, transform.position);

        GameObject.Find("Main").GetComponent <MainController>().ShowCount(position);
    }
Example #30
0
        protected virtual void TranslateUI(float twistDegrees, Vector2 twistScreenCenter)
        {
            // Screen position of the transform
            var screenPoint = RectTransformUtility.WorldToScreenPoint(Camera, transform.position);

            // Twist screen point around the twistScreenCenter by twistDegrees
            var twistRotation = Quaternion.Euler(0.0f, 0.0f, twistDegrees);
            var screenDelta   = twistRotation * (screenPoint - twistScreenCenter);

            screenPoint.x = twistScreenCenter.x + screenDelta.x;
            screenPoint.y = twistScreenCenter.y + screenDelta.y;

            // Convert back to world space
            var worldPoint = default(Vector3);

            if (RectTransformUtility.ScreenPointToWorldPointInRectangle(transform.parent as RectTransform, screenPoint, Camera, out worldPoint) == true)
            {
                transform.position = worldPoint;
            }
        }