devNotes 4-29-16 ArgosFibonacci.cs – iTween Callbacks

CallBack

FibRider.cs

using UnityEngine;
using System.Collections;
using ProceduralToolkit;
using System.Collections.Generic;
using System.IO;


public class Fibo_Rider : MonoBehaviour
{
    StreamWriter sWrite;

    public ArgosMeshDraft_Fibonacci AMD_Base;

    List<GameObject> gO_List = new List<GameObject>();

    public int iSpwanLoc = 205;

    public int iDelt = 8;

    public float pathTime = 10f;

    public int numPoints = 10;
    GameObject goMyPivot;
    GameObject goTweenFollower;

    Quaternion qStart;

    void Start ()
    {

    }

    public void initFromSpawner(int FibLoc)
    {
        GameObject gFibSphere = GameObject.Find("Fibonacci_Sphere");
        ArgosFibonacci aF = gFibSphere.GetComponent<ArgosFibonacci>();
        AMD_Base = aF.aMF_Base;

        qStart = Quaternion.LookRotation(AMD_Base.funcVerts[FibLoc].vPos.normalized);
        transform.rotation = qStart;
        transform.position = AMD_Base.funcVerts[FibLoc].vPos;

        goTweenFollower = transform.Find("TweenFollower").gameObject;

        goMyPivot = new GameObject();
        goMyPivot.transform.position = new Vector3(0, 0, 0);
        goMyPivot.transform.rotation = qStart;

        transform.SetParent(goMyPivot.transform);
        goTweenFollower.transform.SetParent(transform);//this
        goTweenFollower.transform.position = Vector3.zero;

        iTween.MoveTo(goTweenFollower, iTween.Hash("x", 1, "time", 3, "easetype", "easeinoutexpo", "onstart", "fibTweenStarted", "onstartparams", "FIB Rider Started...", "onupdate", "fibTweenUpdate", "onupdateparams", FibLoc.ToString(), "oncomplete", "fibTweenComplete", "oncompleteparams", "fib Tween DONE", "onCompleteTarget", gameObject, "onStartTarget", gameObject, "onUpdateTarget", gameObject));

    }

    void fibTweenStarted(string textToDisplay)
    {
        print("fibTween on Start " + textToDisplay);
    }

    int CBcount = 0;
    void fibTweenUpdate(string textToDisplay)
    {
        print("fibTweenUpdate " + textToDisplay + " call count = " + CBcount.ToString() + " pos = " + goTweenFollower.transform.position.x.ToString("F3") + " deltaTime = " + Time.deltaTime.ToString("F3"));
        CBcount++;
    }

    void fibTweenComplete(string textToDisplay)
    {
        print("fibTweenComplete " + textToDisplay + " call count = " + CBcount.ToString());
    }

	void Update ()
    {
	
	}
}

Unity Console Log

(Filename: Assets/argos_scripts/Fibo_Rider.cs Line: 75)

fibTweenUpdate 285 call count = 207 pos = 0.999 deltaTime = 0.043
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
UnityEngine.MonoBehaviour:print(Object) (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineMonoBehaviourBindings.gen.cs:106)
Fibo_Rider:fibTweenUpdate(String) (at Assets\argos_scripts\Fibo_Rider.cs:75)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
iTween:CallBack(String) (at Assets\Plugins\Pixelplacement\iTween\iTween.cs:7074)
iTween:TweenUpdate() (at Assets\Plugins\Pixelplacement\iTween\iTween.cs:4630)
iTween:Update() (at Assets\Plugins\Pixelplacement\iTween\iTween.cs:6581)
 
(Filename: Assets/argos_scripts/Fibo_Rider.cs Line: 75)

fibTweenUpdate 285 call count = 208 pos = 1.000 deltaTime = 0.048
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
UnityEngine.MonoBehaviour:print(Object) (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineMonoBehaviourBindings.gen.cs:106)
Fibo_Rider:fibTweenUpdate(String) (at Assets\argos_scripts\Fibo_Rider.cs:75)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
iTween:CallBack(String) (at Assets\Plugins\Pixelplacement\iTween\iTween.cs:7074)
iTween:TweenUpdate() (at Assets\Plugins\Pixelplacement\iTween\iTween.cs:4630)
iTween:Update() (at Assets\Plugins\Pixelplacement\iTween\iTween.cs:6581)
 
(Filename: Assets/argos_scripts/Fibo_Rider.cs Line: 75)

fibTweenComplete fib Tween DONE call count = 209
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
UnityEngine.MonoBehaviour:print(Object) (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineMonoBehaviourBindings.gen.cs:106)
Fibo_Rider:fibTweenComplete(String) (at Assets\argos_scripts\Fibo_Rider.cs:81)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
iTween:CallBack(String) (at Assets\Plugins\Pixelplacement\iTween\iTween.cs:7074)
iTween:TweenComplete() (at Assets\Plugins\Pixelplacement\iTween\iTween.cs:4657)
iTween:Update() (at Assets\Plugins\Pixelplacement\iTween\iTween.cs:6583)

ghjkhgjk-4

 

