コード例 #1
0
        public static void DrawSpritePopup(SpriteAtlas atlas, SerializedProperty spriteProperty)
        {
            GUIContent label      = new GUIContent(spriteProperty.displayName, spriteProperty.tooltip);
            string     spriteName = string.IsNullOrEmpty(spriteProperty.stringValue) ? "----" : spriteProperty.stringValue;

            using (new EditorGUI.DisabledGroupScope(!atlas))
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.PrefixLabel(label);
                    if (GUILayout.Button(string.IsNullOrEmpty(spriteName) ? "-" : spriteName, "minipopup") && atlas)
                    {
                        AtlasSpriteSelector.Show(atlas, spriteName, (selectedSpriteName) =>
                        {
                            if (selectedSpriteName == null)
                            {
                                return;
                            }

                            spriteProperty.stringValue = selectedSpriteName;
                            spriteProperty.serializedObject.ApplyModifiedProperties();
                        });
                    }
                }
            }
        }
コード例 #2
0
 public static void Hide()
 {
     if (instance != null)
     {
         instance.Close();
         instance = null;
     }
 }
コード例 #3
0
 public static void Show(UGUIAtlas atlas, UnityAction <Sprite> onClickSprite = null, UnityAction <Sprite> onDoubleClickSprite = null, Sprite currentSprite = null)
 {
     if (instance != null)
     {
         instance.Close();
         instance = null;
     }
     instance                     = ScriptableWizard.DisplayWizard <AtlasSpriteSelector> ("Select a Sprite");
     instance.targetAtlas         = atlas;
     instance.onClickSprite       = onClickSprite;
     instance.onDoubleClickSprite = onDoubleClickSprite;
     instance.currentSprite       = currentSprite;
 }
コード例 #4
0
 void OnDisable()
 {
     instance = null;
 }
コード例 #5
0
 void OnEnable()
 {
     instance   = this;
     searchName = "";
 }
コード例 #6
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        if (atlasProperty != null)
        {
            using (EditorGUILayout.HorizontalScope horizontalScope = new EditorGUILayout.HorizontalScope()) {
                if (GUILayout.Button("Atlas", "DropDown", GUILayout.Width(EditorGUIUtility.labelWidth - 10)) == true)
                {
                    AtlasSelector.Show(null, OnDoubleClickAtlas, atlasProperty.objectReferenceValue as UGUIAtlas);
                }
                //绘制图集属性
                UGUIAtlas selectedAtlas = EditorGUILayout.ObjectField(atlasProperty.objectReferenceValue, typeof(UGUIAtlas), true) as UGUIAtlas;
                if (selectedAtlas != atlasProperty.objectReferenceValue)
                {
                    atlasProperty.objectReferenceValue  = selectedAtlas;
                    spriteProperty.objectReferenceValue = null;
                    serializedObject.ApplyModifiedProperties();
                }
            }


            using (EditorGUILayout.HorizontalScope horizontalScope = new EditorGUILayout.HorizontalScope()) {
                var atlas = atlasProperty.objectReferenceValue as UGUIAtlas;
                if (atlas != null)
                {
                    if (GUILayout.Button("Sprite", "DropDown", GUILayout.Width(EditorGUIUtility.labelWidth - 10)) == true)
                    {
                        AtlasSpriteSelector.Show(atlas, OnClickSprite, OnDoubleClickSprite, spriteProperty.objectReferenceValue as Sprite);
                    }
                }
                else
                {
                    GUILayout.Label("Sprite", GUILayout.Width(EditorGUIUtility.labelWidth - 10));
                }

                using (EditorGUI.DisabledScope disableGroup = new EditorGUI.DisabledScope(atlas != null)) {
                    using (EditorGUI.ChangeCheckScope changeCheckScope = new EditorGUI.ChangeCheckScope()) {
                        EditorGUILayout.PropertyField(spriteProperty, new GUIContent(""));

                        if (changeCheckScope.changed == true)
                        {
                            var newSprite = spriteProperty.objectReferenceValue as Sprite;
                            if (newSprite)
                            {
                                Image.Type oldType = (Image.Type)typeProperty.enumValueIndex;
                                if (newSprite.border.SqrMagnitude() > 0)
                                {
                                    typeProperty.enumValueIndex = (int)Image.Type.Sliced;
                                }
                                else if (oldType == Image.Type.Sliced)
                                {
                                    typeProperty.enumValueIndex = (int)Image.Type.Simple;
                                }
                            }
                        }
                        serializedObject.ApplyModifiedProperties();
                    }
                }
            }

            AppearanceControlsGUI();
            RaycastControlsGUI();

            showType.target = spriteProperty.objectReferenceValue != null;
            if (EditorGUILayout.BeginFadeGroup(showType.faded))
            {
                TypeGUI();
            }
            EditorGUILayout.EndFadeGroup();

            SetShowNativeSize(true, true);
            if (EditorGUILayout.BeginFadeGroup(m_ShowNativeSize.faded))
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(preserveAspectProperty);
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.EndFadeGroup();

            NativeSizeButtonGUI();
            serializedObject.ApplyModifiedProperties();
        }
    }
コード例 #7
0
 private void OnDoubleClickSprite(Sprite sprite)
 {
     AtlasSpriteSelector.Hide();
 }
コード例 #8
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            instance = target as ButtonReactiveImage;

            if (instance.Atlas != null)
            {
                var backgroundColor = new Color(0.3f, 0.3f, 0.5f);
                var labelColor      = new Color(0.8f, 0.8f, 0.8f, 0.8f);

                if (instance.Atlas.Sprites.Any())
                {
                    EditorGUILayout.Separator();

                    EditorLayoutTools.DrawLabelWithBackground("EnableSprite", backgroundColor, labelColor);

                    using (new GUILayout.HorizontalScope())
                    {
                        var enableSpriteName = Reflection.GetPrivateField <ButtonReactiveImage, string>(instance, "enableSpriteName");

                        GUILayout.Space(5f);

                        if (EditorLayoutTools.DrawPrefixButton("Sprite"))
                        {
                            EditorAtlasPrefs.atlas          = instance.Atlas;
                            EditorAtlasPrefs.selectedSprite = enableSpriteName;
                            AtlasSpriteSelector.Show(SelectEnableSprite);
                        }

                        if (!string.IsNullOrEmpty(enableSpriteName))
                        {
                            EditorGUILayout.SelectableLabel(enableSpriteName, EditorStyles.textArea, GUILayout.Height(18f));
                        }
                    }

                    EditorGUILayout.Separator();

                    EditorLayoutTools.DrawLabelWithBackground("DisableSprite", backgroundColor, labelColor);

                    using (new GUILayout.HorizontalScope())
                    {
                        var disableSpriteName = Reflection.GetPrivateField <ButtonReactiveImage, string>(instance, "disableSpriteName");

                        GUILayout.Space(5f);

                        if (EditorLayoutTools.DrawPrefixButton("Sprite"))
                        {
                            EditorAtlasPrefs.atlas          = instance.Atlas;
                            EditorAtlasPrefs.selectedSprite = disableSpriteName;
                            AtlasSpriteSelector.Show(SelectDisableSprite);
                        }

                        if (!string.IsNullOrEmpty(disableSpriteName))
                        {
                            EditorGUILayout.SelectableLabel(disableSpriteName, EditorStyles.textArea, GUILayout.Height(18f));
                        }
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("No sprites found", MessageType.Warning);
                }
            }
        }