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);
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
        protected void AutoMapping()
        {
            Dictionary <int, Transform> mapping = AvatarAutoMapper.MapBones(gameObject.transform, modelBones);

            foreach (KeyValuePair <int, Transform> kvp in mapping)
            {
                AvatarSetupTool.BoneWrapper bone = m_Bones[kvp.Key];
                bone.bone = kvp.Value;
                bone.Serialize(serializedObject);
            }
        }
Beispiel #4
0
        protected void AutoMapping()
        {
            Dictionary <int, Transform> mapping = AvatarAutoMapper.MapBones(gameObject.transform, modelBones);

            foreach (KeyValuePair <int, Transform> kvp in mapping)
            {
                AvatarSetupTool.BoneWrapper bone = m_Bones[kvp.Key];
                bone.bone = kvp.Value;
                bone.Serialize(m_HumanBoneArray);
            }
            m_AutoGenerateAvatarMappingIfUnspecified.boolValue = false;
        }
Beispiel #5
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);
         }
     }
 }
        protected void DisplayFoldout()
        {
            Dictionary <Transform, bool> bones = modelBones;

            EditorGUIUtility.SetIconSize(Vector2.one * 16);

            // Legend
            EditorGUILayout.BeginHorizontal();
            GUI.color = Color.grey;
            GUILayout.Label(styles.dotFrameDotted.image, GUILayout.ExpandWidth(false));
            GUI.color = Color.white;
            GUILayout.Label("Optional Bone", GUILayout.ExpandWidth(true));
            EditorGUILayout.EndHorizontal();

            // Avatar body part has nothing to show
            for (int i = 1; i < m_BodyPartToggle.Length; i++)
            {
                if (m_BodyPartToggle[i])
                {
                    //  Unfold body part ui whenever a new selection is made.
                    if ((s_DirtySelection == true) && (m_BodyPartFoldout[i] == false))
                    {
                        for (int j = 0; j < m_BodyPartHumanBone[i].Length; j++)
                        {
                            int boneIndex = m_BodyPartHumanBone[i][j];
                            if (s_SelectedBoneIndex == boneIndex)
                            {
                                m_BodyPartFoldout[i] = true;
                            }
                        }
                    }

                    m_BodyPartFoldout[i] = GUILayout.Toggle(m_BodyPartFoldout[i], styles.BodyPartMapping[i], EditorStyles.foldout);
                    EditorGUI.indentLevel++;
                    if (m_BodyPartFoldout[i])
                    {
                        for (int j = 0; j < m_BodyPartHumanBone[i].Length; j++)
                        {
                            int boneIndex = m_BodyPartHumanBone[i][j];
                            if (boneIndex == -1)
                            {
                                continue;
                            }

                            AvatarSetupTool.BoneWrapper bone = m_Bones[boneIndex];
                            string displayBoneName           = bone.humanBoneName;

                            // @TODO@MECANIM: do properly
                            if ((BodyPart)i == BodyPart.RightArm || (BodyPart)i == BodyPart.RightFingers || (BodyPart)i == BodyPart.RightLeg)
                            {
                                displayBoneName = displayBoneName.Replace("Right", "");
                            }
                            if ((BodyPart)i == BodyPart.LeftArm || (BodyPart)i == BodyPart.LeftFingers || (BodyPart)i == BodyPart.LeftLeg)
                            {
                                displayBoneName = displayBoneName.Replace("Left", "");
                            }

                            displayBoneName = ObjectNames.NicifyVariableName(displayBoneName);

                            Rect r = EditorGUILayout.GetControlRect();

                            Rect selectRect = r;
                            selectRect.width -= 15;

                            Rect rect = new Rect(r.x + EditorGUI.indent, r.y - 1, AvatarSetupTool.BoneWrapper.kIconSize, AvatarSetupTool.BoneWrapper.kIconSize);

                            bone.BoneDotGUI(rect, selectRect, boneIndex, true, false, true, serializedObject, this);
                            r.xMin += AvatarSetupTool.BoneWrapper.kIconSize;

                            Transform newBoneTransform = EditorGUI.ObjectField(r, new GUIContent(displayBoneName), bone.bone, typeof(Transform), true) as Transform;
                            if (newBoneTransform != bone.bone)
                            {
                                Undo.RegisterCompleteObjectUndo(this, "Avatar mapping modified");
                                bone.bone = newBoneTransform;
                                bone.Serialize(m_HumanBoneArray);

                                // User adding a bone manually, if it not in the modelBones dict, we must explictly add it
                                if (newBoneTransform != null && !bones.ContainsKey(newBoneTransform))
                                {
                                    bones[newBoneTransform] = true;
                                }
                            }

                            if (!string.IsNullOrEmpty(bone.error))
                            {
                                GUILayout.BeginHorizontal();
                                GUILayout.Space(EditorGUI.indent + AvatarSetupTool.BoneWrapper.kIconSize + 4);
                                GUILayout.Label(bone.error, s_Styles.errorLabel);
                                GUILayout.EndHorizontal();
                            }
                        }
                    }
                    EditorGUI.indentLevel--;
                }
            }

            s_DirtySelection = false;

            EditorGUIUtility.SetIconSize(Vector2.zero);
        }
