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(); } } }
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(); } } }
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(); } } }
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; }
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; }