Error found while importing rig in this animation file unity

Всем приветБратцы и сёстры, выручайте:Если Animator отключён, всё работает стандартно(модель в T-pose двигается), если включить, то модель начинает трястись

Проблема с анимациями

Проблема с анимациями

Всем привет
Братцы и сёстры, выручайте:
Если Animator отключён, всё работает стандартно(модель в T-pose двигается), если включить, то модель начинает трястись

https://yadi.sk/i/boe9kYEwp5Z-Lw

Если подключить Animate Physics, то модель проваливается, если отключить Use Gravity, то просто стоит неподвижно

https://yadi.sk/d/Kf4-b1CYACoGCQ

Прилагаю также скрипт анимации:

Используется csharp

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class Enemy : MonoBehaviour
{
    private NavMeshAgent myAgent;

    public Animator myAnimator;
    // Start is called before the first frame update
    void Start()
    {
        myAgent = GetComponent<NavMeshAgent>();
        myAnimator = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.W))
        {

            // myAgent.enabled = false;
            myAnimator.Play(«Run»);
        }
        else
        {
            // myAgent.enabled = false;
            myAnimator.Play(«Idle»);
        }

        //Debug.Log(«Space key was pressed.»);
    }
}

Yellow_Phoenix
UNец
 
Сообщения: 12
Зарегистрирован: 12 июл 2020, 19:25


Re: Проблема с анимациями

Сообщение Yellow_Phoenix 07 янв 2021, 16:20

проблема решена, оказалось модель и анимации в разных Animation Type
Спасибо всем, кто пытался помочь :)

Yellow_Phoenix
UNец
 
Сообщения: 12
Зарегистрирован: 12 июл 2020, 19:25

Re: Проблема с анимациями

Сообщение Yellow_Phoenix 07 янв 2021, 18:01

Если тут кто-нибудь есть может подсказать почему не работает Random — запускается только одна анимация атаки

Используется csharp

else if (Input.GetKeyDown(KeyCode.Mouse0))
        {

           
            int ChoiceAttack = Random.Range(0, 1);
            if (ChoiceAttack == 0)
            {

               
                myAnimator.Play(«Attack02»);
            }
            else if (ChoiceAttack == 1)
            {
                myAnimator.Play(«Attack01»);
            }
        }

Yellow_Phoenix
UNец
 
Сообщения: 12
Зарегистрирован: 12 июл 2020, 19:25

Re: Проблема с анимациями

Сообщение samana 07 янв 2021, 18:29

Рандом для типа int исключает верхний предел, об этом написано в документации. Если вы хотите получить случайное число 0 или 1, то вам нужно

.

Аватара пользователя
samana
Адепт
 
Сообщения: 4733
Зарегистрирован: 21 фев 2015, 13:00
Откуда: Днепропетровск

Re: Проблема с анимациями

Сообщение Yellow_Phoenix 07 янв 2021, 19:08

samana писал(а):Рандом для типа int исключает верхний предел, об этом написано в документации. Если вы хотите получить случайное число 0 или 1, то вам нужно

.

Спасибо, запомню :-bd

Yellow_Phoenix
UNец
 
Сообщения: 12
Зарегистрирован: 12 июл 2020, 19:25


Вернуться в Скрипты

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 12



Содержание

  1. Import character Unity
  2. Answers
  3. Import character Unity
  4. Answers
  5. Importing a model with humanoid animations
  6. Overview
  7. Set up the Avatar
  8. Configure the Avatar
  9. Mapping strategies
  10. Resetting the pose
  11. Creating an Avatar Mask

Import character Unity

I have brought one character from here now i want to how i import character in unity, Ihave FBX and Mb extension file

Answers

Drag and drop FBX to your project-assets panel or in top menu Assets — Import New Asset.
Or go to youtube and search for «import fbx to unity» to learn more.

I did this and when i import AssasinGirl@attack1 file its not showing character or animation

The file is an animation file and does not need to contain a model to save file size.
When you look at the animation file in Unity inspector on the bottom where is preview window and play button on the right side is Humanoid icon. If you click on it you can choose default unity model or your imported model to preview a animation.

You would also probably need to change Animation type to Humanoid in the Rig Tab and change Avatar definition to Copy from Other Avatar and set the Source to Avatar from imported Character model.

To use the animation with your imported model you need to make an Animation Controller, set it with animations, add it to your character with Animator Component and so on.. this is complex subject and only youtube tutorials can help you properly.

Источник

Import character Unity

I have brought one character from here now i want to how i import character in unity, Ihave FBX and Mb extension file

Answers

Drag and drop FBX to your project-assets panel or in top menu Assets — Import New Asset.
Or go to youtube and search for «import fbx to unity» to learn more.

I did this and when i import AssasinGirl@attack1 file its not showing character or animation

The file is an animation file and does not need to contain a model to save file size.
When you look at the animation file in Unity inspector on the bottom where is preview window and play button on the right side is Humanoid icon. If you click on it you can choose default unity model or your imported model to preview a animation.

You would also probably need to change Animation type to Humanoid in the Rig Tab and change Avatar definition to Copy from Other Avatar and set the Source to Avatar from imported Character model.

