public static int GetCurveGroupID(AnimationClip clip, EditorCurveBinding curveData)
 {
   if (curveData.type != typeof (Transform))
     return -1;
   int num = !((UnityEngine.Object) clip == (UnityEngine.Object) null) ? clip.GetInstanceID() : 0;
   string str = curveData.propertyName.Substring(0, curveData.propertyName.Length - 1);
   return num * 19603 ^ curveData.path.GetHashCode() * 729 ^ curveData.type.GetHashCode() * 27 ^ str.GetHashCode();
 }
		public static int GetCurveGroupID(AnimationClip clip, EditorCurveBinding curveData)
		{
			if (curveData.type != typeof(Transform))
			{
				return -1;
			}
			int num = (!(clip == null)) ? clip.GetInstanceID() : 0;
			string text = curveData.propertyName.Substring(0, curveData.propertyName.Length - 1);
			return num * 19603 ^ curveData.path.GetHashCode() * 729 ^ curveData.type.GetHashCode() * 27 ^ text.GetHashCode();
		}
Example #3
0
 public static int GetCurveGroupID(AnimationClip clip, EditorCurveBinding curveData)
 {
     if (curveData.type != typeof(Transform))
     {
         return -1;
     }
     int num = (clip != null) ? clip.GetInstanceID() : 0;
     string str = curveData.propertyName.Substring(0, curveData.propertyName.Length - 1);
     return ((((num * 0x4c93) ^ (curveData.path.GetHashCode() * 0x2d9)) ^ (curveData.type.GetHashCode() * 0x1b)) ^ str.GetHashCode());
 }
 public static int GetCurveID(AnimationClip clip, EditorCurveBinding curveData)
 {
   return (!((UnityEngine.Object) clip == (UnityEngine.Object) null) ? clip.GetInstanceID() : 0) * 19603 ^ curveData.path.GetHashCode() * 729 ^ curveData.type.GetHashCode() * 27 ^ curveData.propertyName.GetHashCode();
 }
		public static int GetCurveID(AnimationClip clip, EditorCurveBinding curveData)
		{
			int num = (!(clip == null)) ? clip.GetInstanceID() : 0;
			return num * 19603 ^ curveData.path.GetHashCode() * 729 ^ curveData.type.GetHashCode() * 27 ^ curveData.propertyName.GetHashCode();
		}
Example #6
0
    void CloneAni(AnimationClip clip, float fps)
    {

        var ani = target as Animator;

        //创建CleanData.Ani
        FB.PosePlus.AniClip _clip = ScriptableObject.CreateInstance<FB.PosePlus.AniClip>();
        _clip.boneinfo = new List<string>();//也增加了每个动画中的boneinfo信息.

        //这里重新检查动画曲线,找出动画中涉及的Transform部分,更精确
        List<Transform> cdpath = new List<Transform>();
        AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(clip, true);
        foreach (var dd in curveDatas)
        {
            Transform tran = ani.transform.Find(dd.path);
            if (cdpath.Contains(tran) == false)
            {
                _clip.boneinfo.Add(dd.path);
                cdpath.Add(tran);
            }
        }
        Debug.LogWarning("curve got path =" + cdpath.Count);


        string path = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(clip.GetInstanceID()));
        _clip.name = clip.name;
        _clip.frames = new List<FB.PosePlus.Frame>();
        _clip.fps = fps;
        _clip.loop = clip.isLooping;
        float flen = (clip.length * fps);
        int framecount = (int)flen;
        if (flen - framecount > 0.0001) framecount++;
        //if (framecount < 1) framecount = 1;

        framecount += 1;
        FB.PosePlus.Frame last = null;

        //ani.StartPlayback();
        //逐帧复制
        //ani.Play(_clip.name, 0, 0);
        for (int i = 0; i < framecount; i++)
        {
            ani.Play(_clip.name, 0, (i * 1.0f / fps) / clip.length);
            ani.Update(0);

            last = new FB.PosePlus.Frame(last, i, cdpath);
            _clip.frames.Add(last);
        }
        if (_clip.loop)
        {
            _clip.frames[0].LinkLoop(last);
        }
        Debug.Log("FrameCount." + framecount);

        FB.PosePlus.AniPlayer con = ani.GetComponent<FB.PosePlus.AniPlayer>();

        List<FB.PosePlus.AniClip> clips = null;
        if (con.clips != null)
        {
            clips = new List<FB.PosePlus.AniClip>(con.clips);
        }
        else
        {
            clips = new List<FB.PosePlus.AniClip>();
        }
        foreach (var c in clips)
        {
            if (c.name == _clip.name + ".FBAni")
            {
                clips.Remove(c);
                break;
            }
        }

        //ani.StopPlayback();
        string outpath = path + "/" + clip.name + ".FBAni.asset";
        AssetDatabase.CreateAsset(_clip, outpath);
        var src = AssetDatabase.LoadAssetAtPath(outpath, typeof(FB.PosePlus.AniClip)) as FB.PosePlus.AniClip;

        //设置clip

        //FB.CleanData.AniController con = ani.GetComponent<FB.CleanData.AniController>();

        clips.Add(src);
        con.clips = clips;
    }
