Exemple #1
0
        static public GameObject FindBestFittingRenderableGameObjectFromModelAsset(Object asset,
                                                                                   ModelImporterAnimationType animationType)
        {
            if (asset == null)
            {
                return(null);
            }

            ModelImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(asset)) as ModelImporter;

            if (importer == null)
            {
                return(null);
            }

            string     assetPath = ReflectionHelper.Instance.ModelImporter.CalculateBestFittingPreviewGameObject();
            GameObject tempGO    = AssetDatabase.LoadMainAssetAtPath(assetPath) as GameObject;

            // We should also check for isHumanClip matching the animationclip requiremenets...
            if (IsValidPreviewGameObject(tempGO, ModelImporterAnimationType.None))
            {
                return(tempGO);
            }
            else
            {
                return(null);
            }
        }
Exemple #2
0
 private void DrawRig()
 {
     EditorGUILayout.BeginHorizontal();
     EditorGUILayout.LabelField("Animation Type");
     m_animationType = (ModelImporterAnimationType)EditorGUILayout.EnumPopup(m_animationType);
     EditorGUILayout.EndHorizontal();
 }
 void CheckAvatar(Avatar sourceAvatar)
 {
     if (sourceAvatar != null)
     {
         if (sourceAvatar.isHuman && (animationType != ModelImporterAnimationType.Human))
         {
             if (EditorUtility.DisplayDialog("Assigning a Humanoid Avatar on a Generic Rig",
                                             "Do you want to change Animation Type to Humanoid ?", "Yes", "No"))
             {
                 animationType = ModelImporterAnimationType.Human;
             }
             else
             {
                 m_AvatarSource.objectReferenceValue = null;
             }
         }
         else if (!sourceAvatar.isHuman && (animationType != ModelImporterAnimationType.Generic))
         {
             if (EditorUtility.DisplayDialog("Assigning a Generic Avatar on a Humanoid Rig",
                                             "Do you want to change Animation Type to Generic ?", "Yes", "No"))
             {
                 animationType = ModelImporterAnimationType.Generic;
             }
             else
             {
                 m_AvatarSource.objectReferenceValue = null;
             }
         }
     }
 }
Exemple #4
0
    /// <summary>
    /// 导出一个模型的所有动画
    /// </summary>
    /// <param name="modelImport">模型</param>
    /// <param name="animationType">导出的动画类型,如果为None,则用模型自己的动画类型</param>
    /// <returns>导出的动画</returns>
    private void ExportAnimations(ModelImporter modelImport, ModelImporterAnimationType animationType, float scal)
    {
        if (null == modelImport)
        {
            //路径非模型,返回//
            return;
        }

        if (!modelImport.importAnimation)
        {
            //没有动画,也返回//
            return;
        }

        string folderPath = CreateAnimationClipsFolder(modelImport);

        if (null == folderPath)
        {
            return;
        }
        DirectoryInfo info = new DirectoryInfo(folderPath);

        if (!info.Exists)
        {
            info.Create();
        }
        //先把模型的动画类型保存//
        ModelImporterAnimationType modelAnimationType = modelImport.animationType;

        //转为Legacy,这样模型对应的import object才会有animations//
        modelImport.animationType = ModelImporterAnimationType.Legacy;
        modelImport.globalScale   = scal;
        //Apply//
        AssetDatabase.ImportAsset(modelImport.assetPath, ImportAssetOptions.ImportRecursive);
        AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
        //取到对应的import object//
        GameObject importObject = AssetDatabase.LoadMainAssetAtPath(modelImport.assetPath) as GameObject;

        if (null != importObject)
        {
            AnimationClip[] clips = AnimationUtility.GetAnimationClips(importObject);
            for (int i = 0; i < clips.Length; ++i)
            {
                AnimationClip dstClip = CopyClip(clips[i], folderPath);
                if (null != dstClip)
                {
#if UNITY_5
                    //DO NOTHING
#else
                    AnimationUtility.SetAnimationType(dstClip, animationType);
#endif
                }
            }
        }

        //还原//
        modelImport.animationType = modelAnimationType;
        //Apply//
        AssetDatabase.ImportAsset(modelImport.assetPath, ImportAssetOptions.ForceSynchronousImport);
    }
