public static bool CheckAnimationInfo(GameObject asset)
        {
            var path = AssetDatabase.GetAssetPath(asset);

            Debug.Log("Path: " + path);
            ModelImporter importer = AssetImporter.GetAtPath(path) as ModelImporter;

            Debug.Log("Clipcount: " + importer.clipAnimations.Length);
            ModelImporterClipAnimation[] animationClips = new ModelImporterClipAnimation[importer.clipAnimations.Length];

            //string relativePath = path + "/" + file.Name;
            AnimationClip clip = AssetDatabase.LoadAssetAtPath <AnimationClip>(path);

            Debug.Log(clip.name);

            Debug.Log(
                nameof(clip.apparentSpeed) + " : " + clip.apparentSpeed + "\n "
                + nameof(clip.averageSpeed) + " : " + clip.averageSpeed + "\n "
                + nameof(clip.hasGenericRootTransform) + " : " + clip.hasGenericRootTransform + "\n "
                + nameof(clip.hasMotionCurves) + " : " + clip.hasMotionCurves + "\n "
                + nameof(clip.hasRootCurves) + " : " + clip.hasRootCurves + "\n "
                + nameof(clip.isHumanMotion) + " : " + clip.isHumanMotion + "\n "
                + nameof(clip.isLooping) + " : " + clip.isLooping);
            //for (int i = 0; i < importer.clipAnimations.Length; i++)
            //{
            //    //mporter.
            //    animationClips[i] = importer.clipAnimations[i];
            //    if (animationClips[i].firstFrame
            //}
            return(false);
        }
예제 #2
0
        private static void SetAnimationSettings(ModelImporter importer, SoModelPostprocessor so)
        {
            importer.animationType   = so.AnimationType;
            importer.importAnimation = so.ImportAnimation;
            if (importer.importAnimation)
            {
                importer.animationCompression = so.AnimationCompression;

                if (so.IsRoleAnimation)
                {
                    var avatarPath   = AssetDatabase.GUIDToAssetPath(so.SourceAvatarGuid);
                    var sourceAvatar = AssetDatabase.LoadAssetAtPath <Avatar>(avatarPath);
                    if (sourceAvatar == null)
                    {
                        throw new Exception("未指定 Source Avatar,请检查配置:" + AssetDatabase.GetAssetPath(so));
                    }

                    importer.sourceAvatar = sourceAvatar;

                    ModelImporterClipAnimation[] anim = new ModelImporterClipAnimation[1];
                    anim[0]                         = new ModelImporterClipAnimation();
                    anim[0].name                    = importer.defaultClipAnimations[0].name;
                    anim[0].firstFrame              = importer.defaultClipAnimations[0].firstFrame;
                    anim[0].lastFrame               = importer.defaultClipAnimations[0].lastFrame;
                    anim[0].lockRootHeightY         = true;
                    anim[0].lockRootPositionXZ      = true;
                    anim[0].lockRootRotation        = true;
                    anim[0].keepOriginalOrientation = true;
                    anim[0].keepOriginalPositionXZ  = true;
                    anim[0].keepOriginalPositionY   = true;

                    importer.clipAnimations = anim;
                }
            }
        }
예제 #3
0
    static ModelImporterClipAnimation ParseAnimFile(string lineStr)
    {
        if (string.IsNullOrEmpty(lineStr))
        {
            return(null);
        }

        lineStr = lineStr.Replace(" ", "").Replace(":", ":");
        // Debug.Log(lineStr);
        try
        {
            string[] slashArr = lineStr.Split('/', '/');
            string[] colonArr = slashArr[0].Split(':');
            string[] hArr     = colonArr[1].Split('-');
//        Match match = regexString.Match(sAnimList);
            ModelImporterClipAnimation clip = new ModelImporterClipAnimation();
            clip.firstFrame = float.Parse(hArr[0]);
            clip.lastFrame  = float.Parse(hArr[1]);
            clip.name       = colonArr[0];
            return(clip);
        }
        catch (Exception e)
        {
            Debug.LogError("该行数据出错,请检查中英文标点等:" + lineStr);
            return(null);
        }
    }
        //TODO 替换震屏参数改成id,定义了一个全局列表?
        public override bool OnFormat(Object _obj, string _path, AssetImporter _importer)
        {
            ModelImporter modelImporter = _importer as ModelImporter;

            if (modelImporter == null)
            {
                return(true);
            }

            ModelImporterClipAnimation[] mcAnimationArr = modelImporter.clipAnimations;

            int mcAnimationArrLen = mcAnimationArr.Length;
            int animEventArrLen   = 0;

            for (int i = 0; i < mcAnimationArrLen; i++)
            {
                ModelImporterClipAnimation mcAnimation = mcAnimationArr[i];

                AnimationEvent[] animEventArr = mcAnimation.events;

                animEventArrLen = animEventArr.Length;

                for (int j = 0; j < animEventArrLen; j++)
                {
                    AnimationEvent animEvent = animEventArr[j];

                    if (AssetCheckTool.IsShakeCameraName(animEvent.functionName))
                    {
                        return(true);
                    }
                }
            }

            return(base.OnFormat(_obj, _path, _importer));
        }
