void Start()
    {
        Application.targetFrameRate = 240;

        // Make the track from the provided transforms
        List<Vector3> randList = new List<Vector3>();
        float degree = 0f;
        int nodeLength = trackNodes + 1;// We need to add some extra because the first and last nodes just act as *guides* to the first and last curvature
        for(int i = 0; i < nodeLength; i++){
            float x = Mathf.Cos( degree * Mathf.Deg2Rad ) * circleLength + Random.Range(0f, randomRange);
            float z = Mathf.Sin( degree * Mathf.Deg2Rad ) * circleLength + Random.Range(0f, randomRange);
            randList.Add( new Vector3(x,1f,z ) );

            degree += 360f/(float)trackNodes;
        }
        randList[0] = randList[ randList.Count-1 ]; // set the zero-ith one as the last position so it will flow smoothly into the first curve
        randList.Add( randList[1] ); // Add the first and second one in, so the circle connects to itself
        randList.Add( randList[2] );

        track = new LTSpline( randList.ToArray() );

        carAdd = carSpeed / track.distance;

        tracerSpeed = track.distance / (carSpeed*1.2f);

        // Optional technique to show the trails in game
        LeanTween.moveSpline( trackTrailRenderers, track, tracerSpeed ).setOrientToPath(true).setRepeat(-1);
    }
예제 #2
0
	void Start () {
		cr = new LTSpline( new Vector3[] {trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position} );
		ltLogo = GameObject.Find("LeanTweenLogo1");
		ltLogo2 = GameObject.Find("LeanTweenLogo2");

		LeanTween.moveSpline( ltLogo2, new Vector3[] {trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position}, 1f).setEase(LeanTweenType.easeInOutQuad).setLoopPingPong().setOrientToPath(true);
	}
 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
 }
예제 #4
0
    void Start()
    {
        // Make the track from the provided transforms
        track = new LTSpline( new Vector3[] {trackOnePoints[0].position, trackOnePoints[1].position, trackOnePoints[2].position, trackOnePoints[3].position, trackOnePoints[4].position, trackOnePoints[5].position, trackOnePoints[6].position} );

        // Optional technique to show the trails in game
        LeanTween.moveSpline( trackTrailRenderers, track, 2f ).setOrientToPath(true).setRepeat(-1);
    }
예제 #5
0
	void Start () {
		cr = new LTSpline( new Vector3[] {trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position} );
		ltLogo = GameObject.Find("LeanTweenLogo1");
		ltLogo2 = GameObject.Find("LeanTweenLogo2");

		// LeanTween.moveSpline( ltLogo2, new Vector3[] {trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position}, 1f).setEase(LeanTweenType.easeInOutQuad).setLoopPingPong().setOrientToPath(true);

		LTDescr zoomInPath_LT = LeanTween.moveSpline(ltLogo2, new Vector3[]{Vector3.zero, Vector3.zero, new Vector3(1,1,1), new Vector3(2,1,1), new Vector3(2,1,1)}, 1.5f);
		zoomInPath_LT.setUseEstimatedTime(true);
	}
예제 #6
0
	void Start () {
		cr = new LTSpline( new Vector3[] {trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position} );
		sprite1 = GameObject.Find("sprite1");
		sprite2 = GameObject.Find("sprite2");
		#if !(UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
			sprite1.AddComponent<SpriteRenderer>();
			sprite1.GetComponent<SpriteRenderer>().sprite = Sprite.Create( spriteTexture, new Rect(0.0f,0.0f,100.0f,100.0f), new Vector2(50.0f,50.0f), 10.0f);
			sprite2.AddComponent<SpriteRenderer>();
			sprite2.GetComponent<SpriteRenderer>().sprite = Sprite.Create( spriteTexture, new Rect(0.0f,0.0f,100.0f,100.0f), new Vector2(0.0f,0.0f), 10.0f);
		#endif
		// LeanTween.moveSpline( ltLogo2, new Vector3[] {trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position}, 1f).setEase(LeanTweenType.easeInOutQuad).setLoopPingPong().setOrientToPath(true);

		LTDescr zoomInPath_LT = LeanTween.moveSpline(sprite2, new Vector3[]{Vector3.zero, Vector3.zero, new Vector3(1,1,1), new Vector3(2,1,1), new Vector3(2,1,1)}, 1.5f).setOrientToPath2d(true);
		zoomInPath_LT.setUseEstimatedTime(true);
	}
예제 #7
0
    static int get_pts(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LTSpline obj = (LTSpline)o;
            UnityEngine.Vector3[] ret = obj.pts;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index pts on a nil value"));
        }
    }
예제 #8
0
    static int get_constantSpeed(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LTSpline obj = (LTSpline)o;
            bool     ret = obj.constantSpeed;
            LuaDLL.lua_pushboolean(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index constantSpeed on a nil value"));
        }
    }
예제 #9
0
    static int get_distance(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LTSpline obj = (LTSpline)o;
            float    ret = obj.distance;
            LuaDLL.lua_pushnumber(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index distance on a nil value"));
        }
    }
예제 #10
0
    void Start()
    {
        Vector3[] path = new Vector3[] {
            cubes[0].position,
            cubes[1].position,
            cubes[2].position,
            cubes[3].position,
            cubes[4].position
        };

        visualizePath = new LTSpline(path);
        // move
        LeanTween.moveSpline(dude1, path, 10f).setOrientToPath2d(true).setSpeed(2f);

        // move Local
        LeanTween.moveSplineLocal(dude2, path, 10f).setOrientToPath2d(true).setSpeed(2f);
    }
예제 #11
0
 static int drawLinesGLLines(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 4);
         LTSpline             obj  = (LTSpline)ToLua.CheckObject <LTSpline>(L, 1);
         UnityEngine.Material arg0 = (UnityEngine.Material)ToLua.CheckObject <UnityEngine.Material>(L, 2);
         UnityEngine.Color    arg1 = ToLua.ToColor(L, 3);
         float arg2 = (float)LuaDLL.luaL_checknumber(L, 4);
         obj.drawLinesGLLines(arg0, arg1, arg2);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