dfghfghgh1

    public void initFromSpawner(int FibLoc)
    {
        qStart = Quaternion.LookRotation(AMD_Base.funcVerts[FibLoc].vPos.normalized);
        transform.rotation = qStart;
        transform.position = AMD_Base.funcVerts[FibLoc].vPos;

        GameObject gFibSphere = GameObject.Find("Fibonacci_Sphere");
        ArgosFibonacci aF = gFibSphere.GetComponent<ArgosFibonacci>();
        AMD_Base = aF.aMF_Base;

        goTweenFollower = transform.Find("TweenFollower").gameObject;

        goMyPivot = new GameObject();
        goMyPivot.transform.position = new Vector3(0, 0, 0);
        goMyPivot.transform.rotation = qStart;

        transform.SetParent(goMyPivot.transform);
        goTweenFollower.transform.SetParent(transform);//this
    }

 

SHIM

dfghfgh

SHIM

slerperewer

using UnityEngine;
using System.Collections;

public class CallbacksExample : MonoBehaviour{
	public GUIStyle style;
	public GUIText statusText;
	private bool buttonActivated;
	
	void Start(){
		tween();
	}
	
	void OnGUI (){
		if(buttonActivated){
			if(GUI.Button (new Rect (67,178,113,32), "",style)){
				reset();
				tween();
			}
		}
	}
	
	void reset(){
		transform.position=new Vector3(0,0,0);
		transform.rotation=Quaternion.identity;
		statusText.text="";
		buttonActivated=false;
	}
	
	void tween(){
		iTween.MoveBy(gameObject,iTween.Hash("y",2,"time",2,"easetype","easeinoutexpo","onstart","segmentStarted","onstartparams","Rise started...","onupdate","segmentUpdated","onupdateparams","move","oncomplete","segmentComplete","oncompleteparams","Rise stopped."));
		iTween.RotateBy(gameObject,iTween.Hash("z",.25,"time",1,"easetype","easeinoutback","delay",2.5,"onstart","segmentStarted","onstartparams","Rotate started...","onupdate","segmentUpdated","onupdateparams","rotate","oncomplete","segmentComplete","oncompleteparams","Rotate stopped."));
		iTween.MoveTo(gameObject,iTween.Hash("y",0,"time",.9,"easetype","easeInExpo","delay",4,"onstart","segmentStarted","onstartparams","Fall started...","onupdate","segmentUpdated","onupdateparams","move","oncomplete","segmentComplete","oncompleteparams","Fall stopped."));
		
		//Notice that since we ae putting shake on the camera we need to tell the callbacks which target contains the method they need to call,
		iTween.ShakePosition(Camera.main.gameObject,iTween.Hash("y",.5,"time",.8,"delay",4.95,"onstart","segmentStarted","onstartparams","Shake started...","onstarttarget",gameObject,"onupdate","segmentUpdated","onupdateparams","shake","onupdatetarget",gameObject,"oncomplete","allComplete","oncompletetarget",gameObject));
	}
	
	void segmentStarted(string textToDisplay){
		statusText.text+=textToDisplay + "\n";
	}
	
	void segmentUpdated(string method){
		switch(method){
		case "move":
			Debug.Log("Height at, " + transform.position.y);
			break;
			
		case "rotate":
			Debug.Log("Rotation at, " + transform.eulerAngles.z);
			break;
			
		case "shake":
			Debug.Log("Shake at, " + Camera.main.transform.position.y);
			break;
		}
	}
	
	void segmentComplete(string textToDisplay){
		statusText.text+=textToDisplay + "\n";
	}
	
	void allComplete(){
		buttonActivated=true;	
		statusText.text += "All done animating!";
	}
}

fdghfghdfgdh

from PixelPlacement

One of the most frequent problems I see people have with iTween is with callbacks that don’t fire.

At it’s core iTween leverages Unity’s SendMessage method for carrying out it’s 3 callbacks: “onStart”, “onUpdate” and “onComplete”. When you add an iTween to a GameObject, iTween will throw all callbacks against the GameObject that is being animated. Where most people have difficulties is when they assign iTweens to GameObjects that don’t physically contain the methods they are attempting to call.

For example, the following code with never execute the “ShakeComplete” method because the “target” GameObject does not have a script attachted to it containing this method:

using UnityEngine;
using System.Collections;

public class UnderstandingCallbacks : MonoBehaviour
{
	public GameObject target;
	
	void Start ()
	{
		iTween.ShakePosition(target, iTween.Hash("x", 1, "onComplete", ShakeComplete));
	}
	
	void ShakeComplete(){
		Debug.Log("The shake completed!");	
	}
}

There’s 2 ways to correct the previous script. The long route: create another script, attach it to our actual “target” GameObject and transfer the “ShakeComplete” method to that new script. The easy route: utilize iTween’s callback “target modifiers”!

Each of iTween’s 3 callbacks have an additional “target modifier” that can be used to tell iTween to look somewhere else for the callback method: “onStartTarget”, “onUpdateTarget” and “onCompleteTarget”.

The following corrected script will now fire the “onComplete” callback since we are now using “onCompleteTarget” to tell iTween that the “ShakeComplete” method is located on the GameObject that actually set up the iTween:

using UnityEngine;
using System.Collections;

public class UnderstandingCallbacks : MonoBehaviour
{
	public GameObject target;
	
	void Start ()
	{
		iTween.ShakePosition(target, iTween.Hash("x", 1, "onComplete", "ShakeComplete", "onCompleteTarget", gameObject));
	}
	
	void ShakeComplete(){
		Debug.Log("The shake completed!");	
	}
}

 


float sTime = ElasticEaseInOut(toFromList[i].timer, 0.0f, 1.0f, toFromList[i].movetime);

asu.aQuads[toFromList[i].aIdx].go.transform.rotation = Quaternion.LerpUnclamped(toFromList[i].q0, toFromList[i].q1, sTime);