コード例 #1
0
    private void RaycastBounce(int bounces, Vector3 origin, Vector3 dir)
    {
        if (bounces == 0)
        {
            return;
        }

        Vector2    _dir       = AngularTweeks.DirectionOffset(playerForwardSide);
        Ray        _rayOrigin = new Ray(origin, _dir);
        RaycastHit _hitInfo;

        Debug.DrawRay(origin, _dir, Color.green, Mathf.Infinity);
        if (Physics.Raycast(_rayOrigin, out _hitInfo, 1000f))
        {
            Debug.Log("hit");
            ShootingTarget _st = _hitInfo.transform.GetComponent <ShootingTarget>();
            if (_st != null)
            {
                _st.GetShot(gunData);
                Vector3 bounceDir = Vector3.Reflect(_dir, _hitInfo.normal);

                RaycastBounce(gunData.bounces - 1, _hitInfo.point, bounceDir);
            }
        }
    }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InteractingShootingTargetEventArgs"/> class.
 /// </summary>
 /// <param name="player"><inheritdoc cref="Player"/></param>
 /// <param name="shootingTarget"><inheritdoc cref="ShootingTarget"/></param>
 /// <param name="targetButton"><inheritdoc cref="TargetButton"/></param>
 /// <param name="maxHp"><inheritdoc cref="NewMaxHp"/></param>
 /// <param name="autoResetTime"><inheritdoc cref="NewAutoResetTime"/></param>
 /// <param name="isAllowed"><inheritdoc cref="IsAllowed"/></param>
 public InteractingShootingTargetEventArgs(Player player, AdminToys.ShootingTarget shootingTarget, ShootingTargetButton targetButton, int maxHp, int autoResetTime, bool isAllowed = true)
 {
     Player             = player;
     ShootingTarget     = ShootingTarget.Get(shootingTarget);
     TargetButton       = targetButton;
     IsAllowed          = isAllowed;
     this.maxHp         = maxHp;
     this.autoResetTime = autoResetTime;
 }
コード例 #3
0
    private void Spawn(float timeRemaining)
    {
        GameObject target = targetObjectPool.GetGameObjectFromPool();

        target.transform.position = SpawnPosition();
        ShootingTarget shootingTarget = target.GetComponent <ShootingTarget>();

        shootingTarget.Restart(timeRemaining);
        shootingTarget.onRemove += HandleTargetRemoved;
    }
コード例 #4
0
ファイル: ShootingGunController.cs プロジェクト: a23265471/VR
    private void HandleDown()
    {
        if (shootingGalleryController.IsPlaying == false)
        {
            return;
        }
        ShootingTarget shootingTarget = eyeRaycaster.CurrentInteractible ? eyeRaycaster.CurrentInteractible.GetComponent <ShootingTarget>() : null;
        Transform      target         = shootingTarget ? shootingTarget.transform : null;

        StartCoroutine(Fire(target));
    }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DamagingShootingTargetEventArgs"/> class.
 /// </summary>
 /// <param name="player"><inheritdoc cref="Player"/></param>
 /// <param name="damage"><inheritdoc cref="Amount"/></param>
 /// <param name="distance"><inheritdoc cref="Distance"/></param>
 /// <param name="shootingTarget"><inheritdoc cref="ShootingTarget"/></param>
 /// <param name="damageHandler"><inheritdoc cref="Item"/></param>
 /// <param name="hitLocation"><inheritdoc cref="HitLocation"/></param>
 /// <param name="isAllowed"><inheritdoc cref="IsAllowed"/></param>
 public DamagingShootingTargetEventArgs(Player player, float damage, float distance, Vector3 hitLocation, AdminToys.ShootingTarget shootingTarget, DamageHandlerBase damageHandler, bool isAllowed = true)
 {
     Player         = player;
     Amount         = damage;
     Distance       = distance;
     ShootingTarget = ShootingTarget.Get(shootingTarget);
     Item           = player.CurrentItem;
     DamageHandler  = (AttackerDamageHandler)damageHandler;
     HitLocation    = hitLocation;
     IsAllowed      = isAllowed;
 }
