ratioAtPoint() public method

public ratioAtPoint ( Vector3 pt ) : float
pt Vector3
return float
コード例 #1
0
 void refreshSpline()
 {
     track   = new LTSpline(trackPts.ToArray());
     carIter = track.ratioAtPoint(car.transform.position); // we created a new spline so we need to update the cars iteration point on this new spline
     // Debug.Log("distance:"+track.distance+" carIter:"+carIter);
     carAdd = 40f / track.distance;                        // we want to make sure the speed is based on the distance of the spline for a more constant speed
 }
コード例 #2
0
 void refreshSpline()
 {
     track = new LTSpline( trackPts.ToArray() );
     carIter = track.ratioAtPoint( car.transform.position ); // we created a new spline so we need to update the cars iteration point on this new spline
     // Debug.Log("distance:"+track.distance+" carIter:"+carIter);
     carAdd = 40f / track.distance; // we want to make sure the speed is based on the distance of the spline for a more constant speed
 }
コード例 #3
0
ファイル: Lua_LTSpline.cs プロジェクト: daxingyou/-game
 static public int ratioAtPoint(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         LTSpline            self = (LTSpline)checkSelf(l);
         UnityEngine.Vector3 a1;
         checkType(l, 2, out a1);
         var ret = self.ratioAtPoint(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
コード例 #4
0
 static public int ratioAtPoint(IntPtr l)
 {
     try {
         LTSpline            self = (LTSpline)checkSelf(l);
         UnityEngine.Vector3 a1;
         checkType(l, 2, out a1);
         var ret = self.ratioAtPoint(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #5
0
ファイル: LTSplineWrap.cs プロジェクト: vasu93/HelloWorld
 static int ratioAtPoint(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         LTSpline            obj  = (LTSpline)ToLua.CheckObject(L, 1, typeof(LTSpline));
         UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 2);
         float o = obj.ratioAtPoint(arg0);
         LuaDLL.lua_pushnumber(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #6
0
        void Start()
        {
            LeanTest.timeout = 46f;
            LeanTest.expected = 36;

            LeanTween.init(15 + 1200);
            // add a listener
            LeanTween.addListener(cube1, 0, eventGameObjectCalled);

            LeanTest.expect(LeanTween.isTweening() == false, "NOTHING TWEEENING AT BEGINNING" );

            LeanTest.expect(LeanTween.isTweening(cube1) == false, "OBJECT NOT TWEEENING AT BEGINNING" );

            LeanTween.scaleX( cube4, 2f, 0f).setOnComplete( ()=>{
                LeanTest.expect( cube4.transform.localScale.x == 2f, "TWEENED WITH ZERO TIME" );
            });

            // dispatch event that is received
            LeanTween.dispatchEvent(0);
            LeanTest.expect( eventGameObjectWasCalled, "EVENT GAMEOBJECT RECEIVED" );

            // do not remove listener
            LeanTest.expect(LeanTween.removeListener(cube2, 0, eventGameObjectCalled)==false, "EVENT GAMEOBJECT NOT REMOVED" );
            // remove listener
            LeanTest.expect(LeanTween.removeListener(cube1, 0, eventGameObjectCalled), "EVENT GAMEOBJECT REMOVED" );

            // add a listener
            LeanTween.addListener(1, eventGeneralCalled);

            // dispatch event that is received
            LeanTween.dispatchEvent(1);
            LeanTest.expect( eventGeneralWasCalled, "EVENT ALL RECEIVED" );

            // remove listener
            LeanTest.expect( LeanTween.removeListener( 1, eventGeneralCalled), "EVENT ALL REMOVED" );

            lt1Id = LeanTween.move( cube1, new Vector3(3f,2f,0.5f), 1.1f ).id;
            LeanTween.move( cube2, new Vector3(-3f,-2f,-0.5f), 1.1f );

            LeanTween.reset();

            Vector3[] splineArr = new Vector3[] {new Vector3(-1f,0f,0f), new Vector3(0f,0f,0f), new Vector3(4f,0f,0f), new Vector3(20f,0f,0f), new Vector3(30f,0f,0f)};
            LTSpline cr = new LTSpline( splineArr );
            cr.place( cube4.transform, 0.5f );
            LeanTest.expect( (Vector3.Distance( cube4.transform.position, new Vector3(10f,0f,0f) ) <= 0.7f), "SPLINE POSITIONING AT HALFWAY", "position is:"+cube4.transform.position+" but should be:(10f,0f,0f)");
            LeanTween.color(cube4, Color.green, 0.01f);

            Debug.Log("Point 2:"+cr.ratioAtPoint(splineArr[2]));

            // OnStart Speed Test for ignoreTimeScale vs normal timeScale
            GameObject cube = Instantiate( boxNoCollider ) as GameObject;
            cube.name = "normalTimeScale";
            // float timeElapsedNormal = Time.time;
            LeanTween.moveX(cube, 12f, 1f).setIgnoreTimeScale( false ).setOnComplete( ()=>{
                timeElapsedNormalTimeScale = Time.time;
            });

            LTDescr[] descr = LeanTween.descriptions( cube );
            LeanTest.expect( descr.Length >= 0 && descr[0].to.x == 12f, "WE CAN RETRIEVE A DESCRIPTION");

            cube = Instantiate( boxNoCollider ) as GameObject;
            cube.name = "ignoreTimeScale";
            LeanTween.moveX(cube, 5f, 1f).setIgnoreTimeScale( true ).setOnComplete( ()=>{
                timeElapsedIgnoreTimeScale = Time.time;
            });

            GameObject cubeDest = Instantiate( boxNoCollider ) as GameObject;
            cubeDest.name = "cubeDest";
            Vector3 cubeDestEnd = new Vector3(100f,20f,0f);
            LeanTween.move( cubeDest, cubeDestEnd, 0.7f);
            GameObject cubeToTrans = Instantiate( boxNoCollider ) as GameObject;
            cubeToTrans.name = "cubeToTrans";

            LeanTween.move( cubeToTrans, cubeDest.transform, 1.2f).setEase( LeanTweenType.easeOutQuad ).setOnComplete( ()=>{
                LeanTest.expect( cubeToTrans.transform.position == cubeDestEnd, "MOVE TO TRANSFORM WORKS");
            });

            GameObject cubeDestroy = Instantiate( boxNoCollider ) as GameObject;
            cubeDestroy.name = "cubeDestroy";
            LeanTween.moveX( cubeDestroy, 200f, 0.05f).setDelay(0.02f).setDestroyOnComplete(true);
            LeanTween.moveX( cubeDestroy, 200f, 0.1f).setDestroyOnComplete(true).setOnComplete( ()=>{
                LeanTest.expect(true, "TWO DESTROY ON COMPLETE'S SUCCEED");
            });

            GameObject cubeSpline = Instantiate( boxNoCollider ) as GameObject;
            cubeSpline.name = "cubeSpline";
            LeanTween.moveSpline(cubeSpline, new Vector3[]{new Vector3(0.5f,0f,0.5f),new Vector3(0.75f,0f,0.75f),new Vector3(1f,0f,1f),new Vector3(1f,0f,1f)}, 0.1f).setOnComplete( ()=>{
                LeanTest.expect(Vector3.Distance(new Vector3(1f,0f,1f), cubeSpline.transform.position) < 0.01f, "SPLINE WITH TWO POINTS SUCCEEDS");
            });

            // This test works when it is positioned last in the test queue (probably worth fixing when you have time)
            GameObject jumpCube = Instantiate( boxNoCollider ) as GameObject;
            jumpCube.name = "jumpTime";
            int jumpTimeId = LeanTween.moveX( jumpCube, 1f, 1f).id;

            LeanTween.delayedCall(jumpCube, 0.2f, ()=>{
                LTDescr d = LeanTween.descr( jumpTimeId );
                float beforeX = jumpCube.transform.position.x;
                d.setTime( 0.5f );
                LeanTween.delayedCall( 0.01f, ()=>{ }).setOnStart( ()=>{
                    LeanTest.expect( Mathf.Abs( jumpCube.transform.position.x - beforeX ) < 0.01f , "CHANGING TIME DOESN'T JUMP AHEAD", "Difference:"+Mathf.Abs( jumpCube.transform.position.x - beforeX ));
                });
            });

            // Tween with time of zero is needs to be set to it's final value
            GameObject zeroCube = Instantiate( boxNoCollider ) as GameObject;
            zeroCube.name = "zeroCube";
            LeanTween.moveX( zeroCube, 10f, 0f).setOnComplete( ()=>{
                LeanTest.expect( zeroCube.transform.position.x == 10f, "ZERO TIME FINSHES CORRECTLY", "final x:"+ zeroCube.transform.position.x);
            });

            StartCoroutine( timeBasedTesting() );
        }
コード例 #7
0
ファイル: PathRider.cs プロジェクト: facybenbook/Loveline
    /// <summary>
    /// This function is called every fixed framerate frame, if the MonoBehaviour is enabled.
    /// </summary>
    void FixedUpdate()
    {
        // For convenience
        box = new Rect(
            cd.bounds.min.x,
            cd.bounds.min.y,
            cd.bounds.size.x,
            cd.bounds.size.y
            );

        // Apply gravity
        if (!onPath)
        {
            velocity = new Vector2(velocity.x, Mathf.Max(velocity.y - gravity, -maxFall));
        }
        // Ride path
        else
        {
            // Calculate velocity based on movement along path
            while (currentSpline.ratioAtPoint(nextPathVector) < currentSpline.ratioAtPoint(transform.position))
            {
                currentPathVector = nextPathVector;
                currentPathVectorIndex++;
                nextPathVector = currentPathVectors[currentPathVectorIndex + 1];
            }
            velocity = (nextPathVector - currentPathVector).normalized * onPathSpeed;
        }

        // Calculate ray distance (current fall speed) and direction
        //float rayDistance = box.height / 2 + Mathf.Abs(velocity.y * Time.deltaTime);
        // TODO: This can't be right. The 2f is just to lengthen it a little to reduce the chance of missing an edge collider.
        float rayDistance = Mathf.Abs(velocity.magnitude * 2f * Time.deltaTime);

        // Check for paths
        // Cast the ray to check for paths
        RaycastHit2D[] pathHitInfo         = new RaycastHit2D[numPathRays];
        bool           pathHit             = false;
        float          closestPathHit      = float.MaxValue;
        int            closestPathHitIndex = 0;

        for (int i = 0; i < numPathRays; i++)
        {
            // Create and cast ray
            //float lerpDistance = (float)i / (float)((numPathRays > 1) ? numPathRays - 1 : numPathRays);
            Vector2 rayOrigin = transform.position;             //Vector2.Lerp(minRay, maxRay, lerpDistance);
            Ray2D   ray       = new Ray2D(rayOrigin, velocity.normalized);
            pathHitInfo[i] = Physics2D.Raycast(rayOrigin, velocity.normalized, rayDistance, 1 << LayerMask.NameToLayer("Path"));
            Debug.DrawRay(ray.origin, ray.direction * rayDistance, Color.cyan, 10f);
            // Check raycast results and keep track of closest path hit
            if (pathHitInfo[i].fraction > 0)
            {
                pathHit = true;
                Debug.DrawRay(ray.origin, ray.direction * rayDistance, Color.black, 10f);
                if (pathHitInfo[i].fraction < closestPathHit)
                {
                    closestPathHit      = pathHitInfo[i].fraction;
                    closestPathHitIndex = i;
                    closestPathHitInfo  = pathHitInfo[i];
                }
            }
        }

        // Check and handle what path we hit
        if (pathHit)
        {
            RidePath path = closestPathHitInfo.collider.gameObject.GetComponentInParent <RidePath>();
            // If path exists and is drawOrder is greater than current path's, snap to hit point
            if (path && canRidePath)
            {
                if (currentPath == null || (path.drawOrder > currentPath.drawOrder && path != currentPath))
                {
                    PlaceSelfInPath(closestPathHitInfo.point, path);
                }
            }
        }
    }
コード例 #8
0
        void Start()
        {
            LeanTest.timeout  = 46f;
            LeanTest.expected = 36;

            LeanTween.init(15 + 1200);
            // add a listener
            LeanTween.addListener(cube1, 0, eventGameObjectCalled);

            LeanTest.expect(LeanTween.isTweening() == false, "NOTHING TWEEENING AT BEGINNING");

            LeanTest.expect(LeanTween.isTweening(cube1) == false, "OBJECT NOT TWEEENING AT BEGINNING");

            LeanTween.scaleX(cube4, 2f, 0f).setOnComplete(() => {
                LeanTest.expect(cube4.transform.localScale.x == 2f, "TWEENED WITH ZERO TIME");
            });

            // dispatch event that is received
            LeanTween.dispatchEvent(0);
            LeanTest.expect(eventGameObjectWasCalled, "EVENT GAMEOBJECT RECEIVED");

            // do not remove listener
            LeanTest.expect(LeanTween.removeListener(cube2, 0, eventGameObjectCalled) == false, "EVENT GAMEOBJECT NOT REMOVED");
            // remove listener
            LeanTest.expect(LeanTween.removeListener(cube1, 0, eventGameObjectCalled), "EVENT GAMEOBJECT REMOVED");

            // add a listener
            LeanTween.addListener(1, eventGeneralCalled);

            // dispatch event that is received
            LeanTween.dispatchEvent(1);
            LeanTest.expect(eventGeneralWasCalled, "EVENT ALL RECEIVED");

            // remove listener
            LeanTest.expect(LeanTween.removeListener(1, eventGeneralCalled), "EVENT ALL REMOVED");

            lt1Id = LeanTween.move(cube1, new Vector3(3f, 2f, 0.5f), 1.1f).id;
            LeanTween.move(cube2, new Vector3(-3f, -2f, -0.5f), 1.1f);

            LeanTween.reset();

            Vector3[] splineArr = new Vector3[] { new Vector3(-1f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(4f, 0f, 0f), new Vector3(20f, 0f, 0f), new Vector3(30f, 0f, 0f) };
            LTSpline  cr        = new LTSpline(splineArr);

            cr.place(cube4.transform, 0.5f);
            LeanTest.expect((Vector3.Distance(cube4.transform.position, new Vector3(10f, 0f, 0f)) <= 0.7f), "SPLINE POSITIONING AT HALFWAY", "position is:" + cube4.transform.position + " but should be:(10f,0f,0f)");
            LeanTween.color(cube4, Color.green, 0.01f);

            Debug.Log("Point 2:" + cr.ratioAtPoint(splineArr[2]));

            // OnStart Speed Test for ignoreTimeScale vs normal timeScale
            GameObject cube = Instantiate(boxNoCollider) as GameObject;

            cube.name = "normalTimeScale";
            // float timeElapsedNormal = Time.time;
            LeanTween.moveX(cube, 12f, 1f).setIgnoreTimeScale(false).setOnComplete(() => {
                timeElapsedNormalTimeScale = Time.time;
            });

            LTDescr[] descr = LeanTween.descriptions(cube);
            LeanTest.expect(descr.Length >= 0 && descr[0].to.x == 12f, "WE CAN RETRIEVE A DESCRIPTION");

            cube      = Instantiate(boxNoCollider) as GameObject;
            cube.name = "ignoreTimeScale";
            LeanTween.moveX(cube, 5f, 1f).setIgnoreTimeScale(true).setOnComplete(() => {
                timeElapsedIgnoreTimeScale = Time.time;
            });

            GameObject cubeDest = Instantiate(boxNoCollider) as GameObject;

            cubeDest.name = "cubeDest";
            Vector3 cubeDestEnd = new Vector3(100f, 20f, 0f);

            LeanTween.move(cubeDest, cubeDestEnd, 0.7f);
            GameObject cubeToTrans = Instantiate(boxNoCollider) as GameObject;

            cubeToTrans.name = "cubeToTrans";

            LeanTween.move(cubeToTrans, cubeDest.transform, 1.2f).setEase(LeanTweenType.easeOutQuad).setOnComplete(() => {
                LeanTest.expect(cubeToTrans.transform.position == cubeDestEnd, "MOVE TO TRANSFORM WORKS");
            });

            GameObject cubeDestroy = Instantiate(boxNoCollider) as GameObject;

            cubeDestroy.name = "cubeDestroy";
            LeanTween.moveX(cubeDestroy, 200f, 0.05f).setDelay(0.02f).setDestroyOnComplete(true);
            LeanTween.moveX(cubeDestroy, 200f, 0.1f).setDestroyOnComplete(true).setOnComplete(() => {
                LeanTest.expect(true, "TWO DESTROY ON COMPLETE'S SUCCEED");
            });

            GameObject cubeSpline = Instantiate(boxNoCollider) as GameObject;

            cubeSpline.name = "cubeSpline";
            LeanTween.moveSpline(cubeSpline, new Vector3[] { new Vector3(0.5f, 0f, 0.5f), new Vector3(0.75f, 0f, 0.75f), new Vector3(1f, 0f, 1f), new Vector3(1f, 0f, 1f) }, 0.1f).setOnComplete(() => {
                LeanTest.expect(Vector3.Distance(new Vector3(1f, 0f, 1f), cubeSpline.transform.position) < 0.01f, "SPLINE WITH TWO POINTS SUCCEEDS");
            });

            // This test works when it is positioned last in the test queue (probably worth fixing when you have time)
            GameObject jumpCube = Instantiate(boxNoCollider) as GameObject;

            jumpCube.name = "jumpTime";
            int jumpTimeId = LeanTween.moveX(jumpCube, 1f, 1f).id;

            LeanTween.delayedCall(jumpCube, 0.2f, () => {
                LTDescr d     = LeanTween.descr(jumpTimeId);
                float beforeX = jumpCube.transform.position.x;
                d.setTime(0.5f);
                LeanTween.delayedCall(0.01f, () => { }).setOnStart(() => {
                    LeanTest.expect(Mathf.Abs(jumpCube.transform.position.x - beforeX) < 0.01f, "CHANGING TIME DOESN'T JUMP AHEAD", "Difference:" + Mathf.Abs(jumpCube.transform.position.x - beforeX));
                });
            });

            // Tween with time of zero is needs to be set to it's final value
            GameObject zeroCube = Instantiate(boxNoCollider) as GameObject;

            zeroCube.name = "zeroCube";
            LeanTween.moveX(zeroCube, 10f, 0f).setOnComplete(() => {
                LeanTest.expect(zeroCube.transform.position.x == 10f, "ZERO TIME FINSHES CORRECTLY", "final x:" + zeroCube.transform.position.x);
            });

            StartCoroutine(timeBasedTesting());
        }