To use the animation with your imported model you need to make an Animation Controller, set it with animations, add it to your character with Animator Component and so on.. this is complex subject and only youtube tutorials can help you properly.

Источник

Importing a model with humanoid animations

This page contains guidance on importing a model for use with Unity’s Animation System. For information on creating a model for use with the Animation System, see Creating models for animation.

The Animation System works with two types of models:

  • A Humanoid model is a specific structure, containing at least 15 bones organized in a way that loosely conforms to an actual human skeleton. This page contains guidance on importing this type of model.
  • A Generic model is everything else. This might be anything from a teakettle to a dragon. For information on importing this type of model, see Importing a model with non-humanoid (generic) animations.

For general importing guidance that is applicable to all types of models, see Importing a model.

Overview

When Unity imports Model files that contain Humanoid Rigs and Animation, it needs to reconcile the bone structure of the Model to its Animation. It does this by mapping each bone in the file to a Humanoid Avatar so that it can play the Animation properly. For this reason, it is important to carefully prepare your Model file A file containing a 3D data, which may include definitions for meshes, bones, animation, materials and textures. More info
See in Glossary before importing into Unity.

  1. Define the Rig type and create the Avatar.
  2. Correct or verify the Avatar’s mapping.
  3. Once you are finished with the bone mapping, you can optionally click the Muscles & Settings tab to tweak the Avatar’s muscle configuration.
  4. You can optionally save the mapping of your skeleton’s bones to the Avatar as a Human Template A pre-defined bone-mapping. Used for matching bones from FBX files to the Avatar. More info
    See in Glossary (.ht) file.
  5. You can optionally limit the animation that gets imported on certain bones by defining an Avatar Mask.
  6. From the Animation tab, enable the Import Animation option and then set the other Asset-specific properties, .
  7. If the file consists of multiple animations or actions, you can define specific action ranges as Animation Clips.
  8. For each Animation Clip Animation data that can be used for animated characters or simple animations. It is a simple “unit” piece of motion, such as (one specific instance of) “Idle”, “Walk” or “Run”. More info
    See in Glossary defined in the file, you can:
    • Change the pose and root transform
    • Optimize looping
    • Mirror the animation on both sides of the Humanoid skeleton.
    • Add curves to the clip in order to animate the timings of other items
    • Add events to the clip in order to trigger certain actions in time with the animation
    • Discard part of the animation similar to using a runtime Avatar Mask but applied at import time
    • Select a different Root Motion Node to drive the action from
    • Read any messages from Unity about importing the clip
    • Watch a preview of the animation clip
  9. To save your changes, click the Apply button at the bottom of the Import Settings window or Revert to discard your changes.

Set up the Avatar

From the Rig tab of the Inspector window, set the Animation Type to Humanoid. By default, the Avatar Definition property is set to Create From This Model. If you keep this option, Unity attempts to map the set of bones defined in the file to a Humanoid Avatar.

Humanoid Rig

In some cases, you can change this option to Copy From Other Avatar to use an Avatar you already defined for another Model file. For example, if you create a Mesh The main graphics primitive of Unity. Meshes make up a large part of your 3D worlds. Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info
See in Glossary (skin) in your 3D modeling application with several distinct animations, you can export the Mesh to one FBX file, and each animation to its own FBX file. When you import these files into Unity, you only need to create a single Avatar for the first file you import (usually the Mesh). As long as all the files use the same bone structure, you can re-use that Avatar for the rest of the files (for example, all the animations).

If you enable this option, you must specify which Avatar you want to use by setting the Source property.

You can also change the maximum number of bones that can influence a given vertex with the Skin Weights property. By default, this property limits influence to four bones, but you can a different number.

When you click the Apply button, Unity tries to match up the existing bone structure to the Avatar bone structure. In many cases, it can do this automatically by analyzing the connections between bones in the rig.

If the match succeeds, a check mark appears next to the Configure menu. Unity also adds an Avatar sub-Asset to the Model Asset, which you can find in the Project view.

Avatar appears as a sub-Asset of the imported Model

A successful match simply means that Unity was able to match all of the required bones. However, for better results, you also need to match the optional bones and set the model in a proper T-pose The pose in which the character has their arms straight out to the sides, forming a “T”. The required pose for the character to be in, in order to make an Avatar.
See in Glossary .

If Unity can’t create the Avatar, a cross appears next to the Configure button, and no Avatar sub-asset appears in the Project view.

Unity failed to create a valid Avatar

Since the Avatar is such an important aspect of the animation system, it is important to configure it properly for your Model A 3D model representation of an object, such as a character, a building, or a piece of furniture. More info
See in Glossary .

For this reason, whether or not the automatic Avatar creation succeeds, you should always check that your Avatar is valid and properly set up.

Configure the Avatar

If you want to check that Unity correctly mapped your model’s bones to the Avatar, or if Unity failed to create the Avatar for your model, you can click the Configure … button on the Rig A skeletal hierarchy of joints for a mesh. More info
See in Glossary tab to enter the Avatar configuration mode.

If Unity successfully creates an Avatar, the Avatar appears as a sub-asset of the model Asset. You can select the Avatar asset in the Project window A window that shows the contents of your Assets folder (Project tab) More info
See in Glossary , and then click the “Configure Avatar” button in the Inspector to enter the Avatar configuration mode. This mode allows to check or adjust how Unity maps your model’s bones to the Avatar layout.

