Exemplo n.º 1
0
 private void OnCollisionEnter(Collision other)
 {
     VRDebug.Log(other.collider.name + " arrow bump", -1, other.collider);
     if (inFlight)
     {
     }
 }
Exemplo n.º 2
0
    public void ArrowTaken(int index, SelectEnterEventArgs args)
    {
        if (bow.debugLog)
        {
            VRDebug.Log("Arrow taken " + index);
        }
        arrowsSpawned[index].transform.localScale = Vector3.one;
        int killed = menuItems[index].transform.DOKill();

        killed += DOTween.Kill(menuItems[index]);
        if (bow.debugLog)
        {
            Debug.Log("select killed " + killed);
        }
        // ? todo dont remove all listeners
        arrowsSpawned[index].selectEntered.RemoveAllListeners();
        // make sure arrow is already unparented
        if (arrowsSpawned[index].transform.parent == menuItems[index].transform)
        {
            VRDebug.Log("Arrow taken not unparented!");
            arrowsSpawned[index].transform.SetParent(null);
        }
        // remove the menu item
        Destroy(menuItems[index]);
        menuItems.RemoveAt(index);
        arrowsSpawned.RemoveAt(index);
        // recreate it, with a new arrow
        CreateMenuItem(index);
        // disable menu for now
        HideMenuItems();
    }
Exemplo n.º 3
0
    protected override void OnSelectEntered(SelectEnterEventArgs args)
    {
        base.OnSelectEntered(args);
        // need to force hand to go on the string otherwise it could select something else
        // VRDebug.Log("Forcing hand string connection");
        // if (bow.offHand.selectTarget != null && bow.offHand.selectTarget != bowString)
        // {
        //     interactionManager.CancelInteractorSelection(bow.offHand);
        // }
        // interactionManager.SelectEnter(bow.offHand, bowString);
        // interactionManager.ForceSelect(bow.offHand, bowString);

        if (!(args.interactable is ArrowInteractable))
        {
            VRDebug.Log("wrong interaction " + args.interactable.name, 5);
        }

        // get arrow
        currentArrow = args.interactable as ArrowInteractable;
        if (bow.debugLog)
        {
            VRDebug.Log("Arrow '" + currentArrow.gameObject.name + "' notched");
        }
        isArrowArmed = false;
        currentArrow.ArrowSet();
        currentArrow.SetBow(bow);
        bow.ArrowSet();
    }
Exemplo n.º 4
0
 public void Respawn()
 {
     VRDebug.Log("Player respawning");
     bow.canUse = true;
     health.RestoreHealth();
     if (!spawnPoint)
     {
         FindSpawnPoint();
     }
     if (spawnPoint)
     {
         rig.rig.transform.position = spawnPoint.position;
         rig.rig.transform.rotation = spawnPoint.rotation;
     }
     else
     {
         VRDebug.Log("No Spawn point found");
         rig.rig.transform.position = Vector3.zero;
         rig.rig.transform.rotation = Quaternion.identity;
     }
     // velocity?
     // remove thrown arrows?
     // todo reload scene instead?
     // arrows, enemies, lots of stuff
 }
Exemplo n.º 5
0
 public void ReleaseArrow()
 {
     if (currentArrow != null)
     {
         var launchArrow = currentArrow;
         // disconnect with arrow
         interactionManager.CancelInteractorSelection(this);
         // launch or drop it
         if (isArrowArmed)
         {
             float normPullAmount = Mathf.InverseLerp(releaseThreshold, 1f, pullAmount);
             if (bow.debugLog)
             {
                 VRDebug.Log("Arrow launched " + normPullAmount * 100 + "%");
             }
             launchArrow.ArrowLaunched(normPullAmount);
             bow.ArrowLaunched(normPullAmount);
         }
         else
         {
             if (bow.debugLog)
             {
                 VRDebug.Log("Arrow dropped");
             }
             launchArrow.ArrowDropped();
             bow.ArrowDropped();
         }
     }
     bow.ArrowReleased(); // todo move up, do only if have an arrow?
     isArrowArmed = false;
 }