Exemple #5
0
 private static GameObject CalculatePreviewGameObject(UnityEngine.Animator selectedAnimator, Motion motion, ModelImporterAnimationType animationType)
 {
     AnimationClip firstAnimationClipFromMotion = GetFirstAnimationClipFromMotion(motion);
     GameObject preview = AvatarPreviewSelection.GetPreview(animationType);
     if (IsValidPreviewGameObject(preview, ModelImporterAnimationType.None))
     {
         return preview;
     }
     if ((selectedAnimator != null) && IsValidPreviewGameObject(selectedAnimator.gameObject, animationType))
     {
         return selectedAnimator.gameObject;
     }
     preview = FindBestFittingRenderableGameObjectFromModelAsset(firstAnimationClipFromMotion, animationType);
     if (preview != null)
     {
         return preview;
     }
     if (animationType == ModelImporterAnimationType.Human)
     {
         return GetHumanoidFallback();
     }
     if (animationType == ModelImporterAnimationType.Generic)
     {
         return GetGenericAnimationFallback();
     }
     return null;
 }
            public ModelFolderRule(ProjectImportSettings.ModelFolderRule rule)
            {
                maxVertices = rule.maxVertices;
                shouldBatch = rule.shouldBatch;

                m_MeshCompression   = rule.m_MeshCompression;
                m_IsReadable        = rule.m_IsReadable;
                optimizeMeshForGPU  = rule.optimizeMeshForGPU;
                m_ImportBlendShapes = rule.m_ImportBlendShapes;
                m_AddColliders      = rule.m_AddColliders;
                keepQuads           = rule.keepQuads;
                weldVertices        = rule.weldVertices;
                m_ImportVisibility  = rule.m_ImportVisibility;
                m_ImportCameras     = rule.m_ImportCameras;
                m_ImportLights      = rule.m_ImportLights;
                swapUVChannels      = rule.swapUVChannels;
                generateSecondaryUV = rule.generateSecondaryUV;
                normalImportMode    = rule.normalImportMode;
                tangentImportMode   = rule.tangentImportMode;

                m_AnimationType            = rule.m_AnimationType;
                m_LegacyGenerateAnimations = rule.m_LegacyGenerateAnimations;

                importAnimation        = rule.importAnimation;
                m_AnimationCompression = rule.m_AnimationCompression;
                m_OptimizeGameObjects  = rule.m_OptimizeGameObjects;

                importMaterials = rule.importMaterials;

                maxBones       = rule.maxBones;
                maxBoneWeights = rule.maxBoneWeights;
            }
Exemple #7
0
        public override void ApplyDefaults()
        {
            this.RuleName = "New Model Rule";
            SuffixFilter  = ".FBX";

            meshCompression     = ModelImporterMeshCompression.Off;
            isReadable          = false;
            importBlendShapes   = false;
            optimizeMeshForGPU  = true;
            generateColliders   = false;
            keepQuads           = false;
            weldVertices        = true;
            swapUVChannels      = false;
            generateSecondaryUV = false;
            normalImportMode    = ModelImporterNormals.None;
            tangentImportMode   = ModelImporterTangents.CalculateMikk;
            importMaterials     = true;
            materialName        = ModelImporterMaterialName.BasedOnTextureName;
            materialSearch      = ModelImporterMaterialSearch.Everywhere;

            animationType = ModelImporterAnimationType.None;

            importAnimation = false;
            animCompression = ModelImporterAnimationCompression.Off;
        }
Exemple #8
0
 /// <summary>
 /// 模型的动画类型设置
 /// </summary>
 /// <param name="modelImporter"></param>
 /// <param name="animationType"></param>
 private void ModelAnimationTypeSetting(ModelImporter modelImporter, ModelImporterAnimationType animationType)
 {
     if (modelImporter.animationType != animationType)
     {
         modelImporter.animationType = animationType;
     }
 }
Exemple #9
0
        public override bool DoCheck(string asset)
        {
            ModelImporterAnimationType modelImporterAnimationType;

            if (Regex.IsMatch(asset, "Assets/Res/Character/[3-4]{1}[0-9]{4}/.*?\\.(FBX|fbx)$"))
            {
                modelImporterAnimationType = ModelImporterAnimationType.Generic;
            }
            else
            {
                modelImporterAnimationType = ModelImporterAnimationType.Human;
            }
            ModelImporter modelImporter = AssetImporter.GetAtPath(asset) as ModelImporter;

            if (modelImporter != null)
            {
                ModelImporterAnimationType animationType = modelImporter.animationType;
                if (animationType == null)
                {
                    return(true);
                }
                if (modelImporterAnimationType != animationType)
                {
                    this.resultInfo.Add(asset, "May be " + modelImporterAnimationType.ToString() + "  |||   now " + modelImporter.animationType.ToString());
                    return(false);
                }
            }
            return(true);
        }
 public void SetPreview(ModelImporterAnimationType type, GameObject go)
 {
     if (null != _methodInfo)
     {
         _methodInfo.Invoke(null, new object[] { type, go });
     }
 }
