Exemple #1
0
        public Effect(XmlNode node)
        {
            Type      = (SpecialEffectType)Enum.Parse(typeof(SpecialEffectType), node.Attributes["type"].Value.Replace("-", ""), true);
            StartAt   = node.Attributes.Contains("start-at") ? int.Parse(node.Attributes["start-at"].Value) : 0;
            StopEarly = node.Attributes.Contains("stop-early") ? int.Parse(node.Attributes["stop-early"].Value) : int.MaxValue;
            switch (Type)
            {
            case SpecialEffectType.PaletteSwap:
                Palette = (ScreenPalette)Enum.Parse(typeof(ScreenPalette), node.Attributes["palette"].Value.Replace("-", ""), true);
                break;

            case SpecialEffectType.Sequence:
                SequenceName = node.Attributes["sequence"].Value;
                break;

            case SpecialEffectType.Delay:
                DelayFrames = int.Parse(node.Attributes["delay"].Value);
                break;

            case SpecialEffectType.SpriteTransform:
                SpriteTransformation = (SpriteTransformation)Enum.Parse(typeof(SpriteTransformation), node.Attributes["transform"].Value.Replace("-", ""), true);
                Who = (Who)Enum.Parse(typeof(Who), node.Attributes["who"].Value, true);
                break;

            case SpecialEffectType.ScreenTransform:
                ScreenTransformation = (ScreenTransformation)Enum.Parse(typeof(ScreenTransformation), node.Attributes["transform"].Value.Replace("-", ""), true);
                Offset   = int.Parse(node.Attributes["offset"].Value);
                Parallel = node.Attributes.Contains("parallel") ? bool.Parse(node.Attributes["parallel"].Value) : false;
                break;

            case SpecialEffectType.Animation:
                string animationName = string.Join("", node.Attributes["animation"].Value.Split('-').Select(s => s.Substring(0, 1).ToUpper() + s.Substring(1).ToLower()));
                SpriteAnimation = System.Type.GetType("PkMn.Game.Animations." + animationName);
                if (SpriteAnimation == null)
                {
                    throw new Exception("Unable to get type: " + animationName);
                }
                Who         = (Who)Enum.Parse(typeof(Who), node.Attributes["who"].Value, true);
                DelayFrames = int.Parse(node.Attributes["delay"].Value);
                Param       = node.Attributes.Contains("param") ? int.Parse(node.Attributes["param"].Value) : 0;
                break;

            case SpecialEffectType.Temporary:
                break;

            default:
                throw new Exception("Unhandled SpecialEffectType: " + Type.ToString());
            }
        }
Exemple #2
0
    /// <summary>
    /// Creates a special effect based on the type at a specified position
    /// </summary>
    /// <returns>The effect created in the scene</returns>
    /// <param name="position">Position of where the effect is to be created.</param>
    public static GameObject createEffect(Vector3 position, SpecialEffectType effectType)
    {
        Debug.LogError("Don't Pick Monday Night for club meetings\n" +
                       "Maybe 4:30 or 5.");

        GameObject reference = null;

        AudioClip soundEffectReference = null;

        float lifeDuration = 3f;

        //get the correct special effect from our resources
        switch (effectType)
        {
        case SpecialEffectType.ChickenDeath:
            lifeDuration         = 3f;
            reference            = Resources.Load("Effects/ChickenDeath") as GameObject;
            soundEffectReference = Resources.Load("Effects/Death") as AudioClip;
            break;

        case SpecialEffectType.TakeDamage:
            lifeDuration         = 1f;
            reference            = Resources.Load("Effects/TakeDamage") as GameObject;
            soundEffectReference = Resources.Load("Effects/RightHook") as AudioClip;
            break;
        }

        //create the object in the scene
        GameObject effectInstance = Object.Instantiate(reference, position, Quaternion.identity) as GameObject;

        //add sound effect if there is one to add
        if (soundEffectReference != null)
        {
            effectInstance.AddComponent <AudioSource>();
            effectInstance.GetComponent <AudioSource>().clip        = soundEffectReference;
            effectInstance.GetComponent <AudioSource>().playOnAwake = false;
            effectInstance.GetComponent <AudioSource>().Play();
        }

        //Set the object to be destroyed in a certain amount of  time
        Object.Destroy(effectInstance, lifeDuration);

        return(effectInstance);
    }
    /// <summary>
    /// Creates a special effect based on the type at a specified position
    /// </summary>
    /// <returns>The effect created in the scene</returns>
    /// <param name="position">Position of where the effect is to be created.</param>
    public static GameObject createEffect(Vector3 position, SpecialEffectType effectType)
    {
        GameObject reference = null;

        AudioClip soundEffectReference = null;

        float lifeDuration = 3f;

        //get the correct special effect from our resources
        switch(effectType){

        case SpecialEffectType.ChickenDeath:
            lifeDuration = 3f;
            reference = Resources.Load("Effects/ChickenDeath") as GameObject;
            break;

        case SpecialEffectType.TakeDamage:
            lifeDuration = 1f;
            reference = Resources.Load("Effects/TakeDamage") as GameObject;
            soundEffectReference = Resources.Load("Effects/RightHook") as AudioClip;
            break;

        }

        //create the object in the scene
        GameObject effectInstance = Object.Instantiate(reference, position,Quaternion.identity) as GameObject;

        //add sound effect if there is one to add
        if(soundEffectReference != null){
            effectInstance.AddComponent<AudioSource>();
            effectInstance.GetComponent<AudioSource>().clip = soundEffectReference;
            effectInstance.GetComponent<AudioSource>().playOnAwake = false;
            effectInstance.GetComponent<AudioSource>().Play();
        }

        //Set the object to be destroyed in a certain amount of  time
        Object.Destroy (effectInstance, lifeDuration);

        return effectInstance;
    }