Example #1
0
    void Update()
    {
        Transform trans = transform;

        if (trans.childCount == 0)
        {
            return;
        }

        Vector3 pickingPoint = trans.worldToLocalMatrix.MultiplyPoint(mPanelCenter);

        // Determine the closest child
        for (int i = 0, imax = trans.childCount; i < imax; ++i)
        {
            Transform t = trans.GetChild(i);
            if (!t.gameObject.activeInHierarchy)
            {
                continue;
            }
            float sqrDist = Vector3.SqrMagnitude(t.localPosition - pickingPoint);
            float value   = Mathf.Clamp01(sqrDist / mDelta);
            float scale   = Mathf.Lerp(centerScale, 1.0f, value);

            if (1 - value > 0.99f && mCenterChild)
            {
                if (t != mCenterGo)
                {
                    if (mCenterChild.onCenter != null)
                    {
                        mCenterChild.onCenter(t.gameObject);
                    }
                    mCenterGo = t;
                }
            }
            t.localScale = Vector3.one * scale;
            t.gameObject.SetActive(false);
            t.gameObject.SetActive(true);
        }
    }