예제 #5
0
    public static void LoadWeaponAnimation()
    {
        foreach (var go in Selection.gameObjects)
        {
            var    path     = AssetDatabase.GetAssetPath(go);
            string filename = System.IO.Path.GetFileNameWithoutExtension(path);
            Debug.Log(path);
            ModelImporter mi = AssetImporter.GetAtPath(path) as ModelImporter;

            ModelImporterClipAnimation[] clips = mi.clipAnimations;
            Debug.Log(clips.Length);
            if (clips.Length == 0)
            {
                clips         = new ModelImporterClipAnimation[1];
                clips[0]      = new ModelImporterClipAnimation();
                clips[0].name = filename;

                AnimationClip orgClip = (AnimationClip)AssetDatabase.LoadAssetAtPath(path, typeof(AnimationClip));
                clips[0].firstFrame = 0;
                clips[0].lastFrame  = (int)(orgClip.length * orgClip.frameRate);
            }


            for (int i = 0; i < clips.Length; i++)
            {
                ModelImporterClipAnimation mica = clips[i];

                mica.loopTime                = true;
                mica.loopPose                = false;
                mica.lockRootRotation        = true;
                mica.lockRootPositionXZ      = true;
                mica.lockRootHeightY         = true;
                mica.keepOriginalOrientation = true;
                mica.keepOriginalPositionXZ  = true;
                mica.keepOriginalPositionY   = true;
            }
            mi.clipAnimations = clips;

            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
            AssetDatabase.Refresh();

            var assets = AssetDatabase.LoadAllAssetsAtPath(path);
            foreach (var asset in assets)
            {
                if (asset.GetType() == typeof(AnimationClip))
                {
                    Debug.Log(asset.name);
                    if (asset.name.IndexOf("__preview__") >= 0)
                    {
                        continue;
                    }

                    AnimationClip orgClip   = (AnimationClip)asset;
                    AnimationClip placeClip = new AnimationClip();
                    EditorUtility.CopySerialized(orgClip, placeClip);
                    AssetDatabase.CreateAsset(placeClip, System.IO.Path.GetDirectoryName(path) + "/Resources/" + placeClip.name + ".anim");
                }
            }
        }
    }
        public static void RenameClips(GameObject asset, string prefix, bool forceLooping = false)
        {
            var path = AssetDatabase.GetAssetPath(asset);

            Debug.Log("Path: " + path);
            ModelImporter importer = AssetImporter.GetAtPath(path) as ModelImporter;

            Debug.Log("Clipcount: " + importer.defaultClipAnimations.Length);
            ModelImporterClipAnimation[] animationClips = new ModelImporterClipAnimation[importer.defaultClipAnimations.Length];
            //foreach(var nfo in importer.importedTakeInfos)
            //{
            //    Debug.Log(nfo.defaultClipName);
            //}
            for (int i = 0; i < importer.defaultClipAnimations.Length; i++)
            {
                animationClips[i] = importer.defaultClipAnimations[i];
                Debug.Log(animationClips[i].takeName);
                if (forceLooping)
                {
                    animationClips[i].loop     = true;
                    animationClips[i].loopTime = true;
                }
                animationClips[i].name = asset.name;
            }
            importer.clipAnimations = animationClips;
            importer.SaveAndReimport();
            if (asset.name.Length < prefix.Length || asset.name.Substring(0, prefix.Length) != prefix)
            {
                AssetDatabase.RenameAsset(path, prefix + asset.name);
            }
        }
