Exemple #1
0
    // method to create a new creature and add it to the table
    public void AddCreatureAtIndex(CardAsset ca, int UniqueID, int index)
    {
        // create a new creature from prefab
        GameObject creature = GameObject.Instantiate(GlobalSettings.Instance.CreaturePrefab, slots.Children[index].transform.position, Quaternion.identity) as GameObject;

        // apply the look from CardAsset
        CreatureManager manager = creature.GetComponent <CreatureManager>();

        manager.cardAsset = ca;
        manager.ReadCreatureFromAsset();

        // add tag according to owner
        foreach (Transform t in creature.GetComponentsInChildren <Transform>())
        {
            t.tag = owner.ToString() + "Creature";
        }

        // parent a new creature gameObject to table slots
        creature.transform.SetParent(slots.transform);

        // add a new creature to the list
        CreaturesOnTable.Insert(index, creature);

        // let this creature know about its position
        WhereIsTheCardOrCreature w = creature.GetComponent <WhereIsTheCardOrCreature>();

        w.Slot = index;
        if (owner == AreaPosition.Low)
        {
            w.VisualState = VisualStates.LowTable;
        }
        else
        {
            w.VisualState = VisualStates.TopTable;
        }

        // add our unique ID to this creature
        IDHolder id = creature.AddComponent <IDHolder>();

        id.UniqueID = UniqueID;

        // after a new creature is added update placing of all the other creatures
        ShiftSlotsGameObjectAccordingToNumberOfCreatures();
        PlaceCreaturesOnNewSlots();

        // end command execution
        Command.CommandExecutionComplete();
    }