Ejemplo n.º 1
0
 void Awake()
 {
     input = new GameInput();
     input.GamePlay.SetCallbacks(this);
     CachedJump      = new BooleanCache(JumpCacheTime);
     CachedJumpPress = new BooleanCache(JumpCacheTime);
 }
        protected override void Awake()
        {
            base.Awake();
            animator            = GetComponent <Animator>();
            motionController    = GetComponent <PlayerMotionController>();
            input               = GetComponent <PlayerInput>();
            actionController    = GetComponent <ActionController>();
            CachedWallContact   = new BooleanCache(CoyoteTime);
            CachedGroundContact = new BooleanCache(CoyoteTime);

            (Entity as Player).OnPlayerDead += () =>
            {
                StopAllCoroutines();
                StartCoroutine(PlayerDead());
            };
            motionController.OnBlockWallContacted += (block, normal) =>
            {
                contactedWallNormal = normal;
                if (block && block.AllowWallJump)
                {
                    CachedWallContact.Record(Time.fixedUnscaledTime);
                }
            };
            motionController.OnBlockGroundContacted += (contact) =>
            {
                CachedGroundContact.Record(Time.fixedUnscaledTime);
            };
            motionController.OnPreBlockDetect += () =>
            {
                contactedBlocks.Clear();
            };
            motionController.OnBlockContacted += (contact) =>
            {
                contactedBlocks.Add(contact.Block);
                if (contact.IsMainContact)
                {
                    if (SpecialStateBlock && SpecialStateBlock != contact.Block && contact.Block.OverrideSpecialState(SpecialStateBlock))
                    {
                        var processor = contact.Block.ProcessPlayerContact(Entity, contact);
                        if (processor != null)
                        {
                            StopAllCoroutines();
                            StartCoroutine(ControlledByBlock(contact.Block, processor));
                        }
                    }
                    else if (!SpecialStateBlock)
                    {
                        var processor = contact.Block.ProcessPlayerContact(Entity, contact);
                        if (processor != null)
                        {
                            StopAllCoroutines();
                            StartCoroutine(ControlledByBlock(contact.Block, processor));
                        }
                    }
                }
            };
            motionController.OnSceneEffectAreaContacted += (contact) =>
            {
                (contact.BlockType as GameMap.Data.EffectArea).ProcessPlayerContact(Entity);
            };
        }