PropertyFieldFitLabel() public static method

public static PropertyFieldFitLabel ( SerializedProperty property, GUIContent label = null, float extraSpace = 5f ) : void
property SerializedProperty
label GUIContent
extraSpace float
return void
        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();
                }
            }
        }
        protected virtual void DrawInspectorGUI(bool multi)
        {
            bool valid             = TargetIsValid;
            var  reloadWidth       = GUILayout.Width(GUI.skin.label.CalcSize(new GUIContent(ReloadButtonLabel)).x + 20);
            var  reloadButtonStyle = EditorStyles.miniButtonRight;

            if (multi)
            {
                using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox)) {
                    SpineInspectorUtility.PropertyFieldFitLabel(skeletonDataAsset, SkeletonDataAssetLabel);
                    if (GUILayout.Button(ReloadButtonLabel, reloadButtonStyle, reloadWidth))
                    {
                        foreach (var c in targets)
                        {
                            var component = c as SkeletonRenderer;
                            if (component.skeletonDataAsset != null)
                            {
                                foreach (AtlasAsset aa in component.skeletonDataAsset.atlasAssets)
                                {
                                    if (aa != null)
                                    {
                                        aa.Clear();
                                    }
                                }
                                component.skeletonDataAsset.Clear();
                            }
                            component.Initialize(true);
                        }
                    }
                }

                foreach (var c in targets)
                {
                    var component = c as SkeletonRenderer;
                    if (!component.valid)
                    {
                        if (Event.current.type == EventType.Layout)
                        {
                            component.Initialize(true);
                            component.LateUpdate();
                        }
                        if (!component.valid)
                        {
                            continue;
                        }
                    }

                                        #if NO_PREFAB_MESH
                    if (isInspectingPrefab)
                    {
                        MeshFilter meshFilter = component.GetComponent <MeshFilter>();
                        if (meshFilter != null)
                        {
                            meshFilter.sharedMesh = null;
                        }
                    }
                                        #endif
                }

                if (valid)
                {
                    EditorGUILayout.PropertyField(initialSkinName);
                }
            }
            else
            {
                var component = (SkeletonRenderer)target;

                if (!component.valid && Event.current.type == EventType.Layout)
                {
                    component.Initialize(true);
                    component.LateUpdate();
                }

                using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox)) {
                    SpineInspectorUtility.PropertyFieldFitLabel(skeletonDataAsset, SkeletonDataAssetLabel);
                    if (component.valid)
                    {
                        if (GUILayout.Button(ReloadButtonLabel, reloadButtonStyle, reloadWidth))
                        {
                            if (component.skeletonDataAsset != null)
                            {
                                foreach (AtlasAsset aa in component.skeletonDataAsset.atlasAssets)
                                {
                                    if (aa != null)
                                    {
                                        aa.Clear();
                                    }
                                }
                                component.skeletonDataAsset.Clear();
                            }
                            component.Initialize(true);
                        }
                    }
                }

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

                                #if NO_PREFAB_MESH
                if (isInspectingPrefab)
                {
                    MeshFilter meshFilter = component.GetComponent <MeshFilter>();
                    if (meshFilter != null)
                    {
                        meshFilter.sharedMesh = null;
                    }
                }
                                #endif

                // Initial skin name.
                if (component.valid)
                {
                    string[] skins     = new string[component.skeleton.Data.Skins.Count];
                    int      skinIndex = 0;
                    for (int i = 0; i < skins.Length; i++)
                    {
                        string skinNameString = component.skeleton.Data.Skins.Items[i].Name;
                        skins[i] = skinNameString;
                        if (skinNameString == initialSkinName.stringValue)
                        {
                            skinIndex = i;
                        }
                    }
                    skinIndex = EditorGUILayout.Popup("Initial Skin", skinIndex, skins);
                    if (skins.Length > 0)                     // Support attachmentless/skinless SkeletonData.
                    {
                        initialSkinName.stringValue = skins[skinIndex];
                    }
                }
            }

            EditorGUILayout.Space();

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

            if (!TargetIsValid)
            {
                return;
            }

            // More Render Options...
            using (new SpineInspectorUtility.BoxScope()) {
                EditorGUI.BeginChangeCheck();
                if (advancedFoldout = EditorGUILayout.Foldout(advancedFoldout, "Advanced"))
                {
                    using (new SpineInspectorUtility.IndentScope()) {
                        using (new SpineInspectorUtility.LabelWidthScope()) {
                            // Optimization options
                            EditorGUILayout.PropertyField(meshes, MeshesLabel);
                            EditorGUILayout.PropertyField(immutableTriangles, ImmubleTrianglesLabel);
                            EditorGUILayout.PropertyField(tintBlack, TintBlackLabel);
                            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("Vertex Data", EditorStyles.boldLabel);
                            EditorGUILayout.PropertyField(pmaVertexColors, PMAVertexColorsLabel);

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

                            EditorGUILayout.Space();

                            EditorGUILayout.LabelField("Editor Preview", EditorStyles.boldLabel);
                            showBoneNames   = EditorGUILayout.Toggle("Show Bone Names", showBoneNames);
                            showPaths       = EditorGUILayout.Toggle("Show Paths", showPaths);
                            showShapes      = EditorGUILayout.Toggle("Show Shapes", showShapes);
                            showConstraints = EditorGUILayout.Toggle("Show Constraints", showConstraints);
                        }

                        EditorGUILayout.Space();
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    SceneView.RepaintAll();
                }
            }
        }