예제 #12
0
 static public int drawLinesGLLines(IntPtr l)
 {
     try {
         LTSpline             self = (LTSpline)checkSelf(l);
         UnityEngine.Material a1;
         checkType(l, 2, out a1);
         UnityEngine.Color a2;
         checkType(l, 3, out a2);
         System.Single a3;
         checkType(l, 4, out a3);
         self.drawLinesGLLines(a1, a2, a3);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #13
0
    private void GiveCardToHand(List <Card> deck, Transform hand, int i)
    {
        if (deck.Count == 0)
        {
            return;
        }

        Card card = deck[0];

        GameObject cardGO = Instantiate(cardPref, hand, false);
        LTSpline   spline = new LTSpline(path);

        spline.place2d(cardGO.transform, .2f * i);
        LeanTween.move(cardGO, path[i], .1f);
        cardGO.GetComponent <CardInfo>().ShowCardInfo(card);
        playerHandCards.Add(cardGO.GetComponent <CardInfo>());
        deck.RemoveAt(0);
    }
예제 #14
0
    void Start()
    {
        Vector3[] points = new Vector3[waypoints.Length];
        for (int i = 0; i < waypoints.Length; i++)
        {
            points[i] = waypoints[i].position;
        }
        pathIntro = new LTSpline(points);

        System.Array.Reverse(points);
        pathEnding = new LTSpline(points);

        if (enableRotation)
        {
            Rotation();
        }
        LeanTween.moveSpline(gameObject, pathIntro, movementDuration).setOrientToPath(true).setOnStart(OnStart.Invoke).setOnComplete(OnComplete.Invoke);
    }
예제 #15
0
    public void OnDrawGizmos()
    {
        init();

        if (pathType == LeanTweenPathType.bezier)
        {
            for (int i = 0; i < pts.Length - 3; i += 4)
            {
                if (pts[i + 1] && pts[i + 2] && pts[i + 3])
                {
                    Vector3 first = i > 3 ? pts[i - 1].position : pts[i].position;

                    Gizmos.color = Color.magenta;
                    LeanTween.drawBezierPath(first, pts[i + 2].position, pts[i + 1].position, pts[i + 3].position);

                    Gizmos.color = Color.white;
                    Gizmos.DrawLine(first, pts[i + 2].position);
                    Gizmos.DrawLine(pts[i + 1].position, pts[i + 3].position);
                }
            }
            for (int i = 0; i < pts.Length; i++)
            {
                int  iMod    = i % 4;
                bool isPoint = iMod == 0 || iMod == 3;
                if (pts[i])
                {
                    pts[i].localScale = isPoint ? Vector3.one * controlSize * 0.5f : new Vector3(1f, 1f, 0.5f) * controlSize * 0.5f;
                }
            }
        }
        else
        {
            for (i = 0; i < pts.Length; i++)
            {
                if (pts[i])
                {
                    pts[i].localScale = Vector3.one * controlSize * 0.25f;
                }
            }
            LTSpline s = new LTSpline(splineVector());
            Gizmos.color = Color.magenta;
            s.gizmoDraw();
        }
    }
예제 #16
0
    void LeavePath(bool setVelocity = true)
    {
        // Set velocity according to last direction of travel on path
        int     last      = currentPathVectors.Length - 1;
        Vector2 direction = (currentPathVectors[last] - currentPathVectors[last - 1]).normalized;

        if (setVelocity)
        {
            velocity = direction * offPathSpeed;
        }

        // Exit from end of path
        Debug.Log("exiting path!");
        LeanTween.cancel(gameObject);
        onPath             = false;
        currentPath        = null;
        currentPathVectors = null;
        currentSpline      = null;
    }
예제 #17
0
 void Start()
 {
     init();
     for (i = 0; i < pts.Length; i++)
     {
         if (pts[i])
         {
             pts[i].gameObject.SetActive(false);
         }
     }
     if (pathType == LeanTweenPathType.bezier)
     {
         this.bezierPath = new LTBezierPath(this.vec3);
     }
     else
     {
         this.splinePath = new LTSpline(this.splineVector());
     }
 }
예제 #18
0
    private void Start()
    {
        // select every transform.position from the List<Transform> Points
        spline = new LTSpline(Points.Select(transform => transform.position).ToArray());

        initialRotation = transform.rotation;
        finalRotation   = Points.Last().rotation;

        if (StartPingPongOnLoad)
        {
            movement = LeanTween.moveSpline(gameObject, spline.pts, MovementSpeed).setEase(LeanTweenType.easeInOutQuad).setLoopPingPong();
            rotation = LeanTween.rotate(gameObject, finalRotation.eulerAngles, MovementSpeed).setLoopPingPong();
        }
        else
        {
            GameEvents.Instance.onMovingBlockTriggerEnter += OnMovingBlockTriggerEnter;
            GameEvents.Instance.onMovingBlockTriggerExit  += OnMovingBlockTriggerExit;
        }
    }
    private void OnDrawGizmos()
    {
        if (ShowGizmos)
        {
            wayPoints = new Vector3[waypoint.childCount];
            for (int i = 0; i < waypoint.childCount; i++)
            {
                wayPoints[i] = waypoint.GetChild(i).transform.position;
            }

            spline = new LTSpline(wayPoints);

            Gizmos.color = Color.blue;
            if (spline != null)
            {
                spline.gizmoDraw();
            }
        }
    }
    private void Start()
    {
        if (waypoint == null)
        {
            waypoint = transform;
        }

        cameraInitPosition = objectCamera.transform.position;

        if (waypoint.childCount > 0)
        {
            wayPoints = new Vector3[waypoint.childCount];
            for (int i = 0; i < waypoint.childCount; i++)
            {
                wayPoints[i] = waypoint.GetChild(i).transform.position;
            }

            spline = new LTSpline(wayPoints);
        }
    }
예제 #21
0
        public override void SpawnUnits(int numUnits)
        {
            for (int i = 0; i < numUnits; i++)
            {
                var go = Instantiate(abaUnitPrefab);
                go.transform.position = GetEdgePointWithinInfluence();

                go.transform.SetParent(unitsContainer);
                var unit = go.GetComponent <AbaUnit>();
                unit.agent.map = map;
                unit.tower     = this;

                var scale = unit.transform.localScale;
                unit.transform.localScale = Vector3.zero;

                unitSpawnTrail.emitting = true;
                unitSpawnTrail.transform.localPosition = Vector2.zero;
                AddUnit(unit);
                var      seq      = LeanTween.sequence();
                LTSpline ltSpline = new LTSpline(
                    new Vector3[] {
                    new Vector3(UnityEngine.Random.Range(0, 1), UnityEngine.Random.Range(0, 1), 0f),
                    transform.position,
                    unit.transform.position,
                    new Vector3(UnityEngine.Random.Range(0, 1), UnityEngine.Random.Range(0, 1), 0f)
                });
                seq.append(LeanTween.moveSpline(unitSpawnTrail.gameObject, ltSpline, 0.1f));

                seq.append(LeanTween.scale(unit.gameObject, scale * 2, 0.1f));
                seq.append(LeanTween.scale(unit.gameObject, scale, 0.25f));
                seq.append(() =>
                {
                    if (unitSpawnTrail)
                    {
                        //Debug.Break();
                        unitSpawnTrail.emitting = false;
                        unitSpawnTrail.transform.localPosition = Vector2.zero;
                    }
                });
            }
        }
예제 #22
0
    // Use this for initialization
    void Start()
    {
        rend        = GetComponent <LineRenderer>();
        pathVectors = new Vector3[rend.positionCount];
        numVectors  = rend.GetPositions(pathVectors);

        // Set up collider and its requisite rigidbody
        rb          = gameObject.AddComponent(typeof(Rigidbody2D)) as Rigidbody2D;
        rb.bodyType = RigidbodyType2D.Kinematic;
        GameObject cdGO = new GameObject("Collider");

        cdGO.layer            = LayerMask.NameToLayer("Path");
        cdGO.transform.parent = gameObject.transform;
        cd           = cdGO.AddComponent(typeof(EdgeCollider2D)) as EdgeCollider2D;
        cd.points    = ConvertToVector2Array(pathVectors);
        cd.isTrigger = true;
        pathSpline   = SplineHelper.CreateSpline(pathVectors);

        rend.sortingLayerName = "Character";

        // Get position with largest x value (used to determine whether path is still on screen)
        maxX = GetMaximumXVector();
        LevelManager lm = GameObject.FindWithTag("GameController").GetComponent <LevelManager>();

        lm.paths.Add(this);

        if (unidirectional)
        {
            shine = new GameObject("Shine");
            GameObject     shineRendGO = (GameObject)Instantiate(Resources.Load("Prefabs/RoundShine"));
            SpriteRenderer shineRend   = shineRendGO.GetComponent <SpriteRenderer>();
            shineRend.sortingLayerName     = "Character";
            shineRend.color                = new Color(rend.material.color.r, rend.material.color.g, rend.material.color.b, .75f);
            shine.transform.parent         = gameObject.transform;
            shineRendGO.transform.parent   = shine.transform;
            shineRendGO.transform.position = new Vector3(shine.transform.position.x, shine.transform.position.y, shine.transform.position.z + 1);
            ShinePathDirection();
        }
    }
예제 #23
0
 public static void drawGizmo(Transform[] arr, Color color)
 {
     if ((int)arr.Length >= 4)
     {
         Vector3[] vector3Array = new Vector3[(int)arr.Length];
         for (int i = 0; i < (int)arr.Length; i++)
         {
             vector3Array[i] = arr[i].position;
         }
         LTSpline lTSpline = new LTSpline(vector3Array);
         Vector3  vector3  = lTSpline.ptsAdj[0];
         Color    color1   = Gizmos.color;
         Gizmos.color = color;
         for (int j = 0; j < lTSpline.ptsAdjLength; j++)
         {
             Vector3 vector31 = lTSpline.ptsAdj[j];
             Gizmos.DrawLine(vector3, vector31);
             vector3 = vector31;
         }
         Gizmos.color = color1;
     }
 }
예제 #24
0
 public static void drawGizmo(Transform[] arr, Color color)
 {
     if (arr.Length >= 4)
     {
         Vector3[] array = new Vector3[arr.Length];
         for (int i = 0; i < arr.Length; i++)
         {
             array[i] = arr[i].position;
         }
         LTSpline lTSpline = new LTSpline(array);
         Vector3  from     = lTSpline.ptsAdj[0];
         Color    color2   = Gizmos.color;
         Gizmos.color = color;
         for (int j = 0; j < lTSpline.ptsAdjLength; j++)
         {
             Vector3 vector = lTSpline.ptsAdj[j];
             Gizmos.DrawLine(from, vector);
             from = vector;
         }
         Gizmos.color = color2;
     }
 }
예제 #25
0
    static int _CreateLTSpline(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (TypeChecker.CheckParamsType(L, typeof(UnityEngine.Vector3), 1, count))
            {
                UnityEngine.Vector3[] arg0 = ToLua.CheckParamsObject <UnityEngine.Vector3>(L, 1, count);
                LTSpline obj = new LTSpline(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: LTSpline.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
예제 #26
0
	static int _CreateLTSpline(IntPtr L)
	{
		try
		{
			int count = LuaDLL.lua_gettop(L);

			if (TypeChecker.CheckParamsType(L, typeof(UnityEngine.Vector3), 1, count))
			{
				UnityEngine.Vector3[] arg0 = ToLua.CheckParamsObject<UnityEngine.Vector3>(L, 1, count);
				LTSpline obj = new LTSpline(arg0);
				ToLua.PushObject(L, obj);
				return 1;
			}
			else
			{
				return LuaDLL.luaL_throw(L, "invalid arguments to ctor method: LTSpline.New");
			}
		}
		catch(Exception e)
		{
			return LuaDLL.toluaL_exception(L, e);
		}
	}
예제 #27
0
        private void SendTrail(float duration)
        {
            var go = Instantiate(trailPrefab);

            go.transform.position = transform.position;
            var currencyRT =
                Util.bootController.gameplayUI.currencyContainer.GetComponent <RectTransform>();

            var targetPos = Util.GetUIWorldPos(currencyRT);

            targetPos.z = transform.position.z;

            LTSpline ltSpline = new LTSpline(
                new Vector3[] {
                new Vector3(UnityEngine.Random.Range(-10, 10), UnityEngine.Random.Range(-10, 10), 0f),
                transform.position,
                targetPos,
                targetPos
            });

            // for (int i = 0; i < 10; i++)
            // {
            //     if (i + 1 < 10)
            //     {
            //         var point1 = ltSpline.point(i / 10.0f);
            //         var point2 = ltSpline.point((i + 1) / 10.0f);
            //         Debug.DrawLine(point1, point2, Color.red);
            //     }
            // }

            // Debug.Break();

            LeanTween.moveSpline(go, ltSpline, duration).setOnComplete(() =>
            {
                Destroy(go);
            });
        }
예제 #28
0
 static public int placeLocal(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 3)
         {
             LTSpline self = (LTSpline)checkSelf(l);
             UnityEngine.Transform a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             self.placeLocal(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 4)
         {
             LTSpline self = (LTSpline)checkSelf(l);
             UnityEngine.Transform a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             UnityEngine.Vector3 a3;
             checkType(l, 4, out a3);
             self.placeLocal(a1, a2, a3);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function placeLocal to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #29
0
 static public int drawLinesGLLines(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.Material a1;
         checkType(l, 2, out a1);
         UnityEngine.Color a2;
         checkType(l, 3, out a2);
         System.Single a3;
         checkType(l, 4, out a3);
         self.drawLinesGLLines(a1, a2, a3);
         pushValue(l, true);
         return(1);
     }
     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
 }
예제 #30
0
        void Start()
        {
            //			Time.timeScale = 0.25f;

            LeanTest.timeout = 46f;
            LeanTest.expected = 56;

            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();

            // Queue up a bunch of tweens, cancel some of them but expect the remainder to finish
            GameObject[] cubes = new GameObject[99];
            int[] tweenIds = new int[cubes.Length];
            for (int i = 0; i < cubes.Length; i++) {
                GameObject c = cubeNamed("cancel"+i);
                tweenIds[i] = LeanTween.moveX (c, 100f, 1f).id;
                cubes [i] = c;
            }
            int onCompleteCount = 0;
            LeanTween.delayedCall (cubes[0], 0.2f, () => {
                for (int i = 0; i < cubes.Length; i++) {
                    if(i%3==0){
                        LeanTween.cancel( cubes [i] );
                    }else if(i%3==1){
                        LeanTween.cancel( tweenIds[i] );
                    }else if(i%3==2){
                        LTDescr descr = LeanTween.descr(tweenIds[i]);
            //						Debug.Log("descr:"+descr);
                        descr.setOnComplete( ()=>{
                            onCompleteCount++;
            //							Debug.Log("onCompleteCount:"+onCompleteCount);
                            if(onCompleteCount>=33){
                                LeanTest.expect(true, "CANCELS DO NOT EFFECT FINISHING" );
                            }
                        });
                    }
                }
            });

            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 cubeDest = cubeNamed("cubeDest");
            Vector3 cubeDestEnd = new Vector3(100f,20f,0f);
            LeanTween.move( cubeDest, cubeDestEnd, 0.7f);

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

            GameObject cubeDestroy = cubeNamed("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 = cubeNamed("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 = cubeNamed("jumpTime");
            jumpCube.transform.position = new Vector3(100f,0f,0f);
            jumpCube.transform.localScale *= 100f;
            int jumpTimeId = LeanTween.moveX( jumpCube, 200f, 1f).id;

            LeanTween.delayedCall(gameObject, 0.2f, ()=>{
                LTDescr d = LeanTween.descr( jumpTimeId );
                float beforeX = jumpCube.transform.position.x;
                d.setTime( 0.5f );
                LeanTween.delayedCall( 0.0f, ()=>{ }).setOnStart( ()=>{
                    float diffAmt = 1f;// This variable is dependent on a good frame-rate because it evalutes at the next Update
                    beforeX += Time.deltaTime * 100f * 2f;
                    LeanTest.expect( Mathf.Abs( jumpCube.transform.position.x - beforeX ) < diffAmt , "CHANGING TIME DOESN'T JUMP AHEAD", "Difference:"+Mathf.Abs( jumpCube.transform.position.x - beforeX ) +" beforeX:"+beforeX+" now:"+jumpCube.transform.position.x+" dt:"+Time.deltaTime);
                });
            });

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

            // Scale, and OnStart
            GameObject cubeScale = cubeNamed("cubeScale");
            LeanTween.scale(cubeScale, new Vector3(5f,5f,5f),0.01f).setOnStart(()=>{
                LeanTest.expect( true, "ON START WAS CALLED");
            }).setOnComplete(()=>{
                LeanTest.expect( cubeScale.transform.localScale.z == 5f, "SCALE","expected scale z:"+5f+" returned:"+cubeScale.transform.localScale.z);
            });

            // Rotate
            GameObject cubeRotate = cubeNamed("cubeRotate");
            LeanTween.rotate(cubeRotate, new Vector3(0f,180f,0f),0.02f).setOnComplete(()=>{
                LeanTest.expect( cubeRotate.transform.eulerAngles.y == 180f, "ROTATE","expected rotate y:"+180f+" returned:"+cubeRotate.transform.eulerAngles.y);
            });

            // RotateAround
            GameObject cubeRotateA = cubeNamed("cubeRotateA");
            LeanTween.rotateAround(cubeRotateA,Vector3.forward,90f,0.3f).setOnComplete(()=>{
                LeanTest.expect( cubeRotateA.transform.eulerAngles.z==90f, "ROTATE AROUND","expected rotate z:"+90f+" returned:"+cubeRotateA.transform.eulerAngles.z);
            });

            // RotateAround 360
            GameObject cubeRotateB = cubeNamed("cubeRotateB");
            cubeRotateB.transform.position = new Vector3(200f,10f,8f);
            LeanTween.rotateAround(cubeRotateB,Vector3.forward,360f,0.3f).setPoint(new Vector3(5f,3f,2f)).setOnComplete(()=>{
                LeanTest.expect( cubeRotateB.transform.position.ToString()==(new Vector3(200f,10f,8f)).ToString(), "ROTATE AROUND 360","expected rotate pos:"+(new Vector3(200f,10f,8f))+" returned:"+cubeRotateB.transform.position);
            });

            // Alpha, onUpdate with passing value, onComplete value
            LeanTween.alpha(cubeAlpha1,0.5f,0.1f).setOnUpdate( (float val)=>{
                LeanTest.expect(val!=0f ,"ON UPDATE VAL");
            }).setOnCompleteParam( "Hi!" ).setOnComplete( (object completeObj)=>{
                LeanTest.expect(((string)completeObj)=="Hi!","ONCOMPLETE OBJECT");
                LeanTest.expect(cubeAlpha1.GetComponent<Renderer>().material.color.a == 0.5f,"ALPHA");
            });
            // Color
            float onStartTime = -1f;
            LeanTween.color(cubeAlpha2, Color.cyan, 0.3f).setOnComplete( ()=>{
                LeanTest.expect(cubeAlpha2.GetComponent<Renderer>().material.color==Color.cyan, "COLOR");
                LeanTest.expect(onStartTime>=0f && onStartTime<Time.time, "ON START","onStartTime:"+onStartTime+" time:"+Time.time);
            }).setOnStart(()=>{
                onStartTime = Time.time;
            });
            // moveLocalY (make sure uses y values)
            Vector3 beforePos = cubeAlpha1.transform.position;
            LeanTween.moveY(cubeAlpha1, 3f, 0.2f).setOnComplete( ()=>{
                LeanTest.expect(cubeAlpha1.transform.position.x==beforePos.x && cubeAlpha1.transform.position.z==beforePos.z,"MOVE Y");
            });

            Vector3 beforePos2 = cubeAlpha2.transform.localPosition;
            LeanTween.moveLocalZ(cubeAlpha2, 12f, 0.2f).setOnComplete( ()=>{
                LeanTest.expect(cubeAlpha2.transform.localPosition.x==beforePos2.x && cubeAlpha2.transform.localPosition.y==beforePos2.y,"MOVE LOCAL Z","ax:"+cubeAlpha2.transform.localPosition.x+" bx:"+beforePos.x+" ay:"+cubeAlpha2.transform.localPosition.y+" by:"+beforePos2.y);
            });

            AudioClip audioClip = LeanAudio.createAudio(new AnimationCurve( new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f)), new AnimationCurve( new Keyframe(0f, 0.001f, 0f, 0f), new Keyframe(1f, 0.001f, 0f, 0f)), LeanAudio.options());
            LeanTween.delayedSound(gameObject, audioClip, new Vector3(0f,0f,0f), 0.1f).setDelay(0.2f).setOnComplete( ()=>{
                LeanTest.expect(Time.time>0,"DELAYED SOUND");
            });

            // value2
            bool value2UpdateCalled = false;
            LeanTween.value(gameObject, new Vector2(0, 0), new Vector2(256, 96), 0.1f).setOnUpdate((Vector2 value) => {
                value2UpdateCalled = true;
            });
            LeanTween.delayedCall(0.2f, ()=>{
                LeanTest.expect( value2UpdateCalled, "VALUE2 UPDATE");
            } );

            StartCoroutine( timeBasedTesting() );
        }
예제 #31
0
    //=====================================================
    // Start cutscene. Optional param could be used for door-bolt-index
    public void OnStartCutscene(eCutsceneType cutsceneType, ICutsceneObject cutsceneObject = null, int param = 0)
    {
        Debug.Log("OnStartCutscene");

        // Clear for now - set after fade-in to cutscene
        _currentCutscene = eCutsceneType.NULL;

        // Set up cutscene stuff then fade-out -> fade-in to cutscene -> fade-out (optional fade-in to same scene)
        _cutsceneType   = cutsceneType;
        _cutsceneObject = cutsceneObject;
        _cutsceneTimer  = (_cutsceneObject != null) ? _cutsceneObject.CutsceneDuration() : 2.5f;

        // Is the cutscene using a camera fly-thru object
        if (cutsceneObject != null && cutsceneObject.IsFlyThruAvailable() == true)
        {
            _cameraPathAnimator = cutsceneObject.GetFlyThruAnimator();
        }

        _cameraPath = (_cameraPathAnimator == null && _cutsceneObject != null) ? _cutsceneObject.CameraPath() : null;

        _fadeSpeed       = 1.0f;
        _isFadeCompelete = false;

        switch (_cutsceneType)
        {
        case eCutsceneType.RETURN_TO_START:
        case eCutsceneType.GO_TO_COMMON_ROOM:
        case eCutsceneType.CRAWL_DOOR:
        case eCutsceneType.OBLIVION_PORTAL:
        case eCutsceneType.ENTER_PUZZLE_ROOM:
        case eCutsceneType.LEAVE_PUZZLE_ROOM:
        case eCutsceneType.ENTER_PLAYER_HUB:
        case eCutsceneType.LEAVE_PLAYER_HUB:
        case eCutsceneType.ENTER_BOSS_ROOM:
        case eCutsceneType.LEAVE_BOSS_ROOM:
        case eCutsceneType.COLLECT_KEY:
        case eCutsceneType.SWITCH_OPENS_DOOR_BOLT_01:
        case eCutsceneType.SWITCH_OPENS_DOOR_BOLT_02:
        case eCutsceneType.SWITCH_OPENS_DOOR_BOLT_03:
        case eCutsceneType.SWITCH_OPENS_DOOR:
        case eCutsceneType.SWITCH_ACTIVATES_PLATFORM:
        case eCutsceneType.OPEN_CHEST:
        case eCutsceneType.DEATH_RESPAWN:
        case eCutsceneType.DEATH:
        case eCutsceneType.FLY_THRU:
        case eCutsceneType.BOSS_ROOM_START:
        case eCutsceneType.BOSS_ROOM_BOSS_LOSES:
        case eCutsceneType.BOSS_ROOM_BOSS_WINS:
            _fadeSpeed = 1.0f;
            break;
        }

        _durationStartToEnd = _cutsceneTimer;

        // Fade out from game -> fade in to cutscene
        if (cutsceneType != eCutsceneType.NULL &&
            cutsceneType != eCutsceneType.GO_TO_COMMON_ROOM &&
            cutsceneType != eCutsceneType.RETURN_TO_START &&
            cutsceneType != eCutsceneType.DEATH_RESPAWN &&
            cutsceneType != eCutsceneType.DEATH &&
            _cutsceneType != eCutsceneType.BOSS_ROOM_START)
        {
            ScreenManager.FadeOutCompleteEvent += OnPreCutsceneFadeOutCompleteEvent;
            ScreenManager.FadeOut(_fadeSpeed);
        }
        // Fade in to Boss game immediately
        else if (_cutsceneType == eCutsceneType.BOSS_ROOM_START)
        {
            Invoke("OnPreCutsceneFadeOutCompleteEvent", 0.5f);
        }
        // Fade out from game -> no cutscene
        else
        {
            ScreenManager.FadeOutCompleteEvent += OnPostCutsceneFadeOutCompleteEvent;
            ScreenManager.FadeOut(_fadeSpeed);

            _currentCutscene = cutsceneType;
        }

        // Block player input
        if (InputManager.Instance != null)
        {
            InputManager.Instance.OnBlockInput(true);
        }
    }
예제 #32
0
 void Start()
 {
     s = new LTSpline(ltPath.splineVector());
 }
예제 #33
0
	/**
	* Set the direction of a tween -1f for backwards 1f for forwards (currently only bezier and spline paths are supported)
	* @method setDirection ()
	* @param {float} direction:float the direction that the tween should run, -1f for backwards 1f for forwards
	* @return {LTDescr} LTDescr an object that distinguishes the tween
	* @example
	* LeanTween.moveSpline(gameObject, new Vector3[]{new Vector3(0f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,0f),new Vector3(1f,0f,1f)}, 1.5f).setDirection(-1f);<br>
	*/

	public LTDescr setDirection( float direction )
	{
		if(this.direction!=-1f && this.direction!=1f)
		{
			Debug.LogWarning("You have passed an incorrect direction of '"+direction+"', direction must be -1f or 1f");
			return this;
		}

		if(this.direction!=direction)
		{
			// Debug.Log("reverse path:"+this.path+" spline:"+this.spline);
			if(this.path!=null)
			{
				this.path = new LTBezierPath( LTUtility.reverse( this.path.pts ) );
			}
			else if(this.spline!=null)
			{
				this.spline = new LTSpline( LTUtility.reverse( this.spline.pts ) );
			}
		}

		return this;
	}
예제 #34
0
 void OnEnable()
 {
     // create the path
     cr = new LTSpline(new Vector3[] { trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position });
     // cr = new LTSpline( 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)} );
 }
예제 #35
0
public static LTDescr move(GameObject gameObject, LTSpline to, float time) {
	descr = options();
	descr.spline = to;

	return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_SPLINE, descr);
}
예제 #36
0
    void Start()
    {
        LeanTest.timeout = 45f;
        LeanTest.expected = 33;

        LeanTween.init(14 + 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();

        LTSpline cr = new LTSpline( 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)} );
        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);

        // 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 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");
            });
        });

        StartCoroutine( timeBasedTesting() );
    }
