Esempio n. 1
0
    //calculates the contextForbidDict by examining all effects
    private static void buildContextForbidDict()
    {
        contextForbidDict = new Dictionary <Type, Contexts>();                   //create the dict

        IEnumerable <Type> effectTypes = EffectTypeManagerScript.IEffectTypes(); //gets all classes that implement IEffect

        foreach (Type T in effectTypes)
        {
            //create a Contexts struct for each one
            Contexts C = new Contexts();
            C.playerCard = false;
            C.tower      = false;
            C.enemyCard  = false;
            C.enemyUnit  = false;

            //search for [ForbidEffectContext] on the type and set the appropriate flag if it is found
            foreach (System.Object attribute in T.GetCustomAttributes(true))
            {
                ForbidEffectContextAttribute fec = attribute as ForbidEffectContextAttribute;
                if (fec != null)
                {
                    switch (fec.forbiddenContext)
                    {
                    case EffectContext.playerCard: C.playerCard = true; break;

                    case EffectContext.tower:      C.tower = true; break;

                    case EffectContext.enemyCard:  C.enemyCard = true; break;

                    case EffectContext.enemyUnit:  C.enemyUnit = true; break;

                    default: Debug.LogWarning("Unknown Context"); break;
                    }
                }
            }

            //add it to the dict
            contextForbidDict.Add(T, C);
        }
    }
 // Use this for initialization
 private void Awake()
 {
     instance = this;
 }