Exemple #11
0
    void OnGUI()
    {
        m_Animator = (Animator)EditorGUILayout.ObjectField("Animator", m_Animator, typeof(Animator), true);
        m_AnimType = (ModelImporterAnimationType)EditorGUILayout.EnumPopup("AnimType", m_AnimType);
        if (m_AnimType != ModelImporterAnimationType.Legacy)
        {
            m_AnimType = ModelImporterAnimationType.Generic;
        }

        bool bSet = (m_Animator != null);

        EUtil.PushGUIEnable(bSet);
        if (EUtil.Button("Convert Animation!", bSet ? Color.green : Color.red))
        {
            if (!m_Animator.isHuman)
            {
                EUtil.ShowNotification("The model is not in Humanoid rig!");
                return;
            }

            // save xforms recursively
            m_SavedPose = EUtil.CacheXformData(m_Animator.transform);

            m_Animator.Update(0);
#if !U5
            var ainfos = m_Animator.GetCurrentAnimationClipState(0); //only effect after Update is called
#else
            var ainfos = m_Animator.GetCurrentAnimatorClipInfo(0);   //only effect after Update is called
#endif
            if (ainfos.Length == 0)
            {
                EUtil.ShowNotification("No clip in AnimationController!");
            }
            else
            {
                AnimationClip clip             = ainfos[0].clip;
                string        oldClipAssetPath = AssetDatabase.GetAssetPath(clip);
                string        newClipAssetPath = PathUtil.StripExtension(oldClipAssetPath) + NEW_CLIP_POSTFIX + m_AnimType + ".anim";

                string filePath = EditorUtility.SaveFilePanel("Select export file path",
                                                              Path.GetDirectoryName(newClipAssetPath),
                                                              Path.GetFileNameWithoutExtension(newClipAssetPath),
                                                              "anim");
                if (filePath.Length > 0)
                {
                    filePath = PathUtil.FullPath2ProjectPath(filePath);
                    _ConvertAnim(filePath);
                }
                else
                {
                    EUtil.ShowNotification("Conversion Cancelled...");
                }
            }

            //apply the original pose back
            EUtil.ApplyXformData(m_Animator.transform, m_SavedPose);
        }
        EUtil.PopGUIEnable();
    }
Exemple #12
0
 public static void SetPreview(ModelImporterAnimationType type, GameObject go)
 {
     if (Enum.IsDefined(typeof(ModelImporterAnimationType), type) && (ScriptableSingleton <AvatarPreviewSelection> .instance.m_PreviewModels[(int)type] != go))
     {
         ScriptableSingleton <AvatarPreviewSelection> .instance.m_PreviewModels[(int)type] = go;
         ScriptableSingleton <AvatarPreviewSelection> .instance.Save(false);
     }
 }
 public static GameObject GetPreview(ModelImporterAnimationType type)
 {
     if (!Enum.IsDefined(typeof(ModelImporterAnimationType), (object)type))
     {
         return((GameObject)null);
     }
     return(ScriptableSingleton <AvatarPreviewSelection> .instance.m_PreviewModels[(int)type]);
 }
 public static bool IsValidPreviewGameObject(GameObject target, ModelImporterAnimationType requiredClipType)
 {
     if (target != null && !target.activeSelf)
     {
         Debug.LogWarning("Can't preview inactive object, using fallback object");
     }
     return(target != null && target.activeSelf && GameObjectInspector.HasRenderableParts(target) && (requiredClipType == ModelImporterAnimationType.None || AvatarPreview.GetAnimationType(target) == requiredClipType));
 }
Exemple #15
0
    private void DisplaySettings()
    {
        float w  = 85f;
        float w2 = 22f;
        float w3 = 40f;

        GUILayout.BeginHorizontal();
        GUILayout.Label("Set RotError", GUILayout.Width(w));
        doRot  = EditorGUILayout.Toggle(doRot, GUILayout.Width(w2));
        rotVal = EditorGUILayout.FloatField(rotVal, GUILayout.Width(w3));
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        GUILayout.Label("Set RotError", GUILayout.Width(w));
        doPos  = EditorGUILayout.Toggle(doPos, GUILayout.Width(w2));
        posVal = EditorGUILayout.FloatField(posVal, GUILayout.Width(w3));
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        GUILayout.Label("Set ScaleError", GUILayout.Width(w));
        doScale  = EditorGUILayout.Toggle(doScale, GUILayout.Width(w2));
        scaleVal = EditorGUILayout.FloatField(scaleVal, GUILayout.Width(w3));
        GUILayout.EndHorizontal();
        GUILayout.Space(10f);
        GUILayout.BeginHorizontal();
        GUILayout.Label("Set Animation Type", GUILayout.Width(w + 15f));
        doImportType   = EditorGUILayout.Toggle(doImportType, GUILayout.Width(w2));
        currImportType = (ModelImporterAnimationType)EditorGUILayout.EnumPopup(currImportType, GUILayout.Width(w));
        GUILayout.EndHorizontal();
        GUILayout.Space(10f);
        GUILayout.BeginHorizontal();
        GUILayout.Label("Set Bones", GUILayout.Width(w - 15f));
        doBones = EditorGUILayout.Toggle(doBones, GUILayout.Width(w2));
        GUILayout.Label("SkinWeight Type", GUILayout.Width(w + 25f));
        //   currSkinWeightsType = (ModelImporterSkinWeights)EditorGUILayout.EnumPopup(currSkinWeightsType, GUILayout.Width(w));
        GUILayout.EndHorizontal();

        /*
         * if (currSkinWeightsType == ModelImporterSkinWeights.Custom)
         * {
         *  GUILayout.BeginHorizontal();
         *  GUILayout.Label("Bone Count", GUILayout.Width(w));
         *  boneCount = EditorGUILayout.IntSlider(boneCount, 1, 32);
         *  GUILayout.EndHorizontal();
         *  GUILayout.BeginHorizontal();
         *  GUILayout.Label("Bone MinWeight", GUILayout.Width(w + 15f));
         *  currMinBoneWeight = EditorGUILayout.Slider(currMinBoneWeight, 0.001f, 0.5f);
         *  GUILayout.EndHorizontal();
         *  GUILayout.Space(10f);
         * }
         */
        GUILayout.BeginHorizontal();
        GUILayout.Label("Dupliate anim out of fbx", GUILayout.Width(w + 55f));
        duplicateOutAnim = EditorGUILayout.Toggle(duplicateOutAnim, GUILayout.Width(w2));
        GUILayout.Label("Experimental ImportAsset", GUILayout.Width(w + 66f));
        experimentalApplyImportSettFirst = EditorGUILayout.Toggle(experimentalApplyImportSettFirst, GUILayout.Width(w2));
        GUILayout.EndHorizontal();
        GUILayout.Space(10f);
    }
 public static void SetPreview(ModelImporterAnimationType type, GameObject go)
 {
     if (!Enum.IsDefined(typeof(ModelImporterAnimationType), (object)type) || !((UnityEngine.Object)ScriptableSingleton <AvatarPreviewSelection> .instance.m_PreviewModels[(int)type] != (UnityEngine.Object)go))
     {
         return;
     }
     ScriptableSingleton <AvatarPreviewSelection> .instance.m_PreviewModels[(int)type] = go;
     ScriptableSingleton <AvatarPreviewSelection> .instance.Save(false);
 }
        static public GameObject GetPreview(ModelImporterAnimationType type)
        {
            if (!System.Enum.IsDefined(typeof(ModelImporterAnimationType), type))
            {
                return(null);
            }

            return(instance.m_PreviewModels[(int)type]);
        }
Exemple #18
0
        private void FBXSetting()
        {
            EditorGUILayout.BeginVertical(GUILayout.MaxWidth(600));
            {
                GUILayout.Space(15);
                GUILayout.Label("Basic Setting", XXToolsEdGui.Head2Style);

                EditorGUILayout.Space();

                EditorGUILayout.BeginVertical(XXToolsEdGui.BoxStyle, GUILayout.MaxWidth(300));
                {
                    GUILayout.Label("PostProcess", XXToolsEdGui.Head4Style);
                    ModelImporterAnimationType selectType = (ModelImporterAnimationType)EditorGUILayout.EnumPopup("Animation Type", ed.db.animType);
                    if (selectType == ModelImporterAnimationType.Generic || selectType == ModelImporterAnimationType.Legacy)
                    {
                        ed.db.animType = selectType;
                    }
                    if (ed.db.animType == ModelImporterAnimationType.Generic)
                    {
                        ed.db.optiomaize = GUILayout.Toggle(ed.db.optiomaize, "Optiomaize");
                    }
                }
                EditorGUILayout.EndVertical();
                GUILayout.Space(15);
                GUILayout.Label("Actor Component", XXToolsEdGui.Head2Style);
                EditorGUILayout.BeginVertical(XXToolsEdGui.BoxStyle, GUILayout.MaxWidth(300));
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        GUILayout.Label("AC List", XXToolsEdGui.Head3Style);
                        GUILayout.Space(20);

                        if (XXToolsEdGui.IconButton("Refresh", XXToolsEdGui.Icon_Refresh, GUILayout.Width(100)))
                        {
                            LoadAC();
                        }

                        GUILayout.FlexibleSpace();
                    }
                    EditorGUILayout.EndHorizontal();
                    GUILayout.Space(20);
                    scroll[1] = XXToolsEdGui.BeginScrollView(scroll[1], XXToolsEdGui.ScrollViewNoTLMarginStyle, GUILayout.Height(275));
                    {
                        foreach (GameObject go in ed.db.actorComponesPrefabs)
                        {
                            EditorGUILayout.SelectableLabel(go.name, GUILayout.Height(30));
                        }
                    }
                    XXToolsEdGui.EndScrollView();
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndVertical();
        }
