예제 #1
0
        public static Transform GetNearestObject(ThingRuntimeSet thingRuntimeSet, float detectionRadius, Vector3 origin)
        {
            if (thingRuntimeSet.Items.Count < 1)
            {
                return(null);
            }

            List <Transform> things = new List <Transform>();

            for (int i = 0; i < thingRuntimeSet.Items.Count; i++)
            {
                Transform thing = thingRuntimeSet.Items[i].transform;

                if (thing == null)
                {
                    continue;
                }

                if (Vector3.Distance(origin, thing.transform.position) <= detectionRadius)
                {
                    things.Add(thing);
                }
            }

            things = things.OrderBy(x => Vector3.Distance(origin, x.transform.position)).ToList();

            if (things.Count > 0)
            {
                return(things[0]);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
 private int VerifyIndex(ThingRuntimeSet set, int index)
 {
     if (index >= pathNavSet.Items.Count)
     {
         return(0);
     }
     return(index);
 }
예제 #3
0
        public static RectTransform GetNearestUIObject(ThingRuntimeSet thingRuntimeSet, float detectionRadius, RectTransform origin)
        {
            if (thingRuntimeSet.Items.Count < 1)
            {
                return(null);
            }

            List <RectTransform> things = new List <RectTransform>();

            for (int i = 0; i < thingRuntimeSet.Items.Count; i++)
            {
                RectTransform thing = thingRuntimeSet.Items[i].GetComponent <RectTransform>();

                if (thing == null)
                {
                    continue;
                }

                if (thing == origin)
                {
                    continue;
                }

                //Debug.Log(GetDistance(origin, thing));

                if (GetDistance(origin, thing) <= detectionRadius)
                {
                    things.Add(thing);
                }
            }

            things = things.OrderBy(x => GetDistance(origin, x)).ToList();

            //Debug.Log(things[0].name.ToString());

            if (things.Count > 0)
            {
                return(things[0]);
            }
            else
            {
                return(null);
            }
        }
예제 #4
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);
            }
        }