예제 #37
0
	void Start () {
		s = new LTSpline( ltPath.splineVector() );
		LeanTween.moveSpline( ltLogo, s.pts, .6f).setEase(LeanTweenType.easeOutQuad);
	}
예제 #38
0
	public static LTDescr moveLocal(GameObject gameObject, LTSpline to, float time) {
		d = options().setMoveSplineLocal();
		d.optional.spline = to;

		return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, d);
	}
예제 #39
0
	public static void drawGizmo(Transform[] arr, Color color) {
		if(arr.Length>=4){
			Vector3[] vec3s = new Vector3[arr.Length];
			for(int i = 0; i < arr.Length; i++){
				vec3s[i] = arr[i].position;
			}
			LTSpline spline = new LTSpline(vec3s);
			Vector3 prevPt = spline.ptsAdj[0];

			Color colorBefore = Gizmos.color;
			Gizmos.color = color;
			for (int i = 0; i < spline.ptsAdjLength; i++) {
				Vector3 currPt2 = spline.ptsAdj[i];
				// Debug.Log("currPt2:"+currPt2);

				Gizmos.DrawLine(prevPt, currPt2);
				prevPt = currPt2;
			}
			Gizmos.color = colorBefore;
		}
	}
예제 #40
0
	// Use this for initialization
	void Start () {
		// When manually forming a spline, you must pass a beginning control point and ending control point. These points are not represented on the spline at all but effect how the spline curves.
		s = new LTSpline( new Vector3[]{ p[0].position, p[0].position, p[1].position, p[2].position, p[3].position, p[3].position } );
	}
