Beispiel #1
0
        /// <summary>
        /// Fires the specified animation event. This method performs
        /// null checking and thread synchronization on the
        /// SynchronizedObject when necessary.
        /// </summary>
        ///
        /// <param name="eventToFire">
        /// the animation event to fire.
        /// </param>
        protected void FireEvent(AnimationEventHandler eventToFire)
        {
            // Null check
            if (eventToFire == null)
            {
                return;
            }

            var args = new AnimationEventArgs(this);

            // If a SynchronizationObject is specified, fire the event
            // on the object's synchronized thread.
            if (this.SynchronizationObject != null)
            {
                this.SynchronizationObject.BeginInvoke(new Action(() =>
                {
                    eventToFire(this, args);
                }), null);
            }

            else
            {
                eventToFire(this, args);
            }
        }
Beispiel #2
0
    protected virtual void Awake()
    {
        Animator = GetComponentInChildren <Animator>();
        Debug.AssertFormat(Animator, "Animator not found in Character's children");
        Debug.AssertFormat(Context.StateTransitionRules, "No character state transition rules found");

        AnimationEventHandler = Animator.gameObject.GetComponent <AnimationEventHandler>();

        // Create state machine and register all states
        StateMachine = new StateMachine(this, StateId.Idle);
        StateMachine.RegisterState <IdleState>(StateId.Idle);
        StateMachine.RegisterState <AimState>(StateId.Aim);
        StateMachine.RegisterState <ReloadState>(StateId.Reload);
        StateMachine.RegisterState <ShootState>(StateId.Shoot);
        StateMachine.RegisterState <ThrowState>(StateId.Throw);

        EquipmentManager = new EquipmentManager(AttachmentSlots);
        EquipmentManager.OnEquipmentChanged += OnEquippedHandler;

        // Add the default items to the inventory
        foreach (ItemCountPair itemCountPair in _defaultItems)
        {
            for (int i = 0; i < itemCountPair.count; i++)
            {
                EquipmentManager.AddToInventory(new InventoryItem(itemCountPair.context, null));
            }
        }
    }
        public IntervalAnimation(float interval, AnimationEventHandler callback)
        {
            Interval = interval;
            Callback = callback;

            remaining = interval;
        }
Beispiel #4
0
        public static void StartAnimation(Animation a, int delayMs = 0, AnimationEventHandler OnEnd = null)
        {
            Animation aa = null;

            if (Animation.GetAnimation(a.AnimatedInstance, a.propertyName, ref aa))
            {
                aa.CancelAnimation();
            }
//			if (a.AnimatedInstance is CardInstance) {
//				if ((a.AnimatedInstance as CardInstance).Model.Name.StartsWith ("Spider"))
//                  Debugger.Break ();
//			}
            //a.AnimationFinished += onAnimationFinished;

            a.AnimationFinished += OnEnd;
            a.delayStartMs       = delayMs + DelayMs;


            if (a.delayStartMs > 0)
            {
                a.timer.Start();
            }

            AnimationList.Add(a);
        }
Beispiel #5
0
 public void Start()
 {
     animator        = transform.gameObject.GetComponentInChildren <Animator>();
     triggerCollider = transform.gameObject.GetComponentInChildren <BoxCollider2D>();
     sr                    = transform.gameObject.GetComponentInChildren <SpriteRenderer>();
     defaultColor          = sr.color;
     animationEventHandler = GetComponentInChildren <AnimationEventHandler>();
     pathFinderManager     = player.getSpawner().getPathFinderManager();
 }
Beispiel #6
0
        protected virtual void OnAnimating(AnimationEventArgs e)
        {
            AnimationEventHandler animationEventHandler = (AnimationEventHandler)this.Events[AnimationEngine.AnimatingEventKey];

            if (animationEventHandler == null)
            {
                return;
            }
            animationEventHandler((object)this, e);
        }
Beispiel #7
0
        protected virtual void OnAnimating(AnimationEventArgs e)
        {
            AnimationEventHandler handler1 =
                (AnimationEventHandler)base.Events[AnimationEngine.AnimatingEventKey];

            if (handler1 != null)
            {
                handler1(this, e);
            }
        }
Beispiel #8
0
 public void Start()
 {
     animator              = transform.gameObject.GetComponentInChildren <Animator>();
     triggerCollider       = transform.gameObject.GetComponentInChildren <BoxCollider2D>();
     lastScan              = Time.time;
     animationEventHandler = GetComponentInChildren <AnimationEventHandler>();
     enemyManager          = player.getEnemyManager();
     sr = GetComponentInChildren <SpriteRenderer>();
     pathFinderManager = player.getSpawner().getPathFinderManager();
     maxhealth         = health;
 }
Beispiel #9
0
        /// <summary>
        /// Overriden. Raises the item added event
        /// </summary>
        protected virtual void OnPaintFrame()
        {
            AnimationEventHandler handler = paintFrame;

            if (handler != null)
            {
                using (Graphics graphics = Graphics.FromImage(cache[currentFrame]))
                {
                    graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                    graphics.InterpolationMode = InterpolationMode.Bicubic;

                    handler(this, new AnimationEventArgs(graphics,
                                                         this.animatables));
                }
            }
        }
Beispiel #10
0
        public static void StartAnimation(Animation a, int delayMs = 0, AnimationEventHandler OnEnd = null)
        {
            lock (AnimationList) {
                Animation aa = null;
                if (Animation.GetAnimation(a.AnimatedInstance, a.propertyName, ref aa))
                {
                    aa.CancelAnimation();
                }

                //a.AnimationFinished += onAnimationFinished;

                a.AnimationFinished += OnEnd;
                a.delayStartMs       = delayMs + DelayMs;


                if (a.delayStartMs > 0)
                {
                    a.timer.Start();
                }

                AnimationList.Add(a);
            }
        }
Beispiel #11
0
 public DelayAnimation(float delay, AnimationEventHandler callback)
 {
     Delay    = delay;
     Callback = callback;
 }
Beispiel #12
0
        /// <summary>
        /// イベントの追加
        /// </summary>
        /// <param name="position">ローカルポジション (msec)</param>
        /// <param name="handler">イベントで呼び出される関数</param>
        /// <param name="args">関数に渡される引数</param>
        public void AddEvent(int position, AnimationEventHandler handler, EventArgs args)
        {
            if (position < 0 || position > duration) {
                throw new ArgumentException ("Position is invalid");
            }
            if (handler == null) {
                throw new ArgumentNullException ("Handler is null");
            }

            this.events.Add (new AnimationEvent (position, handler, args));
            events.Sort ();
        }
 public ContinuousAnimation(AnimationEventHandler callback)
 {
     Callback = callback;
 }
Beispiel #14
0
 public void UnregisterListener <T>(T listener) where T : IEventListener
 {
     animationEventHandler -= new AnimationEventHandler(listener.OnNotification);
 }