public static bool IssueWarningsForUnrecommendedTextureSettings(string texturePath)
        {
            TextureImporter texImporter = (TextureImporter)TextureImporter.GetAtPath(texturePath);

            if (texImporter == null)
            {
                return(false);
            }

            int      extensionPos = texturePath.LastIndexOf('.');
            string   materialPath = texturePath.Substring(0, extensionPos) + "_Material.mat";
            Material material     = AssetDatabase.LoadAssetAtPath <Material>(materialPath);

            if (material == null)
            {
                return(true);
            }

            string errorMessage = null;

            if (MaterialChecks.IsTextureSetupProblematic(material, PlayerSettings.colorSpace,
                                                         texImporter.sRGBTexture, texImporter.mipmapEnabled, texImporter.alphaIsTransparency,
                                                         texturePath, materialPath, ref errorMessage))
            {
                Debug.LogWarning(errorMessage);
            }
            return(true);
        }
        protected virtual void DrawInspectorGUI(bool multi)
        {
            // Initialize.
            if (Event.current.type == EventType.Layout)
            {
                if (forceReloadQueued)
                {
                    forceReloadQueued = false;
                    if (multi)
                    {
                        foreach (var c in targets)
                        {
                            EditorForceReloadSkeletonDataAssetAndComponent(c as SkeletonRenderer);
                        }
                    }
                    else
                    {
                        EditorForceReloadSkeletonDataAssetAndComponent(target as SkeletonRenderer);
                    }
                }
                else
                {
                    if (multi)
                    {
                        foreach (var c in targets)
                        {
                            var component = c as SkeletonRenderer;
                            if (!component.valid)
                            {
                                EditorForceInitializeComponent(component);
                                if (!component.valid)
                                {
                                    continue;
                                }
                            }
                        }
                    }
                    else
                    {
                        var component = (SkeletonRenderer)target;
                        if (!component.valid)
                        {
                            EditorForceInitializeComponent(component);
                        }
                    }
                }

                                #if BUILT_IN_SPRITE_MASK_COMPONENT
                if (setMaskNoneMaterialsQueued)
                {
                    setMaskNoneMaterialsQueued = false;
                    foreach (var c in targets)
                    {
                        EditorSetMaskMaterials(c as SkeletonRenderer, SpriteMaskInteraction.None);
                    }
                }
                if (setInsideMaskMaterialsQueued)
                {
                    setInsideMaskMaterialsQueued = false;
                    foreach (var c in targets)
                    {
                        EditorSetMaskMaterials(c as SkeletonRenderer, SpriteMaskInteraction.VisibleInsideMask);
                    }
                }
                if (setOutsideMaskMaterialsQueued)
                {
                    setOutsideMaskMaterialsQueued = false;
                    foreach (var c in targets)
                    {
                        EditorSetMaskMaterials(c as SkeletonRenderer, SpriteMaskInteraction.VisibleOutsideMask);
                    }
                }

                if (deleteInsideMaskMaterialsQueued)
                {
                    deleteInsideMaskMaterialsQueued = false;
                    foreach (var c in targets)
                    {
                        EditorDeleteMaskMaterials(c as SkeletonRenderer, SpriteMaskInteraction.VisibleInsideMask);
                    }
                }
                if (deleteOutsideMaskMaterialsQueued)
                {
                    deleteOutsideMaskMaterialsQueued = false;
                    foreach (var c in targets)
                    {
                        EditorDeleteMaskMaterials(c as SkeletonRenderer, SpriteMaskInteraction.VisibleOutsideMask);
                    }
                }
                                #endif

#if NO_PREFAB_MESH
                if (isInspectingPrefab)
                {
                    if (multi)
                    {
                        foreach (var c in targets)
                        {
                            var        component  = (SkeletonRenderer)c;
                            MeshFilter meshFilter = component.GetComponent <MeshFilter>();
                            if (meshFilter != null && meshFilter.sharedMesh != null)
                            {
                                meshFilter.sharedMesh = null;
                            }
                        }
                    }
                    else
                    {
                        var        component  = (SkeletonRenderer)target;
                        MeshFilter meshFilter = component.GetComponent <MeshFilter>();
                        if (meshFilter != null && meshFilter.sharedMesh != null)
                        {
                            meshFilter.sharedMesh = null;
                        }
                    }
                }
#endif
            }

            bool valid = TargetIsValid;

            // Fields.
            if (multi)
            {
                using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox)) {
                    SpineInspectorUtility.PropertyFieldFitLabel(skeletonDataAsset, SkeletonDataAssetLabel);
                    if (GUILayout.Button(ReloadButtonString, ReloadButtonStyle, ReloadButtonWidth))
                    {
                        forceReloadQueued = true;
                    }
                }

                if (valid)
                {
                    EditorGUILayout.PropertyField(initialSkinName, SpineInspectorUtility.TempContent("Initial Skin"));
                }
            }
            else
            {
                var component = (SkeletonRenderer)target;

                using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox)) {
                    SpineInspectorUtility.PropertyFieldFitLabel(skeletonDataAsset, SkeletonDataAssetLabel);
                    if (component.valid)
                    {
                        if (GUILayout.Button(ReloadButtonString, ReloadButtonStyle, ReloadButtonWidth))
                        {
                            forceReloadQueued = true;
                        }
                    }
                }

                if (component.skeletonDataAsset == null)
                {
                    EditorGUILayout.HelpBox("Skeleton Data Asset required", MessageType.Warning);
                    return;
                }

                if (!SkeletonDataAssetIsValid(component.skeletonDataAsset))
                {
                    EditorGUILayout.HelpBox("Skeleton Data Asset error. Please check Skeleton Data Asset.", MessageType.Error);
                    return;
                }

                if (valid)
                {
                    EditorGUILayout.PropertyField(initialSkinName, SpineInspectorUtility.TempContent("Initial Skin"));
                }
            }

            EditorGUILayout.Space();

            // Sorting Layers
            SpineInspectorUtility.SortingPropertyFields(sortingProperties, applyModifiedProperties: true);

            if (maskInteraction != null)
            {
                EditorGUILayout.PropertyField(maskInteraction, MaskInteractionLabel);
            }

            if (!valid)
            {
                return;
            }

            string errorMessage = null;
            if (MaterialChecks.IsMaterialSetupProblematic((SkeletonRenderer)this.target, ref errorMessage))
            {
                EditorGUILayout.HelpBox(errorMessage, MessageType.Error, true);
            }

            // More Render Options...
            using (new SpineInspectorUtility.BoxScope()) {
                EditorGUI.BeginChangeCheck();

                EditorGUILayout.BeginHorizontal(GUILayout.Height(EditorGUIUtility.singleLineHeight + 5));
                advancedFoldout = EditorGUILayout.Foldout(advancedFoldout, "Advanced");
                if (advancedFoldout)
                {
                    EditorGUILayout.Space();
                    if (GUILayout.Button("Debug", EditorStyles.miniButton, GUILayout.Width(65f)))
                    {
                        SkeletonDebugWindow.Init();
                    }
                }
                else
                {
                    EditorGUILayout.Space();
                }
                EditorGUILayout.EndHorizontal();

                if (advancedFoldout)
                {
                    using (new SpineInspectorUtility.IndentScope()) {
                        using (new EditorGUILayout.HorizontalScope()) {
                            SpineInspectorUtility.ToggleLeftLayout(initialFlipX);
                            SpineInspectorUtility.ToggleLeftLayout(initialFlipY);
                            EditorGUILayout.Space();
                        }

                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField("Renderer Settings", EditorStyles.boldLabel);
                        using (new SpineInspectorUtility.LabelWidthScope()) {
                            // Optimization options
                            if (singleSubmesh != null)
                            {
                                EditorGUILayout.PropertyField(singleSubmesh, SingleSubmeshLabel);
                            }
                                                        #if PER_MATERIAL_PROPERTY_BLOCKS
                            if (fixDrawOrder != null)
                            {
                                EditorGUILayout.PropertyField(fixDrawOrder, FixDrawOrderLabel);
                            }
                                                        #endif
                            if (immutableTriangles != null)
                            {
                                EditorGUILayout.PropertyField(immutableTriangles, ImmubleTrianglesLabel);
                            }
                            EditorGUILayout.PropertyField(clearStateOnDisable, ClearStateOnDisableLabel);
                            EditorGUILayout.Space();
                        }

                        SeparatorsField(separatorSlotNames);
                        EditorGUILayout.Space();

                        // Render options
                        const float MinZSpacing = -0.1f;
                        const float MaxZSpacing = 0f;
                        EditorGUILayout.Slider(zSpacing, MinZSpacing, MaxZSpacing, ZSpacingLabel);
                        EditorGUILayout.Space();

                        using (new SpineInspectorUtility.LabelWidthScope()) {
                            EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Vertex Data", SpineInspectorUtility.UnityIcon <MeshFilter>()), EditorStyles.boldLabel);
                            if (pmaVertexColors != null)
                            {
                                EditorGUILayout.PropertyField(pmaVertexColors, PMAVertexColorsLabel);
                            }
                            EditorGUILayout.PropertyField(tintBlack, TintBlackLabel);

                            // Optional fields. May be disabled in SkeletonRenderer.
                            if (normals != null)
                            {
                                EditorGUILayout.PropertyField(normals, NormalsLabel);
                            }
                            if (tangents != null)
                            {
                                EditorGUILayout.PropertyField(tangents, TangentsLabel);
                            }
                        }

                                                #if BUILT_IN_SPRITE_MASK_COMPONENT
                        EditorGUILayout.Space();
                        if (maskMaterialsNone.arraySize > 0 || maskMaterialsInside.arraySize > 0 || maskMaterialsOutside.arraySize > 0)
                        {
                            EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Mask Interaction Materials", SpineInspectorUtility.UnityIcon <SpriteMask>()), EditorStyles.boldLabel);
                            bool differentMaskModesSelected = maskInteraction.hasMultipleDifferentValues;
                            int  activeMaskInteractionValue = differentMaskModesSelected ? -1 : maskInteraction.intValue;

                            bool ignoredParam = true;
                            MaskMaterialsEditingField(ref setMaskNoneMaterialsQueued, ref ignoredParam, maskMaterialsNone, MaskMaterialsNoneLabel,
                                                      differentMaskModesSelected, allowDelete: false, isActiveMaterial: activeMaskInteractionValue == (int)SpriteMaskInteraction.None);
                            MaskMaterialsEditingField(ref setInsideMaskMaterialsQueued, ref deleteInsideMaskMaterialsQueued, maskMaterialsInside, MaskMaterialsInsideLabel,
                                                      differentMaskModesSelected, allowDelete: true, isActiveMaterial: activeMaskInteractionValue == (int)SpriteMaskInteraction.VisibleInsideMask);
                            MaskMaterialsEditingField(ref setOutsideMaskMaterialsQueued, ref deleteOutsideMaskMaterialsQueued, maskMaterialsOutside, MaskMaterialsOutsideLabel,
                                                      differentMaskModesSelected, allowDelete: true, isActiveMaterial: activeMaskInteractionValue == (int)SpriteMaskInteraction.VisibleOutsideMask);
                        }
                                                #endif

                        EditorGUILayout.Space();

                        if (valid && !isInspectingPrefab)
                        {
                            if (multi)
                            {
                                // Support multi-edit SkeletonUtility button.
                                //	EditorGUILayout.Space();
                                //	bool addSkeletonUtility = GUILayout.Button(buttonContent, GUILayout.Height(30));
                                //	foreach (var t in targets) {
                                //		var component = t as Component;
                                //		if (addSkeletonUtility && component.GetComponent<SkeletonUtility>() == null)
                                //			component.gameObject.AddComponent<SkeletonUtility>();
                                //	}
                            }
                            else
                            {
                                var component = (Component)target;
                                if (component.GetComponent <SkeletonUtility>() == null)
                                {
                                    if (SpineInspectorUtility.CenteredButton(SkeletonUtilityButtonContent, 21, true, 200f))
                                    {
                                        component.gameObject.AddComponent <SkeletonUtility>();
                                    }
                                }
                            }
                        }

                        EditorGUILayout.Space();
                    }
                }

                if (EditorGUI.EndChangeCheck())
                {
                    SceneView.RepaintAll();
                }
            }
        }
