protected virtual MaterialSpinnerActivity CreateSpinnerActivity(MaterialFrame frame)
        {
            if (frame == null)
            {
                return(null);
            }

            MaterialSpinnerActivity activity = new GameObject(frame.name + " (SpinnerActivity)").AddComponent <MaterialSpinnerActivity>();

            //Setup Has Background
            MaterialDialogCompat dialogFrame = frame as MaterialDialogCompat;

            if (dialogFrame != null)
            {
                activity.hasBackground = dialogFrame.hasBackground;
            }

            if (DialogManager.rectTransform != null)
            {
                activity.Build(DialogManager.rectTransform);
            }
            else
            {
                activity.Build(this.transform.GetRootCanvas());
            }

            activity.SetFrame(frame, this);

            return(activity);
        }
        //Replace internal frame
        public MaterialFrame SetFrame(MaterialFrame frame, bool inflate)
        {
            if (frame == null)
            {
                return(null);
            }

            var anchoredPosition = frame.transform is RectTransform ? (frame.transform as RectTransform).anchoredPosition3D : frame.transform.localPosition;
            var localScale       = frame.transform.localScale;
            var localRotation    = frame.transform.localRotation;

            //Is a prefab
            if (!frame.transform.root.gameObject.scene.IsValid())
            {
                frame = GameObject.Instantiate(frame);
            }

            //Delete Default Frame
            if (m_Frame != null && m_Frame != frame)
            {
                GameObject.Destroy(m_Frame.gameObject);
            }

            //MaterialDialogActivity does not support activities in same object as the frame added
            var frameActivity = frame.GetComponent <MaterialActivity>();

            if (frameActivity != null)
            {
                Component.DestroyImmediate(frameActivity);
            }

            frame.transform.SetParent(this.transform, false);
            m_Frame = frame;
            if (frame is MaterialDialogFrame)
            {
                (frame as MaterialDialogFrame).activity = this;
            }

            if (inflate)
            {
                Inflate(frame.transform as RectTransform, false);
            }
            else
            {
                if (frame.transform is RectTransform)
                {
                    (frame.transform as RectTransform).anchoredPosition3D = anchoredPosition;
                }
                else
                {
                    frame.transform.localPosition = anchoredPosition;
                }
                frame.transform.localScale    = localScale;
                frame.transform.localRotation = localRotation;
            }

            m_Frame.transform.SetAsLastSibling();

            return(frame);
        }
        protected virtual Vector2 GetValidLocalPositionInsideActivity(MaterialFrame frame)
        {
            if (frame == null)
            {
                return(Vector2.zero);
            }

            var frameRectTranform = (frame.transform as RectTransform);

            if (frameRectTranform == null)
            {
                return(frame.transform.localPosition);
            }

            var frameAnchoredPosition = frameRectTranform.localPosition;

            //Convert FrameRect to Activity Space
            var frameRect = frameRectTranform.rect;
            var frameMin  = this.rectTransform.InverseTransformPoint(frameRectTranform.TransformPoint(frameRect.min));
            var frameMax  = this.rectTransform.InverseTransformPoint(frameRectTranform.TransformPoint(frameRect.max));

            frameRect = Rect.MinMaxRect(frameMin.x, frameMin.y, frameMax.x, frameMax.y);

            var acvitityRect = this.rectTransform.rect;

            //  Left edge
            float activityEdge = acvitityRect.xMin;
            float frameEdge    = frameRect.xMin;

            if (frameEdge < activityEdge)
            {
                frameAnchoredPosition.x += activityEdge - frameEdge;
            }

            //  Right edge
            activityEdge = acvitityRect.xMax;
            frameEdge    = frameRect.xMax;
            if (frameEdge > activityEdge)
            {
                frameAnchoredPosition.x += activityEdge - frameEdge;
            }

            //  Top edge
            activityEdge = acvitityRect.yMax;
            frameEdge    = frameRect.yMax;
            if (frameEdge > activityEdge)
            {
                frameAnchoredPosition.y += activityEdge - frameEdge;
            }

            //  Bottom edge
            activityEdge = acvitityRect.yMin;
            frameEdge    = frameRect.yMin;
            if (frameEdge < activityEdge)
            {
                frameAnchoredPosition.y += activityEdge - frameEdge;
            }

            return(frameAnchoredPosition);
        }
        public MaterialFrame SetFrame(MaterialFrame frame, IBaseSpinner spinner)
        {
            frame = SetFrame(frame);
            if (frame != null)
            {
                RecalculatePosition(spinner);
            }

            return(frame);
        }
        public MaterialFrame SetFrame(MaterialFrame frame, Vector3 frameOpenWorldPosition, Vector2 framePivot, Vector2 minSize, Vector2 preferredSize)
        {
            frame = SetFrame(frame);
            if (frame != null)
            {
                RecalculatePosition(frameOpenWorldPosition, framePivot, minSize, preferredSize);
            }

            return(frame);
        }
        public MaterialFrame SetFrame(MaterialFrame frame)
        {
            if (frame == null)
            {
                return(null);
            }

            //Is a prefab
            if (!frame.transform.root.gameObject.scene.IsValid())
            {
                frame = GameObject.Instantiate(frame);
            }

            //Delete Default Frame
            if (m_Frame != null && m_Frame != frame)
            {
                GameObject.Destroy(m_Frame.gameObject);
            }

            //MaterialDialogActivity does not support activities in same object as the frame added
            var frameActivity = frame.GetComponent <MaterialActivity>();

            if (frameActivity != null)
            {
                Component.DestroyImmediate(frameActivity);
            }

            frame.transform.SetParent(this.transform, false);
            m_Frame = frame;
            if (frame is MaterialDialogFrame)
            {
                (frame as MaterialDialogFrame).activity = this;
            }

            m_Frame.transform.SetAsLastSibling();

            return(frame);
        }