public static int ShowBoneMapping(int shownBodyView, AvatarControl.BodyPartFeedback bodyPartCallback, AvatarSetupTool.BoneWrapper[] bones, SerializedObject serializedObject, AvatarMappingEditor editor)
 {
   GUILayout.BeginHorizontal();
   GUILayout.FlexibleSpace();
   if ((bool) ((Object) AvatarControl.styles.Silhouettes[shownBodyView].image))
   {
     Rect rect = GUILayoutUtility.GetRect(AvatarControl.styles.Silhouettes[shownBodyView], GUIStyle.none, new GUILayoutOption[1]{ GUILayout.MaxWidth((float) AvatarControl.styles.Silhouettes[shownBodyView].image.width) });
     AvatarControl.DrawBodyParts(rect, shownBodyView, bodyPartCallback);
     for (int i = 0; i < bones.Length; ++i)
       AvatarControl.DrawBone(shownBodyView, i, rect, bones[i], serializedObject, editor);
   }
   else
     GUILayout.Label("texture missing,\nfix me!");
   GUILayout.FlexibleSpace();
   GUILayout.EndHorizontal();
   Rect lastRect = GUILayoutUtility.GetLastRect();
   string[] strArray = new string[4]{ "Body", "Head", "Left Hand", "Right Hand" };
   lastRect.x += 5f;
   lastRect.width = 70f;
   lastRect.yMin = lastRect.yMax - 69f;
   lastRect.height = 16f;
   for (int index = 0; index < strArray.Length; ++index)
   {
     if (GUI.Toggle(lastRect, shownBodyView == index, strArray[index], EditorStyles.miniButton))
       shownBodyView = index;
     lastRect.y += 16f;
   }
   return shownBodyView;
 }
 public static void DrawSkeleton(Transform reference, Dictionary<Transform, bool> actualBones, AvatarSetupTool.BoneWrapper[] bones)
 {
   if ((Object) reference == (Object) null || actualBones == null)
     return;
   AvatarSkeletonDrawer.sPoseError = false;
   Bounds bounds = new Bounds();
   Renderer[] componentsInChildren = reference.root.GetComponentsInChildren<Renderer>();
   if (componentsInChildren != null)
   {
     foreach (Renderer renderer in componentsInChildren)
     {
       bounds.Encapsulate(renderer.bounds.min);
       bounds.Encapsulate(renderer.bounds.max);
     }
   }
   Quaternion orientation = Quaternion.identity;
   if (bones != null)
     orientation = AvatarSetupTool.AvatarComputeOrientation(bones);
   AvatarSkeletonDrawer.DrawSkeletonSubTree(actualBones, bones, orientation, reference, bounds);
   Camera current = Camera.current;
   if (!AvatarSkeletonDrawer.sPoseError || !((Object) current != (Object) null))
     return;
   GUIStyle style = new GUIStyle(GUI.skin.label);
   style.normal.textColor = Color.red;
   style.wordWrap = false;
   style.alignment = TextAnchor.MiddleLeft;
   style.fontSize = 20;
   GUIContent content = new GUIContent("Character is not in T pose");
   Rect rect = GUILayoutUtility.GetRect(content, style);
   rect.x = 30f;
   rect.y = 30f;
   Handles.BeginGUI();
   GUI.Label(rect, content, style);
   Handles.EndGUI();
 }
 internal static void BipedPose(GameObject go, AvatarSetupTool.BoneWrapper[] bones)
 {
     BipedPose(go.transform, true);
     Quaternion rotation = AvatarSetupTool.AvatarComputeOrientation(bones);
     go.transform.rotation = Quaternion.Inverse(rotation) * go.transform.rotation;
     AvatarSetupTool.MakeCharacterPositionValid(bones);
 }
Esempio n. 4
0
 protected void DebugPoseButtons()
 {
     if (GUILayout.Button("Default Pose", new GUILayoutOption[0]) && this.IsValidHuman())
     {
         Animator component = base.gameObject.GetComponent <Animator>();
         component.WriteDefaultPose();
     }
     if (GUILayout.Button("Description Pose", new GUILayoutOption[0]))
     {
         AvatarSetupTool.TransferDescriptionToPose(base.serializedObject, base.root);
     }
 }
Esempio n. 5
0
        internal static void BipedPose(GameObject go, AvatarSetupTool.BoneWrapper[] bones)
        {
            BipedPose(go.transform, true);

            // Orient Biped
            Quaternion rot = AvatarSetupTool.AvatarComputeOrientation(bones);

            go.transform.rotation = Quaternion.Inverse(rot) * go.transform.rotation;

            // Move Biped feet to ground plane
            AvatarSetupTool.MakeCharacterPositionValid(bones);
        }
Esempio n. 6
0
 protected void TransferPoseIfChanged()
 {
     foreach (GameObject selected in Selection.gameObjects)
     {
         if (TransformChanged(selected.transform))
         {
             AvatarSetupTool.TransferPoseToDescription(m_Skeleton, root);
             m_Inspector.Repaint();
             break;
         }
     }
 }
