private static void SharkUI(CalcSize calcSize, ApplyValue applyValue, RectTransform.Axis axis)
        {
            var list = Utils.GetRectTransforms();

            if (list.Count < 2)
            {
                return;
            }

            float size = 10000000f;

            Vector3[] corners = new Vector3[4];
            for (var i = 0; i < list.Count; i++)
            {
                list[i].GetWorldCorners(corners);
                float _minV, _maxV;
                size = Mathf.Min(size, calcSize(corners, out _minV, out _maxV));
            }
            foreach (var rt in list)
            {
                var v = applyValue(rt, size);
                Undo.RecordObject(rt, "Expand or Shark UI");
                rt.SetSizeWithCurrentAnchors(axis, v.x);
            }
        }
        private static void AlignCenterUI(CalcValueTwo calcValue, ApplyValue applyValue)
        {
            var list = Utils.GetRectTransforms();

            if (list.Count < 2)
            {
                return;
            }

            float minV = 0f, maxV = 0f;

            Vector3[] corners = new Vector3[4];
            for (var i = 0; i < list.Count; i++)
            {
                list[i].GetWorldCorners(corners);
                calcValue(corners, 0 == i, ref minV, ref maxV);
            }
            float v = (minV + maxV) * 0.5f;

            foreach (var rt in list)
            {
                var pos = applyValue(rt, v);
                Undo.RecordObject(rt, "Align Center UI");
                rt.anchoredPosition3D = pos;
            }
        }
        private static void DistributionGapUI(CalcSize calcSize, ApplyValue applyValue)
        {
            var list = Utils.GetRectTransforms();

            if (list.Count < 3)
            {
                return;
            }

            var vlist = new List <Value>(list.Count);

            float minV = 0f, maxV = 0f;
            float sumSize = 0f;

            Vector3[] corners = new Vector3[4];
            for (var i = 0; i < list.Count; i++)
            {
                list[i].GetWorldCorners(corners);
                float _minV, _maxV;
                float size = calcSize(corners, out _minV, out _maxV);
                minV     = 0 == i ? _minV : Mathf.Min(_minV, minV);
                maxV     = 0 == i ? _maxV : Mathf.Max(_maxV, maxV);
                sumSize += size;
                vlist.Add(new Value
                {
                    rt   = list[i],
                    v    = (_minV + _maxV) / 2,
                    size = size,
                });
            }
            ;
            vlist.Sort((a, b) =>
            {
                if (a.v < b.v)
                {
                    return(-1);
                }
                else if (a.v > b.v)
                {
                    return(1);
                }
                return(0);
            });

            float gap  = (maxV - minV - sumSize) / (list.Count - 1);
            float curV = minV + vlist[0].size + gap;

            for (var i = 1; i < vlist.Count - 1; i++)
            {
                var rt  = vlist[i].rt;
                var pos = applyValue(rt, curV + vlist[i].size / 2);
                curV += vlist[i].size + gap;
                Undo.RecordObject(rt, "Distribution UI By Gap");
                rt.anchoredPosition3D = pos;
            }
        }
        private static void DistributionUI(CalcValueTwo calcValue, ApplyValue applyValue)
        {
            var list = Utils.GetRectTransforms();

            if (list.Count < 3)
            {
                return;
            }

            var vlist = new List <Value>(list.Count);

            float minV = 0f, maxV = 0f;

            Vector3[] corners = new Vector3[4];
            for (var i = 0; i < list.Count; i++)
            {
                list[i].GetWorldCorners(corners);
                vlist.Add(new Value
                {
                    rt = list[i],
                    v  = calcValue(corners, 0 == i, ref minV, ref maxV)
                });
            }
            ;
            vlist.Sort((a, b) =>
            {
                if (a.v < b.v)
                {
                    return(-1);
                }
                else if (a.v > b.v)
                {
                    return(1);
                }
                return(0);
            });

            float gap = (maxV - minV) / (list.Count - 1);

            for (var i = 1; i < vlist.Count - 1; i++)
            {
                var rt  = vlist[i].rt;
                var pos = applyValue(rt, minV + gap * i);
                Undo.RecordObject(rt, "Distribution UI");
                rt.anchoredPosition3D = pos;
            }
        }
    /// <summary>
    /// Returns an IEnumerator so that a MonoBehavior-derived class
    /// can run this function as a coroutine.  Animates the value
    /// between startValue and endValue using the lerpValue and applyValue
    /// delegates.
    /// </summary>
    /// <param name="startValue">
    /// The value to start at.
    /// </param>
    /// <param name="endValue">
    /// The value to end at.
    /// </param>
    /// <param name="lerpValue">
    /// A delegate that lerps the value.
    /// </param>
    /// <param name="applyValue">
    /// A delegate that does something with the value as it animates.
    /// </param>
    /// <returns>An IEnumerator for use in coroutines.</returns>
    public IEnumerator Animate(T startValue, T endValue,
                               LerpValue lerpValue, ApplyValue applyValue)
    {
        float progress = 0f;

        T value;

        while (progress < 1f)
        {
            value = lerpValue(startValue, endValue, progress);
            applyValue(value);
            progress += Time.deltaTime * _speed;
            yield return(null);
        }

        applyValue(endValue);
    }
Exemple #6
0
 static void GetValueFromUser(string prompt, ApplyValue apply, bool allowDefaultValue = true)
 {
     while (true)
     {
         Console.Write(prompt);
         var response = Console.ReadLine();
         if (!string.IsNullOrEmpty(response))
         {
             try
             {
                 apply(response);
                 break;
             }
             catch
             {
             }
         }
         else if (allowDefaultValue)
         {
             break;
         }
     }
 }
Exemple #7
0
        private static void AlignUI(CalcValueOne calcValue, ApplyValue applyValue)
        {
            var list = GetRectTransforms();

            if (list.Count < 2)
            {
                return;
            }

            float v = 0f;

            Vector3[] corners = new Vector3[4];
            for (var i = 0; i < list.Count; i++)
            {
                list[i].GetWorldCorners(corners);
                calcValue(corners, 0 == i, ref v);
            }
            foreach (var rt in list)
            {
                var pos = applyValue(rt, v);
                Undo.RecordObject(rt, "Align UI");
                rt.localPosition = pos;
            }
        }
Exemple #8
0
        private static void SharkUI(CalcValueTwo calcValue, ApplyValue applyValue, RectTransform.Axis axis)
        {
            var list = GetRectTransforms();

            if (list.Count < 2)
            {
                return;
            }

            float minV = 0f, maxV = 0f;

            Vector3[] corners = new Vector3[4];
            for (var i = 0; i < list.Count; i++)
            {
                list[i].GetWorldCorners(corners);
                calcValue(corners, 0 == i, ref minV, ref maxV);
            }
            foreach (var rt in list)
            {
                var size = applyValue(rt, minV);
                Undo.RecordObject(rt, "Expand or Shark UI");
                rt.SetSizeWithCurrentAnchors(axis, size.x);
            }
        }