Exemple #1
0
    public void mapLink(BaseGeoEntity geo)
    {
        if (mapFloors.Length < geo.floorNumber)
        {
            Debug.LogWarning("Geoentitys floor not present in map, cannot add");
            return;
        }

        //Creation and setup of new MapObject
        GameObject go = geo.GetMapPresentation(this);

        var floor = mapFloors.FirstOrDefault(f => f.floorNumber == geo.floorNumber);

        go.transform.parent = floor.gameObject.transform;

        MapObject mo = go.AddComponent <MapObject>();

        mo.myMap           = this;
        mo.LinkedGeoEntity = geo;

        //Adding mapObject to right dictonary entry under mapFloors
        Dictionary <GeoEntityType, List <MapObject> > floorObjects = mapFloors[geo.floorNumber].floorMapObjects;

        if (floorObjects.ContainsKey(geo.GetGeoEntityType()))
        {
            floorObjects[geo.GetGeoEntityType()].Add(mo);
        }
        else
        {
            floorObjects.Add(geo.GetGeoEntityType(), new List <MapObject>());
            floorObjects[geo.GetGeoEntityType()].Add(mo);
        }

        mapObjectsOnMap.Add(mo);

        //Adding direct reference of player mapObject for easier positional state upkeep
        if (geo.GetGeoEntityType() == GeoEntityType.player)
        {
            playerMapObject = mo;
        }

        //Adding reference of mapObject to geoEntity
        geo.linkedMapObjects.Add(mo);
        if (mapType == MapType.space)
        {
            geo.MainMap       = this;
            geo.MainMapObject = mo;
        }

        //MapObjects UpdateMapPos is called when geoEntitys geolocation change
        geo.LocationChanged += (sender, args) => {
            mo.UpdateMapPos(args.arg);
        };
    }
Exemple #2
0
    void Awake()
    {
        x = transform.localPosition.x;
        y = transform.localPosition.z;

        MapPos = new Vector2((float)x, (float)y);

        //For dragNdrop movement
        DragMapObject.mapObjectMoved += (sender, args) =>
        {
            if (args.arg1 == this)
            {
                Gps coord = args.arg1.myMap.flatGeo.getGeolocation(args.arg2);

                if (LinkedGeoEntity == null)
                {
                    return;
                }

                //Changes coordinates by changing fake location sources coordinates
                if (LinkedGeoEntity.GetGeoEntityType() == GeoEntityType.player)
                {
                    HashSet <ILocationProvider> providers = LocationSourceManager.ActiveProviders;
                    foreach (ILocationProvider provider in providers)
                    {
                        if (provider.GetSourceType() == SourceType.fake)
                        {
                            FakeLocationSource fake = (FakeLocationSource)provider;
                            fake.geoLocation.latitude  = coord.Latitude;
                            fake.geoLocation.longitude = coord.Longitude;
                        }
                    }
                }
                else
                {
                    //Changes coordinates by changing geoentitys coordinates
                    LinkedGeoEntity.ChangeGeolocation(coord);
                }
            }
        };
    }