Esempio n. 7
0
 protected void ClearMapping()
 {
     if (serializedObject != null)
     {
         Undo.RegisterCompleteObjectUndo(this, "Clear Mapping");
         AvatarSetupTool.ClearHumanBoneArray(m_HumanBoneArray);
         ResetBones();
         ValidateMapping();
         m_AutoGenerateAvatarMappingIfUnspecified.boolValue = false;
         SceneView.RepaintAll();
     }
 }
Esempio n. 8
0
 protected void ClearMapping()
 {
     if (this.serializedObject == null)
     {
         return;
     }
     Undo.RegisterCompleteObjectUndo((UnityEngine.Object) this, "Clear Mapping");
     AvatarSetupTool.ClearHumanBoneArray(this.serializedObject);
     this.ResetBones();
     this.ValidateMapping();
     SceneView.RepaintAll();
 }
Esempio n. 9
0
 protected void TransferPoseIfChanged()
 {
     foreach (GameObject gameObject in Selection.gameObjects)
     {
         if (this.TransformChanged(gameObject.transform))
         {
             AvatarSetupTool.TransferPoseToDescription(this.serializedObject, this.root);
             this.m_Inspector.Repaint();
             break;
         }
     }
 }
Esempio n. 10
0
 protected void DebugPoseButtons()
 {
     if (GUILayout.Button("Default Pose") && this.IsValidHuman())
     {
         this.gameObject.GetComponent <Animator>().WriteDefaultPose();
     }
     if (!GUILayout.Button("Description Pose"))
     {
         return;
     }
     AvatarSetupTool.TransferDescriptionToPose(this.serializedObject, this.root);
 }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
 protected void DebugPoseButtons()
 {
     if (GUILayout.Button("Default Pose") && IsValidHuman())
     {
         Animator animator = gameObject.GetComponent <Animator>();
         animator.WriteDefaultPose();
     }
     if (GUILayout.Button("Description Pose"))
     {
         AvatarSetupTool.TransferDescriptionToPose(serializedObject, root);
     }
 }
Esempio n. 13
0
        private static bool DrawSkeletonSubTree(Dictionary <Transform, bool> actualBones, AvatarSetupTool.BoneWrapper[] bones, Quaternion orientation, Transform tr, Bounds bounds)
        {
            if (!actualBones.ContainsKey(tr))
            {
                return(false);
            }
            int num = 0;

            foreach (Transform tr1 in tr)
            {
                if (AvatarSkeletonDrawer.DrawSkeletonSubTree(actualBones, bones, orientation, tr1, bounds))
                {
                    ++num;
                }
            }
            if (!actualBones[tr] && num <= 1)
            {
                return(false);
            }
            int boneIndex = -1;

            if (bones != null)
            {
                for (int index = 0; index < bones.Length; ++index)
                {
                    if ((Object)bones[index].bone == (Object)tr)
                    {
                        boneIndex = index;
                        break;
                    }
                }
            }
            bool flag = (double)AvatarSetupTool.GetBoneAlignmentError(bones, orientation, boneIndex) > 0.0;

            AvatarSkeletonDrawer.sPoseError |= flag;
            if (flag)
            {
                AvatarSkeletonDrawer.DrawPoseError(tr, bounds);
                Handles.color = AvatarSkeletonDrawer.kErrorColor;
            }
            else
            {
                Handles.color = boneIndex == -1 ? (actualBones[tr] ? AvatarSkeletonDrawer.kSkeletonColor : AvatarSkeletonDrawer.kDummyColor) : AvatarSkeletonDrawer.kHumanColor;
            }
            Handles.DoBoneHandle(tr, actualBones);
            if (Selection.activeObject == (Object)tr)
            {
                Handles.color = AvatarSkeletonDrawer.kSelectedColor;
                Handles.DoBoneHandle(tr, actualBones);
            }
            return(true);
        }
        private void HandleUndoPerformed()
        {
            if (Event.current.type == EventType.ValidateCommand && Event.current.commandName == EventCommandNames.UndoRedoPerformed)
            {
                SetupInternalProperties();

                AvatarSetupTool.TransferPoseToDescription(m_Skeleton, root);
                for (int i = 0; i < m_Bones.Length; i++)
                {
                    m_Bones[i].Serialize(m_HumanBoneArray);
                }
            }
        }
