Пример #1
0
        public static void AvoidOverlap(RectTransform _origin)
        {
            RectTransform nearestTransform = DelegateManager.GetNearestUIObject(allUIObjects, minDistance, _origin);

            RandomizePosition(_origin);

            if (nearestTransform != null &&
                nearestTransform != _origin)
            {
                //Debug.Log(nearestTransform.name.ToString());

                float newX = _origin.anchoredPosition.x - (_origin.anchoredPosition.x - nearestTransform.anchoredPosition.x > 0 ? minDistance : minDistance);
                float newY = _origin.anchoredPosition.y - (_origin.anchoredPosition.y - nearestTransform.anchoredPosition.y > 0 ? minDistance : minDistance);

                _origin.anchoredPosition = new Vector3(newX, newY);

                AvoidOverlap(_origin);
            }
        }
Пример #2
0
        public static void AvoidOverlap(ThingRuntimeSet _thingRuntimeSet, float _detectionRadius, RectTransform _origin)
        {
            RectTransform nearestTransform = DelegateManager.GetNearestUIObject(_thingRuntimeSet, _detectionRadius, _origin);

            RandomizePosition(_origin);

            if (nearestTransform != null &&
                nearestTransform != _origin)
            {
                //Debug.Log(nearestTransform.name.ToString());

                float newX = _origin.anchoredPosition.x - (_origin.anchoredPosition.x - nearestTransform.anchoredPosition.x > 0 ? _detectionRadius : _detectionRadius);
                float newY = _origin.anchoredPosition.y - (_origin.anchoredPosition.y - nearestTransform.anchoredPosition.y > 0 ? _detectionRadius : _detectionRadius);

                _origin.anchoredPosition = new Vector3(newX, newY);

                AvoidOverlap(_thingRuntimeSet, _detectionRadius, _origin);
            }
        }