The Inspector for an Avatar sub-asset

Once you have entered the Avatar configuration mode, the Avatar window appears in the Inspector A Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary displaying bone mapping.

Make sure the bone mapping is correct and that you map any optional bones that Unity did not assign.

Your skeleton needs to have at least the required bones in place for Unity to produce a valid match. In order to improve your chances for finding a match to the Avatar, name your bones in a way that reflects the body parts they represent. For example, “LeftArm” and “RightForearm” make it clear what these bones control.

Mapping strategies

If the model does not yield a valid match, you can use a similar process to the one that Unity uses internally:

  1. Choose Clear from the Mapping menu at the bottom of the Avatar window to reset any mapping that Unity attempted.
  2. Choose Sample Bind-pose from the Pose menu at the bottom of the Avatar window to approximate the Model’s initial modeling pose.
  3. Choose Mapping >Automap to create a bone-mapping from an initial pose.
  4. Choose Pose >Enforce T-Pose to set the Model back to to required T-pose.

If automapping fails completely or partially, you can manually assign bones by either dragging them from the Scene A Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary view or from the Hierarchy view. If Unity thinks a bone fits, it appears in green in the Avatar Mapping tab; otherwise it appears in red.

Resetting the pose

The T-pose is the default pose required by Unity animation and is the recommended pose to model in your 3D modeling application. However, if you did not use the T-pose to model your character and the animation does not work as expected, you can select Reset from the Pose drop-down menu:

The Pose drop-down menu at the bottom of the Avatar window

If the bone assignment is correct, but the character is not in the correct pose, you will see the message “Character not in T-Pose”. You can try to fix that by choosing Enforce T-Pose from the Pose menu. If the pose is still not correct, you can manually rotate the remaining bones into a T-pose.

Creating an Avatar Mask

Masking allows you to discard some of the animation data within a clip, allowing the clip to animate only parts of the object or character rather than the entire thing. For example, you may have a standard walking animation that includes both arm and leg motion, but if a character is carrying a large object with both hands then you wouldn’t want their arms to swing to the side as they walk. However, you could still use the standard walking animation while carrying the object by using a mask to only play the upper body portion of the carrying animation over the top of the walking animation.

You can apply masking to animation clips either during import time, or at runtime. Masking during import time is preferable, because it allows the discarded animation data to be omitted from your build, making the files smaller and therefore using less memory. It also makes for faster processing because there is less animation data to be blended at runtime. In some cases, import masking may not be suitable for your purposes. In that case, you can apply a mask at runtime by creating an Avatar Mask A specification for which body parts to include or exclude for an animation rig. Used in Animation Layers and in the importer. More info
See in Glossary Asset, and using it in the layer settings of your Animator Controller Controls animation through Animation Layers with Animation State Machines and Animation Blend Trees, controlled by Animation Parameters. The same Animator Controller can be referenced by multiple models with Animator components. More info
See in Glossary .

To create an empty Avatar Mask Asset, you can either:

  • Choose Create >Avatar Mask from the Assets Any media or data that can be used in your game or project. An asset may come from a file created outside of Unity, such as a 3D Model, an audio file or an image. You can also create some asset types in Unity, such as an Animator Controller, an Audio Mixer or a Render Texture. More info
    See in Glossary menu.
  • Click the Model object you want to define the mask on in the Project In Unity, you use a project to design and develop a game. A project stores all of the files that are related to a game, such as the asset and Scene files. More info
    See in Glossary view, and then right-click and choose Create >Avatar Mask.

The new Asset appears in the Project view:

The Avatar Mask window

You can now add portions of the body to the mask and then add the mask to either an Animation Layer An Animation Layer contains an Animation State Machine that controls animations of a model or part of it. An example of this is if you have a full-body layer for walking or jumping and a higher layer for upper-body motions such as throwing an object or shooting. The higher layers take precedence for the body parts they control. More info
See in Glossary or add a reference to it under the Mask Can refer to a Sprite Mask, a UI Mask, or a Layer Mask More info
See in Glossary section of the Animation tab.

Источник