Esempio n. 15
0
 internal void Initialize()
 {
     if (this.m_Bones == null)
     {
         this.m_Bones = AvatarSetupTool.GetHumanBones(base.serializedObject, base.modelBones);
     }
     this.m_FocusedMuscle         = -1;
     this.m_MuscleBodyGroupToggle = new bool[this.m_Muscles.Length];
     for (int i = 0; i < this.m_Muscles.Length; i++)
     {
         this.m_MuscleBodyGroupToggle[i] = false;
     }
     this.m_MuscleName = HumanTrait.MuscleName;
     for (int j = 0; j < this.m_MuscleName.Length; j++)
     {
         if (this.m_MuscleName[j].StartsWith("Right"))
         {
             this.m_MuscleName[j] = this.m_MuscleName[j].Substring(5).Trim();
         }
         if (this.m_MuscleName[j].StartsWith("Left"))
         {
             this.m_MuscleName[j] = this.m_MuscleName[j].Substring(4).Trim();
         }
     }
     this.m_MuscleCount   = HumanTrait.MuscleCount;
     this.m_MuscleToggle  = new bool[this.m_MuscleCount];
     this.m_MuscleValue   = new float[this.m_MuscleCount];
     this.m_MuscleMin     = new SerializedProperty[this.m_MuscleCount];
     this.m_MuscleMax     = new SerializedProperty[this.m_MuscleCount];
     this.m_MuscleMinEdit = new float[this.m_MuscleCount];
     this.m_MuscleMaxEdit = new float[this.m_MuscleCount];
     for (int k = 0; k < this.m_MuscleCount; k++)
     {
         this.m_MuscleToggle[k] = false;
         this.m_MuscleValue[k]  = 0f;
         this.m_MuscleMin[k]    = null;
         this.m_MuscleMin[k]    = null;
     }
     this.m_Modified = new SerializedProperty[this.m_Bones.Length];
     for (int m = 0; m < this.m_Bones.Length; m++)
     {
         this.m_Modified[m] = null;
     }
     this.InitializeProperties();
     this.ResetValuesFromProperties();
     this.m_MuscleMasterValue = new float[this.m_MasterMuscle.Length];
     for (int n = 0; n < this.m_MasterMuscle.Length; n++)
     {
         this.m_MuscleMasterValue[n] = 0f;
     }
 }
 internal void Initialize()
 {
     if (this.m_Bones == null)
     {
         this.m_Bones = AvatarSetupTool.GetHumanBones(this.serializedObject, this.modelBones);
     }
     this.m_FocusedMuscle         = -1;
     this.m_MuscleBodyGroupToggle = new bool[this.m_Muscles.Length];
     for (int index = 0; index < this.m_Muscles.Length; ++index)
     {
         this.m_MuscleBodyGroupToggle[index] = false;
     }
     this.m_MuscleName = HumanTrait.MuscleName;
     for (int index = 0; index < this.m_MuscleName.Length; ++index)
     {
         if (this.m_MuscleName[index].StartsWith("Right"))
         {
             this.m_MuscleName[index] = this.m_MuscleName[index].Substring(5).Trim();
         }
         if (this.m_MuscleName[index].StartsWith("Left"))
         {
             this.m_MuscleName[index] = this.m_MuscleName[index].Substring(4).Trim();
         }
     }
     this.m_MuscleCount   = HumanTrait.MuscleCount;
     this.m_MuscleToggle  = new bool[this.m_MuscleCount];
     this.m_MuscleValue   = new float[this.m_MuscleCount];
     this.m_MuscleMin     = new SerializedProperty[this.m_MuscleCount];
     this.m_MuscleMax     = new SerializedProperty[this.m_MuscleCount];
     this.m_MuscleMinEdit = new float[this.m_MuscleCount];
     this.m_MuscleMaxEdit = new float[this.m_MuscleCount];
     for (int index = 0; index < this.m_MuscleCount; ++index)
     {
         this.m_MuscleToggle[index] = false;
         this.m_MuscleValue[index]  = 0.0f;
         this.m_MuscleMin[index]    = (SerializedProperty)null;
         this.m_MuscleMin[index]    = (SerializedProperty)null;
     }
     this.m_Modified = new SerializedProperty[this.m_Bones.Length];
     for (int index = 0; index < this.m_Bones.Length; ++index)
     {
         this.m_Modified[index] = (SerializedProperty)null;
     }
     this.InitializeProperties();
     this.ResetValuesFromProperties();
     this.m_MuscleMasterValue = new float[this.m_MasterMuscle.Length];
     for (int index = 0; index < this.m_MasterMuscle.Length; ++index)
     {
         this.m_MuscleMasterValue[index] = 0.0f;
     }
 }
Esempio n. 17
0
 protected void TransferPoseIfChanged()
 {
     GameObject[] gameObjects = Selection.gameObjects;
     for (int i = 0; i < gameObjects.Length; i++)
     {
         GameObject gameObject = gameObjects[i];
         if (this.TransformChanged(gameObject.transform))
         {
             AvatarSetupTool.TransferPoseToDescription(base.serializedObject, base.root);
             this.m_Inspector.Repaint();
             break;
         }
     }
 }