Exemple #19
0
 public static bool IsValidPreviewGameObject(GameObject target, ModelImporterAnimationType requiredClipType)
 {
     if ((Object)target != (Object)null && !target.activeSelf)
     {
         Debug.LogWarning((object)"Can't preview inactive object, using fallback object");
     }
     if ((Object)target != (Object)null && target.activeSelf && GameObjectInspector.HasRenderablePartsRecurse(target))
     {
         return((requiredClipType == ModelImporterAnimationType.None ? 0 : (AvatarPreview.GetAnimationType(target) != requiredClipType ? 1 : 0)) == 0);
     }
     return(false);
 }
 public void ApplyDefaults()
 {
     readWriteEnabled       = false;
     optimiseMesh           = true;
     ImportBlendShapes      = false;
     normalImportMode       = ModelImporterNormals.Import;
     animationType          = ModelImporterAnimationType.None;
     meshCompression        = ModelImporterMeshCompression.Off;
     importMaterials        = true;
     importTangents         = ModelImporterTangents.None;
     changeReadableSettings = false;
 }
Exemple #21
0
        public override void CopyData(ImportData data)
        {
            AnimationImportData tData = data as AnimationImportData;

            if (tData == null)
            {
                return;
            }

            base.CopyData(data);
            AnimationType        = tData.AnimationType;
            AnimationCompression = tData.AnimationCompression;
        }
        static public void SetPreview(ModelImporterAnimationType type, GameObject go)
        {
            if (!System.Enum.IsDefined(typeof(ModelImporterAnimationType), type))
            {
                return;
            }

            if (instance.m_PreviewModels[(int)type] != go)
            {
                instance.m_PreviewModels[(int)type] = go;
                instance.Save(false);
            }
        }
Exemple #23
0
        private void DrawRigGUI()
        {
            animationType = (ModelImporterAnimationType)EditorGUILayout.EnumPopup(AssetImportStyles.Model.AnimationType, animationType);

            if (animationType == ModelImporterAnimationType.Generic ||
                animationType == ModelImporterAnimationType.Human)
            {
                isOptimizeObject = true;
            }
            else
            {
                isOptimizeObject = false;
            }
        }
Exemple #24
0
        public static GameObject GetPreview(ModelImporterAnimationType type)
        {
            GameObject result;

            if (!Enum.IsDefined(typeof(ModelImporterAnimationType), type))
            {
                result = null;
            }
            else
            {
                result = ScriptableSingleton <AvatarPreviewSelection> .instance.m_PreviewModels[(int)type];
            }
            return(result);
        }
Exemple #25
0
        void OnWizardCreate()
        {
            string        atlasPath = getAtlasFilePath(path);
            string        directory = Path.GetDirectoryName(atlasPath);
            string        name      = Path.GetFileNameWithoutExtension(path);
            SpritesByName spriteByName;
            Dictionary <string, GameObject> boneGOByName;
            Dictionary <string, Slot>       slotByName;
            List <Skin> skins;
            AttachmentGOByNameBySlot attachmentGOByNameBySlot;

            if (File.Exists(path))
            {
                try{
                    SpineMultiatlas spineMultiAtlas = SpineMultiatlas.deserializeFromFile(atlasPath);
                    SpineData       spineData       = SpineData.deserializeFromFile(path);

                    SpineUtil.updateImporters(spineMultiAtlas, directory, pixelsPerUnit, out spriteByName);
                    GameObject rootGO = SpineUtil.buildSceleton(name, spineData, pixelsPerUnit, out boneGOByName, out slotByName);
                    rootGO.name = name;
                    SpineUtil.addAllAttahcmentsSlots(spineData, spriteByName, slotByName, zStep, pixelsPerUnit, out skins, out attachmentGOByNameBySlot);
                    SkinController sk = SpineUtil.addSkinController(rootGO, spineData, skins, slotByName);
                    if (animationImportType == AnimationImportType.MECANIM)
                    {
                        Animator animator = SpineUtil.addAnimator(rootGO);
                        if (buildAvatarMask)
                        {
                            SpineUtil.builAvatarMask(rootGO, spineData, animator, directory, name);
                        }
                    }

                    ModelImporterAnimationType modelImporterAnimationType = getModelImporterAnimationType();
                    if (spineData.animations != null && spineData.animations.Count > 0)
                    {
                        SpineUtil.addAnimation(rootGO, directory, spineData, boneGOByName, attachmentGOByNameBySlot,
                                               pixelsPerUnit, modelImporterAnimationType, updateResources);
                    }
                    sk.showDefaulSlots();
                    SpineUtil.buildPrefab(rootGO, directory, name);
                    GameObject.DestroyImmediate(rootGO);
                } catch (SpineMultiatlasCreationException e) {
                    Debug.LogException(e);
                } catch (SpineDatatCreationException e) {
                    Debug.LogException(e);
                } catch (AtlasImageDuplicateSpriteName e) {
                    Debug.LogException(e);
                }
            }
        }
    private string GetAvatarName(ModelImporterAnimationType type, Avatar avatar)
    {
        if (type == ModelImporterAnimationType.None || type == ModelImporterAnimationType.Legacy)
        {
            return("No Avatar");
        }
        if (avatar == null)
        {
            return("Create From This Model");
        }
        StringBuilder sb = new StringBuilder(avatar.name.Length + 32);

        sb.Append(avatar.name).Append("(").Append(avatar.GetInstanceID()).Append(")");
        return(sb.ToString());
    }
