コード例 #1
0
        private 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.\nWith this option, this model will not create any avatar but only import animations.", EditorStyles.helpBox, new GUILayoutOption[0]);
            EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(this.m_AvatarSource, GUIContent.Temp("Source"), new GUILayoutOption[0]);
            Avatar objectReferenceValue = this.m_AvatarSource.objectReferenceValue as Avatar;

            if (EditorGUI.EndChangeCheck())
            {
                this.CheckAvatar(objectReferenceValue);
                AvatarSetupTool.ClearAll(base.serializedObject);
                if (objectReferenceValue != null)
                {
                    this.CopyHumanDescriptionFromOtherModel(objectReferenceValue);
                }
                this.m_AvatarCopyIsUpToDate = true;
            }
            if (((objectReferenceValue != null) && !this.m_AvatarSource.hasMultipleDifferentValues) && (!this.m_AvatarCopyIsUpToDate && GUILayout.Button(styles.UpdateMuscleDefinitionFromSource, EditorStyles.miniButton, new GUILayoutOption[0])))
            {
                AvatarSetupTool.ClearAll(base.serializedObject);
                this.CopyHumanDescriptionFromOtherModel(objectReferenceValue);
                this.m_AvatarCopyIsUpToDate = true;
            }
            EditorGUILayout.EndHorizontal();
        }
コード例 #2
0
 internal override void Apply()
 {
     MappingRelevantSettings[] sourceArray = new MappingRelevantSettings[base.targets.Length];
     for (int i = 0; i < base.targets.Length; i++)
     {
         SerializedObject   obj2      = new SerializedObject(base.targets[i]);
         SerializedProperty property  = obj2.FindProperty("m_AnimationType");
         SerializedProperty property2 = obj2.FindProperty("m_CopyAvatar");
         sourceArray[i].humanoid       = property.intValue == 3;
         sourceArray[i].hasNoAnimation = property.intValue == 0;
         sourceArray[i].copyAvatar     = property2.boolValue;
     }
     MappingRelevantSettings[] destinationArray = new MappingRelevantSettings[base.targets.Length];
     Array.Copy(sourceArray, destinationArray, base.targets.Length);
     for (int j = 0; j < base.targets.Length; j++)
     {
         if (!this.m_AnimationType.hasMultipleDifferentValues)
         {
             destinationArray[j].humanoid = this.m_AnimationType.intValue == 3;
         }
         if (!this.m_CopyAvatar.hasMultipleDifferentValues)
         {
             destinationArray[j].copyAvatar = this.m_CopyAvatar.boolValue;
         }
     }
     base.serializedObject.ApplyModifiedProperties();
     for (int k = 0; k < base.targets.Length; k++)
     {
         if (sourceArray[k].usesOwnAvatar && !destinationArray[k].usesOwnAvatar)
         {
             SerializedObject serializedObject = new SerializedObject(base.targets[k]);
             AvatarSetupTool.ClearAll(serializedObject);
             serializedObject.ApplyModifiedProperties();
         }
         if (!sourceArray[k].usesOwnAvatar && destinationArray[k].usesOwnAvatar)
         {
             ModelImporter importer = base.targets[k] as ModelImporter;
             if (sourceArray[k].hasNoAnimation)
             {
                 AssetDatabase.ImportAsset(importer.assetPath);
             }
             SerializedObject modelImporterSerializedObject = new SerializedObject(base.targets[k]);
             GameObject       original  = AssetDatabase.LoadMainAssetAtPath(importer.assetPath) as GameObject;
             Animator         component = original.GetComponent <Animator>();
             bool             flag      = (component != null) && !component.hasTransformHierarchy;
             if (flag)
             {
                 original = UnityEngine.Object.Instantiate <GameObject>(original);
                 AnimatorUtility.DeoptimizeTransformHierarchy(original);
             }
             AvatarSetupTool.AutoSetupOnInstance(original, modelImporterSerializedObject);
             this.m_IsBiped = AvatarBipedMapper.IsBiped(original.transform);
             if (flag)
             {
                 UnityEngine.Object.DestroyImmediate(original);
             }
             modelImporterSerializedObject.ApplyModifiedProperties();
         }
     }
 }