Exemplo n.º 6
0
    protected void Knockback(Vector3 point, Vector3 vel)
    {
        float mag = vel.magnitude;

        // todo fix
        VRDebug.Log("Knockback " + mag);
        rb.AddExplosionForce(mag, point, 1, 1.5f);
    }
Exemplo n.º 7
0
    protected virtual void LaunchForce()
    {
        SetPhysicsEnabled(true);
        float forceAmount = GetLaunchForce(launchPullAmount);

        VRDebug.Log("Launching at " + forceAmount + " force", debugContext: this);
        rb.AddForce(transform.forward * forceAmount, ForceMode.Impulse);
    }
Exemplo n.º 8
0
 void Die()
 {
     VRDebug.Log("Player died");
     lastDeathTime = Time.time;
     Invoke("StartReloading", deathWaitMinDur);
     bow.canUse = false;
     EnemyManager.Instance.PlayerDefeated();
     // todo death state
     // cannot fire arrows, time frozen? enemies frozen or something
 }
Exemplo n.º 9
0
 protected override void OnSelectExited(SelectExitEventArgs args)
 {
     base.OnSelectExited(args);
     if (bow.debugLog)
     {
         VRDebug.Log("Arrow exited notch");
     }
     currentArrow.ArrowUnSet();
     bow.ArrowUnSet();
     currentArrow = null;
 }
Exemplo n.º 10
0
 protected override void OnSelectEntered(SelectEnterEventArgs args)
 {
     if (bow.debugLog)
     {
         VRDebug.Log("String Grabbed");
     }
     // bowstring grabbed by player
     base.OnSelectEntered(args);
     pullingInteractor = args.interactor;
     bowNotch.Grabbed();
     UpdateLine();
 }
Exemplo n.º 11
0
 private void Update()
 {
     if (transform.position.y <= minHeight)
     {
         VRDebug.Log(name + " fell off the map!");
         if (justDestroy)
         {
             Destroy(gameObject);
         }
         fallEvent.Invoke();
     }
 }
Exemplo n.º 12
0
    protected override void OnSelectEntered(SelectEnterEventArgs args)
    {
        VRDebug.Log("Quiver new arrow");
        base.OnSelectEntered(args);
        // spawn arrow
        Transform          interT = args.interactor.transform;
        GameObject         arrow  = Instantiate(arrowPrefab, interT.position, interT.rotation);
        XRBaseInteractable arrInt = arrow.GetComponent <XRBaseInteractable>();

        // force select it
        interactionManager.ForceSelect(args.interactor, arrInt);
    }
Exemplo n.º 13
0
 public void SpawnAllArrows()
 {
     if (bow.debugLog)
     {
         VRDebug.Log("Spawning all arrows");
     }
     for (int i = 0; i < arrowPrefabs.Length; i++)
     {
         CreateMenuItem(i);
     }
     // curSel = -1;// force update
     UpdateSel();
 }
Exemplo n.º 14
0
 public void HideMenuItems()
 {
     if (bow.debugLog)
     {
         VRDebug.Log("Hiding Arrows");
     }
     for (int i = 0; i < menuItems.Count; i++)
     {
         menuItems[i].transform.DOKill();
         menuItems[i].gameObject.SetActive(false);
         // menuItems[i].transform.localScale = 0.1f * Vector3.one;
     }
 }
Exemplo n.º 15
0
    IEnumerator Start()
    {
        yield return(new WaitForSecondsRealtime(vrTimeout));

        if (!disableVR && !XRSettings.isDeviceActive)
        {
            Debug.LogWarning("No VR detected!");
        }
        if (!disableVR && XRSettings.isDeviceActive)
        {
            VRDebug.Log("VR detected!");
        }
    }
Exemplo n.º 16
0
 public void DeSpawnAllArrows()
 {
     if (bow.debugLog)
     {
         VRDebug.Log("Despawning all arrows");
     }
     for (int i = menuItems.Count - 1; i >= 0; i--)
     {
         Destroy(menuItems[i]);
     }
     menuItems.Clear();
     arrowsSpawned.Clear();
 }
