Esempio n. 1
0
    void OnHit(List <RewinderHitboxHit> hits)
    {
        var firstHit = hits.FirstOrDefault();

        /* Keeping this for easy debugging
         * foreach (var hit in hits)
         * {
         *      Debug.Log("We hit: " + hit.Hitbox.Transform.gameObject.name);
         *      if (hit.Hitbox.Transform.parent != null)
         *              Debug.Log("Hits parent is: " + hit.Hitbox.Transform.transform.parent.gameObject.name);
         * }
         */
        RewinderSnapshot.Recycle(hits);

        if (firstHit.Transform.gameObject.tag == "Enemy")
        {
            //Check for a parent object, if one is found. Get it's Enemy script and apply damage
            if (firstHit.Transform.parent != null)
            {
                var enemyObj = firstHit.Transform.parent.gameObject;
                enemyObj.GetComponent <Enemy>().photonView.RPC("NetworkApplyDamageToEnemy", PhotonTargets.All, primaryWeapon.damage);
            }
            else
            {
                var enemyObj = firstHit.Transform.gameObject;
                enemyObj.GetComponent <Enemy>().photonView.RPC("NetworkApplyDamageToEnemy", PhotonTargets.All, primaryWeapon.damage);
            }
        }
    }
Esempio n. 2
0
    void Update()
    {
        if (Application.isPlaying && RewinderSnapshot.Count > 0)
        {
            RewinderSnapshot snapshot = RewinderSnapshot.Find(Time.time - behind);

            if (snapshot != null)
            {
                accuracy = (float)System.Math.Round(Mathf.Abs((Time.time - behind) - snapshot.Time), 3);
                RewinderHitboxGroupSnapshot group = snapshot.Groups.First();

                // On first time, setup debug display

#if REWINDER_DEBUG
                if (debugDict.Count == 0)
                {
                    foreach (RewinderHitbox hitbox in group.Group.BodyHitboxes)
                    {
                        switch (hitbox.ColliderType)
                        {
                        case RewinderColliderType.Sphere:
                        {
                            GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                            go.renderer.material    = Resources.Load("RewinderDebug", typeof(Material)) as Material;
                            go.transform.localScale = hitbox.Collider.bounds.size;
                            debugDict.Add(hitbox, go);
                        }
                        break;

                        case RewinderColliderType.Box:
                        {
                            GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
                            go.transform.localScale = hitbox.Bounds.size;
                            go.renderer.material    = Resources.Load("RewinderDebug", typeof(Material)) as Material;
                            debugDict.Add(hitbox, go);
                        }
                        break;
                        }
                    }
                }

                // Move debug display

                for (int i = 0; i < group.HitboxMatrices_Debug.Length; ++i)
                {
                    Matrix4x4      m      = group.HitboxMatrices_Debug[i];
                    RewinderHitbox hitbox = group.Group.BodyHitboxes[i];
                    GameObject     go     = debugDict[hitbox];
                    go.transform.position = m.MultiplyPoint(Vector3.zero);
                    go.transform.rotation = group.HitboxRotations_Debug[i];
                }
#endif

                // Do collision detection (if any)

                if (Input.GetMouseButtonDown(0))
                {
                    RaycastHit rHit;
                    Ray        r = Camera.main.ScreenPointToRay(Input.mousePosition);
                    System.Diagnostics.Stopwatch sw = null;

                    switch (selected)
                    {
                    case 0:
                    {
                        List <RewinderHitboxHit> hits;

                        // Time how long the raycast takes
                        sw = System.Diagnostics.Stopwatch.StartNew();
                        RewinderSnapshot.Raycast(behind, r.origin, r.direction, out hits);
                        sw.Stop();

                        hit = hits.FirstOrDefault();
                        RewinderSnapshot.Recycle(hits);
                        sphereExample.active = false;
                    }
                    break;

                    case 1:
                        if (Physics.Raycast(r, out rHit, 1024f, 1 << 8))
                        {
                            drawPosition = rHit.point;
                            List <RewinderHitboxHit> hits;

                            // Time how long the overlap takes
                            sw = System.Diagnostics.Stopwatch.StartNew();
                            RewinderSnapshot.OverlapSphere(behind, drawPosition, 0.5f, out hits);
                            sw.Stop();

                            hit = hits.FirstOrDefault();
                            RewinderSnapshot.Recycle(hits);
                            sphereExample.transform.position = drawPosition;
                            sphereExample.active             = true;
                        }
                        break;
                    }

                    sw.Stop();
                    time = (float)((double)sw.ElapsedTicks / (double)System.Diagnostics.Stopwatch.Frequency);
                }
            }
        }
    }