コード例 #3
0
 internal override void Apply()
 {
     ModelImporterRigEditor.MappingRelevantSettings[] array = new ModelImporterRigEditor.MappingRelevantSettings[base.targets.Length];
     for (int i = 0; i < base.targets.Length; i++)
     {
         SerializedObject   serializedObject    = new SerializedObject(base.targets[i]);
         SerializedProperty serializedProperty  = serializedObject.FindProperty("m_AnimationType");
         SerializedProperty serializedProperty2 = serializedObject.FindProperty("m_CopyAvatar");
         array[i].humanoid       = (serializedProperty.intValue == 3);
         array[i].hasNoAnimation = (serializedProperty.intValue == 0);
         array[i].copyAvatar     = serializedProperty2.boolValue;
     }
     ModelImporterRigEditor.MappingRelevantSettings[] array2 = new ModelImporterRigEditor.MappingRelevantSettings[base.targets.Length];
     Array.Copy(array, array2, base.targets.Length);
     for (int j = 0; j < base.targets.Length; j++)
     {
         if (!this.m_AnimationType.hasMultipleDifferentValues)
         {
             array2[j].humanoid = (this.m_AnimationType.intValue == 3);
         }
         if (!this.m_CopyAvatar.hasMultipleDifferentValues)
         {
             array2[j].copyAvatar = this.m_CopyAvatar.boolValue;
         }
     }
     base.serializedObject.ApplyModifiedProperties();
     for (int k = 0; k < base.targets.Length; k++)
     {
         if (array[k].usesOwnAvatar && !array2[k].usesOwnAvatar)
         {
             SerializedObject serializedObject2 = new SerializedObject(base.targets[k]);
             AvatarSetupTool.ClearAll(serializedObject2);
             serializedObject2.ApplyModifiedProperties();
         }
         if (!array[k].usesOwnAvatar && array2[k].usesOwnAvatar)
         {
             ModelImporter modelImporter = base.targets[k] as ModelImporter;
             if (array[k].hasNoAnimation)
             {
                 AssetDatabase.ImportAsset(modelImporter.assetPath);
             }
             SerializedObject serializedObject3 = new SerializedObject(base.targets[k]);
             GameObject       gameObject        = AssetDatabase.LoadMainAssetAtPath(modelImporter.assetPath) as GameObject;
             Animator         component         = gameObject.GetComponent <Animator>();
             bool             flag = component && !component.hasTransformHierarchy;
             if (flag)
             {
                 gameObject = UnityEngine.Object.Instantiate <GameObject>(gameObject);
                 AnimatorUtility.DeoptimizeTransformHierarchy(gameObject);
             }
             AvatarSetupTool.AutoSetupOnInstance(gameObject, serializedObject3);
             this.m_IsBiped = AvatarBipedMapper.IsBiped(gameObject.transform, this.m_BipedMappingReport);
             if (flag)
             {
                 UnityEngine.Object.DestroyImmediate(gameObject);
             }
             serializedObject3.ApplyModifiedProperties();
         }
     }
 }
コード例 #4
0
 internal override void Apply()
 {
     ModelImporterRigEditor.MappingRelevantSettings[] relevantSettingsArray1 = new ModelImporterRigEditor.MappingRelevantSettings[this.targets.Length];
     for (int index = 0; index < this.targets.Length; ++index)
     {
         SerializedObject   serializedObject = new SerializedObject(this.targets[index]);
         SerializedProperty property1        = serializedObject.FindProperty("m_AnimationType");
         SerializedProperty property2        = serializedObject.FindProperty("m_CopyAvatar");
         relevantSettingsArray1[index].humanoid       = property1.intValue == 3;
         relevantSettingsArray1[index].hasNoAnimation = property1.intValue == 0;
         relevantSettingsArray1[index].copyAvatar     = property2.boolValue;
     }
     ModelImporterRigEditor.MappingRelevantSettings[] relevantSettingsArray2 = new ModelImporterRigEditor.MappingRelevantSettings[this.targets.Length];
     Array.Copy((Array)relevantSettingsArray1, (Array)relevantSettingsArray2, this.targets.Length);
     for (int index = 0; index < this.targets.Length; ++index)
     {
         if (!this.m_AnimationType.hasMultipleDifferentValues)
         {
             relevantSettingsArray2[index].humanoid = this.m_AnimationType.intValue == 3;
         }
         if (!this.m_CopyAvatar.hasMultipleDifferentValues)
         {
             relevantSettingsArray2[index].copyAvatar = this.m_CopyAvatar.boolValue;
         }
     }
     this.serializedObject.ApplyModifiedProperties();
     for (int index = 0; index < this.targets.Length; ++index)
     {
         if (relevantSettingsArray1[index].usesOwnAvatar && !relevantSettingsArray2[index].usesOwnAvatar)
         {
             SerializedObject serializedObject = new SerializedObject(this.targets[index]);
             AvatarSetupTool.ClearAll(serializedObject);
             serializedObject.ApplyModifiedProperties();
         }
         if (!relevantSettingsArray1[index].usesOwnAvatar && relevantSettingsArray2[index].usesOwnAvatar)
         {
             ModelImporter target = this.targets[index] as ModelImporter;
             if (relevantSettingsArray1[index].hasNoAnimation)
             {
                 AssetDatabase.ImportAsset(target.assetPath);
             }
             SerializedObject modelImporterSerializedObject = new SerializedObject(this.targets[index]);
             GameObject       gameObject = AssetDatabase.LoadMainAssetAtPath(target.assetPath) as GameObject;
             Animator         component  = gameObject.GetComponent <Animator>();
             bool             flag       = (bool)((UnityEngine.Object)component) && !component.hasTransformHierarchy;
             if (flag)
             {
                 gameObject = UnityEngine.Object.Instantiate <GameObject>(gameObject);
                 AnimatorUtility.DeoptimizeTransformHierarchy(gameObject);
             }
             AvatarSetupTool.AutoSetupOnInstance(gameObject, modelImporterSerializedObject);
             this.m_IsBiped = AvatarBipedMapper.IsBiped(gameObject.transform, this.m_BipedMappingReport);
             if (flag)
             {
                 UnityEngine.Object.DestroyImmediate((UnityEngine.Object)gameObject);
             }
             modelImporterSerializedObject.ApplyModifiedProperties();
         }
     }
 }