예제 #7
0
        static void ParseAnimFile(string sAnimList, ref System.Collections.ArrayList List)
        {
            Regex regexString = new Regex(" *(?<firstFrame>[0-9]+) *- *(?<lastFrame>[0-9]+) *(?<loop>(loop|noloop| )) *(?<name>[^\r^\n]*[^\r^\n^ ])",
                                          RegexOptions.Compiled | RegexOptions.ExplicitCapture);

            Match match = regexString.Match(sAnimList, 0);

            while (match.Success)
            {
                ModelImporterClipAnimation clip = new ModelImporterClipAnimation();

                if (match.Groups["firstFrame"].Success)
                {
                    clip.firstFrame = System.Convert.ToInt32(match.Groups["firstFrame"].Value, 10);
                }
                if (match.Groups["lastFrame"].Success)
                {
                    clip.lastFrame = System.Convert.ToInt32(match.Groups["lastFrame"].Value, 10);
                }
                if (match.Groups["loop"].Success)
                {
                    clip.loopTime = match.Groups["loop"].Value == "loop";
                }
                if (match.Groups["name"].Success)
                {
                    clip.name = match.Groups["name"].Value;
                }

                List.Add(clip);

                match = regexString.Match(sAnimList, match.Index + match.Length);
            }
        }
    public void ProcessAnimationNames(ModelImporter modelImporter, GameObject root)
    {
        //  Grab all model clips.
        ModelImporterClipAnimation[] clipAnimations = modelImporter.defaultClipAnimations;
        //  Grab the first clip.
        ModelImporterClipAnimation clipAnimation = clipAnimations[0];


        clipAnimation.name = ProcessName(root.name);
        if (m_UpdateNameOnly == false)
        {
            clipAnimation.loop     = m_Loop;
            clipAnimation.loopTime = m_LoopTime;
            clipAnimation.loopPose = m_LoopPose;

            clipAnimation.lockRootRotation   = m_LockRootRotation;
            clipAnimation.lockRootHeightY    = m_LockRootHeightY;
            clipAnimation.lockRootPositionXZ = m_LockRootPositionXZ;

            clipAnimation.keepOriginalOrientation = m_KeepOriginalOrientation;
            clipAnimation.keepOriginalPositionY   = m_KeepOriginalPositionY;
            clipAnimation.keepOriginalPositionXZ  = m_KeepOriginalPositionXZ;

            if (m_HeightFromFeet)
            {
                clipAnimation.keepOriginalPositionY = false;
                clipAnimation.heightFromFeet        = m_HeightFromFeet;
            }
        }

        //Debug.LogFormat("\"{0}\" {1}", clipAnimation.name, clipAnimation.m_Loop ? "does m_Loop" : "does NOT m_Loop");
        modelImporter.clipAnimations = clipAnimations;
        // Save
        modelImporter.SaveAndReimport();
    }
예제 #9
0
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        if (currentFBX != null && currentCSV != null && importedAssets.Length == 2)
        {
            Debug.Log("FBX file has a CSV counterpart. Creating Animations...");
            if (currentCSV.Length % 3 != 0)
            {
                Debug.LogWarning("Invalid .CSV file, current length is " + currentCSV.Length.ToString());
                return;
            }

            int animationCount = currentCSV.Length / 3;
            Debug.Log("Parsing animations, " + animationCount.ToString() + " clips found.");
            ModelImporterClipAnimation[] anim = new ModelImporterClipAnimation[animationCount];
            for (int i = 0; i < animationCount; i++)
            {
                int index = i * 3;
                anim[i]            = new ModelImporterClipAnimation();
                anim[i].name       = currentCSV[index];
                anim[i].firstFrame = float.Parse(currentCSV[index + 1]);
                anim[i].lastFrame  = float.Parse(currentCSV[index + 2]);
            }

            currentFBX.clipAnimations = anim;
            FileUtil.DeleteFileOrDirectory(currentCSVpath);
        }

        currentFBX     = null;
        currentCSV     = null;
        currentCSVpath = null;
    }
    public void OnPreprocessModel()
    {
        //当前正在导入的模型
        ModelImporter modelImporter = (ModelImporter)assetImporter;

        AnimationClipConfig.init();

        foreach (AnimationClipConfig.modelST item in AnimationClipConfig.modelList)
        {
            //当前导入模型的路径包含我们modelST动作数据表中的模型名字,那就要对这个模型的动画进行切割
            if (assetPath.Contains(item.ModelName))
            {
                modelImporter.animationType = ModelImporterAnimationType.Legacy;

                //modelImporter.splitAnimations = true;
                modelImporter.generateAnimations = ModelImporterGenerateAnimations.GenerateAnimations;

                ModelImporterClipAnimation[] animations = new ModelImporterClipAnimation[item.clipSTs.Length];
                for (int i = 0; i < item.clipSTs.Length; i++)
                {
                    animations[i] = SetClipAnimation(item.clipSTs[i].name, item.clipSTs[i].firstFrame, item.clipSTs[i].lastFrame, item.clipSTs[i].isloop);
                }

                modelImporter.clipAnimations = animations;
            }
        }
    }
