Пример #1
0
 private void HandleNewSnapshot(RewinderSnapshot obj)
 {
     if (photonView.isMine)
     {
         RewinderHitboxGroupSnapshot group = obj.Groups.Where(e => e.Group == hitboxGroup).First();            //obj.Groups.First();
         correctPos = group.Position;
         correctRot = group.Rotation;
     }
 }
Пример #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);
                }
            }
        }
    }