Beispiel #7
0
        protected void DisplayFoldout()
        {
            Dictionary <Transform, bool> modelBones = base.modelBones;

            EditorGUIUtility.SetIconSize(Vector2.one * 16f);
            EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUI.color = Color.grey;
            GUILayout.Label(AvatarMappingEditor.styles.dotFrameDotted.image, new GUILayoutOption[]
            {
                GUILayout.ExpandWidth(false)
            });
            GUI.color = Color.white;
            GUILayout.Label("Optional Bone", new GUILayoutOption[]
            {
                GUILayout.ExpandWidth(true)
            });
            EditorGUILayout.EndHorizontal();
            for (int i = 1; i < this.m_BodyPartToggle.Length; i++)
            {
                if (this.m_BodyPartToggle[i])
                {
                    if (AvatarMappingEditor.s_DirtySelection && !this.m_BodyPartFoldout[i])
                    {
                        for (int j = 0; j < this.m_BodyPartHumanBone[i].Length; j++)
                        {
                            int num = this.m_BodyPartHumanBone[i][j];
                            if (AvatarMappingEditor.s_SelectedBoneIndex == num)
                            {
                                this.m_BodyPartFoldout[i] = true;
                            }
                        }
                    }
                    this.m_BodyPartFoldout[i] = GUILayout.Toggle(this.m_BodyPartFoldout[i], AvatarMappingEditor.styles.BodyPartMapping[i], EditorStyles.foldout, new GUILayoutOption[0]);
                    EditorGUI.indentLevel++;
                    if (this.m_BodyPartFoldout[i])
                    {
                        for (int k = 0; k < this.m_BodyPartHumanBone[i].Length; k++)
                        {
                            int num2 = this.m_BodyPartHumanBone[i][k];
                            if (num2 != -1)
                            {
                                AvatarSetupTool.BoneWrapper boneWrapper = this.m_Bones[num2];
                                string text = boneWrapper.humanBoneName;
                                if (i == 5 || i == 6 || i == 8)
                                {
                                    text = text.Replace("Right", string.Empty);
                                }
                                if (i == 3 || i == 4 || i == 7)
                                {
                                    text = text.Replace("Left", string.Empty);
                                }
                                text = ObjectNames.NicifyVariableName(text);
                                Rect controlRect = EditorGUILayout.GetControlRect(new GUILayoutOption[0]);
                                Rect selectRect  = controlRect;
                                selectRect.width -= 15f;
                                boneWrapper.HandleClickSelection(selectRect, num2);
                                boneWrapper.BoneDotGUI(new Rect(controlRect.x + EditorGUI.indent, controlRect.y - 1f, 19f, 19f), num2, false, false, base.serializedObject, this);
                                controlRect.xMin += 19f;
                                Transform transform = EditorGUI.ObjectField(controlRect, new GUIContent(text), boneWrapper.bone, typeof(Transform), true) as Transform;
                                if (transform != boneWrapper.bone)
                                {
                                    Undo.RegisterCompleteObjectUndo(this, "Avatar mapping modified");
                                    boneWrapper.bone = transform;
                                    boneWrapper.Serialize(base.serializedObject);
                                    if (transform != null && !modelBones.ContainsKey(transform))
                                    {
                                        modelBones[transform] = true;
                                    }
                                }
                                if (!string.IsNullOrEmpty(boneWrapper.error))
                                {
                                    GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                                    GUILayout.Space(EditorGUI.indent + 19f + 4f);
                                    GUILayout.Label(boneWrapper.error, AvatarMappingEditor.s_Styles.errorLabel, new GUILayoutOption[0]);
                                    GUILayout.EndHorizontal();
                                }
                            }
                        }
                    }
                    EditorGUI.indentLevel--;
                }
            }
            AvatarMappingEditor.s_DirtySelection = false;
            EditorGUIUtility.SetIconSize(Vector2.zero);
        }