Esempio n. 18
0
        internal void SwitchToEditMode()
        {
            this.m_EditMode = AvatarEditor.EditMode.Starting;
            this.ChangeInspectorLock(true);
            this.sceneSetup = EditorSceneManager.GetSceneManagerSetup();
            EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects).name = "Avatar Configuration";
            this.m_GameObject = UnityEngine.Object.Instantiate <GameObject>(this.prefab);
            if (base.serializedObject.FindProperty("m_OptimizeGameObjects").boolValue)
            {
                AnimatorUtility.DeoptimizeTransformHierarchy(this.m_GameObject);
            }
            Animator component = this.m_GameObject.GetComponent <Animator>();

            if (component != null && component.runtimeAnimatorController == null)
            {
                AnimatorController animatorController = new AnimatorController();
                animatorController.hideFlags = HideFlags.DontSave;
                animatorController.AddLayer("preview");
                animatorController.layers[0].stateMachine.hideFlags = HideFlags.DontSave;
                component.runtimeAnimatorController = animatorController;
            }
            Dictionary <Transform, bool> modelBones = AvatarSetupTool.GetModelBones(this.m_GameObject.transform, true, null);

            AvatarSetupTool.BoneWrapper[] humanBones = AvatarSetupTool.GetHumanBones(base.serializedObject, modelBones);
            this.m_ModelBones      = AvatarSetupTool.GetModelBones(this.m_GameObject.transform, false, humanBones);
            Selection.activeObject = this.m_GameObject;
            UnityEngine.Object[] array = Resources.FindObjectsOfTypeAll(typeof(SceneHierarchyWindow));
            for (int i = 0; i < array.Length; i++)
            {
                SceneHierarchyWindow sceneHierarchyWindow = (SceneHierarchyWindow)array[i];
                sceneHierarchyWindow.SetExpandedRecursive(this.m_GameObject.GetInstanceID(), true);
            }
            this.CreateEditor();
            this.m_EditMode    = AvatarEditor.EditMode.Editing;
            this.m_SceneStates = new List <AvatarEditor.SceneStateCache>();
            foreach (SceneView sceneView in SceneView.sceneViews)
            {
                this.m_SceneStates.Add(new AvatarEditor.SceneStateCache
                {
                    state = new SceneView.SceneViewState(sceneView.m_SceneViewState),
                    view  = sceneView
                });
                sceneView.m_SceneViewState.showFlares         = false;
                sceneView.m_SceneViewState.showMaterialUpdate = false;
                sceneView.m_SceneViewState.showFog            = false;
                sceneView.m_SceneViewState.showSkybox         = false;
                sceneView.m_SceneViewState.showImageEffects   = false;
                sceneView.FrameSelected();
            }
        }
Esempio n. 19
0
        void CopyAvatarGUI()
        {
            GUILayout.Label(
                @"If you have already created an Avatar for another model with a rig identical to this one, you can copy its Avatar definition.
With this option, this model will not create any avatar but only import animations.", EditorStyles.helpBox);

            EditorGUILayout.BeginHorizontal();

            Avatar previousAvatar = (Avatar)m_AvatarSource.objectReferenceValue;

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

            if (EditorGUI.EndChangeCheck())
            {
                if (IsAvatarValid(sourceAvatar))
                {
                    AvatarSetupTool.ClearAll(m_HumanBoneArray, m_Skeleton);

                    if (sourceAvatar != null)
                    {
                        CopyHumanDescriptionFromOtherModel(sourceAvatar);
                    }
                }
                else
                {
                    //Avatar is invalid so revert to the previous Avatar
                    m_AvatarSource.objectReferenceValue = previousAvatar;
                }
            }

            if (sourceAvatar != null && !m_AvatarSource.hasMultipleDifferentValues && !AvatarCopyIsUpToDate())
            {
                if (GUILayout.Button(Styles.UpdateMuscleDefinitionFromSource, EditorStyles.miniButton))
                {
                    if (IsAvatarValid(sourceAvatar))
                    {
                        AvatarSetupTool.ClearAll(m_HumanBoneArray, m_Skeleton);
                        CopyHumanDescriptionFromOtherModel(sourceAvatar);
                    }
                }
            }

            EditorGUILayout.EndHorizontal();
        }
Esempio n. 20
0
        public static void DrawSkeleton(Transform reference, Dictionary <Transform, bool> actualBones, AvatarSetupTool.BoneWrapper[] bones)
        {
            if ((Object)reference == (Object)null || actualBones == null)
            {
                return;
            }
            AvatarSkeletonDrawer.sPoseError = false;
            Bounds bounds = new Bounds();

            Renderer[] componentsInChildren = reference.root.GetComponentsInChildren <Renderer>();
            if (componentsInChildren != null)
            {
                foreach (Renderer renderer in componentsInChildren)
                {
                    bounds.Encapsulate(renderer.bounds.min);
                    bounds.Encapsulate(renderer.bounds.max);
                }
            }
            Quaternion orientation = Quaternion.identity;

            if (bones != null)
            {
                orientation = AvatarSetupTool.AvatarComputeOrientation(bones);
            }
            AvatarSkeletonDrawer.DrawSkeletonSubTree(actualBones, bones, orientation, reference, bounds);
            Camera current = Camera.current;

            if (!AvatarSkeletonDrawer.sPoseError || !((Object)current != (Object)null))
            {
                return;
            }
            GUIStyle style = new GUIStyle(GUI.skin.label);

            style.normal.textColor = Color.red;
            style.wordWrap         = false;
            style.alignment        = TextAnchor.MiddleLeft;
            style.fontSize         = 20;
            GUIContent content = new GUIContent("Character is not in T pose");
            Rect       rect    = GUILayoutUtility.GetRect(content, style);

            rect.x = 30f;
            rect.y = 30f;
            Handles.BeginGUI();
            GUI.Label(rect, content, style);
            Handles.EndGUI();
        }
Esempio n. 21
0
 private void OnEnable()
 {
     EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.update, new EditorApplication.CallbackFunction(this.Update));
     this.m_SwitchToEditMode  = false;
     if (this.m_EditMode == AvatarEditor.EditMode.Editing)
     {
         this.m_ModelBones = AvatarSetupTool.GetModelBones(this.m_GameObject.transform, false, null);
         this.editor.Enable(this);
     }
     else if (this.m_EditMode == AvatarEditor.EditMode.NotEditing)
     {
         this.editor = null;
         if (AvatarEditor.s_EditImmediatelyOnNextOpen)
         {
             this.m_CameFromImportSettings            = true;
             AvatarEditor.s_EditImmediatelyOnNextOpen = false;
         }
     }
 }
		public static void DrawSkeleton(Transform reference, Dictionary<Transform, bool> actualBones, AvatarSetupTool.BoneWrapper[] bones)
		{
			if (reference == null || actualBones == null)
			{
				return;
			}
			AvatarSkeletonDrawer.sPoseError = false;
			Bounds bounds = default(Bounds);
			Renderer[] componentsInChildren = reference.root.GetComponentsInChildren<Renderer>();
			if (componentsInChildren != null)
			{
				Renderer[] array = componentsInChildren;
				for (int i = 0; i < array.Length; i++)
				{
					Renderer renderer = array[i];
					bounds.Encapsulate(renderer.bounds.min);
					bounds.Encapsulate(renderer.bounds.max);
				}
			}
			Quaternion orientation = Quaternion.identity;
			if (bones != null)
			{
				orientation = AvatarSetupTool.AvatarComputeOrientation(bones);
			}
			AvatarSkeletonDrawer.DrawSkeletonSubTree(actualBones, bones, orientation, reference, bounds);
			Camera current = Camera.current;
			if (AvatarSkeletonDrawer.sPoseError && current != null)
			{
				GUIStyle gUIStyle = new GUIStyle(GUI.skin.label);
				gUIStyle.normal.textColor = Color.red;
				gUIStyle.wordWrap = false;
				gUIStyle.alignment = TextAnchor.MiddleLeft;
				gUIStyle.fontSize = 20;
				GUIContent content = new GUIContent("Character is not in T pose");
				Rect rect = GUILayoutUtility.GetRect(content, gUIStyle);
				rect.x = 30f;
				rect.y = 30f;
				Handles.BeginGUI();
				GUI.Label(rect, content, gUIStyle);
				Handles.EndGUI();
			}
		}