예제 #41
0
 public static LTDescr LeanMoveSpline(this GameObject gameObject, LTSpline to, float time)
 {
     return(LeanTween.moveSpline(gameObject, to, time));
 }
예제 #42
0
	void Start () {
		LeanTest.timeout = 45f;
		LeanTest.expected = 31;

		LeanTween.init(10 + 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();


		LTSpline cr = new LTSpline( 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)} );
		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);	

		// 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;
		});

		StartCoroutine( timeBasedTesting() );
	}
예제 #43
0
	public void OnDrawGizmos(){
		init();
		
		if(pathType==LeanTweenPathType.bezier){
			for(int i = 0; i < pts.Length-3; i += 4){
				if(pts[i+1] && pts[i+2] && pts[i+3]){
					Vector3 first = i>3 ? pts[i-1].position : pts[i].position;
					
					Gizmos.color = Color.magenta;
					LeanTween.drawBezierPath(first, pts[i+2].position, pts[i+1].position, pts[i+3].position);
					
					Gizmos.color = Color.white;
					Gizmos.DrawLine(first,pts[i+2].position);
					Gizmos.DrawLine(pts[i+1].position,pts[i+3].position);
				}
			}
			for(int i = 0; i < pts.Length; i++){
				int iMod = i%4;
				bool isPoint = iMod==0||iMod==3;
				if(pts[i])
					pts[i].localScale = isPoint ? Vector3.one * controlSize * 0.5f : new Vector3(1f,1f,0.5f) * controlSize * 0.5f;
			}
		}else{
			for(i=0;i<pts.Length;i++){
				if(pts[i]){
					pts[i].localScale = Vector3.one * controlSize * 0.25f;
				}
			}
			LTSpline s = new LTSpline( splineVector() );
			Gizmos.color = Color.magenta;
			s.gizmoDraw();
		}
	}