// Unity C# reference source // Copyright (c) Unity Technologies. For terms of use, see // https://unity3d.com/legal/licenses/Unity_Reference_Only_License using System; using UnityEngine; using System.Collections.Generic; using Object = UnityEngine.Object; using UnityEditor.AssetImporters; using System.Linq; namespace UnityEditor { internal class ModelImporterRigEditor : BaseAssetImporterTabUI { ModelImporter singleImporter { get { return targets[0] as ModelImporter; } } public int m_SelectedClipIndex = 1; Avatar m_Avatar; #pragma warning disable 0649 [CacheProperty] SerializedProperty m_AnimationType; [CacheProperty] SerializedProperty m_AvatarSetup; [CacheProperty(«m_LastHumanDescriptionAvatarSource«)] SerializedProperty m_AvatarSource; [CacheProperty] SerializedProperty m_LegacyGenerateAnimations; [CacheProperty] SerializedProperty m_AnimationCompression; [CacheProperty(«skinWeightsMode«)] SerializedProperty m_SkinWeightsMode; [CacheProperty(«maxBonesPerVertex«)] SerializedProperty m_MaxBonesPerVertex; [CacheProperty(«minBoneWeight«)] SerializedProperty m_MinBoneWeight; [CacheProperty(«optimizeBones«)] SerializedProperty m_OptimizeBones; [CacheProperty] SerializedProperty m_OptimizeGameObjects; [CacheProperty(«m_HumanDescription.m_RootMotionBoneName«)] SerializedProperty m_RootMotionBoneName; [CacheProperty(«m_HasExtraRoot«)] SerializedProperty m_SrcHasExtraRoot; [CacheProperty(«m_HumanDescription.m_HasExtraRoot«)] SerializedProperty m_DstHasExtraRoot; [CacheProperty(«m_HumanDescription.m_Human«)] SerializedProperty m_HumanBoneArray; [CacheProperty(«m_HumanDescription.m_Skeleton«)] SerializedProperty m_Skeleton; [CacheProperty] SerializedProperty m_AutoGenerateAvatarMappingIfUnspecified; #pragma warning restore 0649 private static bool importMessageFoldout = false; GUIContent[] m_RootMotionBoneList; private ExposeTransformEditor m_ExposeTransformEditor; private SerializedObject m_AvatarSourceSerializedObject; SerializedObject avatarSourceSerializedObject { get { // to keep the serialized object in sync with the current source avatar Object currentAvatar = m_AvatarSource?.objectReferenceValue; if (currentAvatar == null || currentAvatar != m_AvatarSourceSerializedObject?.targetObject) { m_AvatarSourceSerializedObject?.Dispose(); m_AvatarSourceSerializedObject = null; if (currentAvatar != null) m_AvatarSourceSerializedObject = new SerializedObject(currentAvatar); } m_AvatarSourceSerializedObject?.Update(); return m_AvatarSourceSerializedObject; } } private ModelImporterAnimationType animationType { get { return (ModelImporterAnimationType)m_AnimationType.intValue; } set { m_AnimationType.intValue = (int)value; } } private bool m_CanMultiEditTransformList; private const string k_RigErrorPrefix = «Rig Error: «; bool m_IsBiped = false; List<string> m_BipedMappingReport = null; bool m_ExtraExposedTransformFoldout = false; static class Styles { public static GUIContent AnimationType = EditorGUIUtility.TrTextContent(«Animation Type«, «The type of animation to support / import.«); public static GUIContent[] AnimationTypeOpt = { EditorGUIUtility.TrTextContent(«None«, «No animation present.«), EditorGUIUtility.TrTextContent(«Legacy«, «Legacy animation system.«), EditorGUIUtility.TrTextContent(«Generic«, «Generic Mecanim animation.«), EditorGUIUtility.TrTextContent(«Humanoid«, «Humanoid Mecanim animation system.«) }; public static GUIContent SaveAvatar = EditorGUIUtility.TrTextContent(«Save Avatar«, «Saves the generated Avatar as a sub-asset.«); public static GUIContent AnimLabel = EditorGUIUtility.TrTextContent(«Generation«, «Controls how animations are imported.«); public static GUIContent[] AnimationsOpt = { EditorGUIUtility.TrTextContent(«Don’t Import«, «No animation or skinning is imported.«), EditorGUIUtility.TrTextContent(«Store in Original Roots (Deprecated)«, «Animations are stored in the root objects of your animation package (these might be different from the root objects in Unity).«), EditorGUIUtility.TrTextContent(«Store in Nodes (Deprecated)«, «Animations are stored together with the objects they animate. Use this when you have a complex animation setup and want full scripting control.«), EditorGUIUtility.TrTextContent(«Store in Root (Deprecated)«, «Animations are stored in the scene’s transform root objects. Use this when animating anything that has a hierarchy.«), EditorGUIUtility.TrTextContent(«Store in Root (New)«) }; public static GUIContent avatar = EditorGUIUtility.TrTextContent(«Animator«); public static GUIContent configureAvatar = EditorGUIUtility.TrTextContent(«Configure…«); public static GUIContent avatarValid = EditorGUIUtility.TrTextContent(«u2713«); public static GUIContent avatarInvalid = EditorGUIUtility.TrTextContent(«u2715«); public static GUIContent avatarPending = EditorGUIUtility.TrTextContent(««); public static GUIContent UpdateMuscleDefinitionFromSource = EditorGUIUtility.TrTextContent(«Update«, «Update the copy of the muscle definition from the source.«); public static GUIContent RootNode = EditorGUIUtility.TrTextContent(«Root node«, «Specify the root node used to extract the animation translation.«); public static GUIContent AvatarDefinition = EditorGUIUtility.TrTextContent(«Avatar Definition«, «Choose between Create From This Model or Copy From Other Avatar. The first one creates an Avatar for this file and the second one uses an Avatar from another file to import animation.«); public static GUIContent SkinWeightsMode = EditorGUIUtility.TrTextContent(«Skin Weights«, «Control how many bone weights are imported.«); public static GUIContent[] SkinWeightsModeOpt = { EditorGUIUtility.TrTextContent(«Standard (4 Bones)«, «Import a maximum of 4 bones per vertex.«), EditorGUIUtility.TrTextContent(«Custom«, «Import a custom number of bones per vertex.«) }; public static GUIContent MaxBonesPerVertex = EditorGUIUtility.TrTextContent(«Max Bones/Vertex«, «Number of bones that can affect each vertex.«); public static GUIContent MinBoneWeight = EditorGUIUtility.TrTextContent(«Min Bone Weight«, «Bone weights smaller than this value are rejected. The remaining weights are scaled to add up to 1.0.«); public static GUIContent OptimizeBones = EditorGUIUtility.TrTextContent(«Strip Bones«, «Only adds bones to SkinnedMeshRenderers that have skin weights assigned to them.«); public static GUIContent UpdateReferenceClips = EditorGUIUtility.TrTextContent(«Update reference clips«, «Click on this button to update all the @convention files referencing this file. Should set all these files to Copy From Other Avatar, set the source Avatar to this one and reimport all these files.«); public static GUIContent ImportMessages = EditorGUIUtility.TrTextContent(«Import Messages«); public static GUIContent ExtraExposedTransform = EditorGUIUtility.TrTextContent(«Extra Transforms to Expose«, «Select the list of transforms to expose in the optimized GameObject hierarchy.«); } public ModelImporterRigEditor(AssetImporterEditor panelContainer) : base(panelContainer) {} internal override void OnEnable() { Editor.AssignCachedProperties(this, serializedObject.GetIterator()); m_ExposeTransformEditor = new ExposeTransformEditor(); string[] transformPaths = singleImporter.transformPaths; m_RootMotionBoneList = new GUIContent[transformPaths.Length]; for (int i = 0; i < transformPaths.Length; i++) m_RootMotionBoneList[i] = new GUIContent(transformPaths[i]); if (m_RootMotionBoneList.Length > 0) m_RootMotionBoneList[0] = EditorGUIUtility.TrTextContent(«None«); m_ExposeTransformEditor.OnEnable(singleImporter.transformPaths, serializedObject); m_CanMultiEditTransformList = CanMultiEditTransformList(); m_IsBiped = false; m_BipedMappingReport = new List<string>(); UpdateBipedMappingReport(); if (m_AnimationType.intValue == (int)ModelImporterAnimationType.Human && m_Avatar == null) { ResetAvatar(); } } internal override void OnDisable() { if (m_AvatarSourceSerializedObject != null) m_AvatarSourceSerializedObject.Dispose(); } private void UpdateBipedMappingReport() { if (m_AnimationType.intValue == (int)ModelImporterAnimationType.Human) { GameObject go = assetTarget as GameObject; if (go != null) { m_IsBiped = AvatarBipedMapper.IsBiped(go.transform, m_BipedMappingReport); } } } private bool CanMultiEditTransformList() { string[] transformPaths = singleImporter.transformPaths; for (int i = 1; i < targets.Length; ++i) { ModelImporter modelImporter = targets[i] as ModelImporter; if (!ArrayUtility.ArrayEquals(transformPaths, modelImporter.transformPaths)) return false; } return true; } bool AvatarCopyIsUpToDate() { if (!(animationType == ModelImporterAnimationType.Human || animationType == ModelImporterAnimationType.Generic) || m_AvatarSource.objectReferenceValue == null) return true; SerializedProperty humanDescription = serializedObject.FindProperty(«m_HumanDescription«); //Because of the constraint that Editors must share an Animation Source, if we have a mix of different human descriptions, then *at least* one is out of date if (humanDescription.hasMultipleDifferentValues) return false; //Does the HumanDescription in the Importer match the one in the referenced Avatar? return SerializedProperty.DataEquals(humanDescription, avatarSourceSerializedObject.FindProperty(«m_HumanDescription«)); } internal override void OnDestroy() { m_Avatar = null; } internal override void ResetValues() { base.ResetValues(); ResetAvatar(); m_ExposeTransformEditor.ResetExposedTransformList(); } internal override void PostApply() { base.PostApply(); //The import process may generate a new avatar, find it. ResetAvatar(); } void ResetAvatar() { if (assetTarget != null) { var path = singleImporter.assetPath; m_Avatar = AssetDatabase.LoadAssetAtPath<Avatar>(path); } } void LegacyGUI() { EditorGUILayout.Popup(m_LegacyGenerateAnimations, Styles.AnimationsOpt, Styles.AnimLabel); // Show warning and fix button for deprecated import formats if (m_LegacyGenerateAnimations.intValue == 1 || m_LegacyGenerateAnimations.intValue == 2 || m_LegacyGenerateAnimations.intValue == 3) EditorGUILayout.HelpBox(«The animation import setting «« + Styles.AnimationsOpt[m_LegacyGenerateAnimations.intValue].text + «« is deprecated.«, MessageType.Warning); } void GenericGUI() { using (var horizontal = new EditorGUILayout.HorizontalScope()) { using (var propertyField = new EditorGUI.PropertyScope(horizontal.rect, Styles.AvatarDefinition, m_AvatarSetup)) { EditorGUI.showMixedValue = m_AvatarSetup.hasMultipleDifferentValues; using (var change = new EditorGUI.ChangeCheckScope()) { var value = (ModelImporterAvatarSetup)EditorGUILayout.EnumPopup(propertyField.content, (ModelImporterAvatarSetup)m_AvatarSetup.intValue); if (change.changed) m_AvatarSetup.intValue = (int)value; } EditorGUI.showMixedValue = false; } } if (!m_AvatarSetup.hasMultipleDifferentValues) { if (m_AvatarSetup.intValue == (int)ModelImporterAvatarSetup.CreateFromThisModel) { // Do not allow multi edit of root node if all rigs doesn’t match using (new EditorGUI.DisabledScope(!m_CanMultiEditTransformList)) { if (assetTarget == null) { m_RootMotionBoneName.stringValue = EditorGUILayout.TextField(Styles.RootNode, m_RootMotionBoneName.stringValue); } else { EditorGUI.BeginChangeCheck(); var currentIndex = ArrayUtility.FindIndex(m_RootMotionBoneList, content => FileUtil.GetLastPathNameComponent(content.text) == m_RootMotionBoneName.stringValue); currentIndex = currentIndex < 1 ? 0 : currentIndex; currentIndex = EditorGUILayout.Popup(Styles.RootNode, currentIndex, m_RootMotionBoneList); if (EditorGUI.EndChangeCheck()) { if (currentIndex > 0 && currentIndex < m_RootMotionBoneList.Length) { m_RootMotionBoneName.stringValue = FileUtil.GetLastPathNameComponent(m_RootMotionBoneList[currentIndex].text); } else { m_RootMotionBoneName.stringValue = ««; } } } } } else if (m_AvatarSetup.intValue == (int)ModelImporterAvatarSetup.CopyFromOther) CopyAvatarGUI(); } } void HumanoidGUI() { using (var horizontal = new EditorGUILayout.HorizontalScope()) { using (var propertyField = new EditorGUI.PropertyScope(horizontal.rect, Styles.AvatarDefinition, m_AvatarSetup)) { EditorGUI.showMixedValue = m_AvatarSetup.hasMultipleDifferentValues; using (var change = new EditorGUI.ChangeCheckScope()) { Rect r = EditorGUILayout.GetControlRect(true, EditorGUI.kSingleLineHeight, EditorStyles.popup); var value = (ModelImporterAvatarSetup)EditorGUI.EnumPopup(r, propertyField.content, (ModelImporterAvatarSetup)m_AvatarSetup.intValue, e => (ModelImporterAvatarSetup)e != ModelImporterAvatarSetup.NoAvatar); if (change.changed) { m_AvatarSetup.intValue = (int)value; //Case 1213138 — When changing avatar setup value, we must reset the human, skeleton & auto-mapping to their default values. //NB: This fix will be defunct once we have a reference-based solution for copying avatars. AvatarSetupTool.ClearAll(m_HumanBoneArray, m_Skeleton); m_AutoGenerateAvatarMappingIfUnspecified.boolValue = true; } } EditorGUI.showMixedValue = false; } } if (!m_AvatarSetup.hasMultipleDifferentValues) { if (m_AvatarSetup.intValue == (int)ModelImporterAvatarSetup.CreateFromThisModel) ConfigureAvatarGUI(); else CopyAvatarGUI(); } if (m_IsBiped) { if (m_BipedMappingReport.Count > 0) { string report = «A Biped was detected, but cannot be configured properly because of an unsupported hierarchy. Adjust Biped settings in 3DS Max before exporting to correct this problem.n«; for (int reportIter = 0; reportIter < m_BipedMappingReport.Count; reportIter++) { report += m_BipedMappingReport[reportIter]; } EditorGUILayout.HelpBox(report, MessageType.Warning); } else { EditorGUILayout.HelpBox(«A Biped was detected. Default Biped mapping and T-Pose have been configured for this avatar. Translation DoFs have been activated. Use Configure to modify default Biped setup.«, MessageType.Info); } } EditorGUILayout.Space(); } void ConfigureAvatarGUI() { if (targets.Length > 1) { GUILayout.Label(«Can’t configure avatar in multi-editing mode«, EditorStyles.helpBox); return; } if (singleImporter.transformPaths.Length <= HumanTrait.RequiredBoneCount) { GUILayout.Label(string.Format(«Not enough bones to create human avatar (requires {0})«, HumanTrait.RequiredBoneCount), EditorStyles.helpBox); } // Validation text GUIContent validationContent; if (m_Avatar && !HasModified()) { if (m_Avatar.isHuman) validationContent = Styles.avatarValid; else validationContent = Styles.avatarInvalid; } else { validationContent = Styles.avatarPending; GUILayout.Label(«The avatar can be configured after settings have been applied.«, EditorStyles.helpBox); } Rect r = EditorGUILayout.GetControlRect(); const int buttonWidth = 80; GUI.Label(new Rect(r.xMax buttonWidth 18, r.y, 18, r.height), validationContent, EditorStyles.label); // Configure button using (new EditorGUI.DisabledScope(m_Avatar == null)) { if (GUI.Button(new Rect(r.xMax buttonWidth, r.y + 1, buttonWidth, r.height 1), Styles.configureAvatar, EditorStyles.miniButton)) { if (!isLocked) { Selection.activeObject = m_Avatar; AvatarEditor.s_EditImmediatelyOnNextOpen = true; GUIUtility.ExitGUI(); } else Debug.Log(«Cannot configure avatar, inspector is locked«); } } } 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; } void CopyAvatarGUI() { GUILayout.Label( If you have already created an Avatar for another model with a rig identical to this one, you can copy its Avatar definition. With this option, this model will not create any avatar but only import animations.«, EditorStyles.helpBox); EditorGUILayout.BeginHorizontal(); Avatar previousAvatar = (Avatar)m_AvatarSource.objectReferenceValue; EditorGUI.BeginChangeCheck(); EditorGUILayout.ObjectField(m_AvatarSource, typeof(Avatar), GUIContent.Temp(«Source«), ValidateAvatarSource); var sourceAvatar = m_AvatarSource.objectReferenceValue as Avatar; if (EditorGUI.EndChangeCheck()) { if (IsAvatarValid(sourceAvatar)) { AvatarSetupTool.ClearAll(m_HumanBoneArray, m_Skeleton); if (sourceAvatar != null) CopyHumanDescriptionFromOtherModel(sourceAvatar); } else //Avatar is invalid so revert to the previous Avatar m_AvatarSource.objectReferenceValue = previousAvatar; } if (sourceAvatar != null && !m_AvatarSource.hasMultipleDifferentValues && !AvatarCopyIsUpToDate()) { if (GUILayout.Button(Styles.UpdateMuscleDefinitionFromSource, EditorStyles.miniButton)) { if (IsAvatarValid(sourceAvatar)) { AvatarSetupTool.ClearAll(m_HumanBoneArray, m_Skeleton); CopyHumanDescriptionFromOtherModel(sourceAvatar); } } } EditorGUILayout.EndHorizontal(); } Object ValidateAvatarSource(Object[] references, Type objType, SerializedProperty property, EditorGUI.ObjectFieldValidatorOptions options) { if (references.Length == 0) return null; string avatarPath = AssetDatabase.GetAssetPath(references[0]); foreach (AssetImporter importer in targets) { if (avatarPath == importer.assetPath) { return null; } } return references[0]; } void ShowUpdateReferenceClip() { if (targets.Length > 1 || m_AvatarSetup.intValue == (int)ModelImporterAvatarSetup.CopyFromOther || !m_Avatar || !m_Avatar.isValid) return; string[] paths = new string[0]; ModelImporter importer = target as ModelImporter; if (importer.referencedClips.Length > 0) { foreach (string clipGUID in importer.referencedClips) ArrayUtility.Add(ref paths, AssetDatabase.GUIDToAssetPath(clipGUID)); } // Show only button if some clip reference this avatar. if (paths.Length > 0 && GUILayout.Button(Styles.UpdateReferenceClips, GUILayout.Width(150))) { foreach (string path in paths) SetupReferencedClip(path); try { AssetDatabase.StartAssetEditing(); foreach (string path in paths) AssetDatabase.ImportAsset(path); } finally { AssetDatabase.StopAssetEditing(); } } } public override void OnInspectorGUI() { serializedObject.Update(); ImportLog importLog = AssetImporter.GetImportLog(singleImporter.assetPath); ImportLog.ImportLogEntry[] importRigErrors = importLog ? importLog.logEntries.Where(x => x.flags == ImportLogFlags.Error && x.message.StartsWith(k_RigErrorPrefix)).ToArray() : new ImportLog.ImportLogEntry[0]; ImportLog.ImportLogEntry[] importRigWarnings = importLog ? importLog.logEntries.Where(x => x.flags == ImportLogFlags.Warning && x.message.StartsWith(k_RigErrorPrefix)).ToArray() : new ImportLog.ImportLogEntry[0]; if (importRigErrors.Length > 0) { EditorGUILayout.Space(); EditorGUILayout.HelpBox(«Error(s) found while importing rig in this animation file. Open «Import Messages« foldout below for more details«, MessageType.Error); } else if (importRigWarnings.Length > 0) { EditorGUILayout.Space(); EditorGUILayout.HelpBox(«Warning(s) found while importing rig in this animation file. Open «Import Messages« foldout below for more details«, MessageType.Warning); } // Animation type EditorGUI.BeginChangeCheck(); EditorGUILayout.Popup(m_AnimationType, Styles.AnimationTypeOpt, Styles.AnimationType); if (EditorGUI.EndChangeCheck()) { m_AvatarSource.objectReferenceValue = null; if (m_AvatarSourceSerializedObject != null) m_AvatarSourceSerializedObject.Dispose(); m_AvatarSourceSerializedObject = null; if (animationType == ModelImporterAnimationType.Legacy) m_AnimationCompression.intValue = (int)ModelImporterAnimationCompression.KeyframeReduction; else if (animationType == ModelImporterAnimationType.Generic || animationType == ModelImporterAnimationType.Human) m_AnimationCompression.intValue = (int)ModelImporterAnimationCompression.Optimal; m_DstHasExtraRoot.boolValue = m_SrcHasExtraRoot.boolValue; } EditorGUILayout.Space(); if (!m_AnimationType.hasMultipleDifferentValues) { // Show GUI depending on animation type if (animationType == ModelImporterAnimationType.Human) HumanoidGUI(); else if (animationType == ModelImporterAnimationType.Generic) GenericGUI(); else if (animationType == ModelImporterAnimationType.Legacy) LegacyGUI(); } if (animationType != ModelImporterAnimationType.None || m_AnimationType.hasMultipleDifferentValues) { EditorGUILayout.Popup(m_SkinWeightsMode, Styles.SkinWeightsModeOpt, Styles.SkinWeightsMode); if (m_SkinWeightsMode.intValue == (int)ModelImporterSkinWeights.Custom) { EditorGUILayout.IntSlider(m_MaxBonesPerVertex, 1, 255, Styles.MaxBonesPerVertex); EditorGUILayout.Slider(m_MinBoneWeight, 0.001f, 0.5f, Styles.MinBoneWeight); } int currentSkinWeights = m_SkinWeightsMode.intValue == (int)ModelImporterSkinWeights.Standard ? 4 : m_MaxBonesPerVertex.intValue; if ((int)QualitySettings.skinWeights < currentSkinWeights) { var msg = Skin Weights is set to {(int)QualitySettings.skinWeights} bones per vertex in Quality Settings. Some bone influences may not be rendered.«; EditorGUILayout.HelpBox(msg, MessageType.Info); } } if (animationType != ModelImporterAnimationType.None) { EditorGUILayout.PropertyField(m_OptimizeBones, Styles.OptimizeBones); ShowUpdateReferenceClip(); } // OptimizeGameObject is only supported on our own avatar when animation type is not Legacy. if (m_AvatarSetup.intValue == (int)ModelImporterAvatarSetup.CreateFromThisModel && animationType != ModelImporterAnimationType.Legacy) { EditorGUILayout.PropertyField(m_OptimizeGameObjects); if (m_OptimizeGameObjects.boolValue && serializedObject.targetObjectsCount == 1) // SerializedProperty can’t handle multiple string arrays properly. { bool wasChanged = GUI.changed; m_ExtraExposedTransformFoldout = EditorGUILayout.Foldout(m_ExtraExposedTransformFoldout, Styles.ExtraExposedTransform, true); GUI.changed = wasChanged; if (m_ExtraExposedTransformFoldout) { // Do not allow multi edit of exposed transform list if all rigs doesn’t match using (new EditorGUI.DisabledScope(!m_CanMultiEditTransformList)) using (new EditorGUI.IndentLevelScope()) m_ExposeTransformEditor.OnGUI(); } } } if (importRigErrors.Length > 0 || importRigWarnings.Length > 0) { EditorGUILayout.Space(); importMessageFoldout = EditorGUILayout.Foldout(importMessageFoldout, Styles.ImportMessages, true); if (importMessageFoldout) { foreach (var importRigError in importRigErrors) EditorGUILayout.HelpBox(importRigError.message, MessageType.Error); foreach (var importRigWarning in importRigWarnings) EditorGUILayout.HelpBox(importRigWarning.message, MessageType.Warning); } } } static SerializedObject GetModelImporterSerializedObject(string assetPath) { ModelImporter importer = AssetImporter.GetAtPath(assetPath) as ModelImporter; if (importer == null) return null; return new SerializedObject(importer); } static void CopyHumanDescriptionToDestination(SerializedObject sourceObject, SerializedObject targetObject) { targetObject.CopyFromSerializedProperty(sourceObject.FindProperty(«m_HumanDescription«)); } private void CopyHumanDescriptionFromOtherModel(Avatar sourceAvatar) { //This could be an Avatar sub-asset, or a distinct avatar asset using (SerializedObject avatarSerializedObject = new SerializedObject(sourceAvatar)) { CopyHumanDescriptionToDestination(avatarSerializedObject, serializedObject); } } private void SetupReferencedClip(string otherModelImporterPath) { SerializedObject targetImporter = GetModelImporterSerializedObject(otherModelImporterPath); // We may receive a path that doesn’t have a importer. if (targetImporter != null) { targetImporter.CopyFromSerializedProperty(serializedObject.FindProperty(«m_AnimationType«)); SerializedProperty copyAvatar = targetImporter.FindProperty(«m_CopyAvatar«); if (copyAvatar != null) copyAvatar.boolValue = true; SerializedProperty avatar = targetImporter.FindProperty(«m_LastHumanDescriptionAvatarSource«); if (avatar != null) avatar.objectReferenceValue = m_Avatar; CopyHumanDescriptionToDestination(serializedObject, targetImporter); targetImporter.ApplyModifiedProperties(); targetImporter.Dispose(); } } public bool isLocked { get { foreach (InspectorWindow i in InspectorWindow.GetAllInspectorWindows()) { ActiveEditorTracker activeEditor = i.tracker; foreach (Editor e in activeEditor.activeEditors) { // the tab is no longer an editor, so we must always refer to the panel container if (e is ModelImporterEditor && ((ModelImporterEditor)e).activeTab == this) { return i.isLocked; } } } return false; } } } }

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Error found when loading home user profile
  • Error found option without preceding group in config file mysql
  • Error forwarding the new session empty pool of vm for setup capabilities
  • Error forward declaration of class
  • Error forward declaration not solved

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии