Exemple #1
0
    private void _SetAnim(string Name)
    {
        _animName = Name;
        _animator.Play(Name);
        _animator.speed = _animSpeed;

        CUtility.DestroyChildren(_propViewContent);

        mUI.CreateTextElement(_propViewContent, Name, "text", CToolkitUI.ETextStyle.TS_HEADING);

        GameObject foldContent;

        mUI.CreateFoldOut(_propViewContent, "Animation Details", out foldContent);

        GameObject fieldEditor;

        mUI.CreateFieldElement(foldContent, "Name", out fieldEditor); mUI.CreateTextElement(fieldEditor, Name);

        Animation.CAnimationEntry entry = Animation.GetAnimEntry(Name);

        if (entry == null)
        {
            mUI.CreateTextElement(_propViewContent, "No Matching Animation Entry!");
        }
        else
        {
            mUI.CreateFieldElement(foldContent, "Framerate", out fieldEditor); mUI.CreateTextElement(fieldEditor, entry.mFPS.ToString());
            mUI.CreateFieldElement(foldContent, "Start Time", out fieldEditor); mUI.CreateTextElement(fieldEditor, entry.mStartTime.ToString());
            mUI.CreateFieldElement(foldContent, "Duration", out fieldEditor); mUI.CreateTextElement(fieldEditor, entry.mDuration.ToString());
            mUI.CreateFieldElement(foldContent, "Speed Mod", out fieldEditor); mUI.CreateTextElement(fieldEditor, entry.mSpeed.ToString());
        }
    }
    public void OnPreprocessModel()
    {
        Debug.Log("Processing: " + assetPath);

        if (!assetPath.Contains("Assets/Animations/Unit/"))
        {
            return;
        }

        int    tagIndex = assetPath.LastIndexOf('/');
        string declName = assetPath.Substring(tagIndex + 1);

        declName = declName.Substring(0, declName.Length - 4);

        Debug.Log("Anim Decl: " + declName);

        string avatarAssetPath = "Assets/Models/unit_default_2.fbx";

        // Resources
        ModelImporter importer      = assetImporter as ModelImporter;
        Avatar        defaultAvatar = null;

        Animation.CAnimationEntry animDecl = Animation.GetAnimEntry(declName);

        importer.importMaterials = false;

        UnityEngine.Object[] objs = AssetDatabase.LoadAllAssetsAtPath(avatarAssetPath);
        foreach (UnityEngine.Object obj in objs)
        {
            if (obj.GetType() == typeof(Avatar))
            {
                defaultAvatar = obj as Avatar;
                break;
            }
        }

        if (animDecl == null)
        {
            Debug.LogError("Can't find animation declaration for '" + declName + "'");
            return;
        }

        if (defaultAvatar == null)
        {
            Debug.LogError("Can't find the default avatar from '" + avatarAssetPath + "'");
            return;
        }

        // Apply settings to imported model
        importer.animationType = ModelImporterAnimationType.Generic;
        importer.sourceAvatar  = defaultAvatar;

        importer.importAnimation        = true;
        importer.resampleCurves         = true;
        importer.animationCompression   = ModelImporterAnimationCompression.KeyframeReduction;
        importer.animationRotationError = 0.5f;
        importer.animationPositionError = 0.5f;
        importer.animationScaleError    = 0.5f;

        // TODO: Get a list of anim clips that could occur in this file. Not just one clip per FBX.

        ModelImporterClipAnimation[] newClips = new ModelImporterClipAnimation[1];
        newClips[0]                    = new ModelImporterClipAnimation();
        newClips[0].name               = declName;
        newClips[0].firstFrame         = animDecl.mStartTime * animDecl.mFPS;
        newClips[0].lastFrame          = animDecl.mDuration * animDecl.mFPS;
        newClips[0].lockRootRotation   = true;
        newClips[0].lockRootHeightY    = true;
        newClips[0].lockRootPositionXZ = true;
        newClips[0].loop               = animDecl.mLoopable;
        newClips[0].loopPose           = animDecl.mLoopable;
        newClips[0].loopTime           = animDecl.mLoopable;

        importer.clipAnimations = newClips;
    }