Exemplo n.º 17
0
    public void SpawnAllEnemies()
    {
        // find all spawnlocations
        string spawnLocString = "EnemySpawnPoint";
        var    splocs         = GameObject.FindGameObjectsWithTag(spawnLocString);

        VRDebug.Log("Spawning " + splocs.Length + " Enemies");
        // just spawn one at each
        foreach (var sploc in splocs)
        {
            SpawnEnemy(allEnemyPrefabs[0], sploc.transform);
        }
        // Debug.Break();
    }
Exemplo n.º 18
0
 protected override void OnSelectExited(SelectExitEventArgs args)
 {
     if (bow.debugLog)
     {
         VRDebug.Log("String released");
     }
     // bowstring released by player
     base.OnSelectExited(args);
     bowNotch.ReleaseArrow();
     SetPullAmount(0);
     pullingInteractor = null;
     // todo snap animation?
     // todo when grabbing arrows quickly, they are being placed into the world
     // actually, not enough time to debug. its not gamebreaking
 }
Exemplo n.º 19
0
    protected virtual void CheckHit()
    {
        if (inFlight)
        {
            float   dist = Vector3.Distance(tip.transform.position, lastPos);
            Vector3 dir  = tip.transform.position - lastPos;
            Debug.DrawRay(lastPos, dir, Color.red, 5);
            if (Physics.SphereCast(lastPos, 0.05f, dir, out var hit, dist, collisionMask, QueryTriggerInteraction.Ignore))
            {
                // todo piercing keep going for range or until hit a non hittable
                // hit something
                VRDebug.Log("Arrow hit " + hit.collider.name, 5, this);
                stopped = true;
                // remove physics
                SetPhysicsEnabled(false);
                // child arrow to new transform for correct scale
                Transform newParent = new GameObject(name + " stick").transform;
                newParent.SetParent(hit.collider.transform, true);
                newParent.position = hit.point;
                newParent.rotation = Quaternion.identity;
                transform.SetParent(newParent, false);
                transform.localPosition = Vector3.zero;

                // disable collisions
                rb.detectCollisions = false;
                // transform.SetParent(hit.collider.transform, true);
                groundHitTime = Time.time;
                ArrowHit(hit);
                // check hittable
                if (hit.collider.gameObject.TryGetComponent <IHittable>(out var hittable))
                {
                    // VRDebug.Log("Arrow hit hittable");
                    HitArgs args = new HitArgs();
                    args.isDirect = true;
                    args.damage   = damage;
                    args.attacker = launchBow.ownerName;
                    args.point    = hit.point;
                    args.velocity = lastVel;
                    // Debug.Log("vel: " + rb.velocity);
                    SetHitArgs(ref args);
                    hittable.Hit(args);
                }
            }
            lastPos = tip.transform.position;
            lastVel = rb.velocity;
        }
    }
Exemplo n.º 20
0
 public void ShowMenu()
 {
     if (menuItems.Count == 0)
     {
         SpawnAllArrows();
     }
     else
     {
         if (bow.debugLog)
         {
             VRDebug.Log("Showing Arrows");
         }
         for (int i = 0; i < menuItems.Count; i++)
         {
             // menuItems[i].transform.localScale = displayModelScale * Vector3.one;
             menuItems[i].gameObject.SetActive(true);
         }
         UpdateSel();
     }
 }
Exemplo n.º 21
0
 public void TakeDamage(HitArgs args)
 {
     VRDebug.Log(name + " hit by " + args.attacker + " for " + args.damage, debugContext: this);
     if (isDead)
     {
         VRDebug.Log(name + " is already dead", debugContext: this);
         return;
     }
     else if (isInvincible)
     {
         // VRDebug.Log(name + " is invincible", debugContext: this);
         return;
     }
     lastHitArgs    = args;
     currentHealth -= args.damage;
     lastDamageTime = Time.time;
     damageEvent.Invoke();
     if (currentHealth <= 0)
     {
         Die();
     }
 }