Esempio n. 23
0
        void OnEnable()
        {
            EditorApplication.update += Update;
            m_SwitchToEditMode        = false;
            if (m_EditMode == EditMode.Editing)
            {
                m_ModelBones = AvatarSetupTool.GetModelBones(m_GameObject.transform, false, null);
                editor.Enable(this);
            }
            else if (m_EditMode == EditMode.NotEditing)
            {
                editor = null;

                if (s_EditImmediatelyOnNextOpen)
                {
                    m_CameFromImportSettings    = true;
                    s_EditImmediatelyOnNextOpen = false;
                }
            }
        }
 private static bool DrawSkeletonSubTree(Dictionary<Transform, bool> actualBones, AvatarSetupTool.BoneWrapper[] bones, Quaternion orientation, Transform tr, Bounds bounds)
 {
   if (!actualBones.ContainsKey(tr))
     return false;
   int num = 0;
   foreach (Transform tr1 in tr)
   {
     if (AvatarSkeletonDrawer.DrawSkeletonSubTree(actualBones, bones, orientation, tr1, bounds))
       ++num;
   }
   if (!actualBones[tr] && num <= 1)
     return false;
   int boneIndex = -1;
   if (bones != null)
   {
     for (int index = 0; index < bones.Length; ++index)
     {
       if ((Object) bones[index].bone == (Object) tr)
       {
         boneIndex = index;
         break;
       }
     }
   }
   bool flag = (double) AvatarSetupTool.GetBoneAlignmentError(bones, orientation, boneIndex) > 0.0;
   AvatarSkeletonDrawer.sPoseError |= flag;
   if (flag)
   {
     AvatarSkeletonDrawer.DrawPoseError(tr, bounds);
     Handles.color = AvatarSkeletonDrawer.kErrorColor;
   }
   else
     Handles.color = boneIndex == -1 ? (actualBones[tr] ? AvatarSkeletonDrawer.kSkeletonColor : AvatarSkeletonDrawer.kDummyColor) : AvatarSkeletonDrawer.kHumanColor;
   Handles.DoBoneHandle(tr, actualBones);
   if (Selection.activeObject == (Object) tr)
   {
     Handles.color = AvatarSkeletonDrawer.kSelectedColor;
     Handles.DoBoneHandle(tr, actualBones);
   }
   return true;
 }
 public static void DrawSkeleton(Transform reference, Dictionary <Transform, bool> actualBones, AvatarSetupTool.BoneWrapper[] bones)
 {
     if (!(reference == null) && actualBones != null)
     {
         AvatarSkeletonDrawer.sPoseError = false;
         Bounds     bounds = default(Bounds);
         Renderer[] componentsInChildren = reference.root.GetComponentsInChildren <Renderer>();
         if (componentsInChildren != null)
         {
             Renderer[] array = componentsInChildren;
             for (int i = 0; i < array.Length; i++)
             {
                 Renderer renderer = array[i];
                 bounds.Encapsulate(renderer.bounds.min);
                 bounds.Encapsulate(renderer.bounds.max);
             }
         }
         Quaternion orientation = Quaternion.identity;
         if (bones != null)
         {
             orientation = AvatarSetupTool.AvatarComputeOrientation(bones);
         }
         AvatarSkeletonDrawer.DrawSkeletonSubTree(actualBones, bones, orientation, reference, bounds);
         Camera current = Camera.current;
         if (AvatarSkeletonDrawer.sPoseError && current != null)
         {
             GUIStyle gUIStyle = new GUIStyle(GUI.skin.label);
             gUIStyle.normal.textColor = Color.red;
             gUIStyle.wordWrap         = false;
             gUIStyle.alignment        = TextAnchor.MiddleLeft;
             gUIStyle.fontSize         = 20;
             GUIContent content = new GUIContent("Character is not in T pose");
             Rect       rect    = GUILayoutUtility.GetRect(content, gUIStyle);
             rect.x = 30f;
             rect.y = 30f;
             Handles.BeginGUI();
             GUI.Label(rect, content, gUIStyle);
             Handles.EndGUI();
         }
     }
 }
 public static void DrawSkeleton(Transform reference, Dictionary <Transform, bool> actualBones, AvatarSetupTool.BoneWrapper[] bones)
 {
     if ((reference != null) && (actualBones != null))
     {
         sPoseError = false;
         Bounds     bounds = new Bounds();
         Renderer[] componentsInChildren = reference.root.GetComponentsInChildren <Renderer>();
         if (componentsInChildren != null)
         {
             foreach (Renderer renderer in componentsInChildren)
             {
                 bounds.Encapsulate(renderer.bounds.min);
                 bounds.Encapsulate(renderer.bounds.max);
             }
         }
         Quaternion identity = Quaternion.identity;
         if (bones != null)
         {
             identity = AvatarSetupTool.AvatarComputeOrientation(bones);
         }
         DrawSkeletonSubTree(actualBones, bones, identity, reference, bounds);
         Camera current = Camera.current;
         if (sPoseError && (current != null))
         {
             GUIStyle style = new GUIStyle(GUI.skin.label)
             {
                 normal    = { textColor = Color.red },
                 wordWrap  = false,
                 alignment = TextAnchor.MiddleLeft,
                 fontSize  = 20
             };
             GUIContent content  = new GUIContent("Character is not in T pose");
             Rect       position = GUILayoutUtility.GetRect(content, style);
             position.x = 30f;
             position.y = 30f;
             Handles.BeginGUI();
             GUI.Label(position, content, style);
             Handles.EndGUI();
         }
     }
 }
