public void Layout(Action repaintCallback)
        {
            if (_combinerState.Combiner == null)
            {
                return;
            }

            var decider = _combinerState.Combiner.GetDecider();

            GUILayout.BeginHorizontal(GUILayout.Width(CgeActivityEditorCombiner.CombinerPreviewWidth * 3));

            GUILayout.BeginVertical(GUILayout.MaxWidth(CgeActivityEditorCombiner.CombinerPreviewWidth));
            GUILayout.Box(_combinerState.Combiner.LeftTexture(), GUILayout.Width(CgeActivityEditorCombiner.CombinerPreviewWidth), GUILayout.Height(CgeActivityEditorCombiner.CombinerPreviewHeight));
            LayoutIntersectionDecider(decider.Intersection, Side.Left);
            LayoutSideDecider(decider.Left, Side.Left);
            GUILayout.Space(CgeLayoutCommon.SingleLineHeight * 2);
            GUILayout.EndVertical();

            GUILayout.BeginVertical(GUILayout.MaxWidth(CgeActivityEditorCombiner.CombinerPreviewCenterWidth), GUILayout.Width(CgeActivityEditorCombiner.CombinerPreviewCenterWidth));
            GUILayout.Space(20);
            GUILayout.Box(_combinerState.Combiner.CombinedTexture(), GUILayout.Width(CgeActivityEditorCombiner.CombinerPreviewCenterWidth), GUILayout.Height(CgeActivityEditorCombiner.CombinerPreviewCenterHeight));
            _combinerState.CombinerCandidateFileName = GUILayout.TextField(_combinerState.CombinerCandidateFileName, GUILayout.MaxWidth(CgeActivityEditorCombiner.CombinerPreviewCenterWidth));
            if (GUILayout.Button("Save and assign to " + _driver.ShortTranslation((_combinerState.CombinerIsAPermutation ? "p_" : "") + _combinerState.CombinerTarget), GUILayout.MaxWidth(CgeActivityEditorCombiner.CombinerPreviewCenterWidth)))
            {
                Save(repaintCallback);
            }
            GUILayout.Space(CgeLayoutCommon.SingleLineHeight * 2);
            _combinerState.ComplexCombiner = EditorGUILayout.Toggle(CgeLocale.CGEE_CombinerShowHidden, _combinerState.ComplexCombiner);
            _combinerState.ShowFullNames   = EditorGUILayout.Toggle(CgeLocale.CGEE_CombinerShowFullPaths, _combinerState.ShowFullNames);
            GUILayout.Space(CgeLayoutCommon.SingleLineHeight * 2);
            GUILayout.EndVertical();

            GUILayout.BeginVertical(GUILayout.MaxWidth(CgeActivityEditorCombiner.CombinerPreviewWidth));
            GUILayout.Box(_combinerState.Combiner.RightTexture(), GUILayout.Width(CgeActivityEditorCombiner.CombinerPreviewWidth), GUILayout.Height(CgeActivityEditorCombiner.CombinerPreviewHeight));
            LayoutIntersectionDecider(decider.Intersection, Side.Right);
            LayoutSideDecider(decider.Right, Side.Right);
            GUILayout.Space(CgeLayoutCommon.SingleLineHeight * 2);
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();
        }
        private void LayoutLimitedLipsyncEditor(Action repaintCallback)
        {
            Rect RectAt(int xGrid, int yGrid)
            {
                return(new Rect(xGrid * CgeLayoutCommon.GuiSquareWidth * 2, yGrid * CgeLayoutCommon.GuiSquareHeight * 2, CgeLayoutCommon.GuiSquareWidth * 2, CgeLayoutCommon.GuiSquareHeight * 2));
            }

            if (_lipsyncState.LimitedLipsync == null)
            {
                EditorGUILayout.LabelField("Select a ComboGestureLimitedLipsync component in the scene or choose one:");
                var newLipsync = (ComboGestureLimitedLipsync)EditorGUILayout.ObjectField(null, typeof(ComboGestureLimitedLipsync), true);
                if (newLipsync != null)
                {
                    SetLipsync(newLipsync, repaintCallback);
                }
                return;
            }

            void DrawLipsync(int visemeNumber, bool previewable)
            {
                GUILayout.Label(_driver.ShortTranslation("viseme" + visemeNumber), _common.MiddleAligned);

                GUILayout.BeginArea(new Rect(CgeLayoutCommon.GuiSquareWidth - CgeLayoutCommon.PictureWidth, CgeLayoutCommon.SingleLineHeight, CgeLayoutCommon.PictureWidth * 2, CgeLayoutCommon.PictureHeight * 2 + CgeLayoutCommon.SingleLineHeight * 4));
                GUILayout.Box(_lipsyncState.Lipsync.TextureForViseme(visemeNumber), GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true));

                EditorGUI.BeginDisabledGroup(!previewable || AnimationMode.InAnimationMode());
                if (GUILayout.Button("Regenerate preview"))
                {
                    RegenerateLipsyncPreview(visemeNumber);
                }
                EditorGUI.EndDisabledGroup();

                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Amp Mul", GUILayout.Width(80));
                EditorGUILayout.Slider(_lipsyncState.SerializedLimitedLipsync.FindProperty("amplitude" + visemeNumber), 0f, 1f, GUIContent.none, GUILayout.Width(150));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Duration Mul", GUILayout.Width(80));
                EditorGUILayout.Slider(_lipsyncState.SerializedLimitedLipsync.FindProperty("transition" + visemeNumber), 0f, 1f, GUIContent.none, GUILayout.Width(150));
                GUILayout.EndHorizontal();
                GUILayout.EndArea();

                GUILayout.Space(CgeLayoutCommon.PictureHeight);
            }

            GUILayout.BeginArea(RectAt(0, 0));
            EditorGUILayout.LabelField("Limited Lipsync Component", EditorStyles.boldLabel);
            var otherNewLipsync = (ComboGestureLimitedLipsync)EditorGUILayout.ObjectField(_lipsyncState.LimitedLipsync, typeof(ComboGestureLimitedLipsync), true);

            if (!IsLimitedLipsyncSameAs(otherNewLipsync))
            {
                SetLipsync(otherNewLipsync, repaintCallback);
            }

            EditorGUILayout.PropertyField(_lipsyncState.SerializedLimitedLipsync.FindProperty("limitation"), new GUIContent("Category"));
            EditorGUILayout.Slider(_lipsyncState.SerializedLimitedLipsync.FindProperty("amplitudeScale"), 0f, 0.25f, "Viseme Amplitude");
            EditorGUILayout.Slider(_lipsyncState.SerializedLimitedLipsync.FindProperty("amplitudeScale"), 0f, 1f, "(scaled to 1)");
            EditorGUILayout.PropertyField(_lipsyncState.SerializedLimitedLipsync.FindProperty("transitionDuration"), new GUIContent("Transition Duration (s)"));

            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Preview", EditorStyles.boldLabel);
            var previewables      = ListAllPreviewableNames();
            var previewIsPossible = previewables.Any();

            if (previewIsPossible)
            {
                if (_lipsyncState.LimitedLipsyncPreviewIndex >= previewables.Length)
                {
                    _lipsyncState.LimitedLipsyncPreviewIndex = 0;
                }
                _lipsyncState.LimitedLipsyncPreviewIndex = EditorGUILayout.Popup(
                    _lipsyncState.LimitedLipsyncPreviewIndex,
                    previewables
                    );
                var avatarHasVisemeBlendShapes = _editorEffector.IsPreviewSetupValid() && _editorEffector.PreviewSetup().TempCxSmr;
                if (!avatarHasVisemeBlendShapes)
                {
                    EditorGUILayout.HelpBox("The avatar has no lipsync face mesh.", MessageType.Error);
                }
                EditorGUI.BeginDisabledGroup(AnimationMode.InAnimationMode());
                if (GUILayout.Button("Regenerate all previews"))
                {
                    RegenerateLipsyncPreviews();
                }
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                if (GUILayout.Button("Select an animation..."))
                {
                    // _editorEffector.SwitchTo(ActivityEditorMode.MakeLipsyncMovementsSubtle);
                    _lipsyncState.EditorLipsyncTool = 0;
                }
            }

            GUILayout.EndArea();

            for (var viseme = 0; viseme < 15; viseme++)
            {
                var gridIndex = viseme + 1;
                GUILayout.BeginArea(RectAt(gridIndex % 4, gridIndex / 4));
                DrawLipsync(viseme, previewIsPossible);
                GUILayout.EndArea();
            }
        }