Example #7
0
 public static int GetCurveID(AnimationClip clip, EditorCurveBinding curveData)
 {
     int num = (clip != null) ? clip.GetInstanceID() : 0;
     return ((((num * 0x4c93) ^ (curveData.path.GetHashCode() * 0x2d9)) ^ (curveData.type.GetHashCode() * 0x1b)) ^ curveData.propertyName.GetHashCode());
 }
Example #8
0
    //从一个Animator中获取所有的Animation
    public static void CloneAni(UnityEngine.AnimationClip clip, float fps, Animator ani)
    {
        //创建CleanData.Ani
        FB.PosePlus.AniClip _clip = ScriptableObject.CreateInstance <FB.PosePlus.AniClip>();
        _clip.boneinfo = new List <string>();//也增加了每个动画中的boneinfo信息.

        //这里重新检查动画曲线,找出动画中涉及的Transform部分,更精确
        List <Transform> cdpath = new List <Transform>();
        var curveDatas          = AnimationUtility.GetCurveBindings(clip);

        //AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(clip, true);
        foreach (var dd in curveDatas)
        {
            Transform tran = ani.transform.Find(dd.path);
            if (tran == null)
            {
                Debug.LogWarning("trans not found:" + dd.path);
                //丢弃无法被找到的动画通道
            }
            else
            {
                if (cdpath.Contains(tran) == false)
                {
                    _clip.boneinfo.Add(tran.name);
                    cdpath.Add(tran);
                }
            }
        }
        FB.PosePlus.AniPlayer con = ani.gameObject.GetComponent <FB.PosePlus.AniPlayer>();
        foreach (var b in con.bones)
        {
            //if (b.bone.GetComponent<asbone>() != null)
            {
                //特别关注的骨骼
                if (_clip.boneinfo.Contains(b.bone.name) == false)
                {
                    _clip.boneinfo.Add(b.bone.name);
                    cdpath.Add(b.bone);
                }
            }
        }
        Debug.LogWarning("curve got path =" + cdpath.Count);

        string path = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(clip.GetInstanceID()));

        _clip.name   = clip.name;
        _clip.frames = new List <FB.PosePlus.Frame>();
        _clip.fps    = fps;
        _clip.loop   = clip.isLooping;

        float flen       = (clip.length * fps);
        int   framecount = (int)flen;

        if (flen - framecount > 0.0001)
        {
            framecount++;
        }
        //if (framecount < 1) framecount = 1;

        for (int i = 0, l = clip.events.Length; i < l; i++)
        {
            var        aniEvent = clip.events[i];
            FrameEvent evt      = new FrameEvent();
            evt.name           = aniEvent.functionName;
            evt.position       = aniEvent.time;
            evt.intVariable    = aniEvent.intParameter;
            evt.floatVariable  = aniEvent.floatParameter;
            evt.stringVariable = aniEvent.stringParameter;

            _clip.events.Add(evt);
        }

        framecount += 1;
        FB.PosePlus.Frame last = null;

        //ani.StartPlayback();
        //逐帧复制
        //ani.Play(_clip.name, 0, 0);
        for (int i = 0; i < framecount; i++)
        {
            ani.Play(mapClip2State[_clip.name], 0, (i * 1.0f / fps) / clip.length);
            ani.Update(0);
            last = new FB.PosePlus.Frame(_clip, con, last, i, ani.transform, cdpath);

            _clip.frames.Add(last);
        }

        //特殊处理:写文件后,clips中的内容会丢失
        //这里用clipcache保存clips的内容
        //Debug.Log(con.clips[0].name);
        Dictionary <string, int> clipcache = new Dictionary <string, int>();

        if (con.clips != null)
        {
            for (int i = 0; i < con.clips.Count; i++)
            {
                if (con.clips[i])
                {
                    clipcache[con.clips[i].name] = i;
                }
                else
                {
                    con.clips.RemoveAt(i);
                }
            }
        }
        con.clipcache = clipcache;


        string outpath = PathHelper.CheckFileName(path + "/" + ani.gameObject.name + "_" + clip.name + ".FBAni.asset");

        /*FB.PosePlus.AniClip src = null;
         * if (Pretreatment.AnimatorCache.ContainsKey(outpath))
         * {
         *  src = Pretreatment.AnimatorCache[outpath];
         * }
         * else
         * {
         *  AssetDatabase.CreateAsset(_clip, outpath);
         *  src = AssetDatabase.LoadAssetAtPath(outpath, typeof(FB.PosePlus.AniClip)) as FB.PosePlus.AniClip;
         *  Pretreatment.AnimatorCache[outpath] = src;
         * }*/
        AssetDatabase.CreateAsset(_clip, outpath);
        var src = AssetDatabase.LoadAssetAtPath(outpath, typeof(FB.PosePlus.AniClip)) as FB.PosePlus.AniClip;

        Pretreatment.AnimatorCache[outpath] = src;
        src.clipName = PathHelper.CheckFileName(clip.name);

        con.AddAni(src);
    }