Ejemplo n.º 3
0
        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 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 (!valid)
            {
                return;
            }

            // 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 (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);
                            }
                        }

                        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();
                }
            }
        }
Ejemplo n.º 4
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;
            }
        }
        protected virtual void DrawInspectorGUI(bool multi)
        {
            bool valid             = TargetIsValid;
            var  reloadWidth       = GUILayout.Width(GUI.skin.label.CalcSize(new GUIContent(ReloadButtonLabel)).x + 20);
            var  reloadButtonStyle = EditorStyles.miniButtonRight;

            if (multi)
            {
                using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox)) {
                    SpineInspectorUtility.PropertyFieldFitLabel(skeletonDataAsset, SkeletonDataAssetLabel);
                    if (GUILayout.Button(ReloadButtonLabel, reloadButtonStyle, reloadWidth))
                    {
                        foreach (var c in targets)
                        {
                            var component = c as SkeletonRenderer;
                            if (component.skeletonDataAsset != null)
                            {
                                foreach (AtlasAsset aa in component.skeletonDataAsset.atlasAssets)
                                {
                                    if (aa != null)
                                    {
                                        aa.Clear();
                                    }
                                }
                                component.skeletonDataAsset.Clear();
                            }
                            component.Initialize(true);
                        }
                    }
                }

                foreach (var c in targets)
                {
                    var component = c as SkeletonRenderer;
                    if (!component.valid)
                    {
                        if (Event.current.type == EventType.Layout)
                        {
                            component.Initialize(true);
                            component.LateUpdate();
                        }
                        if (!component.valid)
                        {
                            continue;
                        }
                    }

                                        #if NO_PREFAB_MESH
                    if (isInspectingPrefab)
                    {
                        MeshFilter meshFilter = component.GetComponent <MeshFilter>();
                        if (meshFilter != null)
                        {
                            meshFilter.sharedMesh = null;
                        }
                    }
                                        #endif
                }

                if (valid)
                {
                    EditorGUILayout.PropertyField(initialSkinName);
                }
            }
            else
            {
                var component = (SkeletonRenderer)target;

                if (!component.valid && Event.current.type == EventType.Layout)
                {
                    component.Initialize(true);
                    // component.LateUpdate();
                }

                using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox)) {
                    SpineInspectorUtility.PropertyFieldFitLabel(skeletonDataAsset, SkeletonDataAssetLabel);
                    if (component.valid)
                    {
                        if (GUILayout.Button(ReloadButtonLabel, reloadButtonStyle, reloadWidth))
                        {
                            if (component.skeletonDataAsset != null)
                            {
                                foreach (AtlasAsset aa in component.skeletonDataAsset.atlasAssets)
                                {
                                    if (aa != null)
                                    {
                                        aa.Clear();
                                    }
                                }
                                component.skeletonDataAsset.Clear();
                            }
                            component.Initialize(true);
                        }
                    }
                }

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

                                #if NO_PREFAB_MESH
                if (isInspectingPrefab)
                {
                    MeshFilter meshFilter = component.GetComponent <MeshFilter>();
                    if (meshFilter != null)
                    {
                        meshFilter.sharedMesh = null;
                    }
                }
                                #endif

                // Initial skin name.
                if (component.valid)
                {
                    var skeletonDataSkins = component.skeleton.Data.Skins;
                    int skinCount         = skeletonDataSkins.Count;
                    if (loadedSkinList != skeletonDataSkins)
                    {
                        skins          = new GUIContent[skinCount];
                        loadedSkinList = skeletonDataSkins;
                        for (int i = 0; i < skins.Length; i++)
                        {
                            string skinNameString = skeletonDataSkins.Items[i].Name;
                            skins[i] = new GUIContent(skinNameString, Icons.skin);
                        }
                    }

                    int skinIndex = 0;
                    for (int i = 0; i < skins.Length; i++)
                    {
                        string skinNameString = skeletonDataSkins.Items[i].Name;
                        if (skinNameString == initialSkinName.stringValue)
                        {
                            skinIndex = i;
                        }
                    }

                    skinIndex = EditorGUILayout.Popup(SpineInspectorUtility.TempContent("Initial Skin"), skinIndex, skins);
                    if (skins.Length > 0)                     // Support attachmentless/skinless SkeletonData.
                    {
                        initialSkinName.stringValue = skins[skinIndex].text;
                    }
                }
            }

            EditorGUILayout.Space();

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

            if (!TargetIsValid)
            {
                return;
            }
            // 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()) {
                            initialFlipX.boolValue = EditorGUILayout.ToggleLeft(initialFlipX.displayName, initialFlipX.boolValue, GUILayout.Width(120f));
                            initialFlipY.boolValue = EditorGUILayout.ToggleLeft(initialFlipY.displayName, initialFlipY.boolValue, GUILayout.Width(120f));
                            EditorGUILayout.Space();
                        }

                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField("Renderer Settings", EditorStyles.boldLabel);
                        using (new SpineInspectorUtility.LabelWidthScope()) {
                            // Optimization options
                            if (singleSubmesh != null)
                            {
                                EditorGUILayout.PropertyField(singleSubmesh, SingleSubmeshLabel);
                            }
                            //if (meshes != null) EditorGUILayout.PropertyField(meshes, MeshesLabel);
                            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);
                            }
                        }

                        EditorGUILayout.Space();

                        if (TargetIsValid && !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();
                }
            }
        }