當前位置: 首頁>>代碼示例>>C#>>正文


C# AnimationClip.AddEvent方法代碼示例

本文整理匯總了C#中UnityEngine.AnimationClip.AddEvent方法的典型用法代碼示例。如果您正苦於以下問題:C# AnimationClip.AddEvent方法的具體用法?C# AnimationClip.AddEvent怎麽用?C# AnimationClip.AddEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UnityEngine.AnimationClip的用法示例。


在下文中一共展示了AnimationClip.AddEvent方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AddAnimEvent

    public static void AddAnimEvent(Animator animator, AnimationClip clip, string methodName, float param)
    {
        AnimationEvent ev = new AnimationEvent ();
        ev.functionName = methodName;
        ev.floatParameter = param;

        // at the begining
        ev.time = 0;

        clip.AddEvent (ev);
    }
開發者ID:DylanYasen,項目名稱:Project-together,代碼行數:11,代碼來源:AnimHelper.cs

示例2: AddAnimEvent

    /// <summary>
    /// 注冊無參事件
    /// </summary>
    /// <param name="clip">動畫片</param>
    /// <param name="time">事件</param>
    /// <param name="onAnimEvent">回調</param>
    public void AddAnimEvent(AnimationClip clip, float time, System.Action onAnimEvent)
    {
        AnimationEvent animEvent = new AnimationEvent();
        //固定一個事件方法,就不需要對每個事件都寫一個
        animEvent.functionName = "OnAnimEvent";
        animEvent.time = time;
        animEvent.messageOptions = SendMessageOptions.RequireReceiver;
        //用hash碼記錄是哪一個回調函數,還沒想到更好的方法
        animEvent.intParameter = onAnimEvent.GetHashCode();

        if (!onAnimEventDic.ContainsKey(animEvent.intParameter))
        {
            onAnimEventDic.Add(animEvent.intParameter, onAnimEvent);
        }

        clip.AddEvent(animEvent);
    }
開發者ID:zs9024,項目名稱:Jungle,代碼行數:23,代碼來源:AnimEvent.cs

示例3: AddAnimEventAtEnd

    public static void AddAnimEventAtEnd(Animator animator, AnimationClip clip, string methodName, int param)
    {
        AnimationEvent ev = new AnimationEvent ();
        ev.functionName = methodName;
        ev.intParameter = param;

        // at the begining
        ev.time = clip.length;

        clip.AddEvent (ev);
    }
開發者ID:DylanYasen,項目名稱:Project-together,代碼行數:11,代碼來源:AnimHelper.cs

示例4: SetEvents

 private static AnimationClip SetEvents(AnimationClip clip, string[] methodNames)
 {
     // AnimationCurveの生成.
     foreach (string methodName in methodNames) {
         AnimationEvent aEvent = new AnimationEvent();
         aEvent.functionName = methodName;
         aEvent.time = 0.1f;
         clip.AddEvent (aEvent);
     }
     return clip;
 }
開發者ID:OhtaS,項目名稱:Petlian,代碼行數:11,代碼來源:ButtonAnimation.cs

示例5: AnimationMove


//.........這裏部分代碼省略.........
        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 );
    }
開發者ID:Joon-min,項目名稱:wiper,代碼行數:101,代碼來源:ScriptBinder.cs

示例6: AddAnimationMoveToPlayerDeck

    private void AddAnimationMoveToPlayerDeck(Vector3 endPosition)
    {
        var clip = new AnimationClip();
        var curve = AnimationCurve.EaseInOut(0, transform.position.x, 1, endPosition.x);
        clip.SetCurve("",typeof(Transform),"localPosition.x", curve);
        curve = AnimationCurve.EaseInOut(0, transform.position.y, 0.7f, 0f);
        clip.SetCurve("",typeof(Transform),"localPosition.y", curve);
        curve = new AnimationCurve();
        curve.AddKey(0, transform.position.z);
        var keyframe = curve[0];
        keyframe.outTangent = 1;
        curve.MoveKey(0, keyframe);
        curve.AddKey(0.4f, transform.position.z-2.5f);
        curve.AddKey(0.70f, transform.position.z-4.7f);
        curve.AddKey(1f, endPosition.z);
        keyframe = curve[3];
        keyframe.inTangent = 0;
        curve.MoveKey(3, keyframe);
        clip.SetCurve("",typeof(Transform),"localPosition.z", curve);
        clip.wrapMode = WrapMode.Once;

        var animEv= new AnimationEvent();
        animEv.functionName="animFinished";
        animEv.time=clip.length;
        clip.AddEvent(animEv);

        clip.legacy = true;
        GetComponent<Animation>().AddClip(clip, "MoveToPlayerDeckAnimation");
    }
開發者ID:AlexeyPuchko,項目名稱:Unity3D_Catan,代碼行數:29,代碼來源:ResourceCard.cs

示例7: MoveTo

    public static void MoveTo( GameObject target , Vector3 position , float time )
    {
        Vector3 fromPos = target.transform.localPosition;

        Animation animation = target.GetComponent<Animation>();
        if( animation == null ){
            animation = target.AddComponent<Animation>();
        }
        AnimationClip clip = new AnimationClip();
        //        clip.wrapMode = WrapMode.;
        AnimationCurve animCurveX = AnimationCurve.Linear( 0f , fromPos.x , time , position.x );
        AnimationCurve animCurveY = AnimationCurve.Linear( 0f , fromPos.y , time , position.y );
        AnimationCurve animCurveZ = AnimationCurve.Linear( 0f , fromPos.z , time , position.z );
        clip.SetCurve("", typeof(Transform), "localPosition.x", animCurveX );
        clip.SetCurve("", typeof(Transform), "localPosition.y", animCurveY );
        clip.SetCurve("", typeof(Transform), "localPosition.z", animCurveZ );

        ViNoAnimationListener animcb = target.GetComponent<ViNoAnimationListener>();
        if( animcb == null ){
            target.AddComponent<ViNoAnimationListener>();
        }

        AnimationEvent tweenFinished = new AnimationEvent();
        tweenFinished.time = time;
        tweenFinished.intParameter = 123;
        tweenFinished.stringParameter = "end";
        tweenFinished.functionName = "AnimationFinishedCallback";

        clip.AddEvent( tweenFinished );

        animation.AddClip(clip, target.name );

        // Now, Start the Animation.
        animation.Play( target.name );
    }
開發者ID:Joon-min,項目名稱:wiper,代碼行數:35,代碼來源:AnimationNode.cs


注:本文中的UnityEngine.AnimationClip.AddEvent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。