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); } }
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); } }
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); } }
protected BoneState GetBoneState(int i, out string error) { error = string.Empty; AvatarSetupTool.BoneWrapper bone = this.m_Bones[i]; if (bone.bone == null) { return(BoneState.None); } AvatarSetupTool.BoneWrapper boneWrapper = this.m_Bones[AvatarSetupTool.GetFirstHumanBoneAncestor(this.m_Bones, i)]; if (i == 0 && bone.bone.parent == null) { error = bone.messageName + " cannot be the root transform"; return(BoneState.InvalidHierarchy); } if (boneWrapper.bone != null && !bone.bone.IsChildOf(boneWrapper.bone)) { error = bone.messageName + " is not a child of " + boneWrapper.messageName + "."; return(BoneState.InvalidHierarchy); } if (i != 23 && boneWrapper.bone != null && boneWrapper.bone != bone.bone && (bone.bone.position - boneWrapper.bone.position).sqrMagnitude < Mathf.Epsilon) { error = bone.messageName + " has bone length of zero."; return(BoneState.BoneLenghtIsZero); } IEnumerable <AvatarSetupTool.BoneWrapper> source = from f in this.m_Bones where f.bone == bone.bone select f; if (source.Count <AvatarSetupTool.BoneWrapper>() > 1) { error = bone.messageName + " is also assigned to "; bool flag = true; for (int j = 0; j < this.m_Bones.Length; j++) { if (i != j && this.m_Bones[i].bone == this.m_Bones[j].bone) { if (flag) { flag = false; } else { error += ", "; } error += ObjectNames.NicifyVariableName(this.m_Bones[j].humanBoneName); } } error += "."; return(BoneState.Duplicate); } return(BoneState.Valid); }
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; }
protected static void DrawBone(int shownBodyView, int i, Rect rect, AvatarSetupTool.BoneWrapper bone, SerializedObject serializedObject, AvatarMappingEditor editor) { if (s_BonePositions[shownBodyView, i] != Vector2.zero) { Vector2 vector = s_BonePositions[shownBodyView, i]; vector.y *= -1f; vector.Scale(new Vector2(rect.width * 0.5f, rect.height * 0.5f)); vector = rect.center + vector; int num = 0x13; Rect rect2 = new Rect(vector.x - (num * 0.5f), vector.y - (num * 0.5f), (float)num, (float)num); bone.BoneDotGUI(rect2, i, true, true, serializedObject, editor); } }
protected static void DrawBone(int shownBodyView, int i, Rect rect, AvatarSetupTool.BoneWrapper bone, SerializedObject serializedObject, AvatarMappingEditor editor) { if (!(AvatarControl.s_BonePositions[shownBodyView, i] == Vector2.zero)) { Vector2 b = AvatarControl.s_BonePositions[shownBodyView, i]; b.y *= -1f; b.Scale(new Vector2(rect.width * 0.5f, rect.height * 0.5f)); b = rect.center + b; int num = 19; Rect rect2 = new Rect(b.x - (float)num * 0.5f, b.y - (float)num * 0.5f, (float)num, (float)num); bone.BoneDotGUI(rect2, rect2, i, true, true, true, serializedObject, editor); } }
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); } } }
static protected void DrawBone(int shownBodyView, int i, Rect rect, AvatarSetupTool.BoneWrapper bone, SerializedObject serializedObject, AvatarMappingEditor editor) { if (s_BonePositions[shownBodyView, i] == Vector2.zero) { return; } Vector2 pos = s_BonePositions[shownBodyView, i]; pos.y *= -1; // because higher values should be up pos.Scale(new Vector2(rect.width * 0.5f, rect.height * 0.5f)); pos = rect.center + pos; int kIconSize = AvatarSetupTool.BoneWrapper.kIconSize; Rect r = new Rect(pos.x - kIconSize * 0.5f, pos.y - kIconSize * 0.5f, kIconSize, kIconSize); bone.BoneDotGUI(r, r, i, true, true, true, serializedObject, editor); }
protected BoneState GetBoneState(int i, out string error) { error = string.Empty; AvatarSetupTool.BoneWrapper bone = m_Bones[i]; if (bone.bone == null) { return(BoneState.None); } int ancestorIndex = AvatarSetupTool.GetFirstHumanBoneAncestor(m_Bones, i); AvatarSetupTool.BoneWrapper ancestor = m_Bones[ancestorIndex > 0 ? ancestorIndex : 0]; if (i == 0 && bone.bone.parent == null) { error = bone.messageName + " cannot be the root transform"; return(BoneState.InvalidHierarchy); } if (ancestor.bone != null && !bone.bone.IsChildOf(ancestor.bone)) { error = bone.messageName + " is not a child of " + ancestor.messageName + "."; return(BoneState.InvalidHierarchy); } if (i == (int)HumanBodyBones.UpperChest) { AvatarSetupTool.BoneWrapper chest = m_Bones[(int)HumanBodyBones.Chest]; if (chest.bone == null) { error = "Chest must be assigned before assigning UpperChest."; return(BoneState.InvalidHierarchy); } } // Hips bone is a special case, for hips GetFirstAnscestor return hips if (i != (int)HumanBodyBones.Jaw && ancestor.bone != null && ancestor.bone != bone.bone && (bone.bone.position - ancestor.bone.position).sqrMagnitude < Mathf.Epsilon) { error = bone.messageName + " has bone length of zero."; return(BoneState.BoneLenghtIsZero); } // Does this transfrom is already set //List<BoneWrapper> match = ArrayUtility.FindAll (m_BoneWrappers, delegate (Transform t) { return t == m_BoneWrappers[i].bone; }); IEnumerable <AvatarSetupTool.BoneWrapper> match = m_Bones.Where(f => f.bone == bone.bone); // when we search in the list we must add 1 because the bone is in this list if (match.Count() > 1) { error = bone.messageName + " is also assigned to "; bool first = true; for (int j = 0; j < m_Bones.Length; j++) { if (i != j && m_Bones[i].bone == m_Bones[j].bone) { if (first) { first = false; } else { error += ", "; } error += ObjectNames.NicifyVariableName(m_Bones[j].humanBoneName); } } error += "."; return(BoneState.Duplicate); } else { return(BoneState.Valid); } }
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); }
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); }
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; } }
protected BoneState GetBoneState(int i, out string error) { // ISSUE: object of a compiler-generated type is created // ISSUE: variable of a compiler-generated type AvatarMappingEditor.\u003CGetBoneState\u003Ec__AnonStorey9D stateCAnonStorey9D = new AvatarMappingEditor.\u003CGetBoneState\u003Ec__AnonStorey9D(); error = string.Empty; // ISSUE: reference to a compiler-generated field stateCAnonStorey9D.bone = this.m_Bones[i]; // ISSUE: reference to a compiler-generated field if ((UnityEngine.Object)stateCAnonStorey9D.bone.bone == (UnityEngine.Object)null) { return(BoneState.None); } AvatarSetupTool.BoneWrapper bone = this.m_Bones[AvatarSetupTool.GetFirstHumanBoneAncestor(this.m_Bones, i)]; // ISSUE: reference to a compiler-generated field if (i == 0 && (UnityEngine.Object)stateCAnonStorey9D.bone.bone.parent == (UnityEngine.Object)null) { // ISSUE: reference to a compiler-generated field error = stateCAnonStorey9D.bone.messageName + " cannot be the root transform"; return(BoneState.InvalidHierarchy); } // ISSUE: reference to a compiler-generated field if ((UnityEngine.Object)bone.bone != (UnityEngine.Object)null && !stateCAnonStorey9D.bone.bone.IsChildOf(bone.bone)) { // ISSUE: reference to a compiler-generated field error = stateCAnonStorey9D.bone.messageName + " is not a child of " + bone.messageName + "."; return(BoneState.InvalidHierarchy); } // ISSUE: reference to a compiler-generated field // ISSUE: reference to a compiler-generated field if (i != 23 && (UnityEngine.Object)bone.bone != (UnityEngine.Object)null && (UnityEngine.Object)bone.bone != (UnityEngine.Object)stateCAnonStorey9D.bone.bone && (double)(stateCAnonStorey9D.bone.bone.position - bone.bone.position).sqrMagnitude < (double)Mathf.Epsilon) { // ISSUE: reference to a compiler-generated field error = stateCAnonStorey9D.bone.messageName + " has bone length of zero."; return(BoneState.BoneLenghtIsZero); } // ISSUE: reference to a compiler-generated method if (((IEnumerable <AvatarSetupTool.BoneWrapper>) this.m_Bones).Where <AvatarSetupTool.BoneWrapper>(new Func <AvatarSetupTool.BoneWrapper, bool>(stateCAnonStorey9D.\u003C\u003Em__1CA)).Count <AvatarSetupTool.BoneWrapper>() <= 1) { return(BoneState.Valid); } // ISSUE: reference to a compiler-generated field error = stateCAnonStorey9D.bone.messageName + " is also assigned to "; bool flag = true; for (int index = 0; index < this.m_Bones.Length; ++index) { if (i != index && (UnityEngine.Object) this.m_Bones[i].bone == (UnityEngine.Object) this.m_Bones[index].bone) { if (flag) { flag = false; } else { error = error + ", "; } error = error + ObjectNames.NicifyVariableName(this.m_Bones[index].humanBoneName); } } error = error + "."; return(BoneState.Duplicate); }
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); }