コード例 #5
0
        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();
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        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();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(m_AvatarSource, GUIContent.Temp("Source"));
            var sourceAvatar = m_AvatarSource.objectReferenceValue as Avatar;

            if (EditorGUI.EndChangeCheck())
            {
                CheckAvatar(sourceAvatar);

                AvatarSetupTool.ClearAll(serializedObject);

                if (sourceAvatar != null)
                {
                    CopyHumanDescriptionFromOtherModel(sourceAvatar);
                }

                m_AvatarCopyIsUpToDate = true;
            }

            if (sourceAvatar != null && !m_AvatarSource.hasMultipleDifferentValues && !m_AvatarCopyIsUpToDate)
            {
                if (GUILayout.Button(styles.UpdateMuscleDefinitionFromSource, EditorStyles.miniButton))
                {
                    AvatarSetupTool.ClearAll(serializedObject);
                    CopyHumanDescriptionFromOtherModel(sourceAvatar);
                    m_AvatarCopyIsUpToDate = true;
                }
            }

            EditorGUILayout.EndHorizontal();
        }
コード例 #8
0
 internal override void PostApply()
 {
     for (int i = 0; i < base.targets.Length; i++)
     {
         if (this.oldModelSettings[i].usesOwnAvatar && !this.newModelSettings[i].usesOwnAvatar && !this.newModelSettings[i].copyAvatar)
         {
             SerializedObject serializedObject = new SerializedObject(base.targets[i]);
             AvatarSetupTool.ClearAll(serializedObject);
             serializedObject.ApplyModifiedPropertiesWithoutUndo();
         }
         if (!this.m_CopyAvatar.boolValue && !this.newModelSettings[i].humanoid && this.rootIndex > 0)
         {
             ModelImporter modelImporter = base.targets[i] as ModelImporter;
             GameObject    gameObject    = AssetDatabase.LoadMainAssetAtPath(modelImporter.assetPath) as GameObject;
             Animator      component     = gameObject.GetComponent <Animator>();
             bool          flag          = component && !component.hasTransformHierarchy;
             if (flag)
             {
                 gameObject = (this.Instantiate(gameObject) as GameObject);
                 AnimatorUtility.DeoptimizeTransformHierarchy(gameObject);
             }
             Transform transform = gameObject.transform.Find(this.m_RootMotionBoneList[this.rootIndex].text);
             if (transform != null)
             {
                 this.m_RootMotionBoneRotation.quaternionValue = transform.rotation;
             }
             SerializedObject serializedObject2 = new SerializedObject(base.targets[i]);
             serializedObject2.ApplyModifiedPropertiesWithoutUndo();
             if (flag)
             {
                 this.DestroyImmediate(gameObject);
             }
         }
         if (!this.oldModelSettings[i].usesOwnAvatar && this.newModelSettings[i].usesOwnAvatar)
         {
             ModelImporter modelImporter2 = base.targets[i] as ModelImporter;
             if (this.oldModelSettings[i].hasNoAnimation)
             {
                 ModelImporterAnimationType animationType = modelImporter2.animationType;
                 modelImporter2.animationType = ModelImporterAnimationType.Generic;
                 AssetDatabase.ImportAsset(modelImporter2.assetPath);
                 modelImporter2.animationType = animationType;
             }
             SerializedObject serializedObject3 = new SerializedObject(base.targets[i]);
             GameObject       gameObject2       = AssetDatabase.LoadMainAssetAtPath(modelImporter2.assetPath) as GameObject;
             Animator         component2        = gameObject2.GetComponent <Animator>();
             bool             flag2             = component2 && !component2.hasTransformHierarchy;
             if (flag2)
             {
                 gameObject2 = (this.Instantiate(gameObject2) as GameObject);
                 AnimatorUtility.DeoptimizeTransformHierarchy(gameObject2);
             }
             AvatarSetupTool.AutoSetupOnInstance(gameObject2, serializedObject3);
             this.m_IsBiped = AvatarBipedMapper.IsBiped(gameObject2.transform, this.m_BipedMappingReport);
             if (flag2)
             {
                 this.DestroyImmediate(gameObject2);
             }
             serializedObject3.ApplyModifiedPropertiesWithoutUndo();
         }
     }
     this.oldModelSettings = null;
     this.newModelSettings = null;
 }