Exemple #27
0
        ModelImporterAnimationType getModelImporterAnimationType()
        {
            ModelImporterAnimationType result = ModelImporterAnimationType.Generic;

            switch (animationImportType)
            {
            case AnimationImportType.LEGACY:
                result = ModelImporterAnimationType.Legacy;
                break;

            case AnimationImportType.MECANIM:
                result = ModelImporterAnimationType.Generic;
                break;
            }
            return(result);
        }
    public void ApplyDefaults()
    {
        m_MeshCompression   = ModelImporterMeshCompression.Off;
        m_IsReadable        = false;
        m_ImportBlendShapes = false;
        m_AddColliders      = false;
        keepQuads           = false;
        m_weldVertices      = true;
        swapUVChannels      = false;
        generateSecondaryUV = false;
        normalImportMode    = ModelImporterNormals.None;
        tangentImportMode   = ModelImporterTangents.None;
        m_ImportMaterials   = true;
        m_MaterialName      = ModelImporterMaterialName.BasedOnMaterialName;
        m_MaterialSearch    = ModelImporterMaterialSearch.Everywhere;

        AnimationType = ModelImporterAnimationType.None;

        ImportAnimation = false;
    }
Exemple #29
0
        static GameObject CalculatePreviewGameObject(Animator selectedAnimator, Motion motion,
                                                     ModelImporterAnimationType animationType)
        {
            AnimationClip sourceClip = GetFirstAnimationClipFromMotion(motion);

            // Use selected preview
            GameObject selected = EditorHelper.InstantiateGoByPrefab(selectedAnimator.gameObject, null);

            selected.tag = Constants.PREVIRE_TAG;
            InitInstantiatedPreviewRecursive(selected);
            if (IsValidPreviewGameObject(selected, ModelImporterAnimationType.None))
            {
                return(selected);
            }

            if (selectedAnimator != null && IsValidPreviewGameObject(selectedAnimator.gameObject, animationType))
            {
                return(selectedAnimator.gameObject);
            }

            // Find the best fitting preview game object for the asset we are viewing (Handles @ convention, will pick base path for you)
            selected = FindBestFittingRenderableGameObjectFromModelAsset(sourceClip, animationType);
            if (selected != null)
            {
                return(selected);
            }

            if (animationType == ModelImporterAnimationType.Human)
            {
                return(GetHumanoidFallback());
            }
            else if (animationType == ModelImporterAnimationType.Generic)
            {
                return(GetGenericAnimationFallback());
            }

            return(null);
        }
Exemple #30
0
        bool IsAvatarValid(Avatar newAvatar)
        {
            if (newAvatar != null)
            {
                if (newAvatar.isHuman && (animationType != ModelImporterAnimationType.Human))
                {
                    if (EditorUtility.DisplayDialog("Assigning a Humanoid Avatar on a Generic Rig",
                                                    "Do you want to change Animation Type to Humanoid ?", "Yes", "No"))
                    {
                        animationType = ModelImporterAnimationType.Human;
                        return(true);
                    }
                    else
                    {
                        //New Avatar is invalid
                        return(false);
                    }
                }
                else if (!newAvatar.isHuman && (animationType != ModelImporterAnimationType.Generic))
                {
                    if (EditorUtility.DisplayDialog("Assigning a Generic Avatar on a Humanoid Rig",
                                                    "Do you want to change Animation Type to Generic ?", "Yes", "No"))
                    {
                        animationType = ModelImporterAnimationType.Generic;
                        return(true);
                    }
                    else
                    {
                        //New Avatar is invalid
                        return(false);
                    }
                }
            }

            return(true);
        }
 public static bool IsValidPreviewGameObject(GameObject target, ModelImporterAnimationType requiredClipType)
 {
   if ((Object) target != (Object) null && !target.activeSelf)
     Debug.LogWarning((object) "Can't preview inactive object, using fallback object");
   if ((Object) target != (Object) null && target.activeSelf && GameObjectInspector.HasRenderablePartsRecurse(target))
     return (requiredClipType == ModelImporterAnimationType.None ? 0 : (AvatarPreview.GetAnimationType(target) != requiredClipType ? 1 : 0)) == 0;
   return false;
 }