Beispiel #8
0
 public override void OnInspectorGUI()
 {
     if (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed")
     {
         AvatarSetupTool.TransferPoseToDescription(base.serializedObject, base.root);
         for (int i = 0; i < this.m_Bones.Length; i++)
         {
             this.m_Bones[i].Serialize(base.serializedObject);
         }
     }
     this.UpdateSelectedBone();
     if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.Backspace || Event.current.keyCode == KeyCode.Delete) && AvatarMappingEditor.s_SelectedBoneIndex != -1 && AvatarMappingEditor.s_SelectedBoneIndex < this.m_Bones.Length)
     {
         Undo.RegisterCompleteObjectUndo(this, "Avatar mapping modified");
         AvatarSetupTool.BoneWrapper boneWrapper = this.m_Bones[AvatarMappingEditor.s_SelectedBoneIndex];
         boneWrapper.bone  = null;
         boneWrapper.state = BoneState.None;
         boneWrapper.Serialize(base.serializedObject);
         Selection.activeTransform = null;
         GUI.changed = true;
         Event.current.Use();
     }
     GUILayout.BeginVertical(new GUILayoutOption[0]);
     EditorGUI.BeginChangeCheck();
     GUILayout.BeginVertical(string.Empty, "TE NodeBackground", new GUILayoutOption[0]);
     this.m_BodyView = AvatarControl.ShowBoneMapping(this.m_BodyView, new AvatarControl.BodyPartFeedback(this.IsValidBodyPart), this.m_Bones, base.serializedObject, this);
     this.HandleBodyView(this.m_BodyView);
     GUILayout.EndVertical();
     this.m_FoldoutScroll = GUILayout.BeginScrollView(this.m_FoldoutScroll, AvatarMappingEditor.styles.box, new GUILayoutOption[]
     {
         GUILayout.MinHeight(80f),
         GUILayout.MaxHeight(500f),
         GUILayout.ExpandHeight(true)
     });
     this.DisplayFoldout();
     GUILayout.FlexibleSpace();
     GUILayout.EndScrollView();
     if (EditorGUI.EndChangeCheck())
     {
         this.ValidateMapping();
         SceneView.RepaintAll();
     }
     this.DisplayMappingButtons();
     GUILayout.EndVertical();
     if (GUIUtility.hotControl == 0)
     {
         this.TransferPoseIfChanged();
     }
     base.ApplyRevertGUI();
     if (Selection.activeTransform != null)
     {
         if (this.m_CurrentTransformEditor != null && this.m_CurrentTransformEditor.target != Selection.activeTransform)
         {
             UnityEngine.Object.DestroyImmediate(this.m_CurrentTransformEditor);
         }
         if (this.m_CurrentTransformEditor == null)
         {
             this.m_CurrentTransformEditor = Editor.CreateEditor(Selection.activeTransform);
         }
         EditorGUILayout.Space();
         this.m_CurrentTransformEditorFoldout = EditorGUILayout.InspectorTitlebar(this.m_CurrentTransformEditorFoldout, Selection.activeTransform, true);
         if (this.m_CurrentTransformEditorFoldout && this.m_CurrentTransformEditor != null)
         {
             this.m_CurrentTransformEditor.OnInspectorGUI();
         }
     }
     else if (this.m_CurrentTransformEditor != null)
     {
         UnityEngine.Object.DestroyImmediate(this.m_CurrentTransformEditor);
         this.m_CurrentTransformEditor = null;
     }
 }