Esempio n. 3
0
        public override void OnInspectorGUI()
        {
            if (UnityEngine.Event.current.type == EventType.Layout)
            {
                if (forceReloadQueued)
                {
                    forceReloadQueued = false;
                    foreach (var c in targets)
                    {
                        SpineEditorUtilities.ReloadSkeletonDataAssetAndComponent(c as SkeletonGraphic);
                    }
                }
                else
                {
                    foreach (var c in targets)
                    {
                        var component = c as SkeletonGraphic;
                        if (!component.IsValid)
                        {
                            SpineEditorUtilities.ReinitializeComponent(component);
                            if (!component.IsValid)
                            {
                                continue;
                            }
                        }
                    }
                }
            }

            bool wasChanged = false;

            EditorGUI.BeginChangeCheck();

            using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox)) {
                SpineInspectorUtility.PropertyFieldFitLabel(skeletonDataAsset, SkeletonDataAssetLabel);
                if (GUILayout.Button(ReloadButtonString, ReloadButtonStyle, ReloadButtonWidth))
                {
                    forceReloadQueued = true;
                }
            }

            EditorGUILayout.PropertyField(material);
            EditorGUILayout.PropertyField(color);

            if (thisSkeletonGraphic.skeletonDataAsset == null)
            {
                EditorGUILayout.HelpBox("You need to assign a SkeletonDataAsset first.", MessageType.Info);
                serializedObject.ApplyModifiedProperties();
                serializedObject.Update();
                return;
            }

            string errorMessage = null;

            if (SpineEditorUtilities.Preferences.componentMaterialWarning &&
                MaterialChecks.IsMaterialSetupProblematic(thisSkeletonGraphic, ref errorMessage))
            {
                EditorGUILayout.HelpBox(errorMessage, MessageType.Error, true);
            }

            bool isSingleRendererOnly = (!allowMultipleCanvasRenderers.hasMultipleDifferentValues && allowMultipleCanvasRenderers.boolValue == false);
            bool isSeparationEnabledButNotMultipleRenderers =
                isSingleRendererOnly && (!enableSeparatorSlots.hasMultipleDifferentValues && enableSeparatorSlots.boolValue == true);
            bool meshRendersIncorrectlyWithSingleRenderer =
                isSingleRendererOnly && SkeletonHasMultipleSubmeshes();

            if (isSeparationEnabledButNotMultipleRenderers || meshRendersIncorrectlyWithSingleRenderer)
            {
                meshGeneratorSettings.isExpanded = true;
            }

            using (new SpineInspectorUtility.BoxScope()) {
                EditorGUILayout.PropertyField(meshGeneratorSettings, SpineInspectorUtility.TempContent("Advanced..."), includeChildren: true);
                SkeletonRendererInspector.advancedFoldout = meshGeneratorSettings.isExpanded;

                if (meshGeneratorSettings.isExpanded)
                {
                    EditorGUILayout.Space();
                    using (new SpineInspectorUtility.IndentScope()) {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.PropertyField(allowMultipleCanvasRenderers, SpineInspectorUtility.TempContent("Multiple CanvasRenderers"));

                        if (GUILayout.Button(new GUIContent("Trim Renderers", "Remove currently unused CanvasRenderer GameObjects. These will be regenerated whenever needed."),
                                             EditorStyles.miniButton, GUILayout.Width(100f)))
                        {
                            foreach (var skeletonGraphic in targets)
                            {
                                ((SkeletonGraphic)skeletonGraphic).TrimRenderers();
                            }
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.PropertyField(updateWhenInvisible);

                        // warning box
                        if (isSeparationEnabledButNotMultipleRenderers)
                        {
                            using (new SpineInspectorUtility.BoxScope()) {
                                meshGeneratorSettings.isExpanded = true;
                                EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("'Multiple Canvas Renderers' must be enabled\nwhen 'Enable Separation' is enabled.", Icons.warning), GUILayout.Height(42), GUILayout.Width(340));
                            }
                        }
                        else if (meshRendersIncorrectlyWithSingleRenderer)
                        {
                            using (new SpineInspectorUtility.BoxScope()) {
                                meshGeneratorSettings.isExpanded = true;
                                EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("This mesh uses multiple atlas pages. You\n" +
                                                                                             "need to enable 'Multiple Canvas Renderers'\n" +
                                                                                             "for correct rendering. Consider packing\n" +
                                                                                             "attachments to a single atlas page if possible.", Icons.warning), GUILayout.Height(60), GUILayout.Width(340));
                            }
                        }
                    }

                    EditorGUILayout.Space();
                    SeparatorsField(separatorSlotNames, enableSeparatorSlots, updateSeparatorPartLocation);
                }
            }

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(initialSkinName);
            {
                var rect = GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, EditorGUIUtility.singleLineHeight);
                EditorGUI.PrefixLabel(rect, SpineInspectorUtility.TempContent("Initial Flip"));
                rect.x    += EditorGUIUtility.labelWidth;
                rect.width = 30f;
                SpineInspectorUtility.ToggleLeft(rect, initialFlipX, SpineInspectorUtility.TempContent("X", tooltip: "initialFlipX"));
                rect.x += 35f;
                SpineInspectorUtility.ToggleLeft(rect, initialFlipY, SpineInspectorUtility.TempContent("Y", tooltip: "initialFlipY"));
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Animation", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(startingAnimation);
            EditorGUILayout.PropertyField(startingLoop);
            EditorGUILayout.PropertyField(timeScale);
            EditorGUILayout.PropertyField(unscaledTime, SpineInspectorUtility.TempContent(unscaledTime.displayName, tooltip: "If checked, this will use Time.unscaledDeltaTime to make this update independent of game Time.timeScale. Instance SkeletonGraphic.timeScale will still be applied."));
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(freeze);
            EditorGUILayout.Space();
            SkeletonRendererInspector.SkeletonRootMotionParameter(targets);
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("UI", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(raycastTarget);

            EditorGUILayout.BeginHorizontal(GUILayout.Height(EditorGUIUtility.singleLineHeight + 5));
            EditorGUILayout.PrefixLabel("Match RectTransform with Mesh");
            if (GUILayout.Button("Match", EditorStyles.miniButton, GUILayout.Width(65f)))
            {
                foreach (var skeletonGraphic in targets)
                {
                    MatchRectTransformWithBounds((SkeletonGraphic)skeletonGraphic);
                }
            }
            EditorGUILayout.EndHorizontal();

            if (TargetIsValid && !isInspectingPrefab)
            {
                EditorGUILayout.Space();
                if (SpineInspectorUtility.CenteredButton(new GUIContent("Add Skeleton Utility", Icons.skeletonUtility), 21, true, 200f))
                {
                    foreach (var t in targets)
                    {
                        var component = t as Component;
                        if (component.GetComponent <SkeletonUtility>() == null)
                        {
                            component.gameObject.AddComponent <SkeletonUtility>();
                        }
                    }
                }
            }

            wasChanged |= EditorGUI.EndChangeCheck();

            if (wasChanged)
            {
                serializedObject.ApplyModifiedProperties();
                slotsReapplyRequired = true;
            }

            if (slotsReapplyRequired && UnityEngine.Event.current.type == EventType.Repaint)
            {
                foreach (var target in targets)
                {
                    var skeletonGraphic = (SkeletonGraphic)target;
                    skeletonGraphic.ReapplySeparatorSlotNames();
                    skeletonGraphic.LateUpdate();
                    SceneView.RepaintAll();
                }
                slotsReapplyRequired = false;
            }
        }