Exemplo n.º 1
0
 public void SetRank(UnitRank rank)
 {
     this.rank = rank;
     //Initialize the values
     unitName.text  = UnitUtilities.ReadableRank(rank);
     image.sprite   = UnitImageManager.GetRankImage(rank);
     remaining.text = UnitManager.GetPlacementAmountForUnit(rank).ToString();
 }
Exemplo n.º 2
0
    public void AddPiece(BoardPosition position, UnitRank rank)
    {
        //Check for existing piece, remove it if needed.
        //Debug.Log("atteming to add " + UnitUtilities.ReadableRank(rank) + " at " + position.ToString());
        bool equal = false;

        if (pieces.ContainsKey(position))
        {
            UnitPiece existing;
            if (pieces.TryGetValue(position, out existing))
            {
                if (existing.Rank.Equals(rank))
                {
                    //We're not going to remove then add the same exact piece to the same position
                    equal = true;
                }
                else
                {
                    RemovePiece(position);
                }
            }
        }
        if (!equal)
        {
            Transform target = BoardManager.GetTransformForPosition(position);
            if (!EqualityComparer <Transform> .Default.Equals(target, default(Transform)))
            {
                GameObject plane = Instantiate(UnitPlane);
                UnitPiece  piece = GeneratePiece(rank, plane);
                if (piece.Owner != null)
                {
                    piece.Piece.transform.SetParent(piece.Owner.Holder.transform);
                    plane.name  = UnitUtilities.ReadableRank(rank);
                    plane.layer = LayerMask.NameToLayer("Pieces");
                    Vector3 planePos = target.position;
                    planePos.z = GOLayer.UNIT_LAYER;
                    plane.transform.position = planePos;
                    Renderer r = plane.GetComponent <Renderer>();
                    r.material = MaterialManager.GetRankMaterial(rank);
                    pieces.Add(position, piece);
                    EventManager.Raise(new UnitPlacedEvent(position, piece));
                }
                else
                {
                    piece.Destroy();
                    Destroy(plane);
                }
            }
        }
    }