Exemple #1
0
        protected float GetMenuItemAngularHeight()
        {
            float menuItemHeight;

            if (!tryToDetermineHeight || !DetermineMenuItemHeight(menuItemPrefab, out menuItemHeight))
            {
                menuItemHeight = height;
            }
            menuItemHeight *= scaleFactor;

            return(DealingWithAngles.CalcAngularSize(menuItemHeight, cylinderRadius));
        }
        protected bool IsRotationWithinRange()
        {
            Quaternion relativeRotation = transform.localRotation * transform.parent.localRotation;
            float      edX = DealingWithAngles.Runtime2Editor(relativeRotation.eulerAngles.x);

            if (edX >= ceiling && edX <= floor)
            {
                return(true);
            }

            return(false);
        }
        protected void UpdateFirstAndLastItemRotations(Quaternion rotation)
        {
            if (!firstMenuItemLocalRotation.HasValue)
            {
                firstMenuItemLocalRotation = lastMenuItemLocalRotation = rotation;
            }
            else
            {
                float xRotation = DealingWithAngles.Runtime2Editor(rotation.eulerAngles.x);
                if (xRotation < DealingWithAngles.Runtime2Editor(firstMenuItemLocalRotation.Value.eulerAngles.x))
                {
                    firstMenuItemLocalRotation = rotation;
                    return;
                }

                if (xRotation > DealingWithAngles.Runtime2Editor(lastMenuItemLocalRotation.Value.eulerAngles.x))
                {
                    lastMenuItemLocalRotation = rotation;
                }
            }
        }
        protected virtual void Awake()
        {
            if (scrollableObject == null)
            {
                Debug.LogError("HorizontalCylinderScrollArea: The 'ScrollableObject' field cannot be left unassigned. Disabling the script");
                enabled = false;
                return;
            }

            Transform obj = transform.Find("Ceiling Holder/Ceiling");

            if (obj == null)
            {
                Debug.LogError("HorizontalCylinderScrollArea: Couldn't find a child object named 'Ceiling' or its parent. Disabling the script");
                enabled = false;
                return;
            }
            ceiling = DealingWithAngles.Runtime2Editor(obj.parent.localRotation.eulerAngles.x);

            Collider c = obj.GetComponent <Collider>();

            if (c == null)
            {
                Debug.LogError("HorizontalCylinderScrollArea: Couldn't find a collider in an object named 'Ceiling'. Disabling the script");
                enabled = false;
                return;
            }
            angularOffset = DealingWithAngles.CalcAngularSize(c.bounds.size.y, obj.localPosition.z);

            obj = transform.Find("Floor Holder/Floor");
            if (obj == null)
            {
                Debug.LogError("HorizontalCylinderScrollArea: Couldn't find a child object named 'Floor' or its parent. Disabling the script");
                enabled = false;
                return;
            }
            floor = DealingWithAngles.Runtime2Editor(obj.parent.localRotation.eulerAngles.x);
        }
        protected virtual void FixedUpdate()
        {
            if (!firstMenuItemLocalRotation.HasValue)
            {
                return;
            }

            float x = GetRelativeRotationAroundX(firstMenuItemLocalRotation.Value);

            if (DealingWithAngles.Runtime2Editor(x) >= ceiling + angularOffset)
            {
                scrollableObject.angularVelocity = Vector3.zero;

                if (verticalScrollDelta > 0)
                {
                    return;
                }
            }

            x = GetRelativeRotationAroundX(lastMenuItemLocalRotation.Value);
            if (DealingWithAngles.Runtime2Editor(x) <= floor - angularOffset)
            {
                scrollableObject.angularVelocity = Vector3.zero;

                if (verticalScrollDelta < 0)
                {
                    return;
                }
            }

            if (verticalScrollDelta != 0f)
            {
                scrollableObject.AddRelativeTorque(Vector3.right * torque * verticalScrollDelta);
                verticalScrollDelta = 0f;
            }
        }