Esempio n. 1
0
 public void OnAwake(Transform defaultTransform, DReConRewardStats orderToCopy = null)
 {
     _spawnableEnv          = GetComponentInParent <SpawnableEnv>();
     _articulationBodyParts = ObjectToTrack
                              .GetComponentsInChildren <ArticulationBody>()
                              .Distinct()
                              .ToList();
     _rigidbodyParts = ObjectToTrack
                       .GetComponentsInChildren <Rigidbody>()
                       .Distinct()
                       .ToList();
     if (_rigidbodyParts?.Count > 0)
     {
         _bodyParts = _rigidbodyParts.Select(x => x.gameObject).ToList();
     }
     else
     {
         _bodyParts = _articulationBodyParts.Select(x => x.gameObject).ToList();
     }
     _trackRotations = _bodyParts
                       .SelectMany(x => x.GetComponentsInChildren <Transform>())
                       .Select(x => x.gameObject)
                       .Distinct()
                       .Where(x => x.GetComponent <Rigidbody>() != null || x.GetComponent <ArticulationBody>() != null)
                       .ToList();
     _capsuleColliders = _bodyParts
                         .SelectMany(x => x.GetComponentsInChildren <CapsuleCollider>())
                         .Distinct()
                         .ToList();
     if (orderToCopy != null)
     {
         _bodyParts = orderToCopy._bodyParts
                      .Select(x => _bodyParts.First(y => y.name == x.name))
                      .ToList();
         _trackRotations = orderToCopy._trackRotations
                           .Select(x => _trackRotations.First(y => y.name == x.name))
                           .ToList();
         _capsuleColliders = orderToCopy._capsuleColliders
                             .Select(x => _capsuleColliders.First(y => y.name == x.name))
                             .ToList();
     }
     Points = Enumerable.Range(0, _capsuleColliders.Count * 6)
              .Select(x => Vector3.zero)
              .ToArray();
     _lastPoints = Enumerable.Range(0, _capsuleColliders.Count * 6)
                   .Select(x => Vector3.zero)
                   .ToArray();
     PointVelocity = Enumerable.Range(0, _capsuleColliders.Count * 6)
                     .Select(x => Vector3.zero)
                     .ToArray();
     Rotations = Enumerable.Range(0, _trackRotations.Count)
                 .Select(x => Quaternion.identity)
                 .ToList();
     if (_root == null)
     {
         _root = _bodyParts.First(x => x.name == "butt");
     }
     transform.position = defaultTransform.position;
     transform.rotation = defaultTransform.rotation;
 }
Esempio n. 2
0
    public void DrawPointDistancesFrom(DReConRewardStats target, int objIdex)
    {
        int start = 0;
        int end   = Points.Length - 1;

        if (objIdex >= 0)
        {
            start = objIdex * 6;
            end   = (objIdex * 6) + 6;
        }
        for (int i = start; i < end; i++)
        {
            Gizmos.color = Color.white;
            var from     = Points[i];
            var to       = target.Points[i];
            var toTarget = target.Points[i];
            // transform to this object's world space
            from         = this.transform.TransformPoint(from);
            to           = this.transform.TransformPoint(to);
            Gizmos.color = Color.yellow;
            Gizmos.DrawLine(from, to);
            // transform to target's world space
            toTarget     = target.transform.TransformPoint(toTarget);
            Gizmos.color = Color.white;
            Gizmos.DrawLine(from, toTarget);
            // show this objects velocity
            Vector3 velocity = PointVelocity[i];
            Gizmos.color = Color.blue;
            Gizmos.DrawRay(from, velocity);
            // show targets velocity
            Vector3 velocityTarget = target.PointVelocity[i];
            Gizmos.color = Color.green;
            Gizmos.DrawRay(toTarget, velocityTarget);
        }
    }
Esempio n. 3
0
    void Awake()
    {
        _spawnableEnv = GetComponentInParent <SpawnableEnv>();
        Assert.IsNotNull(_spawnableEnv);
        _mocap   = _spawnableEnv.GetComponentInChildren <MocapController>().gameObject;
        _ragDoll = _spawnableEnv.GetComponentInChildren <RagDollAgent>().gameObject;
        Assert.IsNotNull(_mocap);
        Assert.IsNotNull(_ragDoll);
        _inputController = _spawnableEnv.GetComponentInChildren <InputController>();
        // _mocapBodyParts = _mocap.GetComponentsInChildren<ArticulationBody>().ToList();
        // _ragDollBodyParts = _ragDoll.GetComponentsInChildren<ArticulationBody>().ToList();
        // Assert.AreEqual(_mocapBodyParts.Count, _ragDollBodyParts.Count);
        _mocapHead = _mocap
                     .GetComponentsInChildren <Transform>()
                     .First(x => x.name == "head");
        _ragDollHead = _ragDoll
                       .GetComponentsInChildren <Transform>()
                       .First(x => x.name == "head");
        _mocapBodyStats = new GameObject("MocapDReConRewardStats").AddComponent <DReConRewardStats>();
        var mocapController = _spawnableEnv.GetComponentInChildren <MocapController>();

        _mocapBodyStats.ObjectToTrack = mocapController;
        _mocapBodyStats.transform.SetParent(_spawnableEnv.transform);
        _mocapBodyStats.OnAwake(_mocapBodyStats.ObjectToTrack.transform);

        _ragDollBodyStats = new GameObject("RagDollDReConRewardStats").AddComponent <DReConRewardStats>();
        _ragDollBodyStats.ObjectToTrack = this;
        _ragDollBodyStats.transform.SetParent(_spawnableEnv.transform);
        _ragDollBodyStats.OnAwake(transform, _mocapBodyStats);

        _mocapBodyStats.AssertIsCompatible(_ragDollBodyStats);
    }
Esempio n. 4
0
    public List <float> GetPointVelocityDistancesFrom(DReConRewardStats target)
    {
        List <float> distances = new List <float>();

        for (int i = 0; i < PointVelocity.Length; i++)
        {
            float distance = (PointVelocity[i] - target.PointVelocity[i]).magnitude;
            distances.Add(distance);
        }
        return(distances);
    }
Esempio n. 5
0
 public void AssertIsCompatible(DReConRewardStats target)
 {
     Assert.AreEqual(Points.Length, target.Points.Length);
     Assert.AreEqual(_lastPoints.Length, target._lastPoints.Length);
     Assert.AreEqual(PointVelocity.Length, target.PointVelocity.Length);
     Assert.AreEqual(Points.Length, _lastPoints.Length);
     Assert.AreEqual(Points.Length, PointVelocity.Length);
     Assert.AreEqual(_capsuleColliders.Count, target._capsuleColliders.Count);
     for (int i = 0; i < _capsuleColliders.Count; i++)
     {
         string debugStr = $" _capsuleColliders.{_capsuleColliders[i].name} vs target._capsuleColliders.{target._capsuleColliders[i].name}";
         Assert.AreEqual(_capsuleColliders[i].name, target._capsuleColliders[i].name, $"name:{debugStr}");
         Assert.AreEqual(_capsuleColliders[i].direction, target._capsuleColliders[i].direction, $"direction:{debugStr}");
         Assert.AreEqual(_capsuleColliders[i].height, target._capsuleColliders[i].height, $"height:{debugStr}");
         Assert.AreEqual(_capsuleColliders[i].radius, target._capsuleColliders[i].radius, $"radius:{debugStr}");
     }
 }