예제 #1
0
파일: TrackedPath.cs 프로젝트: zimpzon/GFun
        public void FromString(string path)
        {
            Rewind();
            if (string.IsNullOrWhiteSpace(path))
            {
                return;
            }

            int pos = 0;

            TryGetInt(path, ref pos, out baseX_);
            TryGetInt(path, ref pos, out baseY_);
            TryGetInt(path, ref pos, out baseT_);
            fullBaseX_ = baseX_ / Resolution;
            fullBaseY_ = baseY_ / Resolution;
            fullBaseT_ = baseT_ / Resolution;

            idx_ = 0;
            while (TryGetInt(path, ref pos, out int x) && idx_ < MaxPathLen - 1)
            {
                TryGetInt(path, ref pos, out int y);
                TryGetInt(path, ref pos, out int t);
                path_[idx_++] = new TrackedPathSample {
                    x = x, y = y, t = t
                };
            }
        }
예제 #2
0
파일: TrackedPath.cs 프로젝트: zimpzon/GFun
        public bool Sample(Vector3 moveVec, Vector3 pos, float t)
        {
            if (idx_ >= MaxPathLen)
            {
                return(false);
            }

            if (moveVec != latestMoveVec_)
            {
                if (idx_ == 0)
                {
                    baseX_     = (int)(pos.x * Resolution);
                    baseY_     = (int)(pos.y * Resolution);
                    baseT_     = (int)(Time.unscaledTime * Resolution);
                    fullBaseX_ = baseX_ / Resolution;
                    fullBaseY_ = baseY_ / Resolution;
                    fullBaseT_ = baseT_ / Resolution;
                }

                bool isResumingMovement = latestMoveVec_ == Vector3.zero && idx_ != 0;
                if (isResumingMovement && idx_ < MaxPathLen - 2)
                {
                    // Was standing still, but is now moving again. Add and end-sample for the time we were standing still.
                    // If we don't do this the time we should stgand still is actually slowly interpolating to the first
                    // position after the movement.
                    var standingStill = path_[idx_ - 1];
                    standingStill.t = (int)(t * Resolution - baseT_);
                    path_[idx_++]   = standingStill;
                }

                latestMoveVec_ = moveVec;
                var sample = new TrackedPathSample
                {
                    x = (int)(pos.x * Resolution - baseX_),
                    y = (int)(pos.y * Resolution - baseY_),
                    t = (int)(t * Resolution - baseT_),
                };
                path_[idx_++] = sample;
            }

            return(true);
        }