Example #1
0
    public float GetRelativeScaleFactor(Transform objectToSort)
    {
        SortZone sortZone  = GetSortZone(objectToSort);
        int      zoneIndex = SortZones.IndexOf(sortZone);

        float objectY     = objectToSort.transform.position.y;
        float sortingMapY = transform.position.y;

        float relativeScaleFactor = startScaleFactor;

        if (objectY < sortingMapY)
        {
            return(startScaleFactor);
        }

        if (objectY > (sortingMapY + SortZones[SortZones.Count - 1].offsetY))
        {
            return(SortZones[SortZones.Count - 1].scaleFactor);
        }

        float previousZoneEdgeY       = sortingMapY;
        float zoneEdgeY               = sortingMapY + sortZone.offsetY;
        float previousZoneScaleFactor = startScaleFactor;

        if (zoneIndex != 0)
        {
            previousZoneEdgeY      += SortZones[zoneIndex - 1].offsetY;
            previousZoneScaleFactor = SortZones[zoneIndex - 1].scaleFactor;
        }

        float interpolationFactor = (objectY - previousZoneEdgeY) / (zoneEdgeY - previousZoneEdgeY);
        float relativeScale       = Mathf.Lerp(previousZoneScaleFactor, sortZone.scaleFactor, interpolationFactor);

        return(relativeScale);
    }
Example #2
0
    public SortZone GetSortZone(Transform objectToSort)
    {
        SortZone sortZone = new SortZone();

        if (SortZones.Count > 0)
        {
            float objectY     = objectToSort.transform.position.y;
            float sortingMapY = transform.position.y;

            if (objectY < sortingMapY + SortZones[0].offsetY)
            {
                return(SortZones[0]);
            }

            for (int i = SortZones.Count - 1; i >= 1; i--)
            {
                float sortZoneY = sortingMapY + SortZones[i - 1].offsetY;

                if (objectY > sortZoneY)
                {
                    return(SortZones[i]);
                }
            }
        }

        return(sortZone);
    }