Exemplo n.º 1
0
    void ShootRaycast()
    {
        ray.origin    = camTrans.position;
        ray.direction = camTrans.forward;

        if (Physics.Raycast(ray, out hit, enemyLayer.value))
        {
            ShotParameter sp = ParameterPool.GetParameter <ShotParameter>();
            sp.gunDmg     = gunDamage;
            sp.shotObject = hit.transform.gameObject;
            sp.shotPoint  = hit.point;
            GlobalEventQueue.EnQueueEvent(E_Event.Shot, sp);

            EffectParameter ep = ParameterPool.GetParameter <EffectParameter>();
            ep.effectName = "Prefabs/Decals/Bullet Hole";
            ep.parent     = hit.transform;
            ep.position   = hit.point + hit.normal * 0.005f;
            ep.rotation   = Quaternion.LookRotation(-hit.normal);
            ep.scale      = Vector3.one * 0.1f;
            GlobalEventQueue.EnQueueEvent(DefaultEvent.ShowEffect, ep);

            //Debug.LogFormat( "SHOT {0}" , hit.transform.name );
        }
    }
Exemplo n.º 2
0
 public Task ShotAsync(ShotParameter shotParameter)
 {
     Broadcast(room).Shot(shotParameter);
     return(Task.CompletedTask);;
 }
Exemplo n.º 3
0
        private void Awake()
        {
            var system = GameObject.FindGameObjectWithTag("System_Online");

            movement  = system.GetComponent <Movement>();
            behaviour = system.GetComponent <PlayerBehaviour>();

            playerIndex           = GetComponent <IdentifierComponent>().index;
            render                = GetComponent <Renderer>();
            render.material.color = Color.red;

            positionParam.Index  = playerIndex;
            rotationParam.Index  = playerIndex;
            weaponParam.Index    = playerIndex;
            equipmentParam.Index = playerIndex;

            transform
            .ObserveEveryValueChanged(x => x.position)
            .Skip(1)
            .Subscribe(async position =>
            {
                positionParam.Position = position;
                await movement.Move(positionParam);
            });

            transform
            .ObserveEveryValueChanged(x => x.rotation)
            .Skip(1)
            .Subscribe(async rotation =>
            {
                rotationParam.Rotation = rotation;
                await movement.Rotation(rotationParam);
            });

            disposable =
                Observable
                .EveryUpdate()
                .Subscribe(async _ =>
            {
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    weaponParam.Main = WeaponType.Pistol;
                    weaponParam.Sub  = WeaponType.Rifle;
                    await behaviour.RegisterWeapon(weaponParam);
                }

                if (Input.GetKeyDown(KeyCode.C))
                {
                    var subCache    = weaponParam.Sub;
                    weaponParam.Sub = weaponParam.Main;
                    equipmentParam.MainEquipment = weaponParam.Main = subCache;

                    await behaviour.ChangeWeapon(equipmentParam);
                }

                if (Input.GetKeyDown(KeyCode.F))
                {
                    var dropItem = new DroppedItem
                                   (
                        Utility.GetRandomValue(),
                        DroppedItemType.Recovery,
                        transform.position
                                   );

                    await behaviour.Drop(dropItem);
                }

                if (Input.GetMouseButtonDown(0))
                {
                    var transform1 = transform;

                    var shot = new ShotParameter
                    {
                        Index    = playerIndex,
                        Position = transform1.position,
                        Rotation = transform1.rotation
                    };

                    await behaviour.Shot(shot);
                }

                if (Input.GetMouseButtonDown(1))
                {
                    await behaviour.Reload(playerIndex);
                }
            });
        }