コード例 #1
0
    protected override void OnUpdate()
    {
        Entities.WithAllReadOnly <AnimationComponent>()
        .ForEach((Entity id) => {
            //setup listener
            if (!AnimationEventListener.HasListenerSetup(id))
            {
                AnimationEventListener.SetUp(id, OnAnimEvent);
            }

            Rigidbody2D rigidbody2D = EntityUtility.Instance.GetComponent <Rigidbody2D>(id);
            if (rigidbody2D != null)
            {
                Animator animator = EntityUtility.Instance.GetComponent <Animator>(id);
                if (animator != null)
                {
                    animator.SetBool("IsLand", rigidbody2D.velocity.y == 0);
                }
            }
        });

        Entities.WithAllReadOnly <AnimationComponent>()
        .WithAllReadOnly <MoveComponent>()
        .ForEach((Entity id, ref MoveComponent moveData) => {
            Animator animator = EntityUtility.Instance.GetComponent <Animator>(id);
            if (animator != null)
            {
                animator.SetBool("IsRun", moveData.speed != 0);
            }
        });

        Entities.WithAllReadOnly <AnimationComponent>()
        .WithAllReadOnly <JumpComponent>()
        .ForEach((Entity id, ref JumpComponent jumpData) => {
            if (jumpData.jumpTrigger)
            {
                Animator animator = EntityUtility.Instance.GetComponent <Animator>(id);
                if (animator != null)
                {
                    animator.SetTrigger("Jump");
                }
            }
        });


        Entities.WithAllReadOnly <AnimationComponent>().
        WithAllReadOnly <SimpleAttackComponent>().
        ForEach((Entity id, ref SimpleAttackComponent atkData) => {
            if (atkData.attackTrigger)
            {
                Animator animator = EntityUtility.Instance.GetComponent <Animator>(id);
                if (animator != null)
                {
                    animator.SetTrigger("AttackTrigger");
                    Observable.TimerFrame(1)
                    .Subscribe(x => { animator.ResetTrigger("AttackTrigger"); });
                }
            }
        });
    }
コード例 #2
0
    public static AnimationEventListener SetUp(Entity id, Action <Entity, AnimEvent> action)
    {
        AnimationEventListener listener = null;

        if (World.Active.EntityManager.Exists(id))
        {
            Transform transform = EntityUtility.Instance.GetComponent <Transform>(id);
            if (transform != null)
            {
                listener = transform.GetComponent <AnimationEventListener>();
                if (listener == null)
                {
                    listener = transform.gameObject.AddComponent <AnimationEventListener>();
                }
                listener.onAnimEvent += action;
                listener.entity       = id;

                if (listener != null && !listeners.ContainsKey(id))
                {
                    listeners.Add(id, listener);
                }
            }
        }

        return(listener);
    }
コード例 #3
0
ファイル: ItemMonoBehaviour.cs プロジェクト: ldlac/UMod
 private void Awake()
 {
     PlayerCamera   = Camera.allCameras.FirstOrDefault(x => x.CompareTag("Player"));
     _eventListener = GetComponentInChildren <AnimationEventListener>();
     if (_eventListener)
     {
         _eventListener.OnEvent.AddListener(OnAnimationEvent);
     }
 }
コード例 #4
0
    public void Setup()
    {
        if (!anim)
        {
            Debug.Log("<color=red>No animator found.</color>", this);
            return;
        }

        frameEvent = anim.GetComponent <AnimationEventListener>();
        if (!frameEvent)
        {
            frameEvent = anim.gameObject.AddComponent <AnimationEventListener>();
        }

        evt              = new AnimationEvent();
        evt.time         = frame / clip.frameRate;
        evt.functionName = "FrameReached";
        clip.AddEvent(evt);

        frameEvent.OnReached += FrameReached;
    }
コード例 #5
0
 private void Awake()
 {
     _animationEvent = FindObjectOfType <AnimationEventListener>();
 }