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();
         }
     }
 }
 public void OnEnable()
 {
     this.m_AnimationType         = base.serializedObject.FindProperty("m_AnimationType");
     this.m_AvatarSource          = base.serializedObject.FindProperty("m_LastHumanDescriptionAvatarSource");
     this.m_OptimizeGameObjects   = base.serializedObject.FindProperty("m_OptimizeGameObjects");
     this.m_RootMotionBoneName    = base.serializedObject.FindProperty("m_HumanDescription.m_RootMotionBoneName");
     this.m_ExposeTransformEditor = new ExposeTransformEditor();
     string[] transformPaths = this.singleImporter.transformPaths;
     this.m_RootMotionBoneList = new GUIContent[transformPaths.Length];
     for (int i = 0; i < transformPaths.Length; i++)
     {
         this.m_RootMotionBoneList[i] = new GUIContent(transformPaths[i]);
     }
     if (this.m_RootMotionBoneList.Length > 0)
     {
         this.m_RootMotionBoneList[0] = new GUIContent("None");
     }
     this.rootIndex    = ArrayUtility.FindIndex <GUIContent>(this.m_RootMotionBoneList, (GUIContent content) => FileUtil.GetLastPathNameComponent(content.text) == this.m_RootMotionBoneName.stringValue);
     this.rootIndex    = ((this.rootIndex >= 1) ? this.rootIndex : 0);
     this.m_CopyAvatar = base.serializedObject.FindProperty("m_CopyAvatar");
     this.m_LegacyGenerateAnimations = base.serializedObject.FindProperty("m_LegacyGenerateAnimations");
     this.m_AnimationCompression     = base.serializedObject.FindProperty("m_AnimationCompression");
     this.m_ExposeTransformEditor.OnEnable(this.singleImporter.transformPaths, base.serializedObject);
     this.m_CanMultiEditTransformList = this.CanMultiEditTransformList();
     this.CheckIfAvatarCopyIsUpToDate();
     this.m_IsBiped            = false;
     this.m_BipedMappingReport = new List <string>();
     if (this.m_AnimationType.intValue == 3)
     {
         GameObject gameObject = AssetDatabase.LoadMainAssetAtPath(this.singleImporter.assetPath) as GameObject;
         this.m_IsBiped = AvatarBipedMapper.IsBiped(gameObject.transform, this.m_BipedMappingReport);
     }
 }
 private static bool MapBipedBones(Transform root, ref Transform[] humanToTransform, List <string> report)
 {
     for (int i = 0; i < HumanTrait.BoneCount; i++)
     {
         string    a          = AvatarBipedMapper.kBipedHumanBoneNames[i];
         int       parentBone = HumanTrait.GetParentBone(i);
         bool      flag       = HumanTrait.RequiredBone(i);
         bool      flag2      = parentBone == -1 || HumanTrait.RequiredBone(parentBone);
         Transform transform  = (parentBone == -1) ? root : humanToTransform[parentBone];
         if (transform == null && !flag2)
         {
             parentBone = HumanTrait.GetParentBone(parentBone);
             transform  = ((parentBone == -1) ? null : humanToTransform[parentBone]);
         }
         if (a != string.Empty)
         {
             humanToTransform[i] = AvatarBipedMapper.MapBipedBone(i, transform, transform, report);
             if (humanToTransform[i] == null && flag)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
示例#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
        protected void Init()
        {
            if (gameObject == null)
            {
                return;
            }

            m_HumanBoneArray = serializedObject.FindProperty("m_HumanDescription.m_Human");
            m_Skeleton       = serializedObject.FindProperty("m_HumanDescription.m_Skeleton");
            m_AutoGenerateAvatarMappingIfUnspecified = serializedObject.FindProperty("m_AutoGenerateAvatarMappingIfUnspecified");

            m_IsBiped = AvatarBipedMapper.IsBiped(gameObject.transform, null);

            // Handle human bones
            if (m_Bones == null)
            {
                m_Bones = AvatarSetupTool.GetHumanBones(m_HumanBoneArray, modelBones);
            }
            ValidateMapping();

            if (m_CurrentTransformEditor != null)
            {
                DestroyImmediate(m_CurrentTransformEditor);
                m_CurrentTransformEditor = null;
            }
            m_CurrentTransformEditorFoldout = true;
            m_HasSkinnedMesh = (gameObject.GetComponentInChildren <SkinnedMeshRenderer>() != null);

            // Handle pose
            InitPose();

            // Repaint
            SceneView.RepaintAll();
        }
 protected void Init()
 {
     if (!(base.gameObject == null))
     {
         if (AvatarSetupTool.sHumanParent.Length != HumanTrait.BoneCount)
         {
             throw new Exception("Avatar's Human parent list is out of sync");
         }
         this.m_IsBiped = AvatarBipedMapper.IsBiped(base.gameObject.transform, null);
         if (this.m_Bones == null)
         {
             this.m_Bones = AvatarSetupTool.GetHumanBones(base.serializedObject, base.modelBones);
         }
         this.ValidateMapping();
         if (this.m_CurrentTransformEditor != null)
         {
             UnityEngine.Object.DestroyImmediate(this.m_CurrentTransformEditor);
             this.m_CurrentTransformEditor = null;
         }
         this.m_CurrentTransformEditorFoldout = true;
         this.m_HasSkinnedMesh = (base.gameObject.GetComponentInChildren <SkinnedMeshRenderer>() != null);
         this.InitPose();
         SceneView.RepaintAll();
     }
 }
示例#7
0
        protected void BipedPose()
        {
            AvatarBipedMapper.BipedPose(gameObject, m_Bones);

            AvatarSetupTool.TransferPoseToDescription(serializedObject, root);
            m_Inspector.Repaint();
        }
示例#8
0
 private static bool MapBipedBones(Transform root, ref Transform[] humanToTransform, List <string> report)
 {
     for (int index = 0; index < HumanTrait.BoneCount; ++index)
     {
         string    bipedHumanBoneName = AvatarBipedMapper.kBipedHumanBoneNames[index];
         int       parentBone1        = HumanTrait.GetParentBone(index);
         bool      flag1     = HumanTrait.RequiredBone(index);
         bool      flag2     = parentBone1 == -1 || HumanTrait.RequiredBone(parentBone1);
         Transform transform = parentBone1 == -1 ? root : humanToTransform[parentBone1];
         if ((Object)transform == (Object)null && !flag2)
         {
             int parentBone2 = HumanTrait.GetParentBone(parentBone1);
             transform = parentBone2 == -1 ? (Transform)null : humanToTransform[parentBone2];
         }
         if (bipedHumanBoneName != string.Empty)
         {
             humanToTransform[index] = AvatarBipedMapper.MapBipedBone(index, transform, transform, report);
             if ((Object)humanToTransform[index] == (Object)null && flag1)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
示例#9
0
        protected void Init()
        {
            if (gameObject == null)
            {
                return;
            }

            m_IsBiped = AvatarBipedMapper.IsBiped(gameObject.transform, null);

            // Handle human bones
            if (m_Bones == null)
            {
                m_Bones = AvatarSetupTool.GetHumanBones(serializedObject, modelBones);
            }
            ValidateMapping();

            if (m_CurrentTransformEditor != null)
            {
                DestroyImmediate(m_CurrentTransformEditor);
                m_CurrentTransformEditor = null;
            }
            m_CurrentTransformEditorFoldout = true;
            m_HasSkinnedMesh = (gameObject.GetComponentInChildren <SkinnedMeshRenderer>() != null);

            // Handle pose
            InitPose();

            // Repaint
            SceneView.RepaintAll();
        }
示例#10
0
        internal static void BipedPose(GameObject go, AvatarSetupTool.BoneWrapper[] bones)
        {
            AvatarBipedMapper.BipedPose(go.transform, true);
            Quaternion rotation = AvatarSetupTool.AvatarComputeOrientation(bones);

            go.transform.rotation = Quaternion.Inverse(rotation) * go.transform.rotation;
            AvatarSetupTool.MakeCharacterPositionValid(bones);
        }
示例#11
0
        private static Transform MapBipedBone(int bipedBoneIndex, Transform transform, Transform parentTransform, List <string> report)
        {
            Transform transform2 = null;

            if (transform != null)
            {
                int childCount = transform.childCount;
                int num        = 0;
                while (transform2 == null && num < childCount)
                {
                    string name  = AvatarBipedMapper.s_BipedBones[bipedBoneIndex].name;
                    int    index = AvatarBipedMapper.s_BipedBones[bipedBoneIndex].index;
                    if (transform.GetChild(num).name.EndsWith(name))
                    {
                        transform2 = transform.GetChild(num);
                        if (transform2 != null && report != null && index != 0 && transform != parentTransform)
                        {
                            string text = string.Concat(new string[]
                            {
                                "- Invalid parent for ",
                                transform2.name,
                                ". Expected ",
                                parentTransform.name,
                                ", but found ",
                                transform.name,
                                "."
                            });
                            if (index == 1 || index == 2)
                            {
                                text += " Disable Triangle Pelvis";
                            }
                            else if (index == 11 || index == 12)
                            {
                                text += " Enable Triangle Neck";
                            }
                            else if (index == 9)
                            {
                                text += " Preferred is three Spine Links";
                            }
                            else if (index == 10)
                            {
                                text += " Preferred is one Neck Links";
                            }
                            text += "\n";
                            report.Add(text);
                        }
                    }
                    num++;
                }
                int num2 = 0;
                while (transform2 == null && num2 < childCount)
                {
                    transform2 = AvatarBipedMapper.MapBipedBone(bipedBoneIndex, transform.GetChild(num2), parentTransform, report);
                    num2++;
                }
            }
            return(transform2);
        }
示例#12
0
 public static bool IsBiped(Transform root, List <string> report)
 {
     if (report != null)
     {
         report.Clear();
     }
     Transform[] array = new Transform[HumanTrait.BoneCount];
     return(AvatarBipedMapper.MapBipedBones(root, ref array, report));
 }
示例#13
0
        protected void BipedMapping()
        {
            Dictionary <int, Transform> dictionary = AvatarBipedMapper.MapBones(base.gameObject.transform);

            foreach (KeyValuePair <int, Transform> current in dictionary)
            {
                AvatarSetupTool.BoneWrapper boneWrapper = this.m_Bones[current.Key];
                boneWrapper.bone = current.Value;
                boneWrapper.Serialize(base.serializedObject);
            }
        }
示例#14
0
 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);
         }
     }
 }
        protected void BipedMapping()
        {
            Dictionary <int, Transform> mapping = AvatarBipedMapper.MapBones(gameObject.transform);

            foreach (KeyValuePair <int, Transform> kvp in mapping)
            {
                AvatarSetupTool.BoneWrapper bone = m_Bones[kvp.Key];
                bone.bone = kvp.Value;
                bone.Serialize(m_HumanBoneArray);
            }
        }
示例#16
0
 protected void BipedMapping()
 {
     using (Dictionary <int, Transform> .Enumerator enumerator = AvatarBipedMapper.MapBones(this.gameObject.transform).GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             KeyValuePair <int, Transform> current = enumerator.Current;
             AvatarSetupTool.BoneWrapper   bone    = this.m_Bones[current.Key];
             bone.bone = current.Value;
             bone.Serialize(this.serializedObject);
         }
     }
 }
示例#17
0
 private static void BipedPose(Transform t, bool ignore)
 {
     if (t.name.EndsWith("Pelvis"))
     {
         t.localRotation = Quaternion.Euler(270f, 90f, 0f);
         ignore          = false;
     }
     else if (t.name.EndsWith("Thigh"))
     {
         t.localRotation = Quaternion.Euler(0f, 180f, 0f);
     }
     else if (t.name.EndsWith("Toe0"))
     {
         t.localRotation = Quaternion.Euler(0f, 0f, 270f);
     }
     else if (t.name.EndsWith("L Clavicle"))
     {
         t.localRotation = Quaternion.Euler(0f, 270f, 180f);
     }
     else if (t.name.EndsWith("R Clavicle"))
     {
         t.localRotation = Quaternion.Euler(0f, 90f, 180f);
     }
     else if (t.name.EndsWith("L Hand"))
     {
         t.localRotation = Quaternion.Euler(270f, 0f, 0f);
     }
     else if (t.name.EndsWith("R Hand"))
     {
         t.localRotation = Quaternion.Euler(90f, 0f, 0f);
     }
     else if (t.name.EndsWith("L Finger0"))
     {
         t.localRotation = Quaternion.Euler(0f, 315f, 0f);
     }
     else if (t.name.EndsWith("R Finger0"))
     {
         t.localRotation = Quaternion.Euler(0f, 45f, 0f);
     }
     else if (!ignore)
     {
         t.localRotation = Quaternion.identity;
     }
     foreach (Transform t2 in t)
     {
         AvatarBipedMapper.BipedPose(t2, ignore);
     }
 }
示例#18
0
 private static void BipedPose(Transform t)
 {
     if (t.name.EndsWith("Pelvis"))
     {
         t.localRotation        = Quaternion.Euler(270f, 90f, 0.0f);
         t.parent.localRotation = Quaternion.Euler(270f, 90f, 0.0f);
     }
     else
     {
         t.localRotation = !t.name.EndsWith("Thigh") ? (!t.name.EndsWith("Toe0") ? (!t.name.EndsWith("L Clavicle") ? (!t.name.EndsWith("R Clavicle") ? (!t.name.EndsWith("L Hand") ? (!t.name.EndsWith("R Hand") ? (!t.name.EndsWith("L Finger0") ? (!t.name.EndsWith("R Finger0") ? Quaternion.identity : Quaternion.Euler(0.0f, 45f, 0.0f)) : Quaternion.Euler(0.0f, 315f, 0.0f)) : Quaternion.Euler(90f, 0.0f, 0.0f)) : Quaternion.Euler(270f, 0.0f, 0.0f)) : Quaternion.Euler(0.0f, 90f, 180f)) : Quaternion.Euler(0.0f, 270f, 180f)) : Quaternion.Euler(0.0f, 0.0f, 270f)) : Quaternion.Euler(0.0f, 180f, 0.0f);
     }
     foreach (Transform t1 in t)
     {
         AvatarBipedMapper.BipedPose(t1);
     }
 }
        public static Dictionary <int, Transform> MapBones(Transform root)
        {
            Dictionary <int, Transform> dictionary = new Dictionary <int, Transform>();

            Transform[] array = new Transform[HumanTrait.BoneCount];
            if (AvatarBipedMapper.MapBipedBones(root, ref array, null))
            {
                for (int i = 0; i < HumanTrait.BoneCount; i++)
                {
                    if (array[i] != null)
                    {
                        dictionary.Add(i, array[i]);
                    }
                }
            }
            return(dictionary);
        }
示例#20
0
        public static Dictionary <int, Transform> MapBones(Transform root)
        {
            Dictionary <int, Transform> dictionary = new Dictionary <int, Transform>();

            Transform[] humanToTransform = new Transform[HumanTrait.BoneCount];
            if (AvatarBipedMapper.MapBipedBones(root, ref humanToTransform, (List <string>)null))
            {
                for (int key = 0; key < HumanTrait.BoneCount; ++key)
                {
                    if ((Object)humanToTransform[key] != (Object)null)
                    {
                        dictionary.Add(key, humanToTransform[key]);
                    }
                }
            }
            return(dictionary);
        }
示例#21
0
        private static Transform MapBipedBone(int boneIndex, Transform transform, Transform parentTransform, List <string> report)
        {
            Transform transform1 = (Transform)null;

            if ((Object)transform != (Object)null)
            {
                int childCount = transform.childCount;
                for (int index = 0; (Object)transform1 == (Object)null && index < childCount; ++index)
                {
                    if (transform.GetChild(index).name.EndsWith(AvatarBipedMapper.kBipedHumanBoneNames[boneIndex]))
                    {
                        transform1 = transform.GetChild(index);
                        if ((Object)transform1 != (Object)null && report != null && (boneIndex != 0 && (Object)transform != (Object)parentTransform))
                        {
                            string str1 = "- Invalid parent for " + transform1.name + ".Expected " + parentTransform.name + ", but found " + transform.name + ".";
                            if (boneIndex == 1 || boneIndex == 2)
                            {
                                str1 += " Disable Triangle Pelvis";
                            }
                            else if (boneIndex == 11 || boneIndex == 12)
                            {
                                str1 += " Enable Triangle Neck";
                            }
                            else if (boneIndex == 9)
                            {
                                str1 += " Preferred is two Spine Links";
                            }
                            else if (boneIndex == 10)
                            {
                                str1 += " Preferred is one Neck Links";
                            }
                            string str2 = str1 + "\n";
                            report.Add(str2);
                        }
                    }
                }
                for (int index = 0; (Object)transform1 == (Object)null && index < childCount; ++index)
                {
                    transform1 = AvatarBipedMapper.MapBipedBone(boneIndex, transform.GetChild(index), parentTransform, report);
                }
            }
            return(transform1);
        }
示例#22
0
 protected void Init()
 {
     if (base.gameObject == null)
     {
         return;
     }
     this.m_IsBiped = AvatarBipedMapper.IsBiped(base.gameObject.transform, null);
     if (this.m_Bones == null)
     {
         this.m_Bones = AvatarSetupTool.GetHumanBones(base.serializedObject, base.modelBones);
     }
     this.ValidateMapping();
     if (this.m_CurrentTransformEditor != null)
     {
         UnityEngine.Object.DestroyImmediate(this.m_CurrentTransformEditor);
         this.m_CurrentTransformEditor = null;
     }
     this.m_CurrentTransformEditorFoldout = true;
     this.m_HasSkinnedMesh = (base.gameObject.GetComponentInChildren <SkinnedMeshRenderer>() != null);
     this.InitPose();
     SceneView.RepaintAll();
 }
示例#23
0
        public static Dictionary <int, Transform> MapBones(Transform root)
        {
            Dictionary <int, Transform> dictionary = new Dictionary <int, Transform>();

            Transform[] array = new Transform[HumanTrait.BoneCount];
            if (AvatarBipedMapper.MapBipedBones(root, ref array, null))
            {
                for (int i = 0; i < HumanTrait.BoneCount; i++)
                {
                    if (array[i] != null)
                    {
                        dictionary.Add(i, array[i]);
                    }
                }
            }
            if (!dictionary.ContainsKey(8) && dictionary.ContainsKey(54))
            {
                dictionary.Add(8, dictionary[54]);
                dictionary.Remove(54);
            }
            return(dictionary);
        }
        internal override void OnEnable()
        {
            m_AnimationType       = serializedObject.FindProperty("m_AnimationType");
            m_AvatarSource        = serializedObject.FindProperty("m_LastHumanDescriptionAvatarSource");
            m_OptimizeGameObjects = serializedObject.FindProperty("m_OptimizeGameObjects");

            // Generic bone setup
            m_RootMotionBoneName     = serializedObject.FindProperty("m_HumanDescription.m_RootMotionBoneName");
            m_RootMotionBoneRotation = serializedObject.FindProperty("m_HumanDescription.m_RootMotionBoneRotation");

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

            rootIndex = ArrayUtility.FindIndex(m_RootMotionBoneList, delegate(GUIContent content) { return(FileUtil.GetLastPathNameComponent(content.text) == m_RootMotionBoneName.stringValue); });
            rootIndex = rootIndex < 1 ? 0 : rootIndex;

            m_SrcHasExtraRoot = serializedObject.FindProperty("m_HasExtraRoot");
            m_DstHasExtraRoot = serializedObject.FindProperty("m_HumanDescription.m_HasExtraRoot");

            // Animation
            m_CopyAvatar = serializedObject.FindProperty("m_CopyAvatar");
            m_LegacyGenerateAnimations = serializedObject.FindProperty("m_LegacyGenerateAnimations");
            m_AnimationCompression     = serializedObject.FindProperty("m_AnimationCompression");

            m_RigImportErrors   = serializedObject.FindProperty("m_RigImportErrors");
            m_RigImportWarnings = serializedObject.FindProperty("m_RigImportWarnings");

            m_ExposeTransformEditor.OnEnable(singleImporter.transformPaths, serializedObject);

            m_CanMultiEditTransformList = CanMultiEditTransformList();

            // Check if avatar definition is same as the one it's copied from
            CheckIfAvatarCopyIsUpToDate();

            m_IsBiped            = false;
            m_BipedMappingReport = new List <string>();

            if (m_AnimationType.intValue == (int)ModelImporterAnimationType.Human)
            {
                GameObject go = assetTarget as GameObject;
                if (go != null)
                {
                    m_IsBiped = AvatarBipedMapper.IsBiped(go.transform, m_BipedMappingReport);
                }

                if (m_Avatar == null)
                {
                    ResetAvatar();
                }
            }
        }
示例#25
0
 public static void BipedPose(GameObject go)
 {
     AvatarBipedMapper.BipedPose(go.transform);
 }
示例#26
0
        private static void BipedPose(Transform t, bool ignore)
        {
            if (t.name.EndsWith("Pelvis"))
            {
                t.localRotation = Quaternion.Euler(270f, 90f, 0f);
                ignore          = false;
            }
            else if (t.name.EndsWith("Thigh"))
            {
                t.localRotation = Quaternion.Euler(0f, 180f, 0f);
            }
            else if (t.name.EndsWith("Toe0"))
            {
                t.localRotation = Quaternion.Euler(0f, 0f, 270f);
            }
            else if (t.name.EndsWith("L Clavicle"))
            {
                t.localRotation = Quaternion.Euler(0f, 270f, 180f);
            }
            else if (t.name.EndsWith("R Clavicle"))
            {
                t.localRotation = Quaternion.Euler(0f, 90f, 180f);
            }
            else if (t.name.EndsWith("L Hand"))
            {
                t.localRotation = Quaternion.Euler(270f, 0f, 0f);
            }
            else if (t.name.EndsWith("R Hand"))
            {
                t.localRotation = Quaternion.Euler(90f, 0f, 0f);
            }
            else if (t.name.EndsWith("L Finger0"))
            {
                t.localRotation = Quaternion.Euler(0f, 315f, 0f);
            }
            else if (t.name.EndsWith("R Finger0"))
            {
                t.localRotation = Quaternion.Euler(0f, 45f, 0f);
            }
            else if (!ignore)
            {
                t.localRotation = Quaternion.identity;
            }
            IEnumerator enumerator = t.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    Transform t2 = (Transform)enumerator.Current;
                    AvatarBipedMapper.BipedPose(t2, ignore);
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
        }
        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;
        }
 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;
 }
示例#29
0
 protected void BipedPose()
 {
     AvatarBipedMapper.BipedPose(base.gameObject);
     AvatarSetupTool.TransferPoseToDescription(base.serializedObject, base.root);
     this.m_Inspector.Repaint();
 }