Beispiel #9
0
        protected void DisplayFoldout()
        {
            Dictionary <Transform, bool> modelBones = this.modelBones;

            EditorGUIUtility.SetIconSize(Vector2.one * 16f);
            EditorGUILayout.BeginHorizontal();
            GUI.color = Color.grey;
            GUILayout.Label(AvatarMappingEditor.styles.dotFrameDotted.image, new GUILayoutOption[1]
            {
                GUILayout.ExpandWidth(false)
            });
            GUI.color = Color.white;
            GUILayout.Label("Optional Bone", new GUILayoutOption[1]
            {
                GUILayout.ExpandWidth(true)
            });
            EditorGUILayout.EndHorizontal();
            for (int index1 = 1; index1 < this.m_BodyPartToggle.Length; ++index1)
            {
                if (this.m_BodyPartToggle[index1])
                {
                    if (AvatarMappingEditor.s_DirtySelection && !this.m_BodyPartFoldout[index1])
                    {
                        for (int index2 = 0; index2 < this.m_BodyPartHumanBone[index1].Length; ++index2)
                        {
                            int num = this.m_BodyPartHumanBone[index1][index2];
                            if (AvatarMappingEditor.s_SelectedBoneIndex == num)
                            {
                                this.m_BodyPartFoldout[index1] = true;
                            }
                        }
                    }
                    this.m_BodyPartFoldout[index1] = GUILayout.Toggle(this.m_BodyPartFoldout[index1], AvatarMappingEditor.styles.BodyPartMapping[index1], EditorStyles.foldout, new GUILayoutOption[0]);
                    ++EditorGUI.indentLevel;
                    if (this.m_BodyPartFoldout[index1])
                    {
                        for (int index2 = 0; index2 < this.m_BodyPartHumanBone[index1].Length; ++index2)
                        {
                            int boneIndex = this.m_BodyPartHumanBone[index1][index2];
                            if (boneIndex != -1)
                            {
                                AvatarSetupTool.BoneWrapper bone = this.m_Bones[boneIndex];
                                string name = bone.humanBoneName;
                                if (index1 == 5 || index1 == 6 || index1 == 8)
                                {
                                    name = name.Replace("Right", string.Empty);
                                }
                                if (index1 == 3 || index1 == 4 || index1 == 7)
                                {
                                    name = name.Replace("Left", string.Empty);
                                }
                                string text        = ObjectNames.NicifyVariableName(name);
                                Rect   controlRect = EditorGUILayout.GetControlRect();
                                Rect   selectRect  = controlRect;
                                selectRect.width -= 15f;
                                bone.HandleClickSelection(selectRect, boneIndex);
                                bone.BoneDotGUI(new Rect(controlRect.x + EditorGUI.indent, controlRect.y - 1f, 19f, 19f), boneIndex, false, false, this.serializedObject, this);
                                controlRect.xMin += 19f;
                                Transform key = EditorGUI.ObjectField(controlRect, new GUIContent(text), (UnityEngine.Object)bone.bone, typeof(Transform), true) as Transform;
                                if ((UnityEngine.Object)key != (UnityEngine.Object)bone.bone)
                                {
                                    Undo.RegisterCompleteObjectUndo((UnityEngine.Object) this, "Avatar mapping modified");
                                    bone.bone = key;
                                    bone.Serialize(this.serializedObject);
                                    if ((UnityEngine.Object)key != (UnityEngine.Object)null && !modelBones.ContainsKey(key))
                                    {
                                        modelBones[key] = true;
                                    }
                                }
                                if (!string.IsNullOrEmpty(bone.error))
                                {
                                    GUILayout.BeginHorizontal();
                                    GUILayout.Space((float)((double)EditorGUI.indent + 19.0 + 4.0));
                                    GUILayout.Label(bone.error, AvatarMappingEditor.s_Styles.errorLabel, new GUILayoutOption[0]);
                                    GUILayout.EndHorizontal();
                                }
                            }
                        }
                    }
                    --EditorGUI.indentLevel;
                }
            }
            AvatarMappingEditor.s_DirtySelection = false;
            EditorGUIUtility.SetIconSize(Vector2.zero);
        }