Exemple #32
0
        static GameObject CalculatePreviewGameObject(Animator selectedAnimator, Motion motion, ModelImporterAnimationType animationType)
        {
            AnimationClip sourceClip = GetFirstAnimationClipFromMotion(motion);

            // Use selected preview
            GameObject selected = AvatarPreviewSelection.GetPreview(animationType);

            if (IsValidPreviewGameObject(selected, ModelImporterAnimationType.None))
            {
                return(selected);
            }

            if (selectedAnimator != null && IsValidPreviewGameObject(selectedAnimator.gameObject, animationType))
            {
                return(selectedAnimator.gameObject);
            }

            // Find the best fitting preview game object for the asset we are viewing (Handles @ convention, will pick base path for you)
            selected = FindBestFittingRenderableGameObjectFromModelAsset(sourceClip, animationType);
            if (selected != null)
            {
                return(selected);
            }

            if (animationType == ModelImporterAnimationType.Human)
            {
                return(GetHumanoidFallback());
            }
            else if (animationType == ModelImporterAnimationType.Generic)
            {
                return(GetGenericAnimationFallback());
            }

            return(null);
        }
 public static GameObject FindBestFittingRenderableGameObjectFromModelAsset(Object asset, ModelImporterAnimationType animationType)
 {
   if (asset == (Object) null)
     return (GameObject) null;
   ModelImporter atPath = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(asset)) as ModelImporter;
   if ((Object) atPath == (Object) null)
     return (GameObject) null;
   GameObject target = AssetDatabase.LoadMainAssetAtPath(atPath.CalculateBestFittingPreviewGameObject()) as GameObject;
   if (AvatarPreview.IsValidPreviewGameObject(target, animationType))
     return target;
   return (GameObject) null;
 }
 public static void SetAnimationType(AnimationClip clip, ModelImporterAnimationType type)
 {
 }
		public static GameObject FindBestFittingRenderableGameObjectFromModelAsset(UnityEngine.Object asset, ModelImporterAnimationType animationType)
		{
			if (asset == null)
			{
				return null;
			}
			ModelImporter modelImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(asset)) as ModelImporter;
			if (modelImporter == null)
			{
				return null;
			}
			string assetPath = modelImporter.CalculateBestFittingPreviewGameObject();
			GameObject gameObject = AssetDatabase.LoadMainAssetAtPath(assetPath) as GameObject;
			if (AvatarPreview.IsValidPreviewGameObject(gameObject, animationType))
			{
				return gameObject;
			}
			return null;
		}
Exemple #36
0
 public static bool IsValidPreviewGameObject(GameObject target, ModelImporterAnimationType requiredClipType)
 {
     if ((target != null) && !target.activeSelf)
     {
         Debug.LogWarning("Can't preview inactive object, using fallback object");
     }
     return ((((target != null) && target.activeSelf) && GameObjectInspector.HasRenderablePartsRecurse(target)) && ((requiredClipType == ModelImporterAnimationType.None) || (GetAnimationType(target) == requiredClipType)));
 }