コード例 #6
0
        private static bool Prefix(ShootingTarget __instance, ref bool __result, float damage, DamageHandlerBase handler, Vector3 exactHit)
        {
            try
            {
                if (handler is not AttackerDamageHandler attackerDamageHandler)
                {
                    __result = false;
                    return(false);
                }

                if (attackerDamageHandler.Attacker.Hub is null)
                {
                    __result = false;
                    return(false);
                }

                DamagingShootingTargetEventArgs ev = new(
                    Player.Get(attackerDamageHandler.Attacker.Hub),
                    damage,
                    Vector3.Distance(attackerDamageHandler.Attacker.Hub.transform.position, __instance._bullsEye.position),
                    exactHit,
                    __instance,
                    handler);
                Handlers.Player.OnDamagingShootingTarget(ev);

                if (!ev.IsAllowed)
                {
                    __result = false;
                    return(false);
                }

                foreach (ReferenceHub referenceHub in ReferenceHub.GetAllHubs().Values)
                {
                    if (__instance._syncMode || referenceHub == attackerDamageHandler.Attacker.Hub)
                    {
                        __instance.TargetRpcReceiveData(referenceHub.characterClassManager.connectionToClient, ev.Amount, ev.Distance, exactHit, handler);
                    }
                }

                __result = true;
                return(false);
            }
            catch (Exception exception)
            {
                Log.Error($"{typeof(DamagingShootingTarget).FullName}.{nameof(Prefix)}:\n{exception}");
                return(false);
            }
        }
コード例 #7
0
    private void HandleDown()//方法
    {
        if (shootingGalleryController.IsPlaying == false)
        {
            return;
        }
        //------------------------------
        ShootingTarget shootingTarget = eyeRaycaster.CurrentInteractible ? eyeRaycaster.CurrentInteractible.GetComponent <ShootingTarget>():null;

        /*
         * 等同於
         * if(eyeRaycaster.CurrentInteractible){
         * eyeRaycaster.CurrentInteractible.GetComponent<ShootingTarget>();
         * else
         * return null;
         * }
         */
        Transform target = shootingTarget ? shootingTarget.transform:null;

        StartCoroutine(Fire(target));//設定條件等待,條件成立繼續執行
        //------------------------------
    }
コード例 #8
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        ShootingTarget _sT = other.collider.GetComponent <ShootingTarget>();

        if (_sT != null)
        {
            _sT.GetShot(_gData);
        }

        _orgPosition = other.contacts[0].point;

        if (_gData.bounces == 0)
        {
            Destroy(this.gameObject);
        }
        else
        {
            _gData.bounces--;
        }

        SetVelocity();
    }
コード例 #9
0
    public override void Disparar(Transform transform)
    {
        Vector3 _dir = AngularTweeks.DirectionOffset(playerForwardSide);

        _dir = transform.TransformDirection(_dir);
        Ray        _origin = new Ray(transform.position, _dir);
        RaycastHit _hitInfo;

        Debug.DrawRay(transform.position, _dir, Color.green, Mathf.Infinity);

        if (Physics.Raycast(_origin, out _hitInfo, 1000f))
        {
            Debug.Log("Hit");
            ShootingTarget _st = _hitInfo.transform.GetComponent <ShootingTarget>();
            if (_st != null)
            {
                _st.GetShot(gunData);
                Vector3 bounceDir = Vector3.Reflect(_dir, _hitInfo.normal);

                RaycastBounce(gunData.bounces - 1, _hitInfo.point, bounceDir);
            }
        }
    }
コード例 #10
0
 private void HandleTargetRemoved(ShootingTarget target)
 {
     target.onRemove -= HandleTargetRemoved;
     targetObjectPool.ReturnGameObjectToPool(target.gameObject);
 }