private void OnGUI()
        {
            if (_editorEffector.GetCurrentlyEditing() == CurrentlyEditing.Nothing)
            {
                return;
            }

            if (_editorEffector.IsFirstTimeSetup() && _editorEffector.IsPreviewSetupValid())
            {
                _editorEffector.ClearFirstTimeSetup();
            }

            GUILayout.BeginArea(new Rect(position.width - 320, CgeLayoutCommon.SingleLineHeight * 2 + 5, 200, CgeLayoutCommon.SingleLineHeight + 2));
            if (GUILayout.Button(new GUIContent("❈ ExpressionsEditor"), GUILayout.Width(170), GUILayout.Height(CgeLayoutCommon.SingleLineHeight + 2)))
            {
                EeAnimationEditorWindow.Obtain().Show();
            }
            GUILayout.EndArea();

            GUILayout.BeginArea(new Rect(position.width - 130, CgeLayoutCommon.SingleLineHeight * 2 + 5, 100, CgeLayoutCommon.SingleLineHeight + 2));
            if (GUILayout.Button(new GUIContent(" " + CgeLocale.CGEE_Tutorials, _helpIcon16), GUILayout.Width(100), GUILayout.Height(CgeLayoutCommon.SingleLineHeight + 2)))
            {
                Application.OpenURL(CgeLocale.DocumentationUrl());
            }
            GUILayout.EndArea();

            switch (_editorEffector.GetCurrentlyEditing())
            {
            case CurrentlyEditing.Nothing:
                break;

            case CurrentlyEditing.Activity:
                EditingAnActivity();
                break;

            case CurrentlyEditing.Puppet:
                EditingAPuppet();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #2
0
        private void OpenBlendTreeAt(string propertyPath)
        {
            var blendTree = (BlendTree)_editorEffector.SpProperty(propertyPath).objectReferenceValue;

            _blendTreeEffector.BlendTreeBeingEdited = blendTree;
            _editorEffector.SwitchAdditionalEditorTo(AdditionalEditorsMode.ViewBlendTrees);
            if (_editorEffector.GetCurrentlyEditing() == CurrentlyEditing.Activity)
            {
                _editorEffector.SwitchTo(ActivityEditorMode.AdditionalEditors);
            }
        }
Exemple #3
0
 public void DrawPreviewOrRefreshButton(Motion element, bool grayscale = false)
 {
     if (element is AnimationClip clip)
     {
         if (_memoryQuery.HasClip(clip))
         {
             GUILayout.Box(Texture(grayscale, clip), GUIStyle.none, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true));
             InvisibleRankPreservingBox();
             InvisibleRankPreservingBox();
             InvisibleRankPreservingBox();
             InvisibleRankPreservingButton();
         }
         else
         {
             InvisibleRankPreservingBox();
             InvisibleRankPreservingBox();
             InvisibleRankPreservingBox();
             InvisibleRankPreservingBox();
             EditorGUI.BeginDisabledGroup(AnimationMode.InAnimationMode());
             var isPreviewSetupValid = _editorEffector.IsPreviewSetupValid();
             if (GUILayout.Button(isPreviewSetupValid ? CgeLocale.CGEE_GeneratePreview : CgeLocale.CGEE_SetupPreview, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
             {
                 if (isPreviewSetupValid)
                 {
                     _activityPreviewQueryAggregator.GenerateMissingPreviewsPrioritizing(_repaintCallback, clip);
                 }
                 else
                 {
                     if (_editorEffector.GetCurrentlyEditing() == CurrentlyEditing.Activity)
                     {
                         _editorEffector.SwitchTo(ActivityEditorMode.OtherOptions);
                     }
                     else
                     {
                         _editorEffector.SwitchTo(PuppetEditorMode.OtherOptions);
                     }
                 }
             }
             EditorGUI.EndDisabledGroup();
         }
     }
     else if (element is BlendTree tree)
     {
         var animations = ManifestFromPuppet.AllAnimationsOf(tree);
         if (animations.Count == 0)
         {
             InvisibleRankPreservingBox();
             InvisibleRankPreservingBox();
             InvisibleRankPreservingBox();
             InvisibleRankPreservingBox();
             InvisibleRankPreservingButton();
         }
         else if (_memoryQuery.HasClip(animations[0]))
         {
             GUILayout.BeginHorizontal();
             TexturedBox(grayscale, animations, 0);
             TexturedBox(grayscale, animations, 1);
             GUILayout.EndHorizontal();
             GUILayout.BeginHorizontal();
             TexturedBox(grayscale, animations, 2);
             TexturedBox(grayscale, animations, 3);
             GUILayout.EndHorizontal();
             InvisibleRankPreservingButton();
         }
         else
         {
             InvisibleRankPreservingBox();
             InvisibleRankPreservingBox();
             InvisibleRankPreservingBox();
             InvisibleRankPreservingBox();
             EditorGUI.BeginDisabledGroup(AnimationMode.InAnimationMode());
             var isPreviewSetupValid = _editorEffector.IsPreviewSetupValid();
             if (GUILayout.Button(isPreviewSetupValid ? CgeLocale.CGEE_GeneratePreview : CgeLocale.CGEE_SetupPreview, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
             {
                 if (isPreviewSetupValid)
                 {
                     _activityPreviewQueryAggregator.GenerateMissingPreviewsPrioritizing(_repaintCallback, animations[0]);
                 }
                 else
                 {
                     _editorEffector.SwitchTo(ActivityEditorMode.OtherOptions);
                 }
             }
             EditorGUI.EndDisabledGroup();
         }
     }
     else
     {
         InvisibleRankPreservingBox();
         InvisibleRankPreservingBox();
         InvisibleRankPreservingBox();
         InvisibleRankPreservingBox();
         InvisibleRankPreservingButton();
     }
 }
        private void LayoutBlendTreeViewer(Rect position, bool showAsset)
        {
            BlendTree treeBeingEdited;

            if (_editorEffector.GetCurrentlyEditing() == CurrentlyEditing.Puppet)
            {
                var value = _editorEffector.SpProperty("mainTree").objectReferenceValue;
                if (value != null && value is AnimationClip)
                {
                    _editorEffector.SpProperty("mainTree").objectReferenceValue = null;
                    treeBeingEdited = null;
                }
                else
                {
                    treeBeingEdited = (BlendTree)value;
                }
            }
            else
            {
                treeBeingEdited = _blendTreeEffector.BlendTreeBeingEdited;
            }

            if (showAsset)
            {
                // EditorGUI.BeginDisabledGroup(true);
                _blendTreeEffector.BlendTreeBeingEdited = (BlendTree)EditorGUILayout.ObjectField(treeBeingEdited, typeof(BlendTree), false);
                // EditorGUI.EndDisabledGroup();
            }

            if (treeBeingEdited == null)
            {
                return;
            }

            var is2D = treeBeingEdited.blendType == BlendTreeType.Simple1D || treeBeingEdited.blendType == BlendTreeType.Direct;
            var xMin = treeBeingEdited.children.Select(motion => is2D ? motion.threshold : motion.position.x).Min();
            var yMin = treeBeingEdited.children.Select(motion => is2D ? 0 : motion.position.y).Min();
            var xMax = treeBeingEdited.children.Select(motion => is2D ? motion.threshold : motion.position.x).Max();
            var yMax = treeBeingEdited.children.Select(motion => is2D ? 1 : motion.position.y).Max();
            var min  = new Vector2(xMin, yMin);
            var max  = new Vector2(xMax, yMax);

            var headerPadding   = 5 * CgeLayoutCommon.SingleLineHeight;
            var fixture         = 5 * CgeLayoutCommon.SingleLineHeight;
            var sliderThickness = CgeLayoutCommon.SingleLineHeight * 2;

            _blendTreeEffector.DescaleLevel = GUI.HorizontalSlider(
                new Rect(100, fixture - sliderThickness, position.width - 200, sliderThickness),
                _blendTreeEffector.DescaleLevel, 0.01f, 1f
                );
            _blendTreeEffector.HorizontalFocalPoint = GUI.HorizontalSlider(
                new Rect(sliderThickness, fixture, position.width - sliderThickness, sliderThickness),
                _blendTreeEffector.HorizontalFocalPoint, 0, 1f
                );
            _blendTreeEffector.VerticalFocalPoint = GUI.VerticalSlider(
                new Rect(0, fixture + sliderThickness, sliderThickness, position.height - fixture - headerPadding - sliderThickness),
                _blendTreeEffector.VerticalFocalPoint, 0, 1f
                );

            GUILayout.BeginArea(new Rect(
                                    sliderThickness,
                                    fixture + sliderThickness,
                                    position.width - sliderThickness,
                                    position.height - fixture - sliderThickness - CgeLayoutCommon.SingleLineHeight * 4));
            foreach (var child in treeBeingEdited.children)
            {
                var posVec = is2D
                    ? new Vector2(child.threshold, 0.5f)
                    : child.position;
                var centered = CalculateCentered(posVec, min, max, position, headerPadding, fixture, sliderThickness);
                GUILayout.BeginArea(centered);
                GUILayout.BeginArea(new Rect(0, 0, CgeLayoutCommon.PictureWidth, CgeLayoutCommon.PictureHeight));
                _common.DrawPreviewOrRefreshButton(child.motion);
                GUILayout.EndArea();
                GUILayout.EndArea();
            }
            GUILayout.EndArea();
        }
        public void Layout(Action repaintCallback, Rect position)
        {
            _common.BeginLayoutUsingWidth(position, CgeLayoutCommon.GuiSquareHeight * 2, 0, CgeLayoutCommon.GuiSquareWidth * 4);
            if (_editorEffector.IsFirstTimeSetup() || !_editorEffector.IsPreviewSetupValid())
            {
                if (_editorEffector.HasPreviewSetupWhichIsInvalid())
                {
                    EditorGUILayout.LabelField(CgeLocale.CGEE_IncompletePreviewSetup);
                }

                EditorGUILayout.PropertyField(_editorEffector.SpPreviewSetup(), new GUIContent(CgeLocale.CGEE_Preview_setup));
                GUILayout.Space(15);
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button(CgeLocale.CGEE_Automatically_setup_preview, GUILayout.Height(50), GUILayout.Width(300)))
                {
                    DoAutoSetupPreview();
                    if (_editorEffector.GetSetupResult() != EePreviewSetupWizard.SetupResult.NoAvatarFound)
                    {
                        _editorEffector.SwitchTo(ActivityEditorMode.SetFaceExpressions);
                    }
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }
            else
            {
                EditorGUILayout.PropertyField(_editorEffector.SpTransitionDuration(), new GUIContent(CgeLocale.CGEE_Transition_duration));
                EditorGUILayout.PropertyField(_editorEffector.SpPreviewSetup(), new GUIContent(CgeLocale.CGEE_Preview_setup));
                if (_editorEffector.GetSetupResult() != null)
                {
                    var setupResult = (EePreviewSetupWizard.SetupResult)_editorEffector.GetSetupResult();
                    switch (setupResult)
                    {
                    case EePreviewSetupWizard.SetupResult.ReusedExistsAndValidInScene:
                        EditorGUILayout.HelpBox(CgeLocale.CGEE_AutoSetupReused, MessageType.Info);
                        break;

                    case EePreviewSetupWizard.SetupResult.NoAvatarFound:
                        EditorGUILayout.HelpBox(CgeLocale.CGEE_AutoSetupNoActiveAvatarDescriptor, MessageType.Error);
                        break;

                    case EePreviewSetupWizard.SetupResult.CreatedNew:
                        EditorGUILayout.HelpBox(CgeLocale.CGEE_AutoSetupCreated, MessageType.Info);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                EditorGUI.BeginDisabledGroup(AnimationMode.InAnimationMode());
                if (GUILayout.Button(CgeLocale.CGEE_Generate_missing_previews))
                {
                    _activityPreviewQueryAggregator.GenerateMissingPreviews(repaintCallback);
                }

                if (GUILayout.Button(CgeLocale.CGEE_Regenerate_all_previews))
                {
                    _activityPreviewQueryAggregator.GenerateAll(repaintCallback);
                }
                if (_editorEffector.GetCurrentlyEditing() == CurrentlyEditing.Activity)
                {
                    EditorGUILayout.PropertyField(_editorEffector.SpEditorArbitraryAnimations(), new GUIContent(CgeLocale.CGEE_List_of_arbitrary_animations), true);
                }
                EditorGUI.EndDisabledGroup();

                EditorGUI.BeginDisabledGroup(!AnimationMode.InAnimationMode());
                EditorGUI.EndDisabledGroup();

                if (_editorEffector.GetCurrentlyEditing() == CurrentlyEditing.Activity)
                {
                    if (_editorEffector.GetActivity().editorArbitraryAnimations != null)
                    {
                        GUILayout.BeginArea(new Rect(0, CgeLayoutCommon.SingleLineHeight * 10, position.width, CgeLayoutCommon.GuiSquareHeight * 8));
                        var allClips = new HashSet <AnimationClip>(_editorEffector.GetActivity().editorArbitraryAnimations.Where(clip => clip != null)).ToList();
                        var mod      = (int)Math.Max(1, position.width / CgeLayoutCommon.GuiSquareWidth);
                        for (var element = 0; element < allClips.Count; element++)
                        {
                            GUILayout.BeginArea(CgeLayoutCommon.RectAt(element % mod, element / mod));
                            DrawArbitrary(allClips[element]);
                            GUILayout.EndArea();
                        }

                        GUILayout.EndArea();
                        GUILayout.Space((allClips.Count / mod) * CgeLayoutCommon.GuiSquareHeight + CgeLayoutCommon.GuiSquareHeight + CgeLayoutCommon.SingleLineHeight * 2);
                    }
                }
            }
            CgeLayoutCommon.EndLayout();
        }