コード例 #9
0
        internal override void PostApply()
        {
            // But we might not be done yet!
            // For all models which did not have own humanoid before but should have it now,
            // we need to perform auto-mapping. (For the opposite case we also need to clear the mapping.)
            // Iterate through all the models...
            for (int i = 0; i < targets.Length; i++)
            {
                // If this model had its own humanoid avatar before but shouldn't have it now...
                if (oldModelSettings[i].usesOwnAvatar && !newModelSettings[i].usesOwnAvatar && !newModelSettings[i].copyAvatar)
                {
                    // ...then clear auto-setup on this model.
                    SerializedObject so = new SerializedObject(targets[i]);
                    AvatarSetupTool.ClearAll(so);
                    so.ApplyModifiedPropertiesWithoutUndo();
                }

                if (!m_CopyAvatar.boolValue && !newModelSettings[i].humanoid && rootIndex > 0)
                {
                    ModelImporter importer = targets[i] as ModelImporter;

                    GameObject go = AssetDatabase.LoadMainAssetAtPath(importer.assetPath) as GameObject;
                    // The character could be optimized right now
                    // 'm_OptimizeGameObjects' can't be used to tell if it is optimized, because the user can change this value from UI,
                    // and the change hasn't been applied yet.
                    Animator animator             = go.GetComponent <Animator>();
                    bool     noTransformHierarchy = animator && !animator.hasTransformHierarchy;
                    if (noTransformHierarchy)
                    {
                        go = Instantiate(go) as GameObject;
                        AnimatorUtility.DeoptimizeTransformHierarchy(go);
                    }

                    SerializedObject so = new SerializedObject(targets[i]);
                    so.ApplyModifiedPropertiesWithoutUndo();

                    if (noTransformHierarchy)
                    {
                        DestroyImmediate(go);
                    }
                }

                // If this model should have its own humanoid avatar before and didn't have it before,
                // then we need to perform auto-mapping.
                if (!oldModelSettings[i].usesOwnAvatar && newModelSettings[i].usesOwnAvatar)
                {
                    ModelImporter importer = targets[i] as ModelImporter;
                    // Special case if the model didn't have animation before...
                    if (oldModelSettings[i].hasNoAnimation && assetTargets[i] != null)
                    {
                        // We have to do an extra import first, before the automapping works.
                        // Because the model doesn't have any skinned meshes when it was last imported with
                        // Animation Mode: None. And the auro-mapping relies on information in the skinned meshes.
                        var targetAnimationType = importer.animationType;
                        importer.animationType = ModelImporterAnimationType.Generic; // we dont want to build humanoid here, since it will generate errors.
                        AssetDatabase.ImportAsset(importer.assetPath);
                        importer.animationType = targetAnimationType;
                    }

                    // Perform auto-setup on this model.
                    SerializedObject so = new SerializedObject(targets[i]);
                    GameObject       go = assetTargets[i] as GameObject;
                    // The character could be optimized right now
                    // 'm_OptimizeGameObjects' can't be used to tell if it is optimized, because the user can change this value from UI,
                    // and the change hasn't been applied yet.
                    if (go != null)
                    {
                        Animator animator             = go.GetComponent <Animator>();
                        bool     noTransformHierarchy = animator && !animator.hasTransformHierarchy;
                        if (noTransformHierarchy)
                        {
                            go = Instantiate(go) as GameObject;
                            AnimatorUtility.DeoptimizeTransformHierarchy(go);
                        }
                        AvatarSetupTool.AutoSetupOnInstance(go, so);
                        m_IsBiped = AvatarBipedMapper.IsBiped(go.transform, m_BipedMappingReport);

                        if (noTransformHierarchy)
                        {
                            DestroyImmediate(go);
                        }
                    }

                    so.ApplyModifiedPropertiesWithoutUndo();
                }
            }

            oldModelSettings = null;
            newModelSettings = null;
        }