Esempio n. 3
0
        private void DrawInner(string propertyPath, string oppositePath = null, bool partial = false)
        {
            var usePermutations  = oppositePath != null;
            var property         = _editorEffector.SpProperty(propertyPath);
            var oppositeProperty = usePermutations ? _editorEffector.SpProperty(oppositePath) : null;
            var isLeftHand       = String.Compare(propertyPath, oppositePath, StringComparison.Ordinal) > 0;

            if (usePermutations)
            {
                if (propertyPath == oppositePath)
                {
                    CgeLayoutCommon.DrawColoredBackground(CgeLayoutCommon.NeutralSideBg);
                }
                else if (property.objectReferenceValue == null && oppositeProperty.objectReferenceValue == null ||
                         isLeftHand && property.objectReferenceValue == null && oppositeProperty.objectReferenceValue != null ||
                         !isLeftHand && property.objectReferenceValue != null && oppositeProperty.objectReferenceValue == null)
                {
                    if (isLeftHand && partial)
                    {
                        return;
                    }

                    CgeLayoutCommon.DrawColoredBackground(isLeftHand ? CgeLayoutCommon.LeftSymmetricalBg : CgeLayoutCommon.RightSymmetricalBg);
                }
                else if (oppositeProperty.objectReferenceValue == property.objectReferenceValue || isLeftHand && oppositeProperty.objectReferenceValue == null || !isLeftHand && property.objectReferenceValue == null)
                {
                    CgeLayoutCommon.DrawColoredBackground(CgeLayoutCommon.InconsistentBg);
                }
                else
                {
                    CgeLayoutCommon.DrawColoredBackground(isLeftHand ? CgeLayoutCommon.LeftSideBg : CgeLayoutCommon.RightSideBg);
                }
            }

            var translatableProperty = usePermutations
                ? (partial && !isLeftHand && oppositeProperty.objectReferenceValue == null ? propertyPath : ("p_" + propertyPath))
                : propertyPath;
            var isSymmetrical = _driver.IsSymmetrical(translatableProperty);

            if (!usePermutations)
            {
                CgeLayoutCommon.DrawColoredBackground(CgeLayoutCommon.NeutralSideBg);
            }

            GUILayout.Label(_driver.ShortTranslation(translatableProperty), isSymmetrical ? _common.MiddleAlignedBold : _common.MiddleAligned);

            var element = property.objectReferenceValue != null ? (Motion)property.objectReferenceValue : null;

            if (element != null)
            {
                GUILayout.BeginArea(new Rect((CgeLayoutCommon.GuiSquareWidth - CgeLayoutCommon.PictureWidth) / 2, CgeLayoutCommon.SingleLineHeight, CgeLayoutCommon.PictureWidth, CgeLayoutCommon.PictureHeight));
                _common.DrawPreviewOrRefreshButton(element);
                GUILayout.EndArea();
            }
            else if (usePermutations)
            {
                if (oppositeProperty.objectReferenceValue != null && propertyPath != oppositePath && isLeftHand)
                {
                    DrawInnerReversal(oppositePath);
                }
            }
            else
            {
                // ReSharper disable once PossibleLossOfFraction
                GUILayout.BeginArea(new Rect((CgeLayoutCommon.GuiSquareWidth - CgeLayoutCommon.PictureWidth) / 2, CgeLayoutCommon.SingleLineHeight, CgeLayoutCommon.PictureWidth, CgeLayoutCommon.PictureHeight));
                GUILayout.EndArea();
            }


            if (_driver.IsAPropertyThatCanBeCombined(propertyPath, usePermutations) && !(element is BlendTree))
            {
                var rect = element is AnimationClip
                    ? new Rect(-3 + CgeLayoutCommon.GuiSquareWidth - 2 * CgeLayoutCommon.SingleLineHeight, CgeLayoutCommon.PictureHeight - CgeLayoutCommon.SingleLineHeight * 0.5f, CgeLayoutCommon.SingleLineHeight * 2, CgeLayoutCommon.SingleLineHeight * 1.5f)
                    : new Rect(-3 + CgeLayoutCommon.GuiSquareWidth - 100, CgeLayoutCommon.PictureHeight - CgeLayoutCommon.SingleLineHeight * 0.5f, 100, CgeLayoutCommon.SingleLineHeight * 1.5f);

                var areSourcesCompatible = _driver.AreCombinationSourcesDefinedAndCompatible(propertyPath, usePermutations);
                EditorGUI.BeginDisabledGroup(!areSourcesCompatible);
                GUILayout.BeginArea(rect);
                if (ColoredBackground(usePermutations, isLeftHand ? CgeLayoutCommon.LeftSideBg : CgeLayoutCommon.RightSideBg, () => GUILayout.Button((element != null ? "+" : "+ " + CgeLocale.CGEE_Combine))))
                {
                    var merge = _driver.ProvideCombinationPropertySources(propertyPath, usePermutations);
                    OpenMergeWindowFor(merge.Left, merge.Right, propertyPath, usePermutations);
                }
                GUILayout.EndArea();
                EditorGUI.EndDisabledGroup();
            }
            else if (element is BlendTree)
            {
                var rect = new Rect(-3 + CgeLayoutCommon.GuiSquareWidth - 20, CgeLayoutCommon.PictureHeight - CgeLayoutCommon.SingleLineHeight * 0.5f, 20, CgeLayoutCommon.SingleLineHeight * 1.5f);

                EditorGUI.BeginDisabledGroup(false);
                GUILayout.BeginArea(rect);
                if (GUILayout.Button("?"))
                {
                    OpenBlendTreeAt(propertyPath);
                }
                GUILayout.EndArea();
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                BeginInvisibleRankPreservingArea();
                CgeLayoutCommon.InvisibleRankPreservingButton();
                EndInvisibleRankPreservingArea();
            }

            if (_driver.IsAPropertyThatCanBeCombinedDiagonally(propertyPath, usePermutations) && !(element is BlendTree))
            {
                var rect = !_driver.IsSymmetrical(propertyPath) || element != null
                    ? new Rect(0, CgeLayoutCommon.PictureHeight - CgeLayoutCommon.SingleLineHeight * 0.5f, CgeLayoutCommon.SingleLineHeight * 2, CgeLayoutCommon.SingleLineHeight * 1.5f)
                    : new Rect(0, CgeLayoutCommon.PictureHeight - CgeLayoutCommon.SingleLineHeight * 0.5f, 120, CgeLayoutCommon.SingleLineHeight * 1.5f);

                var areSourcesCompatible = _driver.AreDiagonalCombinationSourcesDefinedAndCompatible(propertyPath, usePermutations);
                EditorGUI.BeginDisabledGroup(!areSourcesCompatible);
                GUILayout.BeginArea(rect);
                if (ColoredBackground(!isSymmetrical, !isLeftHand ? CgeLayoutCommon.LeftSideBg : CgeLayoutCommon.RightSideBg, () => GUILayout.Button(!_driver.IsSymmetrical(propertyPath) || element != null ? "⅃" : "⅃ " + CgeLocale.CGEE_CombineAcross)))
                {
                    var merge = _driver.ProvideDiagonalCombinationPropertySources(propertyPath, usePermutations);
                    OpenMergeWindowFor(merge.Left, merge.Right, propertyPath, usePermutations);
                }
                GUILayout.EndArea();
                EditorGUI.EndDisabledGroup();
            }

            if (element == null && !_driver.IsAPropertyThatCanBeCombined(propertyPath, usePermutations))
            {
                EditorGUI.BeginDisabledGroup(false);
                GUILayout.BeginArea(new Rect(-3 + 10, CgeLayoutCommon.PictureHeight - CgeLayoutCommon.SingleLineHeight * 3f, CgeLayoutCommon.GuiSquareWidth - 20, CgeLayoutCommon.SingleLineHeight * 1.5f));
                if (GUILayout.Button("❈ " + CgeLocale.CGEE_Create))
                {
                    CreateNewAnimation(propertyPath);
                }
                GUILayout.EndArea();
                EditorGUI.EndDisabledGroup();
            }

            if (usePermutations && propertyPath != oppositePath && property.objectReferenceValue == oppositeProperty.objectReferenceValue && property.objectReferenceValue != null)
            {
                EditorGUI.BeginDisabledGroup(false);
                GUILayout.BeginArea(new Rect(-3 + 10, CgeLayoutCommon.PictureHeight - CgeLayoutCommon.SingleLineHeight * 1.75f, CgeLayoutCommon.GuiSquareWidth - 10, CgeLayoutCommon.SingleLineHeight * 1.5f));
                if (GUILayout.Button("↗↗ " + CgeLocale.CGEE_Simplify))
                {
                    Simplify(isLeftHand ? propertyPath : oppositePath);
                }
                GUILayout.EndArea();
                EditorGUI.EndDisabledGroup();
            }
            else if (usePermutations && (isLeftHand && property.objectReferenceValue != null && oppositeProperty.objectReferenceValue == null || !isLeftHand && property.objectReferenceValue == null && oppositeProperty.objectReferenceValue != null))
            {
                EditorGUI.BeginDisabledGroup(false);
                GUILayout.BeginArea(new Rect(-3 + 10, CgeLayoutCommon.PictureHeight - CgeLayoutCommon.SingleLineHeight * 1.75f, CgeLayoutCommon.GuiSquareWidth - 10, CgeLayoutCommon.SingleLineHeight * 1.5f));
                if (GUILayout.Button("↗↙ " + CgeLocale.CGEE_SwapToFix))
                {
                    Swap(propertyPath, oppositePath);
                }
                GUILayout.EndArea();
                EditorGUI.EndDisabledGroup();
            }
            else if (usePermutations && isLeftHand && property.objectReferenceValue != null)
            {
                EditorGUI.BeginDisabledGroup(false);
                GUILayout.BeginArea(new Rect(-3 + CgeLayoutCommon.GuiSquareWidth - 2 * CgeLayoutCommon.SingleLineHeight, CgeLayoutCommon.PictureHeight - CgeLayoutCommon.SingleLineHeight * 1.75f, 2 * CgeLayoutCommon.SingleLineHeight, CgeLayoutCommon.SingleLineHeight * 1.5f));
                if (GUILayout.Button("↗↙"))
                {
                    Swap(propertyPath, oppositePath);
                }
                GUILayout.EndArea();
                EditorGUI.EndDisabledGroup();
            }
            else if (element == null && _driver.IsAutoSettable(propertyPath))
            {
                var propertyPathToCopyFrom = _driver.GetAutoSettableSource(propertyPath);
                var animationToBeCopied    = _editorEffector.SpProperty(propertyPathToCopyFrom).objectReferenceValue;

                EditorGUI.BeginDisabledGroup(animationToBeCopied == null);
                GUILayout.BeginArea(new Rect(-3 + CgeLayoutCommon.GuiSquareWidth - 100, CgeLayoutCommon.PictureHeight - CgeLayoutCommon.SingleLineHeight * 1.75f, 100, CgeLayoutCommon.SingleLineHeight * 1.5f));
                if (GUILayout.Button(CgeLocale.CGEE_AutoSet))
                {
                    AutoSet(propertyPath, propertyPathToCopyFrom);
                }
                GUILayout.EndArea();
                EditorGUI.EndDisabledGroup();
            }
            else if (element == null && _driver.AreCombinationSourcesIdentical(propertyPath))
            {
                var propertyPathToCopyFrom = _driver.ProvideCombinationPropertySources(propertyPath, usePermutations).Left;
                var animationToBeCopied    = _editorEffector.SpProperty(propertyPathToCopyFrom).objectReferenceValue;

                EditorGUI.BeginDisabledGroup(animationToBeCopied == null);
                GUILayout.BeginArea(new Rect(-3 + CgeLayoutCommon.GuiSquareWidth - 100, CgeLayoutCommon.PictureHeight - CgeLayoutCommon.SingleLineHeight * 1.75f, 100, CgeLayoutCommon.SingleLineHeight * 1.5f));
                if (GUILayout.Button(CgeLocale.CGEE_AutoSet))
                {
                    AutoSet(propertyPath, propertyPathToCopyFrom);
                }
                GUILayout.EndArea();
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                BeginInvisibleRankPreservingArea();
                CgeLayoutCommon.InvisibleRankPreservingButton();
                EndInvisibleRankPreservingArea();
            }

            GUILayout.Space(CgeLayoutCommon.PictureHeight);
            EditorGUILayout.PropertyField(property, GUIContent.none);
        }