예제 #1
0
 void Awake()
 {
     _buffPool = new Pool <GameObject>();
     _buffPool.SetTemplate(Instantiate(Resources.Load <GameObject>("Prefab/UI/Buff")), new GameObjectAllocator());
     _handView = gameObject.GetComponentInChildren <HandLayout>();
     Bind();
 }
예제 #2
0
        public virtual void GenerateCards(GameObject parent, Vector3 pin, HandLayout layout)
        {
            //hack fix because the opponent card prefabs had different center positions
            Vector3 offset = new Vector3();

            if (layout == HandLayout.LeftToRight)
            {
                offset = new Vector3(0f, 0.3f, 0f);
            }

            for (int i = 1; i <= 3; i++)
            {
                var cardBg = GameObject.Instantiate(this.BackgroundPrefab);
                cardBg.transform.parent   = parent.transform;
                cardBg.transform.position = (new Vector3(pin.x + ((i - 1) * 1.35f), pin.y + 4f, 0f)) - offset;
                backgrounds.Add(cardBg);
                if (this.Hand.Cards.RockCount >= i)
                {
                    var card = GameObject.Instantiate(this.RockPrefab);
                    card.transform.parent   = parent.transform;
                    card.transform.position = new Vector3(pin.x + ((i - 1) * 1.35f), pin.y + 4f, 0f);
                    this.AddEventHooks(card, CardType.Rock);
                    cardArray[i - 1, 0] = card;
                }

                cardBg = GameObject.Instantiate(this.BackgroundPrefab);
                cardBg.transform.parent   = parent.transform;
                cardBg.transform.position = (new Vector3(pin.x + ((i - 1) * 1.35f), pin.y + 2f, 0f)) - offset;
                backgrounds.Add(cardBg);
                if (this.Hand.Cards.PaperCount >= i)
                {
                    var card = GameObject.Instantiate(this.PaperPrefab);
                    card.transform.parent   = parent.transform;
                    card.transform.position = new Vector3(pin.x + ((i - 1) * 1.35f), pin.y + 2f, 0f);
                    this.AddEventHooks(card, CardType.Paper);
                    cardArray[i - 1, 1] = card;
                }

                cardBg = GameObject.Instantiate(this.BackgroundPrefab);
                cardBg.transform.position = (new Vector3(pin.x + ((i - 1) * 1.35f), pin.y, 0f)) - offset;
                cardBg.transform.parent   = parent.transform;
                backgrounds.Add(cardBg);
                if (this.Hand.Cards.ScissorsCount >= i)
                {
                    var card = GameObject.Instantiate(this.ScissorsPrefab);
                    card.transform.parent   = parent.transform;
                    card.transform.position = new Vector3(pin.x + ((i - 1) * 1.35f), pin.y, 0f);
                    this.AddEventHooks(card, CardType.Scissors);
                    cardArray[i - 1, 2] = card;
                }
            }

            if (layout == HandLayout.LeftToRight)
            {
                List <GameObject> cards = new List <GameObject>();
                foreach (var c in cardArray)
                {
                    if (c != null)
                    {
                        cards.Add(c);
                    }
                }

                AiManagerController.Instance.aiCards = cards;
            }
        }
예제 #3
0
    public void GenerateCards(HandState hand, GameObject rockPrefab, GameObject paperPrefab, GameObject scissorsPrefab, GameObject cardBack, HandLayout layout)
    {
        if (this.Cards.Any())
        {
            foreach (var c in Cards)
            {
                GameObject.Destroy(c);
            }

            Cards.Clear();
        }

        Vector3 offset = new Vector3();

        if (layout == HandLayout.LeftToRight)
        {
            offset = new Vector3(0f, 0.3f, 0f);
        }

        for (int i = 1; i <= 3; i++)
        {
            var cardBg = GameObject.Instantiate(cardBack);
            cardBg.transform.parent        = transform;
            cardBg.transform.localPosition = (new Vector3((i - 1) * 1.35f, 4f, 0f)) - offset;
            backgrounds.Add(cardBg);
            if (hand.RockCount >= i)
            {
                var card = GameObject.Instantiate(rockPrefab);
                card.transform.parent        = transform;
                card.transform.localPosition = new Vector3((i - 1) * 1.35f, 4f, 0f);
                cardArray[i - 1, 0]          = card;
            }

            cardBg = GameObject.Instantiate(cardBack);
            cardBg.transform.parent        = transform;
            cardBg.transform.localPosition = (new Vector3((i - 1) * 1.35f, 2f, 0f)) - offset;
            backgrounds.Add(cardBg);
            if (hand.PaperCount >= i)
            {
                var card = GameObject.Instantiate(paperPrefab);
                card.transform.parent        = transform;
                card.transform.localPosition = new Vector3((i - 1) * 1.35f, 2f, 0f);
                cardArray[i - 1, 1]          = card;
            }

            cardBg = GameObject.Instantiate(cardBack);
            cardBg.transform.parent        = transform;
            cardBg.transform.localPosition = (new Vector3((i - 1) * 1.35f, 0f, 0f)) - offset;
            backgrounds.Add(cardBg);
            if (hand.ScissorsCount >= i)
            {
                var card = GameObject.Instantiate(scissorsPrefab);
                card.transform.parent        = transform;
                card.transform.localPosition = new Vector3((i - 1) * 1.35f, 0f, 0f);
                cardArray[i - 1, 2]          = card;
            }
        }

        foreach (var card in cardArray)
        {
            var info = card.AddComponent <CardInfo>();
            this.Cards.Add(info);
        }

        foreach (var card in Cards)
        {
            card.CardSelected += (_, e) => this.CardSelected(this, e);
        }

        for (int i = 0; i < 3; i++)
        {
            cardArray[i, 0].GetComponent <CardInfo>().Type = CardType.Rock;
            cardArray[i, 1].GetComponent <CardInfo>().Type = CardType.Paper;
            cardArray[i, 2].GetComponent <CardInfo>().Type = CardType.Scissors;
        }
    }