예제 #11
0
    public void SetAnimData(GameObject go, GameObject fbx, string path)
    {
        if (go == null)
        {
            Debug.LogError("go is null!!");
            return;
        }

        Animation anim = go.GetComponent <Animation>();

        if (anim == null || anim.GetClipCount() == 0)
        {
            if (anim == null)
            {
                anim = go.AddComponent <Animation>();
            }
            Object target  = PrefabUtility.GetPrefabParent(fbx);
            string fbxpath = AssetDatabase.GetAssetPath(target);
            if (target == null)
            {
                fbxpath = AssetDatabase.GetAssetPath(fbx);
            }
            else
            {
            }

            Debug.Log(fbxpath);
            ModelImporter modelImporter = (ModelImporter)AssetImporter.GetAtPath(fbxpath);
            if (modelImporter.animationType != ModelImporterAnimationType.Legacy)
            {
                modelImporter.animationType = ModelImporterAnimationType.Legacy;
                modelImporter.SaveAndReimport();
            }
            Object[] arr = AssetDatabase.LoadAllAssetsAtPath(fbxpath);
            for (int i = 0; i < modelImporter.clipAnimations.Length; i++)
            {
                ModelImporterClipAnimation clip = modelImporter.clipAnimations[i];
                for (int j = 0; j < arr.Length; j++)
                {
                    if (arr[j] as AnimationClip)
                    {
                        if (arr[j].name == clip.name)
                        {
                            anim.AddClip(arr[j] as AnimationClip, arr[j].name);
                            break;
                        }
                    }
                }
            }
        }
        SkinnedMeshRenderer smr = go.GetComponentInChildren <SkinnedMeshRenderer>();

        if (anim == null || smr == null)
        {
            Debug.LogError("anim or smr is null!!");
            return;
        }
        this.bakedMesh = new Mesh();
        this.animData  = new AnimData(anim, smr, go.name);
    }
예제 #12
0
파일: ImportTool.cs 프로젝트: Yeyunrong/U3d
    void OnPostprocessModel(GameObject g)
    {
        ModelImporter model = (ModelImporter)assetImporter;

        if (model != null)
        {
            if (isLoopAnimation(g.name))
            {
                //由于我们采用动画分离的导出策略,每个fbx只有一个动画
                if (model.defaultClipAnimations.Length > 0)
                {
                    List <ModelImporterClipAnimation> actions = new List <ModelImporterClipAnimation>();
                    ModelImporterClipAnimation        anim    = model.defaultClipAnimations[0];
                    if (!anim.loopTime)
                    {
                        anim.loopTime = true;
                        anim.loopPose = true;
                        actions.Add(anim);
                        model.clipAnimations = actions.ToArray();
                        //  model.SaveAndReimport();
                    }
                }
            }

            //if (model.isReadable)
            //{
            //    model.isReadable = false;
            //    model.SaveAndReimport();
            //}
        }
        //Debug.Log("OnPostprocessModel : " + g.name);
    }
    static bool WeakAddClipAnimation(ref ModelImporterClipAnimation[] clipAnimations, ModelImporterClipAnimation clipAnimation)
    {
        if (clipAnimation == null)
        {
            return(false);
        }

        if (clipAnimations == null || clipAnimations.Length == 0)
        {
            clipAnimations = new ModelImporterClipAnimation[] { clipAnimation };
            return(true);
        }

        foreach (var t in clipAnimations)
        {
            if (t != null)
            {
                if (t.name == clipAnimation.name)
                {
                    return(false);
                }
            }
        }

        int index = clipAnimations.Length;

        System.Array.Resize(ref clipAnimations, index + 1);
        clipAnimations[index] = clipAnimation;
        return(true);
    }