Esempio n. 27
0
 protected void Init()
 {
     if (base.gameObject == null)
     {
         return;
     }
     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();
 }
Esempio n. 28
0
 public static void DrawSkeleton(Transform reference, Dictionary<Transform, bool> actualBones, AvatarSetupTool.BoneWrapper[] bones)
 {
     if ((reference != null) && (actualBones != null))
     {
         sPoseError = false;
         Bounds bounds = new Bounds();
         Renderer[] componentsInChildren = reference.root.GetComponentsInChildren<Renderer>();
         if (componentsInChildren != null)
         {
             foreach (Renderer renderer in componentsInChildren)
             {
                 bounds.Encapsulate(renderer.bounds.min);
                 bounds.Encapsulate(renderer.bounds.max);
             }
         }
         Quaternion identity = Quaternion.identity;
         if (bones != null)
         {
             identity = AvatarSetupTool.AvatarComputeOrientation(bones);
         }
         DrawSkeletonSubTree(actualBones, bones, identity, reference, bounds);
         Camera current = Camera.current;
         if (sPoseError && (current != null))
         {
             GUIStyle style = new GUIStyle(GUI.skin.label) {
                 normal = { textColor = Color.red },
                 wordWrap = false,
                 alignment = TextAnchor.MiddleLeft,
                 fontSize = 20
             };
             GUIContent content = new GUIContent("Character is not in T pose");
             Rect position = GUILayoutUtility.GetRect(content, style);
             position.x = 30f;
             position.y = 30f;
             Handles.BeginGUI();
             GUI.Label(position, content, style);
             Handles.EndGUI();
         }
     }
 }
Esempio n. 29
0
 protected void Init()
 {
     if ((UnityEngine.Object) this.gameObject == (UnityEngine.Object)null)
     {
         return;
     }
     this.m_IsBiped = AvatarBipedMapper.IsBiped(this.gameObject.transform, (List <string>)null);
     if (this.m_Bones == null)
     {
         this.m_Bones = AvatarSetupTool.GetHumanBones(this.serializedObject, this.modelBones);
     }
     this.ValidateMapping();
     if ((UnityEngine.Object) this.m_CurrentTransformEditor != (UnityEngine.Object)null)
     {
         UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_CurrentTransformEditor);
         this.m_CurrentTransformEditor = (Editor)null;
     }
     this.m_CurrentTransformEditorFoldout = true;
     this.m_HasSkinnedMesh = (UnityEngine.Object) this.gameObject.GetComponentInChildren <SkinnedMeshRenderer>() != (UnityEngine.Object)null;
     this.InitPose();
     SceneView.RepaintAll();
 }
