예제 #1
0
        float CalcSliderValue(Vector2 point)
        {
            float   t      = 0;
            float   min    = 0;
            float   max    = 0;
            Vector3 pos    = this.transform.position;
            Vector2 offset = WrapperUnityVersion.GetBoxCollider2DOffset(BoxCollider2D);

            switch (direction)
            {
            case Direction.Horizontal:
                min = (pos.x - offset.x) - BoxCollider2D.size.x / 2;
                max = (pos.x - offset.x) + BoxCollider2D.size.x / 2;
                t   = point.x;
                break;

            case Direction.Vertical:
            default:
                min = (pos.y - offset.y) - BoxCollider2D.size.y / 2;
                max = (pos.y - offset.y) + BoxCollider2D.size.y / 2;
                t   = point.y;
                break;
            }
            return(Mathf.InverseLerp(min, max, t));
        }
예제 #2
0
 //アイテム全体の範囲を取得
 void InitItemsRect()
 {
     if (rootItems.childCount <= 0)
     {
         itemsRect = new Vector4(0, 0, 0, 0);
     }
     else
     {
         float left   = float.MaxValue;
         float top    = float.MinValue;
         float right  = float.MinValue;
         float bottom = float.MaxValue;
         foreach (Transform trans in rootItems.transform)
         {
             BoxCollider2D col    = trans.GetComponent <BoxCollider2D>();
             Vector2       offset = WrapperUnityVersion.GetBoxCollider2DOffset(col);
             left   = Mathf.Min(left, trans.position.x + offset.x - col.size.x / 2);
             top    = Mathf.Max(top, trans.position.y + offset.y + col.size.y / 2);
             right  = Mathf.Max(right, trans.position.x + offset.x + col.size.x / 2);
             bottom = Mathf.Min(bottom, trans.position.y + offset.y - col.size.y / 2);
         }
         itemsRect = new Vector4(left, top, right, bottom);
     }
 }