예제 #14
0
    void OnPreprocessAnimation()
    {
        if (!assetPath.Contains("Assets/Model"))
        {
            return;
        }

        ModelImporter modelImporter = assetImporter as ModelImporter;

        if (modelImporter.clipAnimations.Length == 0)
        {
            modelImporter.clipAnimations = modelImporter.defaultClipAnimations;
        }

        ModelImporterClipAnimation[] clipAnimations = modelImporter.clipAnimations;
        for (int i = 0; i < clipAnimations.Length; i++)
        {
            ModelImporterClipAnimation clip = clipAnimations[i];
            string clipName = clip.name;
            int    indexOf  = clipName.IndexOf('@');
            if (indexOf > 0)
            {
                clipName = clipName.Substring(indexOf + 1, clipName.Length - indexOf - 1);
            }

            if (EntityParamModel.IsLoop(clipName))
            {
                clip.loopTime = true;
            }
        }
        modelImporter.clipAnimations = clipAnimations;
    }
        public static void ApplySettingsToClip(GameObject asset)
        {
            var path = AssetDatabase.GetAssetPath(asset);

            Debug.Log("Path: " + path);
            ModelImporter importer = AssetImporter.GetAtPath(path) as ModelImporter;

            Debug.Log("Clipcount: " + importer.clipAnimations.Length);
            ModelImporterClipAnimation[] animationClips = new ModelImporterClipAnimation[importer.clipAnimations.Length];

            for (int i = 0; i < importer.clipAnimations.Length; i++)
            {
                animationClips[i] = importer.clipAnimations[i];
                if (importSettings.affectIsLooping)
                {
                    animationClips[i].loop = importSettings.isLooping;
                }
                if (importSettings.affectBakeRotation)
                {
                    animationClips[i].lockRootRotation = importSettings.bakeRotation;
                }
                if (importSettings.affectBakeY)
                {
                    animationClips[i].lockRootHeightY = importSettings.bakeY;
                }
                if (importSettings.affectBakeXZ)
                {
                    animationClips[i].lockRootPositionXZ = importSettings.bakeXZ;
                }
            }
            importer.clipAnimations = animationClips;
            importer.SaveAndReimport();
        }
예제 #16
0
    void OnPreprocessModel()
    {
        ModelImporter model = assetImporter as ModelImporter;

        if (model == null)
        {
            return;
        }

        List <ClipData> clipDatas = AnimationClipData.Instance.GetClipData(Path.GetFileName(assetPath));

        if (clipDatas != null && clipDatas.Count > 0)
        {
            bool reset = (clipDatas.Count != model.clipAnimations.Length);

            List <ModelImporterClipAnimation> newClips = new List <ModelImporterClipAnimation>();
            List <ModelImporterClipAnimation> oldClips = new List <ModelImporterClipAnimation>(model.clipAnimations);
            foreach (ClipData clipData in clipDatas)
            {
                ModelImporterClipAnimation clip = oldClips.Find(ret => ret.name == clipData.name);

                if (clip == null)
                {
                    clip = new ModelImporterClipAnimation();
                }

                if (clip.name != clipData.name)
                {
                    clip.name = clipData.name;
                    reset     = true;
                }

                if (Mathf.Abs(clip.firstFrame - clipData.startframe) > 0.001f)
                {
                    clip.firstFrame = clipData.startframe;
                    reset           = true;
                }

                if (Mathf.Abs(clip.lastFrame - clipData.endframe) > 0.001f)
                {
                    clip.lastFrame = clipData.endframe;
                    reset          = true;
                }

                if (clip.loopTime != clipData.loop)
                {
                    clip.loopTime = clipData.loop;
                    reset         = true;
                }

                newClips.Add(clip);
            }

            if (reset)
            {
                model.clipAnimations = newClips.ToArray();
            }
        }
    }
        public static void Setting(string path, string[] loopClips)
        {
            List <string> clipPaths = new List <string>();

            Find(path, clipPaths);

            int numFiles = clipPaths.Count;
            int index    = 0;

            foreach (string clipPath in clipPaths)
            {
                index++;
                if (EditorUtility.DisplayCancelableProgressBar("Setting Fbx Clip", index + "/" + numFiles + " " + clipPath, (float)index / (float)numFiles))
                {
                    break;
                }

                ModelImporter mi = AssetImporter.GetAtPath(clipPath) as ModelImporter;

                if (mi == null)
                {
                    continue;
                }
                mi.importMaterials = false;
                ModelImporterClipAnimation[] clips = mi.defaultClipAnimations;

                ModelImporterClipAnimation[] myclips = new ModelImporterClipAnimation[clips.Length];
                for (int i = 0; i < clips.Length; i++)
                {
                    ModelImporterClipAnimation clip = clips[i];
                    myclips[i] = clip;
//					clip.loop = true;
//					clip.loopTime = true;
//					ModelImporterClipAnimation mc = myclips[i] = new ModelImporterClipAnimation();
//					mc.name = clip.name;
//					mc.takeName = clip.takeName;
//					mc.firstFrame = clip.firstFrame;
//					mc.lastFrame = clip.lastFrame;
//					mc.loop = true;
//					mc.loopTime = true;
                    if (ArrayUtility.IndexOf <string>(loopClips, clip.name) != -1)
                    {
                        clip.loop     = true;
                        clip.loopTime = true;
                    }
                    else
                    {
                        clip.loop     = false;
                        clip.loopTime = false;
                    }
//					Debug.Log(string.Format("name={0}, loop={1}, loopTime={2}, path={3}", clip.name, clip.loop,clip.loopTime, clipPath));
                }
                mi.clipAnimations = myclips;

                mi.SaveAndReimport();
            }

            EditorUtility.ClearProgressBar();
        }