Exemplo n.º 22
0
    protected bool TryTeleportLocation(RaycastHit hit)
    {
        // check if surface is flat
        float hitDotUp = Vector3.Dot(hit.normal, Vector3.up);

        if (hitDotUp >= verticalityThreshold)
        {
            // check if area is wide enough
            bool  areaSizeOk = false;
            float checkDist  = tpMinWidth;
            var   cols       = Physics.OverlapSphere(hit.point + (checkDist + 0.01f) * Vector3.up, checkDist, collisionMask, QueryTriggerInteraction.Ignore);
            if (cols.Length == 0)
            {
                areaSizeOk = true;
            }
            else
            {
                Debug.Log("TP blocked: Cols " + cols.Length);
                foreach (var col in cols)
                {
                    Debug.Log("Col " + col.name);
                }
            }
            if (areaSizeOk)
            {
                // height check
                Debug.DrawRay(hit.point, Vector3.up * tpMinHeight, Color.magenta, 2);
                //? different mask - playercol
                if (!Physics.SphereCast(hit.point, tpMinWidth, Vector3.up, out var hitheight, tpMinHeight, collisionMask, QueryTriggerInteraction.Ignore))
                {
                    TeleportTo(hit.point);
                    return(true);
                }
                else
                {
                    VRDebug.Log("TP blocked by height");
                }
            }
        }
Exemplo n.º 23
0
 protected void Die()
 {
     VRDebug.Log("Enemy " + name + " died");
     foreach (var tween in myTweens)
     {
         // stop all tweening
         tween.Kill();
     }
     EnemyManager.Instance.EnemyDied(this);
     // anim
     if (deathGoDetach)
     {
         // activate rbs and deactivate anim
         anim.enabled = false;
         GetComponentInChildren <RigBuilder>().enabled = false;
         deathGoDetach.transform.SetParent(null);
         Destroy(deathGoDetach, deathGoDetachDestroyDelay);
         ActivateRbs(deathGoDetach.transform, true);
     }
     // todo change eye color
     Destroy(gameObject);
 }
Exemplo n.º 24
0
 public override void ArrowHit(RaycastHit hit)
 {
     base.ArrowHit(hit);
     // VRDebug.Log("tp hit");
     if (TryTeleportLocation(hit))
     {
         return;
     }
     else
     {
         // raycast down to find a good spot
         Vector3 startPos = hit.point + hit.normal * wallOffsetDist;
         Debug.DrawRay(startPos, Vector3.down * tpDropDist, Color.magenta, 2);
         if (Physics.Raycast(startPos, Vector3.down, out var hitDown, tpDropDist, collisionMask, QueryTriggerInteraction.Ignore))
         {
             if (TryTeleportLocation(hitDown))
             {
                 return;
             }
         }
     }
     // failed to teleport
     VRDebug.Log("Failed to teleport");
 }
Exemplo n.º 25
0
 void OnDeviceLoad(string name)
 {
     VRDebug.Log("Device loaded " + name);
     isVRReady = true;
 }
Exemplo n.º 26
0
 void SaveSettings()
 {
     VRDebug.Log("Saving Settings...");
 }
Exemplo n.º 27
0
 void TryLoadSettings()
 {
     VRDebug.Log("Loading Settings...");
 }
Exemplo n.º 28
0
 protected override void OnSelectExited(SelectExitEventArgs args)
 {
     base.OnSelectExited(args);
     VRDebug.Log("Quiver desel");
 }
Exemplo n.º 29
0
 protected override void OnSelectEntering(SelectEnterEventArgs args)
 {
     VRDebug.Log("Quiver selling new arrow");
     base.OnSelectEntering(args);
 }
Exemplo n.º 30
0
 protected override void OnHoverEntered(HoverEnterEventArgs args)
 {
     VRDebug.Log("Quiver hover new arrow");
     base.OnHoverEntered(args);
 }