Exemple #37
0
 public static GameObject FindBestFittingRenderableGameObjectFromModelAsset(UnityEngine.Object asset, ModelImporterAnimationType animationType)
 {
     if (asset != null)
     {
         ModelImporter atPath = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(asset)) as ModelImporter;
         if (atPath == null)
         {
             return null;
         }
         GameObject target = AssetDatabase.LoadMainAssetAtPath(atPath.CalculateBestFittingPreviewGameObject()) as GameObject;
         if (IsValidPreviewGameObject(target, animationType))
         {
             return target;
         }
     }
     return null;
 }
		public static void addAnimation(GameObject                     rootGO, 
		                                string                         rootDirectory,  
		                                SpineData                      spineData, 
		                                Dictionary<string, GameObject> boneGOByName, 
										Dictionary<string, Slot>	   slotByName,
		                                AttachmentGOByNameBySlot       attachmentGOByNameBySlot,
										List<Skin>				       skinList,
		                                int                            pixelsPerUnit,
										float						   zStep,
		                                ModelImporterAnimationType     modelImporterAnimationType,
		                                bool                           updateResources)
		{
			float ratio = 1.0f / (float)pixelsPerUnit;
			foreach(KeyValuePair<string,SpineAnimation> kvp in spineData.animations){
				string animationName = kvp.Key;
				string animationFolder  = rootDirectory+"/"+ANIMATION_FOLDER;
				string assetPath        = animationFolder + "/" + animationName+".anim";

				SpineAnimation spineAnimation = kvp.Value;
				AnimationClip animationClip = new AnimationClip();
				bool updateCurve = false;
				if (File.Exists(assetPath)){
					AnimationClip oldClip = AssetDatabase.LoadAssetAtPath(assetPath, typeof(AnimationClip)) as AnimationClip;
					if (oldClip != null){
						animationClip = oldClip;
						animationClip.ClearCurves();
						updateCurve = true;
					}
				}

				AnimationUtility.SetAnimationType(animationClip, modelImporterAnimationType);
				if (spineAnimation.bones!=null)
					addBoneAnimationToClip(animationClip,spineAnimation.bones, spineData, boneGOByName, ratio);
				if (spineAnimation.slots!=null)
					addSlotAnimationToClip(animationClip, spineAnimation.slots, spineData, skinList, attachmentGOByNameBySlot);

				if ( spineAnimation.events != null )
					AddEvents( animationClip, spineAnimation.events, animationName );
				if (spineAnimation.draworder!=null)
					addDrawOrderAnimation( animationClip, spineAnimation.draworder, spineData, zStep, animationName, slotByName ); 

				if (updateCurve){
					EditorUtility.SetDirty(animationClip);
					AssetDatabase.SaveAssets();
				} else {
					animationClip.frameRate = 30;
					createFolderIfNoExists(rootDirectory, ANIMATION_FOLDER);
					AssetDatabase.CreateAsset(animationClip, assetPath);
					AssetDatabase.SaveAssets();

					if (modelImporterAnimationType == ModelImporterAnimationType.Generic)
						AddClipToAnimatorComponent(rootGO,animationClip);
					else 
						AddClipToLegacyAnimationComponent(rootGO, animationClip);
				}

			}
		}
 private static GameObject CalculatePreviewGameObject(Animator selectedAnimator, Motion motion, ModelImporterAnimationType animationType)
 {
   AnimationClip animationClipFromMotion = AvatarPreview.GetFirstAnimationClipFromMotion(motion);
   GameObject preview = AvatarPreviewSelection.GetPreview(animationType);
   if (AvatarPreview.IsValidPreviewGameObject(preview, ModelImporterAnimationType.None))
     return preview;
   if ((Object) selectedAnimator != (Object) null && AvatarPreview.IsValidPreviewGameObject(selectedAnimator.gameObject, animationType))
     return selectedAnimator.gameObject;
   GameObject objectFromModelAsset = AvatarPreview.FindBestFittingRenderableGameObjectFromModelAsset((Object) animationClipFromMotion, animationType);
   if ((Object) objectFromModelAsset != (Object) null)
     return objectFromModelAsset;
   if (animationType == ModelImporterAnimationType.Human)
     return AvatarPreview.GetHumanoidFallback();
   if (animationType == ModelImporterAnimationType.Generic)
     return AvatarPreview.GetGenericAnimationFallback();
   return (GameObject) null;
 }
		private static GameObject CalculatePreviewGameObject(Animator selectedAnimator, Motion motion, ModelImporterAnimationType animationType)
		{
			AnimationClip firstAnimationClipFromMotion = AvatarPreview.GetFirstAnimationClipFromMotion(motion);
			GameObject gameObject = AvatarPreviewSelection.GetPreview(animationType);
			if (AvatarPreview.IsValidPreviewGameObject(gameObject, ModelImporterAnimationType.None))
			{
				return gameObject;
			}
			if (selectedAnimator != null && AvatarPreview.IsValidPreviewGameObject(selectedAnimator.gameObject, animationType))
			{
				return selectedAnimator.gameObject;
			}
			gameObject = AvatarPreview.FindBestFittingRenderableGameObjectFromModelAsset(firstAnimationClipFromMotion, animationType);
			if (gameObject != null)
			{
				return gameObject;
			}
			if (animationType == ModelImporterAnimationType.Human)
			{
				return AvatarPreview.GetHumanoidFallback();
			}
			if (animationType == ModelImporterAnimationType.Generic)
			{
				return AvatarPreview.GetGenericAnimationFallback();
			}
			return null;
		}