Exemple #1
0
        private void OnClickListener()
        {
            var  characterFactory = CharacterFactory.GetInstance();
            bool isAllPrepared    = true;

            bool[] isPrepared = new bool[Combination.Characters.Count];
            isPrepared[0] = true;

            // Check characters except owner character
            for (int i = 1; i < Combination.Characters.Count; i++)
            {
                isPrepared[i] = false;
                for (int j = 0; j < characterFactory.CurrentCharacters.Count; j++)
                {
                    if (characterFactory.CurrentCharacters[j].tag == Combination.Characters[i].tag)
                    {
                        isPrepared[1] = true;
                        break;
                    }
                }
            }

            for (int i = 0; i < isPrepared.Length; i++)
            {
                if (!isPrepared[i])
                {
                    isAllPrepared = false;
                    break;
                }
            }

            // Every characters are here
            if (isAllPrepared)
            {
                FindObjectOfType <CombinationButtonManager>().RemoveAllCombinationButtons();

                characterFactory.SpawnCharacterByTag(Combination.ResultCharacter.tag, OwnerCharacter.transform.localPosition);
                characterFactory.RemoveCharacter(OwnerCharacter);

                for (int i = 0; i < Combination.Characters.Count; i++)
                {
                    characterFactory.RemoveCharacterByTag(Combination.Characters[i].tag);
                }
            }
            else
            {
                print("COMBINATION NOT READY");
            }
        }
Exemple #2
0
        /// <summary>
        /// Singleton
        /// Return null if failed.
        /// </summary>
        public static CharacterFactory GetInstance()
        {
            if (_instance == null)
            {
                var characterFactories = FindObjectsOfType <CharacterFactory>();
                for (int i = 0; i < characterFactories.Length; i++)
                {
                    if (characterFactories[i].enabled)
                    {
                        _instance = characterFactories[i];
                        break;
                    }
                }
            }

            // If there is no enabled one.
            return(_instance);
        }