예제 #44
0
	void Start () {
		s = new LTSpline( ltPath.splineVector() );
	}
예제 #45
0
    void Start()
    {
        LeanTest.timeout = 45f;
        LeanTest.expected = 29;

        LeanTween.init(6 + 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" );

        // 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" );

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

        LeanTween.reset();

        LTSpline cr = new LTSpline( 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)} );
        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);

        StartCoroutine( timeBasedTesting() );
    }
예제 #46
0
 // Use this for visualizing what the track looks like in the editor (for a full suite of spline tools check out the LeanTween Editor)
 void OnDrawGizmos()
 {
     LTSpline.drawGizmo(trackOnePoints, Color.red);
 }
예제 #47
0
    void Start()
    {
        LeanTest.timeout  = 46f;
        LeanTest.expected = 35;

        LeanTween.init(14 + 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();


        LTSpline cr = new LTSpline(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) });

        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);

        // 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));
            });
        });


        StartCoroutine(timeBasedTesting());
    }
예제 #48
0
	void OnEnable(){
		// create the path
		cr = new LTSpline( new Vector3[] {trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position} );
	}
예제 #49
0
 void OnEnable()
 {
     // create the path
     cr = new LTSpline( new Vector3[] {trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position} );
     // cr = new LTSpline( 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)} );
 }