예제 #18
0
 public static void OnAnimationProcess(ModelImporterClipAnimation clip)
 {
     clip.lockRootHeightY         = true;
     clip.lockRootPositionXZ      = true;
     clip.lockRootRotation        = true;
     clip.keepOriginalOrientation = true;
     clip.keepOriginalPositionXZ  = true;
     clip.keepOriginalPositionY   = true;
 }
    private ModelImporterClipAnimation SetClipAnimation(string name, int firstFrame, int lastFrame, bool loop)
    {
        ModelImporterClipAnimation mica = new ModelImporterClipAnimation();

        mica.name       = name;
        mica.firstFrame = firstFrame;
        mica.lastFrame  = lastFrame;
        mica.loop       = loop;
        return(mica);
    }
예제 #20
0
        public void AddClip(string name, int firstFrame, int lastFrame, WrapMode wrapMode)
        {
            ModelImporterClipAnimation tempClip = new ModelImporterClipAnimation();

            tempClip.name       = name;
            tempClip.firstFrame = firstFrame;
            tempClip.lastFrame  = lastFrame;
            tempClip.wrapMode   = wrapMode;
            clipList.Add(tempClip);
        }
예제 #21
0
        void ShowAnimatorModel()
        {
            _fbxModel = (GameObject)CreateObjectField("model", _fbxModel, typeof(GameObject));

            string path = AssetDatabase.GetAssetPath(_fbxModel);

            ModelImporter modelIm = (ModelImporter)ModelImporter.GetAtPath(path);

            //		AnimationClip newClip = AssetDatabase.LoadAssetAtPath(path, typeof(AnimationClip)) as AnimationClip;

            EditorGUILayout.BeginHorizontal();
            CreateLabel("name");
            CreateLabel("start");
            CreateLabel("end");
            CreateLabel("isLooping");
            EditorGUILayout.EndHorizontal();

            if (modelIm == null)
            {
                return;
            }
            ModelImporterClipAnimation[] animations = modelIm.clipAnimations;
            for (int pos = 0; pos < animations.Length; pos++)
            {
                EditorGUILayout.BeginHorizontal();
                animations[pos].name       = CreateStringField(animations[pos].name);
                animations[pos].firstFrame = CreateFloatField(animations[pos].firstFrame);
                animations[pos].lastFrame  = CreateFloatField(animations[pos].lastFrame);
                animations[pos].loop       = CreateCheckBox(animations[pos].loop);
                //			animations[pos].
                CreateLabel(animations[pos].loop.ToString());
                EditorGUILayout.EndHorizontal();
            }
            if (CreateSpaceButton("Insert"))
            {
                ModelImporterClipAnimation[] newAnim = new ModelImporterClipAnimation[animations.Length + 1];
                animations.CopyTo(newAnim, 0);
                animations = newAnim;
                animations[animations.Length - 1] = animations[0];
            }
            if (CreateSpaceButton("Sub"))
            {
                ModelImporterClipAnimation[] newAnim = new ModelImporterClipAnimation[animations.Length - 1];
                System.Array.Copy(animations, newAnim, newAnim.Length);
                animations = newAnim;
            }
            if (GUI.changed)
            {
                modelIm.clipAnimations = animations;

                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
        }
예제 #22
0
        public static void AutoClip()
        {
            string path = Selection.activeObject == null ? "" : AssetDatabase.GetAssetPath(Selection.activeObject);

            Debug.Log("[切割动画] path=" + path);

            ModelImporter mi = AssetImporter.GetAtPath(path) as ModelImporter;

            if (mi == null)
            {
                Debug.Log("[切割动画] 没找到FBX文件! path=" + path);
            }
            else
            {
                Debug.Log("[切割动画] 开始切割:path=" + path);

                // 注意保留就动画的一些数据,比如绑定的event

                List <ModelImporterClipAnimation> oldClips = new List <ModelImporterClipAnimation>();
                List <ModelImporterClipAnimation> newClips = new List <ModelImporterClipAnimation>();
                if (mi.clipAnimations != null)
                {
                    oldClips.AddRange(mi.clipAnimations);
                }

#if true//TEST
                //AnimationUtility.GetAnimationClipSettings(null);
                ModelImporterClipAnimation test = new ModelImporterClipAnimation();
                test.name                    = "test";
                test.takeName                = "auto";
                test.firstFrame              = 0;
                test.lastFrame               = 30;
                test.wrapMode                = WrapMode.Default;
                test.keepOriginalPositionY   = true;
                test.loop                    = false;
                test.loopTime                = false;
                test.loopPose                = false;
                test.keepOriginalOrientation = false;
                test.keepOriginalPositionY   = false;
                test.keepOriginalPositionXZ  = false;
                test.cycleOffset             = 0;
                test.heightOffset            = 0;
                test.rotationOffset          = 0;

                newClips.Add(test);
                newClips.AddRange(oldClips);
#endif

                mi.clipAnimations = newClips.ToArray();
                EditorUtility.SetDirty(Selection.activeObject);
            }
        }
예제 #23
0
        public override void DoCustomRule(AssetImporter import)
        {
            if (!import.assetPath.StartsWith("Assets/Models/Environment/Models/Environment/COL3Building/Models"))
            {
                return;
            }
            ModelImporter modelImporter = (ModelImporter)import;
            bool          isFindRule    = false;
            bool          isMerge       = false;

            for (int i = 0; i < BuildingAssets.Instance.ConfigList.Count; i++)
            {
                BuildingAssets.BuildingConfig cfg = BuildingAssets.Instance.ConfigList[i];

                int    index     = modelImporter.assetPath.LastIndexOf("/");
                string modelName = modelImporter.assetPath.Substring(index + 1);

                if (modelName.StartsWith(cfg.ModelName) &&
                    modelName.EndsWith(".FBX"))
                {
                    modelImporter.importAnimation = true;
                    isMerge = cfg.IsMergeMesh;
                    if (cfg.ModelLevelList != null)
                    {
                        for (int j = 0; j < cfg.ModelLevelList.Count; j++)
                        {
                            if (!string.IsNullOrEmpty(cfg.ModelLevelList[j].ModelLevelName) &&
                                modelImporter.assetPath.EndsWith(cfg.ModelLevelList[j].ModelLevelName + ".FBX"))
                            {
                                ModelImporterClipAnimation[] anims = new ModelImporterClipAnimation[cfg.ModelLevelList[j].ClipDefine.Count];
                                for (int m = 0; m < cfg.ModelLevelList[j].ClipDefine.Count; m++)
                                {
                                    anims[m] = SetClipAnimation(cfg.ModelLevelList[j].ClipDefine[m].ClipName,
                                                                cfg.ModelLevelList[j].ClipDefine[m].StartFrame,
                                                                cfg.ModelLevelList[j].ClipDefine[m].EndFrame,
                                                                cfg.ModelLevelList[j].ClipDefine[m].IsLoop);
                                }
                                modelImporter.clipAnimations = anims;
                                isFindRule = true;
                            }
                        }
                    }
                }
            }
            //
            if (isFindRule)
            {
                modelImporter.SaveAndReimport();
                GameObject go = AssetDatabase.LoadAssetAtPath <GameObject>(modelImporter.assetPath);
                SplitAnimationClipAndMergeMesh.DoSplitAnimationClipAndMergeMesh(go, isMerge);
            }
        }
예제 #24
0
        void OnPreprocessModel()
        {
            Match match = MODEL_REGEX.Match(this.assetPath);

            if (match.Length == 0)
            {
                return;
            }
            string path = match.Groups[1].Value;

            ModelImporter importer = ( ModelImporter )this.assetImporter;

            importer.isReadable       = false;
            importer.importVisibility = false;
            importer.importCameras    = false;
            importer.importLights     = false;
            importer.importMaterials  = false;

            TextAsset frame = AssetDatabase.LoadAssetAtPath <TextAsset>(path + "frame.txt");

            if (frame == null)
            {
                return;
            }

            List <ModelImporterClipAnimation> micas = new List <ModelImporterClipAnimation>();

            using (StringReader reader = new StringReader(frame.text))
            {
                while (reader.Peek() > -1)
                {
                    string line = reader.ReadLine();
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }
                    string[] args    = line.Split(' ');
                    string   aniName = args[0];
                    args = args[1].Split('-');
                    string startFrame = args[0];
                    string endFrame   = args[1];
                    ModelImporterClipAnimation mica = new ModelImporterClipAnimation();
                    mica.name       = aniName;
                    mica.firstFrame = float.Parse(startFrame);
                    mica.lastFrame  = float.Parse(endFrame);
                    mica.loopTime   = true;
                    micas.Add(mica);
                }
            }
            importer.clipAnimations = micas.ToArray();
        }
