/// <summary>
 /// Sets the UMABoneBoseEditor that should be returned when 'livePopupEditor' is requested. Usually this should only be used by the UMABonePose PropertyDrawer
 /// </summary>
 /// <param name="liveUBPEditor"></param>
 public static void SetLivePopupEditor(UMABonePoseEditor liveUBPEditor)
 {
     if (Application.isPlaying)
     {
         _livePopupEditor = liveUBPEditor;
     }
 }
 public void OnShowPopupInspector(EditorWindow newInspectorPopup)
 {
     if (inspectorPopup != null && inspectorPopup != newInspectorPopup)
     {
         inspectorPopup.Close();
         UMABonePoseEditor.SetLivePopupEditor(null);
     }
     inspectorPopup = newInspectorPopup;
 }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            GUIHelper.InspectableObjectField(position, property, label, OnShowPopupInspector);

            //We need to check this a few times because when the inspector window is created by InspectorUtility.InspectTarget
            //when the user clicks the inspect button next to the field that is drawn above,
            //GetInspectorsEditors doesnt return the actual editors correctly until the popup window repaints
            if (inspectorPopup != null && UMABonePoseEditor.livePopupEditor == null)
            {
                var editors = InspectorUtlity.GetInspectorsEditors(inspectorPopup);
                for (int i = 0; i < editors.Length; i++)
                {
                    if (editors[i].GetType() == typeof(UMABonePoseEditor))
                    {
                        if (editors[i].target == property.objectReferenceValue)
                        {
                            UMABonePoseEditor.SetLivePopupEditor(editors[i] as UMABonePoseEditor);
                        }
                    }
                }
            }
        }
        void OnUpdate()
        {
            if (haveValidContext)
            {
                if (activeBoneIndex != editBoneIndex)
                {
                    activeBoneIndex = BAD_INDEX;
                    mirrorBoneIndex = BAD_INDEX;
                    if (editBoneIndex != BAD_INDEX)
                    {
                        int boneHash = targetPose.poses[editBoneIndex].hash;
                        context.activeTransform = context.activeUMA.skeleton.GetBoneTransform(boneHash);
                        if (context.activeTransform != null)
                        {
                            activeBoneIndex = editBoneIndex;
                        }

                        if (context.mirrorTransform != null)
                        {
                            int mirrorHash = UMASkeleton.StringToHash(context.mirrorTransform.name);
                            for (int i = 0; i < targetPose.poses.Length; i++)
                            {
                                if (targetPose.poses[i].hash == mirrorHash)
                                {
                                    mirrorBoneIndex = i;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        context.activeTransform = null;
                    }
                }
                if (!dynamicDNAConverterMode)
                {
                    context.activeUMA.skeleton.ResetAll();
                    if (context.startingPose != null)
                    {
                        context.startingPose.ApplyPose(context.activeUMA.skeleton, context.startingPoseWeight);
                    }

                    if (haveEditTarget)
                    {
                        targetPose.ApplyPose(context.activeUMA.skeleton, 1f);
                    }
                    else
                    {
                        targetPose.ApplyPose(context.activeUMA.skeleton, previewWeight);
                    }
                }
                else
                {
                    //TODO
                    //how do we deal with poses that are not applied? The user will see the character in its current pose and bone positions for that
                    //which makes no sense
                    //also because this will be hooked up to dna, the dna itself might be causing other changes to happen ('overallScale' for example)
                    //So I think the editor for bonePoseConverters, needs to jump in here and ask the user if they want to apply the dna that makes the pose active?
                    //OR
                    //maybe we create a skeleton how it would be IF the pose was applied to it and the user edits those transforms?
                    //If the pose is applied they will see their character change, if its not it might be clearer that is the case
                }
            }
            if (!Application.isPlaying)
            {
                _livePopupEditor = null;
            }
        }