Exemplo n.º 1
0
 public bool IsEqual(ReplayOption otherRo)
 {
     if (
         BallPosToString() == otherRo.BallPosToString() &&
         BallRotToString() == otherRo.BallRotToString()
         )
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 2
0
    // Update is called once per frame
    void LateUpdate()
    {
        if (_startRecord)
        {
            if (ReplayOptions == null)
            {
                ReplayOptions = new List <ReplayOption>();
            }

            if (ReplayOptions.Count > 10)
            {
                Game.Instance.Ball.CanStopRecording = true;
            }

            frames++;
            if (frames == 5)
            {
                frames = 0;
            }
            else
            {
                return;
            }

            _elapsedTime = _startTime - DateTime.Now;
            float seconds = (float)(Math.Truncate(Convert.ToDouble(_elapsedTime.Milliseconds * 0.00001f) * 1000) / 1000);
            if (seconds > 1)
            {
                seconds = 1;
            }

            var posX = (float)Math.Round((Double)Game.Instance.Ball.transform.position.x, 3);
            var posY = (float)Math.Round((Double)Game.Instance.Ball.transform.position.y, 3);
            var posZ = (float)Math.Round((Double)Game.Instance.Ball.transform.position.z, 3);

            var rotX = (float)Math.Round((Double)Game.Instance.Ball.transform.eulerAngles.x, 3);
            var rotY = (float)Math.Round((Double)Game.Instance.Ball.transform.eulerAngles.y, 3);
            var rotZ = (float)Math.Round((Double)Game.Instance.Ball.transform.eulerAngles.z, 3);

            var replayOption = new ReplayOption()
            {
                BallPos = new Vector3(posX, posY, posZ),
                BallRot = new Vector3(rotX, rotY, rotZ),
                Seconds = seconds
            };

            var index = ReplayOptions.FindIndex(rp => rp.IsEqual(replayOption));
            if (index >= 0)
            {
                // ReplayOptions[index].Seconds += replayOption.Seconds;
                _startTime = DateTime.Now.AddSeconds(60);
                // Debug.Log("Exists");
                return;
            }

            // Debug.Log(replayOption.String());
            ReplayOptions.Add(replayOption);

            _startTime = DateTime.Now.AddSeconds(60);
        }
    }