void IListenerErg.OnErgDataEvent(ErgDataEvent ergDataEvent)
    {
        // currentErgData = ergDataEvent.ergData;
        if (playerref.activeInHierarchy)
        {
            for (int i = 0; i < physicsManagers.Length; ++i)
            {
                Rigidbody rigidBody = players[i].GetComponent <Rigidbody>();

                float v = rigidBody.velocity.x;
                float x = rigidBody.position.x;

                InteroBody1D body = null;
                if (currentSegment != null)
                {
                    ErgData e = new ErgData();
                    e.Copy(ergDataEvent.ergData);
                    e.distance = currentSegment.getProgressedDistance(ergDataEvent.ergData);
                    body       = physicsManagers[i].UpdateLocation(x, v, e);
                    //hud.DisplayCurrentSegment(currentSegment, ergDataEvent.ergData);
                }
                else
                {
                    body = physicsManagers[i].UpdateLocation(x, v, ergDataEvent.ergData);
                }

                rigidBody.velocity = new Vector3(body.velocity, rigidBody.velocity.y, rigidBody.velocity.z);
                rigidBody.position = new Vector3(body.distance, rigidBody.position.y, rigidBody.position.z);
                // print(i+ "update " + body.distance);
            }
        }
    }
    public void UpdateRival(OSCErgDataEvent ergEvent)
    {
        if (rivals == null)
        {
            return;
        }
        print("UpdateRival index1 " + ergEvent.senderId);
        print("UpdateRival index2 " + rivals);
        GameObject     rival          = rivals[ergEvent.senderId];
        PhysicsManager physicsManager = physicsManagers[ergEvent.senderId];
        Rigidbody      rigidBody      = rival.GetComponent <Rigidbody>();
        float          v = rigidBody.velocity.x;
        float          x = rigidBody.position.x;
        // float z = ergEvent.senderId * 2.0f;

        ErgData e = new ErgData();

        e.Copy(ergEvent.ergData);
        e.distance = ergEvent.segment.getProgressedDistance(ergEvent.ergData);
        print("UpdateRival p Distance " + e.distance);
        if (e.distance < 0.1 && e.distance > -0.1)
        {
            physicsManager.ResetLocation();
        }

        InteroBody1D body = physicsManager.UpdateLocation(x, v, e);

        rigidBody.velocity = new Vector3(body.velocity, rigidBody.velocity.y, rigidBody.velocity.z);
        rigidBody.position = new Vector3(body.distance, rigidBody.position.y, rigidBody.position.z);
    }
示例#3
0
    void IListenerErg.OnErgDataEvent(ErgDataEvent ergDataEvent)
    {
        // currentErgData = ergDataEvent.ergData;
        if (player.activeInHierarchy)
        {
            Rigidbody rigidBody = player.GetComponent <Rigidbody>();
            float     v         = rigidBody.velocity.x;
            float     x         = rigidBody.position.x;

            InteroBody1D body = null;

            /*
             *
             *  // update hud
             *  if (currentSegment != null)
             *  {
             *      ErgData e = new ErgData();
             *      e.Copy(ergDataEvent.ergData);
             *      e.distance = currentSegment.getProgressedDistance(ergDataEvent.ergData);
             *      // $"Hello, {name}! Today is {date.DayOfWeek},
             *
             *      print($"Progress d {e.distance}\t{x}\t{v}");
             *      // float d = currentSegment.getProgressedDistance(ergDataEvent.ergData);
             *      // print("loc xx erg " + ergDataEvent.ergData + "|"+d);
             *      // print(ergDataEvent.ergData);
             *
             *      body = physicsManager.UpdateLocation(x, v, e);
             *      hud.DisplayCurrentSegment(currentSegment, ergDataEvent.ergData);
             *      // physicsManager.se
             *
             *  }
             *  else*/
            if (currentSegment != null)
            {
                ErgData e = new ErgData();
                e.Copy(ergDataEvent.ergData);
                e.distance = currentSegment.getProgressedDistance(ergDataEvent.ergData);
                body       = physicsManager.UpdateLocation(x, v, e);
                hud.DisplayCurrentSegment(currentSegment, ergDataEvent.ergData);
            }
            else
            {
                body = physicsManager.UpdateLocation(x, v, ergDataEvent.ergData);
            }


            rigidBody.velocity = new Vector3(body.velocity, rigidBody.velocity.y, rigidBody.velocity.z);
            rigidBody.position = new Vector3(body.distance, rigidBody.position.y, rigidBody.position.z);
        }
    }
示例#4
0
    public void UpdateRank(string name, float v, ErgData ergData, Segment segment)
    {
        if (leaderboard == null)
        {
            return;
        }
        ErgData e = new ErgData();
        Segment s = Segment.Factory(segment);

        e.Copy(ergData);
        leaderboard.UpdateRank(name, v, e, s);
        LinkedList <RankNode> ranks = leaderboard.GetRankings();

        UpdateRankList(ranks);
    }