예제 #1
0
    MapHero CreatePartyOnMap(HeroParty heroParty, PartyData partyData)
    {
        Debug.Log("Creating party on map representation");
        // Create new party on map UI
        MapHero newPartyOnMap = Instantiate(heroPartyOnMapTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapHero>())).GetComponent <MapHero>();

        // place party to original position on map
        //newPartyOnMap.GetComponent<RectTransform>().offsetMin = new Vector2(partyData.partyMapPosition.offsetMinX, partyData.partyMapPosition.offsetMinY);
        //newPartyOnMap.GetComponent<RectTransform>().offsetMax = new Vector2(partyData.partyMapPosition.offsetMaxX, partyData.partyMapPosition.offsetMaxY);
        // place it to original position on map based on the tile coordinates
        newPartyOnMap.transform.position = MapManager.Instance.GetWorldPositionByCoordinates(partyData.partyMapCoordinates);
        // Create hero label on map
        MapObjectLabel newPartyOnMapLabel = Instantiate(heroPartyOnMapLabelTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapObjectLabel>())).GetComponent <MapObjectLabel>();

        // Link hero to the lable and label to the hero
        newPartyOnMap.GetComponent <MapObject>().Label = newPartyOnMapLabel;
        newPartyOnMapLabel.MapObject = newPartyOnMap.GetComponent <MapObject>();
        // create links between party on map and hero party
        newPartyOnMap.LHeroParty = heroParty;
        heroParty.LMapHero       = newPartyOnMap;
        // rename it
        newPartyOnMap.gameObject.name = heroParty.GetPartyLeader().GivenName + " " + heroParty.GetPartyLeader().UnitName + " Party";
        // set color according to the player color preference
        newPartyOnMap.SetColor(GetPlayerByFaction(heroParty.Faction).PlayerColor);
        // activate hero on map
        newPartyOnMap.gameObject.SetActive(true);
        // activate hero label on map
        newPartyOnMapLabel.gameObject.SetActive(true);
        // return result
        return(newPartyOnMap);
    }
예제 #2
0
    void SetHeroPartyRepresentationOnTheMap(HeroParty newLeaderParty, City city = null)
    {
        // Create Hero's object on the map
        // create and update Hero Party panel in UI, (no - parent it to city UI)
        //Transform parentCityOnMap = map.Find(transform.name);
        // Create new hero party on map ui
        MapHero newPartyOnMapUI = Instantiate(ObjectsManager.Instance.HeroPartyOnMapTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapHero>())).GetComponent <MapHero>();

        // Verify if argument is null
        if (city == null)
        {
            // Assign currently linked city
            city = LCity;
        }
        // adjust position, because city and hero transform have differnet anchor points
        // Get ui world corners
        // 12
        // 03
        Vector3[] worldCorners = new Vector3[4];
        newPartyOnMapUI.GetComponent <RectTransform>().GetWorldCorners(worldCorners);
        // get map hero ui width and heigh
        float newPartyOnMapUIHeight = Mathf.Abs(worldCorners[3].x - worldCorners[0].x);
        float newPartyOnMapUIWidth  = Mathf.Abs(worldCorners[1].y - worldCorners[0].y);
        // Debug.Log(newPartyOnMapUIWidth + ":" + newPartyOnMapUIHeight);
        Vector3 positionAdjustment = new Vector3(newPartyOnMapUIHeight / 2f, newPartyOnMapUIWidth / 2f, 0);

        // set it to the same position as the parent city
        newPartyOnMapUI.transform.position = city.LMapCity.transform.position + positionAdjustment;
        // Create hero label on map
        MapObjectLabel newPartyOnMapLabel = Instantiate(ObjectsManager.Instance.HeroPartyOnMapLabelTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapObjectLabel>())).GetComponent <MapObjectLabel>();

        // Link hero to the lable and label to the hero
        newPartyOnMapUI.GetComponent <MapObject>().Label = newPartyOnMapLabel;
        newPartyOnMapLabel.MapObject = newPartyOnMapUI.GetComponent <MapObject>();
        // activate new party on map UI
        newPartyOnMapUI.gameObject.SetActive(true);
        // activate hero label on map
        newPartyOnMapLabel.gameObject.SetActive(true);
        // Link HeroParty to the hero party on the map
        newPartyOnMapUI.LHeroParty = newLeaderParty;
        // Link hero on the map to HeroParty
        newLeaderParty.LMapHero = (newPartyOnMapUI);
        // Link hero on the map to city on the map
        city.LMapCity.GetComponent <MapCity>().LMapHero = newPartyOnMapUI.GetComponent <MapHero>();
        // Link city on the map to hero on the map
        newPartyOnMapUI.GetComponent <MapHero>().lMapCity = city.LMapCity;
        // move hero party to the back, so its UI label is not covering city's UI label
        // but it is in front of map slices
        // newPartyOnMapUI.transform.SetSiblingIndex(1);
        // rename it
        newPartyOnMapUI.gameObject.name = newLeaderParty.GetPartyLeader().GivenName + " " + newLeaderParty.GetPartyLeader().UnitName + " Party";
        // set color according to the player color preference
        newPartyOnMapUI.SetColor(ObjectsManager.Instance.GetPlayerByFaction(newLeaderParty.Faction).PlayerColor);
    }