Esempio n. 30
0
        internal void SwitchToEditMode()
        {
            // Lock inspector
            ChangeInspectorLock(true);

            string assetPath = AssetDatabase.GetAssetPath(target);
            AvatarConfigurationStage stage = AvatarConfigurationStage.CreateStage(assetPath, this);

            StageUtility.GoToStage(stage, true);

            m_EditMode = EditMode.Starting;

            // Instantiate character
            m_GameObject = stage.gameObject;
            if (serializedAssetImporter.FindProperty("m_OptimizeGameObjects").boolValue)
            {
                AnimatorUtility.DeoptimizeTransformHierarchy(m_GameObject);
            }

            SerializedProperty humanBoneArray = serializedAssetImporter.FindProperty("m_HumanDescription.m_Human");

            // First get all available modelBones
            Dictionary <Transform, bool> modelBones = AvatarSetupTool.GetModelBones(m_GameObject.transform, true, null);

            AvatarSetupTool.BoneWrapper[] humanBones = AvatarSetupTool.GetHumanBones(humanBoneArray, modelBones);

            m_ModelBones = AvatarSetupTool.GetModelBones(m_GameObject.transform, false, humanBones);

            // Unfold all nodes in hierarchy
            // TODO@MECANIM: Only expand actual bones
            foreach (SceneHierarchyWindow shw in Resources.FindObjectsOfTypeAll(typeof(SceneHierarchyWindow)))
            {
                shw.SetExpandedRecursive(m_GameObject.GetInstanceID(), true);
            }

            CreateEditor();

            m_EditMode = EditMode.Editing;
        }
        void CopyAvatarGUI()
        {
            GUILayout.Label(
                @"If you have already created an Avatar for another model with a rig identical to this one, you can copy its Avatar definition.
With this option, this model will not create any avatar but only import animations.", EditorStyles.helpBox);

            EditorGUILayout.BeginHorizontal();

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

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

                AvatarSetupTool.ClearAll(serializedObject);

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

                m_AvatarCopyIsUpToDate = true;
            }

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

            EditorGUILayout.EndHorizontal();
        }
Esempio n. 32
0
        private bool TransformChanged(Transform tr)
        {
            SerializedProperty skeletonBone = AvatarSetupTool.FindSkeletonBone(this.serializedObject, tr, false, false);

            if (skeletonBone != null)
            {
                SerializedProperty propertyRelative1 = skeletonBone.FindPropertyRelative(AvatarSetupTool.sPosition);
                if (propertyRelative1 != null && propertyRelative1.vector3Value != tr.localPosition)
                {
                    return(true);
                }
                SerializedProperty propertyRelative2 = skeletonBone.FindPropertyRelative(AvatarSetupTool.sRotation);
                if (propertyRelative2 != null && propertyRelative2.quaternionValue != tr.localRotation)
                {
                    return(true);
                }
                SerializedProperty propertyRelative3 = skeletonBone.FindPropertyRelative(AvatarSetupTool.sScale);
                if (propertyRelative3 != null && propertyRelative3.vector3Value != tr.localScale)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 33
0
 private void OnEnable()
 {
     EditorApplication.update += new EditorApplication.CallbackFunction(this.Update);
     this.m_SwitchToEditMode   = false;
     if (this.m_EditMode == AvatarEditor.EditMode.Editing)
     {
         this.m_ModelBones = AvatarSetupTool.GetModelBones(this.m_GameObject.transform, false, (AvatarSetupTool.BoneWrapper[])null);
         this.editor.Enable(this);
     }
     else
     {
         if (this.m_EditMode != AvatarEditor.EditMode.NotEditing)
         {
             return;
         }
         this.editor = (AvatarSubEditor)null;
         if (!AvatarEditor.s_EditImmediatelyOnNextOpen)
         {
             return;
         }
         this.m_CameFromImportSettings            = true;
         AvatarEditor.s_EditImmediatelyOnNextOpen = false;
     }
 }
Esempio n. 34
0
        private bool TransformChanged(Transform tr)
        {
            SerializedProperty serializedProperty = AvatarSetupTool.FindSkeletonBone(base.serializedObject, tr, false, false);

            if (serializedProperty != null)
            {
                SerializedProperty serializedProperty2 = serializedProperty.FindPropertyRelative(AvatarSetupTool.sPosition);
                if (serializedProperty2 != null && serializedProperty2.vector3Value != tr.localPosition)
                {
                    return(true);
                }
                SerializedProperty serializedProperty3 = serializedProperty.FindPropertyRelative(AvatarSetupTool.sRotation);
                if (serializedProperty3 != null && serializedProperty3.quaternionValue != tr.localRotation)
                {
                    return(true);
                }
                SerializedProperty serializedProperty4 = serializedProperty.FindPropertyRelative(AvatarSetupTool.sScale);
                if (serializedProperty4 != null && serializedProperty4.vector3Value != tr.localScale)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 35
0
 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);
     }
 }
Esempio n. 36
0
 public static int ShowBoneMapping(int shownBodyView, BodyPartFeedback bodyPartCallback, AvatarSetupTool.BoneWrapper[] bones, SerializedObject serializedObject, AvatarMappingEditor editor)
 {
     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
     GUILayout.FlexibleSpace();
     if (styles.Silhouettes[shownBodyView].image != null)
     {
         GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MaxWidth((float) styles.Silhouettes[shownBodyView].image.width) };
         Rect rect = GUILayoutUtility.GetRect(styles.Silhouettes[shownBodyView], GUIStyle.none, options);
         DrawBodyParts(rect, shownBodyView, bodyPartCallback);
         for (int j = 0; j < bones.Length; j++)
         {
             DrawBone(shownBodyView, j, rect, bones[j], serializedObject, editor);
         }
     }
     else
     {
         GUILayout.Label("texture missing,\nfix me!", new GUILayoutOption[0]);
     }
     GUILayout.FlexibleSpace();
     GUILayout.EndHorizontal();
     Rect lastRect = GUILayoutUtility.GetLastRect();
     string[] strArray = new string[] { "Body", "Head", "Left Hand", "Right Hand" };
     lastRect.x += 5f;
     lastRect.width = 70f;
     lastRect.yMin = lastRect.yMax - 69f;
     lastRect.height = 16f;
     for (int i = 0; i < strArray.Length; i++)
     {
         if (GUI.Toggle(lastRect, shownBodyView == i, strArray[i], EditorStyles.miniButton))
         {
             shownBodyView = i;
         }
         lastRect.y += 16f;
     }
     return shownBodyView;
 }
        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 MakePoseValid()
 {
     AvatarSetupTool.MakePoseValid(m_Bones);
     AvatarSetupTool.TransferPoseToDescription(m_Skeleton, root);
     m_Inspector.Repaint();
 }