예제 #50
0
 void Start()
 {
     Vector3 diff = trans[1].position - trans[0].position;
     cr = new LTSpline( new Vector3[] {trans[0].position-diff, trans[0].position, trans[1].position, trans[2].position, trans[2].position+diff} );
     ltLogo = GameObject.Find("LeanTweenLogo");
 }
예제 #51
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();

            LTSpline cr = new LTSpline( 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)} );
            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);

            // 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() );
        }
예제 #52
0
 public static LTDescr LeanMoveSpline(this Transform transform, LTSpline to, float time)
 {
     return(LeanTween.moveSpline(transform.gameObject, to, time));
 }
 public static LTDescr LTMove(this LTDescr self, LTSpline to, float time)
 {
     return LeanTween.move(self.trans.gameObject, to, time);
 }
	public static LTDescr moveLocal(GameObject gameObject, LTSpline to, float time)
	{
		d = options();
		d.spline = to;

		return pushNewTween(gameObject, new Vector3(1.0f, 0.0f, 0.0f), time, TweenAction.MOVE_SPLINE_LOCAL, d);
	}
 public static LTDescr LTMoveLocal(this Transform self, LTSpline to, float time)
 {
     return LeanTween.moveLocal(self.gameObject, to, time);
 }
예제 #56
0
        void Start()
        {
//			Time.timeScale = 0.25f;

            LeanTest.timeout  = 46f;
            LeanTest.expected = 56;

            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();

            // Queue up a bunch of tweens, cancel some of them but expect the remainder to finish
            GameObject[] cubes    = new GameObject[99];
            int[]        tweenIds = new int[cubes.Length];
            for (int i = 0; i < cubes.Length; i++)
            {
                GameObject c = cubeNamed("cancel" + i);
                tweenIds[i] = LeanTween.moveX(c, 100f, 1f).id;
                cubes [i]   = c;
            }
            int onCompleteCount = 0;

            LeanTween.delayedCall(cubes[0], 0.2f, () => {
                for (int i = 0; i < cubes.Length; i++)
                {
                    if (i % 3 == 0)
                    {
                        LeanTween.cancel(cubes [i]);
                    }
                    else if (i % 3 == 1)
                    {
                        LeanTween.cancel(tweenIds[i]);
                    }
                    else if (i % 3 == 2)
                    {
                        LTDescr descr = LeanTween.descr(tweenIds[i]);
//						Debug.Log("descr:"+descr);
                        descr.setOnComplete(() => {
                            onCompleteCount++;
//							Debug.Log("onCompleteCount:"+onCompleteCount);
                            if (onCompleteCount >= 33)
                            {
                                LeanTest.expect(true, "CANCELS DO NOT EFFECT FINISHING");
                            }
                        });
                    }
                }
            });

            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 cubeDest    = cubeNamed("cubeDest");
            Vector3    cubeDestEnd = new Vector3(100f, 20f, 0f);

            LeanTween.move(cubeDest, cubeDestEnd, 0.7f);

            GameObject cubeToTrans = cubeNamed("cubeToTrans");

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

            GameObject cubeDestroy = cubeNamed("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 = cubeNamed("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 = cubeNamed("jumpTime");

            jumpCube.transform.position    = new Vector3(100f, 0f, 0f);
            jumpCube.transform.localScale *= 100f;
            int jumpTimeId = LeanTween.moveX(jumpCube, 200f, 1f).id;

            LeanTween.delayedCall(gameObject, 0.2f, () => {
                LTDescr d     = LeanTween.descr(jumpTimeId);
                float beforeX = jumpCube.transform.position.x;
                d.setTime(0.5f);
                LeanTween.delayedCall(0.0f, () => { }).setOnStart(() => {
                    float diffAmt = 1f;                    // This variable is dependent on a good frame-rate because it evalutes at the next Update
                    beforeX      += Time.deltaTime * 100f * 2f;
                    LeanTest.expect(Mathf.Abs(jumpCube.transform.position.x - beforeX) < diffAmt, "CHANGING TIME DOESN'T JUMP AHEAD", "Difference:" + Mathf.Abs(jumpCube.transform.position.x - beforeX) + " beforeX:" + beforeX + " now:" + jumpCube.transform.position.x + " dt:" + Time.deltaTime);
                });
            });

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

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

            // Scale, and OnStart
            GameObject cubeScale = cubeNamed("cubeScale");

            LeanTween.scale(cubeScale, new Vector3(5f, 5f, 5f), 0.01f).setOnStart(() => {
                LeanTest.expect(true, "ON START WAS CALLED");
            }).setOnComplete(() => {
                LeanTest.expect(cubeScale.transform.localScale.z == 5f, "SCALE", "expected scale z:" + 5f + " returned:" + cubeScale.transform.localScale.z);
            });

            // Rotate
            GameObject cubeRotate = cubeNamed("cubeRotate");

            LeanTween.rotate(cubeRotate, new Vector3(0f, 180f, 0f), 0.02f).setOnComplete(() => {
                LeanTest.expect(cubeRotate.transform.eulerAngles.y == 180f, "ROTATE", "expected rotate y:" + 180f + " returned:" + cubeRotate.transform.eulerAngles.y);
            });

            // RotateAround
            GameObject cubeRotateA = cubeNamed("cubeRotateA");

            LeanTween.rotateAround(cubeRotateA, Vector3.forward, 90f, 0.3f).setOnComplete(() => {
                LeanTest.expect(cubeRotateA.transform.eulerAngles.z == 90f, "ROTATE AROUND", "expected rotate z:" + 90f + " returned:" + cubeRotateA.transform.eulerAngles.z);
            });

            // RotateAround 360
            GameObject cubeRotateB = cubeNamed("cubeRotateB");

            cubeRotateB.transform.position = new Vector3(200f, 10f, 8f);
            LeanTween.rotateAround(cubeRotateB, Vector3.forward, 360f, 0.3f).setPoint(new Vector3(5f, 3f, 2f)).setOnComplete(() => {
                LeanTest.expect(cubeRotateB.transform.position.ToString() == (new Vector3(200f, 10f, 8f)).ToString(), "ROTATE AROUND 360", "expected rotate pos:" + (new Vector3(200f, 10f, 8f)) + " returned:" + cubeRotateB.transform.position);
            });

            // Alpha, onUpdate with passing value, onComplete value
            LeanTween.alpha(cubeAlpha1, 0.5f, 0.1f).setOnUpdate((float val) => {
                LeanTest.expect(val != 0f, "ON UPDATE VAL");
            }).setOnCompleteParam("Hi!").setOnComplete((object completeObj) => {
                LeanTest.expect(((string)completeObj) == "Hi!", "ONCOMPLETE OBJECT");
                LeanTest.expect(cubeAlpha1.GetComponent <Renderer>().material.color.a == 0.5f, "ALPHA");
            });
            // Color
            float onStartTime = -1f;

            LeanTween.color(cubeAlpha2, Color.cyan, 0.3f).setOnComplete(() => {
                LeanTest.expect(cubeAlpha2.GetComponent <Renderer>().material.color == Color.cyan, "COLOR");
                LeanTest.expect(onStartTime >= 0f && onStartTime < Time.time, "ON START", "onStartTime:" + onStartTime + " time:" + Time.time);
            }).setOnStart(() => {
                onStartTime = Time.time;
            });
            // moveLocalY (make sure uses y values)
            Vector3 beforePos = cubeAlpha1.transform.position;

            LeanTween.moveY(cubeAlpha1, 3f, 0.2f).setOnComplete(() => {
                LeanTest.expect(cubeAlpha1.transform.position.x == beforePos.x && cubeAlpha1.transform.position.z == beforePos.z, "MOVE Y");
            });

            Vector3 beforePos2 = cubeAlpha2.transform.localPosition;

            LeanTween.moveLocalZ(cubeAlpha2, 12f, 0.2f).setOnComplete(() => {
                LeanTest.expect(cubeAlpha2.transform.localPosition.x == beforePos2.x && cubeAlpha2.transform.localPosition.y == beforePos2.y, "MOVE LOCAL Z", "ax:" + cubeAlpha2.transform.localPosition.x + " bx:" + beforePos.x + " ay:" + cubeAlpha2.transform.localPosition.y + " by:" + beforePos2.y);
            });

            AudioClip audioClip = LeanAudio.createAudio(new AnimationCurve(new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f)), new AnimationCurve(new Keyframe(0f, 0.001f, 0f, 0f), new Keyframe(1f, 0.001f, 0f, 0f)), LeanAudio.options());

            LeanTween.delayedSound(gameObject, audioClip, new Vector3(0f, 0f, 0f), 0.1f).setDelay(0.2f).setOnComplete(() => {
                LeanTest.expect(Time.time > 0, "DELAYED SOUND");
            });

            // Easing Methods
            int totalEasingCheck        = 0;
            int totalEasingCheckSuccess = 0;

            for (int j = 0; j < 2; j++)
            {
                bool isCheckingFrom       = j == 1;
                int  totalTweenTypeLength = (int)LeanTweenType.easeShake;
                for (int i = (int)LeanTweenType.notUsed; i < totalTweenTypeLength; i++)
                {
                    LeanTweenType easeType = (LeanTweenType)i;
                    GameObject    cube     = cubeNamed("cube" + easeType);
                    LTDescr       descr    = LeanTween.moveLocalX(cube, 5, 0.1f).setOnComplete((object obj) => {
                        GameObject cubeIn = obj as GameObject;
                        totalEasingCheck++;
                        if (cubeIn.transform.position.x == 5f)
                        {
                            totalEasingCheckSuccess++;
                        }
                        if (totalEasingCheck == (2 * totalTweenTypeLength))
                        {
                            LeanTest.expect(totalEasingCheck == totalEasingCheckSuccess, "EASING TYPES");
                        }
                    }).setOnCompleteParam(cube);

                    if (isCheckingFrom)
                    {
                        descr.setFrom(-5f);
                    }
                }
            }

            // value2
            bool value2UpdateCalled = false;

            LeanTween.value(gameObject, new Vector2(0, 0), new Vector2(256, 96), 0.1f).setOnUpdate((Vector2 value) => {
                value2UpdateCalled = true;
            });
            LeanTween.delayedCall(0.2f, () => {
                LeanTest.expect(value2UpdateCalled, "VALUE2 UPDATE");
            });

            // check descr
//			LTDescr descr2 = LeanTween.descr( descrId );
//			LeanTest.expect(descr2 == null,"DESCRIPTION STARTS AS NULL");

            StartCoroutine(timeBasedTesting());
        }
예제 #57
0
    void OnDrawGizmos()
    {
        init();

        if(pathType==LeanTweenPathType.bezier){
            for(int i = 0; i < pts.Length-3; i += 4){
                Vector3 first = i>3 ? pts[i-1].position : pts[i].position;

                Gizmos.color = curveColor;
                LeanTween.drawBezierPath(first, pts[i+2].position, pts[i+1].position, pts[i+3].position);

                Gizmos.color = lineColor;
                Gizmos.DrawLine(first,pts[i+2].position);
                Gizmos.DrawLine(pts[i+1].position,pts[i+3].position);
            }
        }else{

            LTSpline s = new LTSpline( splineVector() );
            Gizmos.color = curveColor;
            s.gizmoDraw();
        }
    }