/// <summary> /// Cross Fade. /// </summary> /// <param name='tweenData'> /// Tween data. /// </param> public override void CROSS_FADE( TweenOperandData tweenData ) { ContainsKey_sendDelayAndStartCoroutine( ref tweenData.paramTable ); float duration = ContainsKey_duration( ref tweenData.paramTable ); if( tweenData.tweenTarget != null ){ if( tweenData.paramTable.ContainsKey( "objectA" ) && tweenData.paramTable.ContainsKey( "objectB" ) ){ string objAName = tweenData.paramTable[ "objectA" ] as string; string objBName = tweenData.paramTable[ "objectB" ] as string; Transform A = tweenData.tweenTarget.transform.FindChild( objAName ); Transform B = tweenData.tweenTarget.transform.FindChild( objBName ); ColorPanel panelA = A.GetComponent<ColorPanel>(); ColorPanel panelB = B.GetComponent<ColorPanel>(); panelA.duration = duration; panelB.duration = duration; if( panelA.alpha > panelB.alpha ){ panelA.StartFade( 0f , 1f ); panelB.StartFade( 1f , 0f ); } else{ panelA.StartFade( 1f , 0f ); panelB.StartFade( 0f , 1f ); } } } }
/// <summary> /// Fade ColorPanel. /// </summary> /// <param name='tweenData'> /// Tween data. /// </param> public override void FADE_PANEL( TweenOperandData tweenData ) { Hashtable paramHash = tweenData.paramTable; GameObject panelAttachedObject = tweenData.tweenTarget; ContainsKey_sendDelayAndStartCoroutine( ref paramHash ); float duration = ContainsKey_duration( ref paramHash ); string fadeStr = (string)paramHash[ "fadeTo" ].ToString(); float fadeTo = float.Parse(fadeStr, CultureInfo.InvariantCulture ); ColorPanel uipanel = panelAttachedObject.GetComponent<ColorPanel>(); float fadeFrom = uipanel.alpha; if( paramHash.ContainsKey( "fadeFrom" ) ){ fadeFrom = GetValueFromKey( ref paramHash , "fadeFrom" ); } if( paramHash.ContainsKey( "fadeTo" ) ){ if( uipanel != null ){ uipanel.enabled = true; uipanel.duration = duration; uipanel.StartFade( fadeTo , fadeFrom ); } } #if false // If root node has Panels in children , Start Fading Each Panels of Children . ColorPanel[] childPanels = panelAttachedObject.GetComponentsInChildren<ColorPanel>(); if( childPanels != null ){ for( int i=0;i<childPanels.Length;i++){ childPanels[ i ].enabled = true; uipanel.duration = duration; childPanels[ i ].StartFade( fadeTo , fadeFrom ); } } #endif }
/// <summary> /// Cross Fade. /// </summary> /// <param name='tweenData'> /// Tween data. /// </param> public override void CROSS_FADE(TweenOperandData tweenData) { ContainsKey_sendDelayAndStartCoroutine(ref tweenData.paramTable); float duration = ContainsKey_duration(ref tweenData.paramTable); if (tweenData.tweenTarget != null) { if (tweenData.paramTable.ContainsKey("objectA") && tweenData.paramTable.ContainsKey("objectB")) { string objAName = tweenData.paramTable["objectA"] as string; string objBName = tweenData.paramTable["objectB"] as string; Transform A = tweenData.tweenTarget.transform.FindChild(objAName); Transform B = tweenData.tweenTarget.transform.FindChild(objBName); ColorPanel panelA = A.GetComponent <ColorPanel>(); ColorPanel panelB = B.GetComponent <ColorPanel>(); panelA.duration = duration; panelB.duration = duration; if (panelA.alpha > panelB.alpha) { panelA.StartFade(0f, 1f); panelB.StartFade(1f, 0f); } else { panelA.StartFade(1f, 0f); panelB.StartFade(0f, 1f); } } } }
/// <summary> /// Change Texture2D of renderer.sharedMaterial. /// </summary> /// <param name='tweenData'> /// Tween data. /// </param> public override void LOAD_IMAGE(TweenOperandData tweenData) { Resources.UnloadUnusedAssets(); string texpath = VM.loadedTextLiteralString; Texture2D tex = Resources.Load(texpath) as Texture2D; GameObject obj = tweenData.tweenTarget; if (obj.renderer != null) { if (obj.renderer.sharedMaterial != null) { obj.renderer.sharedMaterial.mainTexture = tex; ViNoDebugger.Log("loaded texture and the GameObject Name will change to :" + texpath); obj.name = texpath; // obj.transform.localScale = new Vector3( tex.width , tex.height , 1f ); } else { ViNoDebugger.LogError("Material not attached !"); } } else { ViNoDebugger.LogError("renderer not attached !"); } }
/// <summary> /// Fade ColorPanel. /// </summary> /// <param name='tweenData'> /// Tween data. /// </param> public override void FADE_PANEL(TweenOperandData tweenData) { Hashtable paramHash = tweenData.paramTable; GameObject panelAttachedObject = tweenData.tweenTarget; ContainsKey_sendDelayAndStartCoroutine(ref paramHash); float duration = ContainsKey_duration(ref paramHash); string fadeStr = (string)paramHash["fadeTo"].ToString(); float fadeTo = float.Parse(fadeStr, CultureInfo.InvariantCulture); ColorPanel uipanel = panelAttachedObject.GetComponent <ColorPanel>(); float fadeFrom = uipanel.alpha; if (paramHash.ContainsKey("fadeFrom")) { fadeFrom = GetValueFromKey(ref paramHash, "fadeFrom"); } if (paramHash.ContainsKey("fadeTo")) { if (uipanel != null) { uipanel.enabled = true; uipanel.duration = duration; uipanel.StartFade(fadeTo, fadeFrom); } } #if false // If root node has Panels in children , Start Fading Each Panels of Children . ColorPanel[] childPanels = panelAttachedObject.GetComponentsInChildren <ColorPanel>(); if (childPanels != null) { for (int i = 0; i < childPanels.Length; i++) { childPanels[i].enabled = true; uipanel.duration = duration; childPanels[i].StartFade(fadeTo, fadeFrom); } } #endif }
/// <summary> /// Animate the specified target and paramTbl. /// </summary> public void Animate(GameObject target, Hashtable paramTbl) { string _FOR_PREVIEW = "_FOR_PREVIEW"; GameObject forPreviewObj = GameObject.Find(_FOR_PREVIEW); DefaultScriptBinder sb = null; if (forPreviewObj == null) { forPreviewObj = new GameObject(_FOR_PREVIEW); forPreviewObj.hideFlags = HideFlags.HideInHierarchy; sb = forPreviewObj.AddComponent <DefaultScriptBinder>(); } else { sb = forPreviewObj.GetComponent <DefaultScriptBinder>(); } TweenOperandData data = new TweenOperandData(); data.tweenTarget = target; data.paramTable = paramTbl; switch (animationType) { case AnimationType.FADE_PANEL: sb.FADE_PANEL(data); break; case AnimationType.CROSS_FADE: sb.CROSS_FADE(data); break; default: sb.TWEEN(data); break; } }
/// <summary> /// Do the Same Thing with LOAD_IMAGE. /// </summary> /// <param name='tweenData'> /// Tween data. /// </param> public override void CHANGE_IMAGE( TweenOperandData tweenData ) { LOAD_IMAGE( tweenData ); }
/// <summary> /// Using AnimationClip. /// </summary> /// <param name='tweenData'> /// Tween data. /// </param> public override void TWEEN( TweenOperandData tweenData ) { AnimationMove( tweenData ); }
/// <summary> /// Change Texture2D of renderer.sharedMaterial. /// </summary> /// <param name='tweenData'> /// Tween data. /// </param> public override void LOAD_IMAGE( TweenOperandData tweenData ) { Resources.UnloadUnusedAssets(); string texpath = VM.loadedTextLiteralString; Texture2D tex = Resources.Load( texpath ) as Texture2D; GameObject obj = tweenData.tweenTarget; if( obj.renderer != null ){ if( obj.renderer.sharedMaterial != null ){ obj.renderer.sharedMaterial.mainTexture = tex; ViNoDebugger.Log ( "loaded texture and the GameObject Name will change to :" + texpath ); obj.name = texpath; // obj.transform.localScale = new Vector3( tex.width , tex.height , 1f ); } else{ ViNoDebugger.LogError( "Material not attached !" ); } } else{ ViNoDebugger.LogError( "renderer not attached !" ); } }
protected void AnimationMove(TweenOperandData tweenData) { Hashtable paramHash = tweenData.paramTable; string name = ContainsKey_name(ref paramHash); GameObject root = tweenData.tweenTarget; if (root == null) { ViNoDebugger.LogError("tween target not found !"); return; } Transform rootra = root.transform; if (string.IsNullOrEmpty(name)) { name = "__animation"; // default animation name. } Animation animation = root.GetComponent <Animation>(); if (animation == null) { animation = root.AddComponent <Animation>(); } AnimationClip clip = new AnimationClip(); float duration = ContainsKey_duration(ref paramHash); bool isMove = false; bool isRotate = false; bool isScale = false; bool isFromPos = false; bool isFromRot = false; bool isFromScale = false; WrapMode wrapmode = ContainsKey_mode(ref paramHash); int method = 0; if (paramHash.ContainsKey("method")) { string methodStr = paramHash["method"] as string; method = int.Parse(methodStr); } Vector3 move = ContainsKey_moveXorYorZ(out isMove, ref paramHash, rootra.localPosition); Vector3 euler = ContainsKey_rotateXorYorZ(out isRotate, ref paramHash, rootra.localEulerAngles); //localRotation.eulerAngles ); Vector3 scale = ContainsKey_scaleXorYorZ(out isScale, ref paramHash, rootra.localScale); Vector3 fromPos = ContainsKey_StrAndXorYorZ(out isFromPos, "fromPos", ref paramHash, rootra.localPosition); Vector3 fromRot = ContainsKey_StrAndXorYorZ(out isFromRot, "fromRot", ref paramHash, rootra.localEulerAngles); Vector3 fromScale = ContainsKey_StrAndXorYorZ(out isFromScale, "fromScale", ref paramHash, rootra.localScale); clip.wrapMode = wrapmode; if (isMove) { switch (method) { case 0: // Linear. AnimationCurve animCurveX = AnimationCurve.Linear(0f, fromPos.x, duration, move.x); AnimationCurve animCurveY = AnimationCurve.Linear(0f, fromPos.y, duration, move.y); AnimationCurve animCurveZ = AnimationCurve.Linear(0f, fromPos.z, duration, move.z); clip.SetCurve("", typeof(Transform), "localPosition.x", animCurveX); clip.SetCurve("", typeof(Transform), "localPosition.y", animCurveY); clip.SetCurve("", typeof(Transform), "localPosition.z", animCurveZ); break; case 1: // Easeinout. animCurveX = AnimationCurve.EaseInOut(0f, fromPos.x, duration, move.x); animCurveY = AnimationCurve.EaseInOut(0f, fromPos.y, duration, move.y); animCurveZ = AnimationCurve.EaseInOut(0f, fromPos.z, duration, move.z); clip.SetCurve("", typeof(Transform), "localPosition.x", animCurveX); clip.SetCurve("", typeof(Transform), "localPosition.y", animCurveY); clip.SetCurve("", typeof(Transform), "localPosition.z", animCurveZ); break; } } if (isRotate) { Quaternion q1 = Quaternion.Euler(fromRot); Quaternion q2 = Quaternion.Euler(euler); switch (method) { case 0: // Linear. AnimationCurve animCurveX = AnimationCurve.Linear(0f, q1.x, duration, q2.x); AnimationCurve animCurveY = AnimationCurve.Linear(0f, q1.y, duration, q2.y); AnimationCurve animCurveZ = AnimationCurve.Linear(0f, q1.z, duration, q2.z); AnimationCurve animCurveW = AnimationCurve.Linear(0f, q1.w, duration, q2.w); clip.SetCurve("", typeof(Transform), "localRotation.x", animCurveX); clip.SetCurve("", typeof(Transform), "localRotation.y", animCurveY); clip.SetCurve("", typeof(Transform), "localRotation.z", animCurveZ); clip.SetCurve("", typeof(Transform), "localRotation.w", animCurveW); break; case 1: // Easeinout. animCurveX = AnimationCurve.EaseInOut(0f, q1.x, duration, q2.x); animCurveY = AnimationCurve.EaseInOut(0f, q1.y, duration, q2.y); animCurveZ = AnimationCurve.EaseInOut(0f, q1.z, duration, q2.z); animCurveW = AnimationCurve.EaseInOut(0f, q1.w, duration, q2.w); clip.SetCurve("", typeof(Transform), "localRotation.x", animCurveX); clip.SetCurve("", typeof(Transform), "localRotation.y", animCurveY); clip.SetCurve("", typeof(Transform), "localRotation.z", animCurveZ); clip.SetCurve("", typeof(Transform), "localRotation.w", animCurveW); break; } } if (isScale) { switch (method) { case 0: // Linear. AnimationCurve animCurveX = AnimationCurve.Linear(0f, fromScale.x, duration, scale.x); AnimationCurve animCurveY = AnimationCurve.Linear(0f, fromScale.y, duration, scale.y); AnimationCurve animCurveZ = AnimationCurve.Linear(0f, fromScale.z, duration, scale.z); clip.SetCurve("", typeof(Transform), "localScale.x", animCurveX); clip.SetCurve("", typeof(Transform), "localScale.y", animCurveY); clip.SetCurve("", typeof(Transform), "localScale.z", animCurveZ); break; case 1: // Easeinout. animCurveX = AnimationCurve.EaseInOut(0f, fromScale.x, duration, scale.x); animCurveY = AnimationCurve.EaseInOut(0f, fromScale.y, duration, scale.y); animCurveZ = AnimationCurve.EaseInOut(0f, fromScale.z, duration, scale.z); clip.SetCurve("", typeof(Transform), "localScale.x", animCurveX); clip.SetCurve("", typeof(Transform), "localScale.y", animCurveY); clip.SetCurve("", typeof(Transform), "localScale.z", animCurveZ); break; } } ViNoAnimationListener animcb = root.GetComponent <ViNoAnimationListener>(); if (animcb == null) { root.AddComponent <ViNoAnimationListener>(); } AnimationEvent tweenFinished = new AnimationEvent(); tweenFinished.time = duration; tweenFinished.intParameter = 123; tweenFinished.stringParameter = "end"; tweenFinished.functionName = "AnimationFinishedCallback"; clip.AddEvent(tweenFinished); animation.AddClip(clip, name); // Now, Start the Animation. animation.Play(name); // Is paramHash Contains Key "sendDelay" ? . ContainsKey_sendDelayAndStartCoroutine(ref paramHash); }
/// <summary> /// Do the Same Thing with LOAD_IMAGE. /// </summary> /// <param name='tweenData'> /// Tween data. /// </param> public override void CHANGE_IMAGE(TweenOperandData tweenData) { LOAD_IMAGE(tweenData); }
/// <summary> /// Using AnimationClip. /// </summary> /// <param name='tweenData'> /// Tween data. /// </param> public override void TWEEN(TweenOperandData tweenData) { AnimationMove(tweenData); }
protected void AnimationMove( TweenOperandData tweenData ) { Hashtable paramHash = tweenData.paramTable; string name = ContainsKey_name( ref paramHash ); GameObject root = tweenData.tweenTarget; if( root == null ){ ViNoDebugger.LogError( "tween target not found !" ); return; } Transform rootra = root.transform; if( string.IsNullOrEmpty( name ) ){ name= "__animation"; // default animation name. } Animation animation = root.GetComponent<Animation>(); if( animation == null ){ animation = root.AddComponent<Animation>(); } AnimationClip clip = new AnimationClip(); float duration = ContainsKey_duration( ref paramHash ); bool isMove = false; bool isRotate = false; bool isScale = false; bool isFromPos = false; bool isFromRot = false; bool isFromScale = false; WrapMode wrapmode = ContainsKey_mode( ref paramHash ); int method = 0; if( paramHash.ContainsKey( "method" ) ){ string methodStr = paramHash[ "method" ] as string; method = int.Parse( methodStr ); } Vector3 move = ContainsKey_moveXorYorZ( out isMove , ref paramHash , rootra.localPosition ); Vector3 euler = ContainsKey_rotateXorYorZ( out isRotate , ref paramHash , rootra.localEulerAngles );//localRotation.eulerAngles ); Vector3 scale = ContainsKey_scaleXorYorZ( out isScale , ref paramHash , rootra.localScale ); Vector3 fromPos = ContainsKey_StrAndXorYorZ( out isFromPos , "fromPos" , ref paramHash , rootra.localPosition ); Vector3 fromRot = ContainsKey_StrAndXorYorZ( out isFromRot , "fromRot" , ref paramHash , rootra.localEulerAngles ); Vector3 fromScale = ContainsKey_StrAndXorYorZ( out isFromScale , "fromScale" , ref paramHash , rootra.localScale ); clip.wrapMode = wrapmode; if( isMove ){ switch( method ){ case 0 : // Linear. AnimationCurve animCurveX = AnimationCurve.Linear( 0f , fromPos.x , duration , move.x ); AnimationCurve animCurveY = AnimationCurve.Linear( 0f , fromPos.y , duration , move.y ); AnimationCurve animCurveZ = AnimationCurve.Linear( 0f , fromPos.z , duration , move.z ); clip.SetCurve("", typeof(Transform), "localPosition.x", animCurveX ); clip.SetCurve("", typeof(Transform), "localPosition.y", animCurveY ); clip.SetCurve("", typeof(Transform), "localPosition.z", animCurveZ ); break; case 1: // Easeinout. animCurveX = AnimationCurve.EaseInOut( 0f , fromPos.x , duration , move.x ); animCurveY = AnimationCurve.EaseInOut( 0f , fromPos.y , duration , move.y ); animCurveZ = AnimationCurve.EaseInOut( 0f , fromPos.z , duration , move.z ); clip.SetCurve("", typeof(Transform), "localPosition.x", animCurveX ); clip.SetCurve("", typeof(Transform), "localPosition.y", animCurveY ); clip.SetCurve("", typeof(Transform), "localPosition.z", animCurveZ ); break; } } if( isRotate ){ Quaternion q1 = Quaternion.Euler( fromRot ); Quaternion q2 = Quaternion.Euler( euler ); switch( method ){ case 0 : // Linear. AnimationCurve animCurveX = AnimationCurve.Linear( 0f , q1.x , duration , q2.x ); AnimationCurve animCurveY = AnimationCurve.Linear( 0f , q1.y , duration , q2.y ); AnimationCurve animCurveZ = AnimationCurve.Linear( 0f , q1.z , duration , q2.z ); AnimationCurve animCurveW = AnimationCurve.Linear( 0f , q1.w , duration , q2.w ); clip.SetCurve("", typeof(Transform), "localRotation.x", animCurveX ); clip.SetCurve("", typeof(Transform), "localRotation.y", animCurveY ); clip.SetCurve("", typeof(Transform), "localRotation.z", animCurveZ ); clip.SetCurve("", typeof(Transform), "localRotation.w", animCurveW ); break; case 1: // Easeinout. animCurveX = AnimationCurve.EaseInOut( 0f , q1.x , duration , q2.x ); animCurveY = AnimationCurve.EaseInOut( 0f , q1.y , duration , q2.y ); animCurveZ = AnimationCurve.EaseInOut( 0f , q1.z , duration , q2.z ); animCurveW = AnimationCurve.EaseInOut( 0f , q1.w , duration , q2.w ); clip.SetCurve("", typeof(Transform), "localRotation.x", animCurveX ); clip.SetCurve("", typeof(Transform), "localRotation.y", animCurveY ); clip.SetCurve("", typeof(Transform), "localRotation.z", animCurveZ ); clip.SetCurve("", typeof(Transform), "localRotation.w", animCurveW ); break; } } if( isScale ){ switch( method ){ case 0 : // Linear. AnimationCurve animCurveX = AnimationCurve.Linear( 0f , fromScale.x , duration , scale.x ); AnimationCurve animCurveY = AnimationCurve.Linear( 0f , fromScale.y , duration , scale.y ); AnimationCurve animCurveZ = AnimationCurve.Linear( 0f , fromScale.z , duration , scale.z ); clip.SetCurve("", typeof(Transform), "localScale.x", animCurveX ); clip.SetCurve("", typeof(Transform), "localScale.y", animCurveY ); clip.SetCurve("", typeof(Transform), "localScale.z", animCurveZ ); break; case 1: // Easeinout. animCurveX = AnimationCurve.EaseInOut( 0f , fromScale.x , duration , scale.x ); animCurveY = AnimationCurve.EaseInOut( 0f , fromScale.y , duration , scale.y ); animCurveZ = AnimationCurve.EaseInOut( 0f , fromScale.z , duration , scale.z ); clip.SetCurve("", typeof(Transform), "localScale.x", animCurveX ); clip.SetCurve("", typeof(Transform), "localScale.y", animCurveY ); clip.SetCurve("", typeof(Transform), "localScale.z", animCurveZ ); break; } } ViNoAnimationListener animcb = root.GetComponent<ViNoAnimationListener>(); if( animcb == null ){ root.AddComponent<ViNoAnimationListener>(); } AnimationEvent tweenFinished = new AnimationEvent(); tweenFinished.time = duration; tweenFinished.intParameter = 123; tweenFinished.stringParameter = "end"; tweenFinished.functionName = "AnimationFinishedCallback"; clip.AddEvent( tweenFinished ); animation.AddClip(clip, name ); // Now, Start the Animation. animation.Play( name ); // Is paramHash Contains Key "sendDelay" ? . ContainsKey_sendDelayAndStartCoroutine( ref paramHash ); }
/// <summary> /// Animate the specified target and paramTbl. /// </summary> public void Animate( GameObject target , Hashtable paramTbl ) { string _FOR_PREVIEW = "_FOR_PREVIEW"; GameObject forPreviewObj = GameObject.Find( _FOR_PREVIEW ); DefaultScriptBinder sb = null ; if( forPreviewObj == null ){ forPreviewObj = new GameObject( _FOR_PREVIEW ); forPreviewObj.hideFlags = HideFlags.HideInHierarchy; sb = forPreviewObj.AddComponent<DefaultScriptBinder>(); } else{ sb = forPreviewObj.GetComponent<DefaultScriptBinder>(); } TweenOperandData data = new TweenOperandData(); data.tweenTarget = target; data.paramTable = paramTbl; switch( animationType ){ case AnimationType.FADE_PANEL: sb.FADE_PANEL( data ); break; case AnimationType.CROSS_FADE: sb.CROSS_FADE( data ); break; default: sb.TWEEN( data ); break; } }