Example #1
0
        public override void UpdateLayoutHierarchy()
        {
            if (mChildren != null)
            {
                for (int i = 0; i < mChildren.Length; i++)
                {
                    if (mChildren[i] != null)
                    {
                        mChildren[i].SetLayoutParent(null);
                    }
                }
            }

            List <UILayoutBase> children = new List <UILayoutBase>();

            for (int i = 0; i < MyTransform.childCount; i++)
            {
                UILayoutBase child = MyTransform.GetChild(i).GetComponent <UILayoutBase>();

                if (child == null)
                {
                    continue;
                }

                children.Add(child);
                child.SetLayoutParent(this);

                child.UpdateLayoutHierarchy();
            }

            mChildren = children.ToArray();
        }
    // ###########################
    protected override void AddCollider()
    {
        Transform child = MyTransform.GetChild(0);

        if (child != null)
        {
            CapsuleCollider col = MyGameObject.AddComponent <CapsuleCollider>();

            Vector3 toChild         = child.position - MyTransform.position;
            int     dirIndex        = Utils.GetDirectionIndex(MyTransform, toChild.normalized);
            float   distanceToChild = toChild.magnitude / MyTransform.lossyScale[dirIndex];

            col.center    = CalculateCentre(dirIndex, distanceToChild);
            col.direction = dirIndex;
            col.radius    = distanceToChild * 0.2f;
            col.height    = distanceToChild;
        }
    }