Esempio n. 39
0
 private static bool DrawSkeletonSubTree(Dictionary<Transform, bool> actualBones, AvatarSetupTool.BoneWrapper[] bones, Quaternion orientation, Transform tr, Bounds bounds)
 {
     if (!actualBones.ContainsKey(tr))
     {
         return false;
     }
     int num = 0;
     IEnumerator enumerator = tr.GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             Transform current = (Transform) enumerator.Current;
             if (DrawSkeletonSubTree(actualBones, bones, orientation, current, bounds))
             {
                 num++;
             }
         }
     }
     finally
     {
         IDisposable disposable = enumerator as IDisposable;
         if (disposable == null)
         {
         }
         disposable.Dispose();
     }
     if (!actualBones[tr] && (num <= 1))
     {
         return false;
     }
     int boneIndex = -1;
     if (bones != null)
     {
         for (int i = 0; i < bones.Length; i++)
         {
             if (bones[i].bone == tr)
             {
                 boneIndex = i;
                 break;
             }
         }
     }
     bool flag = AvatarSetupTool.GetBoneAlignmentError(bones, orientation, boneIndex) > 0f;
     sPoseError |= flag;
     if (flag)
     {
         DrawPoseError(tr, bounds);
         Handles.color = kErrorColor;
     }
     else if (boneIndex != -1)
     {
         Handles.color = kHumanColor;
     }
     else if (!actualBones[tr])
     {
         Handles.color = kDummyColor;
     }
     else
     {
         Handles.color = kSkeletonColor;
     }
     Handles.DoBoneHandle(tr, actualBones);
     if (Selection.activeObject == tr)
     {
         Handles.color = kSelectedColor;
         Handles.DoBoneHandle(tr, actualBones);
     }
     return true;
 }
		private static bool DrawSkeletonSubTree(Dictionary<Transform, bool> actualBones, AvatarSetupTool.BoneWrapper[] bones, Quaternion orientation, Transform tr, Bounds bounds)
		{
			if (!actualBones.ContainsKey(tr))
			{
				return false;
			}
			int num = 0;
			foreach (Transform tr2 in tr)
			{
				if (AvatarSkeletonDrawer.DrawSkeletonSubTree(actualBones, bones, orientation, tr2, bounds))
				{
					num++;
				}
			}
			if (!actualBones[tr] && num <= 1)
			{
				return false;
			}
			int num2 = -1;
			if (bones != null)
			{
				for (int i = 0; i < bones.Length; i++)
				{
					if (bones[i].bone == tr)
					{
						num2 = i;
						break;
					}
				}
			}
			bool flag = AvatarSetupTool.GetBoneAlignmentError(bones, orientation, num2) > 0f;
			AvatarSkeletonDrawer.sPoseError |= flag;
			if (flag)
			{
				AvatarSkeletonDrawer.DrawPoseError(tr, bounds);
				Handles.color = AvatarSkeletonDrawer.kErrorColor;
			}
			else
			{
				if (num2 != -1)
				{
					Handles.color = AvatarSkeletonDrawer.kHumanColor;
				}
				else
				{
					if (!actualBones[tr])
					{
						Handles.color = AvatarSkeletonDrawer.kDummyColor;
					}
					else
					{
						Handles.color = AvatarSkeletonDrawer.kSkeletonColor;
					}
				}
			}
			Handles.DoBoneHandle(tr, actualBones);
			if (Selection.activeObject == tr)
			{
				Handles.color = AvatarSkeletonDrawer.kSelectedColor;
				Handles.DoBoneHandle(tr, actualBones);
			}
			return true;
		}
 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)
     return;
   Vector2 bonePosition = AvatarControl.s_BonePositions[shownBodyView, i];
   bonePosition.y *= -1f;
   bonePosition.Scale(new Vector2(rect.width * 0.5f, rect.height * 0.5f));
   Vector2 vector2 = rect.center + bonePosition;
   int num = 19;
   Rect rect1 = new Rect(vector2.x - (float) num * 0.5f, vector2.y - (float) num * 0.5f, (float) num, (float) num);
   bone.BoneDotGUI(rect1, i, true, true, serializedObject, editor);
 }