Beispiel #1
0
    //do we need to bulk add static positions? don't think so
    public bool AddStaticItem(MapIconType type, Vector2 staticPosition, int radius = -1)
    {
        for (var i = 0; i < Entries.Length; i++)
        {
            var item = Entries[i] as RadarEntry;
            if (!item)
            {
                continue;
            }

            if (staticPosition == (Vector2)item.StaticPosition)
            {
                return(false);
            }
        }
        //add new entry
        RadarEntry newEntry = Add() as RadarEntry;

        if (!newEntry)
        {
            Logger.LogWarning($"Added {newEntry} is not an RadarEntry!", Category.NetUI);
            return(false);
        }

        //set its elements
        newEntry.Radius         = radius;
        newEntry.Type           = type;
        newEntry.StaticPosition = staticPosition;

        //rescan elements and notify
        NetworkTabManager.Instance.Rescan(MasterTab.NetTabDescriptor);
        RefreshTrackedPos();

        return(true);
    }
Beispiel #2
0
    public void RefreshTrackedPos(bool update = true)
    {
        Vector2 originPos = Origin.ServerState.Position;

        //Refreshing positions of every item
        var entryArray = Entries;

        for (var i = 0; i < entryArray.Length; i++)
        {
            var item = entryArray[i] as RadarEntry;
            if (!item)
            {
                continue;
            }

            item.RefreshTrackedPos(originPos);
            //If item is out of range, stop showing it and place into "out of range" list
            if (item.Position == TransformState.HiddenPos || ProjectionMagnitude(item.Position) > Range)
            {
//				Logger.Log( $"Hiding {item} as it's out of range" );
                OutOfRangeEntries.Add(item);

//				fixme: Old manual (de)activation conflicts with reuse pool, entries still fill up on server
                item.gameObject.SetActive(false);
            }
        }
        //Check if any item in "out of range" list should be shown again
        for (var i = 0; i < OutOfRangeEntries.Count; i++)
        {
            RadarEntry item = OutOfRangeEntries[i];
            item.RefreshTrackedPos(originPos);
            if (item.Position != TransformState.HiddenPos && ProjectionMagnitude(item.Position) <= Range)
            {
//				Logger.Log( $"Unhiding {item} as it's in range again" );
                ToRestore.Add(item);
                item.gameObject.SetActive(true);
                shuttleControl.PlayRadarDetectionSound();
            }
        }

        for (var i = 0; i < ToRestore.Count; i++)
        {
            var item = ToRestore[i];
            OutOfRangeEntries.Remove(item);
        }

        ToRestore.Clear();

        if (update)
        {
            UpdatePeepers();
        }
    }
Beispiel #3
0
    public bool AddItems(MapIconType type, List <GameObject> objects)
    {
        var objectSet  = new HashSet <GameObject>(objects);
        var duplicates = new HashSet <GameObject>();

        for (var i = 0; i < Entries.Length; i++)
        {
            var item = Entries[i] as RadarEntry;
            if (!item)
            {
                continue;
            }

            if (objectSet.Contains(item.TrackedObject))
            {
                duplicates.Add(item.TrackedObject);
            }
        }

        for (var i = 0; i < objects.Count; i++)
        {
            var obj = objects[i];
            //skipping already found objects
            if (duplicates.Contains(obj))
            {
                continue;
            }

            //add new entry
            RadarEntry newEntry = Add() as RadarEntry;
            if (!newEntry)
            {
                Logger.LogWarning($"Added {newEntry} is not an RadarEntry!", Category.NetUI);
                return(false);
            }

            //set its elements
            newEntry.Type          = type;
            newEntry.TrackedObject = obj;
        }
//		Logger.Log( $"RadarList: Item add success! added {objects.Count} items" );

        //rescan elements and notify
        NetworkTabManager.Instance.Rescan(MasterTab.NetTabDescriptor);
        RefreshTrackedPos();

        return(true);
    }