当前位置: 首页>>代码示例>>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;未经允许,请勿转载。