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);
        };
    }