Exemplo n.º 1
0
    public void OnFireSliderDrag(BaseEventData data)
    {
        PointerEventData ped   = data as PointerEventData;
        Vector3          delta = ped.delta;
        Vector3          pp    = BaseUIController.GetUICamera().WorldToScreenPoint(m_SliderButton.transform.position);

        pp.y += delta.y;
        m_SliderButton.transform.position = BaseUIController.GetUICamera().ScreenToWorldPoint(pp);
        Vector3 p = m_SliderTrans.localPosition;

        p.y = Mathf.Clamp(p.y, -m_MaxPower, 0);//y position is negative
        m_SliderTrans.localPosition = p;
        float percentage = p.y / -m_MaxPower;

        DiscreteValue(ref percentage);
        //float power = Mathf.Lerp(0, 1, percentage);
        //Debug.Log("power : " + power);
        m_Background.color = Color.Lerp(m_MinColor, m_MaxColor, percentage);

        if (OnSliderValueChange != null && m_LastValue != percentage)
        {
            OnSliderValueChange(percentage);
        }
        m_LastValue = percentage;
    }
Exemplo n.º 2
0
    private void CalculateAnchorOffset(Vector3 position)
    {
        Vector2 vc = BaseUIController.GetUICamera().ScreenToWorldPoint(position);
        Vector2 coord, newCoord = m_SideballO.worldToLocalMatrix.MultiplyPoint(vc);
        float   mag = newCoord.magnitude;
        float   r   = m_SideballO.rect.width * .5f - m_AnchorO.rect.width * .5f;

        if (mag > r)
        {
            float ang = Mathf.Acos(Mathf.Abs(newCoord.x) / mag);
            coord.x = r * Mathf.Cos(ang) * (newCoord.x >= 0 ? 1 : -1);
            coord.y = r * Mathf.Sin(ang) * (newCoord.y >= 0 ? 1 : -1);
        }
        else
        {
            coord = newCoord;
        }
        _SidingAnchorOffset(coord);
    }
Exemplo n.º 3
0
    public void OnCueDrag(BaseEventData data)
    {
        PointerEventData pd            = data as PointerEventData;
        Vector3          worldPosition = BaseUIController.GetUICamera().ScreenToWorldPoint(pd.position);
        Vector3          v             = (worldPosition - m_MasseCue.position).normalized;
        int angle;

        if (Vector3.Cross(v, Vector3.right).z > 0)
        {
            angle = 0;
        }
        else
        {
            angle = (int)Vector3.Angle(Vector3.right, v);
        }
        angle = Mathf.Clamp(angle, 0, 90);
        if (m_PrevValue != angle)
        {
            m_PrevValue = angle;
            MasseAngle  = angle;
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// switch coordinate form world space to ui space
    /// </summary>
    /// <param name="v"></param>
    /// <returns></returns>
    public static Vector3 World2UI(Vector3 v)
    {
        Vector2 sp = Pools.SceneCamera.WorldToScreenPoint(v);

        return(BaseUIController.GetUICamera().ScreenToWorldPoint(sp));
    }