예제 #26
0
    void GenAnimationDataFile(ModelImporterClipAnimation[] clips, List <AnimationState> curAnims, float frameRate, GameObject go, string path, Dictionary <string, string> dic)
    {
        string luaPath = "Assets/GpuInstancingAnimation/Resources/AnimationData";

        luaPath = Path.Combine(luaPath, go.name + "prefabAnimationData.txt");
        if (File.Exists(luaPath))
        {
            File.Delete(luaPath);
        }

        float s = 1;

        float startTime = 0f;

        string str = "";

        for (int i = 0; i < curAnims.Count; i++)
        {
            ModelImporterClipAnimation curClip = null;
            for (int j = 0; j < clips.Length; j++)
            {
                if (curAnims[i].name == clips[j].name)
                {
                    curClip = clips[j];
                    break;
                }
            }
            string isLoop = "False";
            if (curClip.wrapMode == WrapMode.Loop)
            {
                isLoop = "True";
            }
            float time = (Mathf.CeilToInt(curAnims[i].clip.frameRate * curAnims[i].length * s) + 2) / frameRate;

            float targetEndTime = time + startTime;
            str += curClip.name + "|" + (startTime + 0.5 / frameRate) + "|" + (targetEndTime - 0.5f / frameRate) + "|" + isLoop;

            str += "\n";

            startTime += time;
        }

        string end = "\n";

        str += end;
        Debug.Log(str);
        File.WriteAllText(luaPath, str);
    }
예제 #27
0
    static ModelImporterClipAnimation SetClipAnimation(string _clipName, int _firstFrame, int _lastFrame, bool _isLoop)
    {
        ModelImporterClipAnimation _clip = new ModelImporterClipAnimation();

        _clip.name       = _clipName;
        _clip.firstFrame = _firstFrame;
        _clip.lastFrame  = _lastFrame;
        _clip.loop       = _isLoop;
        if (_isLoop)
        {
            _clip.wrapMode = WrapMode.Loop;
        }
        else
        {
            _clip.wrapMode = WrapMode.Default;
        }
        return(_clip);
    }
예제 #28
0
    static void ImportTest()
    {
        GameObject go   = Selection.activeGameObject;
        string     path = AssetDatabase.GetAssetPath(go);

        Debug.Log(path);
        ModelImporter modelImport = AssetImporter.GetAtPath(path) as ModelImporter;

        ModelImporterClipAnimation[] modelClip = new ModelImporterClipAnimation[2];
        for (int i = 0; i < 2; i++)
        {
            ModelImporterClipAnimation clip = SetClipAnimation(i.ToString(), i * 30, i * 30 + 10, i == 0);
            modelClip[i] = clip;
            Debug.Log(clip.name);
        }
        modelImport.clipAnimations = modelClip;
        modelImport.SaveAndReimport();
    }
    private void OnPreprocessModel()
    {
        if (assetPath.Contains("nameofmodel"))
        {
            ModelImporter modelImporter = assetImporter as ModelImporter;
            modelImporter.splitAnimations    = true;
            modelImporter.generateAnimations = ModelImporterGenerateAnimations.InRoot;

            // Set the number of animations here
            int numAnimations = 1;
            ModelImporterClipAnimation[] animations = new ModelImporterClipAnimation[numAnimations];

            animations[0] = SetClipAnimation("walk", 0, 24, true);
            // Add your new animation splits here, simply changing the arguments

            // Assign the clips to the model importer to automagically do your splits
            modelImporter.clipAnimations = animations;
        }
    }
예제 #30
0
    ModelImporterClipAnimation SetClipAnimation(string _name, int _first, int _last, bool _isLoop)
    {
        ModelImporterClipAnimation tempClip = new ModelImporterClipAnimation();

        tempClip.name       = _name;
        tempClip.firstFrame = _first;
        tempClip.lastFrame  = _last;
        tempClip.loop       = _isLoop;
        if (_isLoop)
        {
            tempClip.wrapMode = WrapMode.Loop;
        }
        else
        {
            tempClip.wrapMode = WrapMode.Default;
        }

        return(tempClip);
    }