Exemple #1
0
        public override void LateInitialize()
        {
            base.LateInitialize();

            icons.Load();

            loader = LoadTexture("Loader.png", CreateTextureOptions.PixelPerfect);
        }
            static Styles()
            {
                // Disabling word wrap because Unity's CalcSize and CalcHeight
                // are broken w.r.t. pixel-perfection and matrix

                title           = new GUIStyle(BoltCore.Styles.nodeLabel);
                title.padding   = new RectOffset(0, 5, 0, 2);
                title.margin    = new RectOffset(0, 0, 0, 0);
                title.fontSize  = 12;
                title.alignment = TextAnchor.MiddleLeft;
                title.wordWrap  = false;

                surtitle           = new GUIStyle(BoltCore.Styles.nodeLabel);
                surtitle.padding   = new RectOffset(0, 5, 0, 0);
                surtitle.margin    = new RectOffset(0, 0, 0, 0);
                surtitle.fontSize  = 10;
                surtitle.alignment = TextAnchor.MiddleLeft;
                surtitle.wordWrap  = false;

                subtitle = new GUIStyle(surtitle);
                subtitle.padding.bottom = 2;

                titleInverted = new GUIStyle(title);
                titleInverted.normal.textColor = ColorPalette.unityBackgroundDark;

                surtitleInverted = new GUIStyle(surtitle);
                surtitleInverted.normal.textColor = ColorPalette.unityBackgroundDark;

                subtitleInverted = new GUIStyle(subtitle);
                subtitleInverted.normal.textColor = ColorPalette.unityBackgroundDark;

                if (EditorGUIUtility.isProSkin)
                {
                    portsBackground = new GUIStyle("In BigTitle")
                    {
                        padding = new RectOffset(0, 0, 6, 5)
                    };
                }
                else
                {
                    TextureResolution[] textureResolution = { 2 };
                    var           createTextureOptions    = CreateTextureOptions.Scalable;
                    EditorTexture normalTexture           = BoltCore.Resources.LoadTexture($"Nodes/NodePortsBackground.png", textureResolution, createTextureOptions);

                    portsBackground = new GUIStyle
                    {
                        normal  = { background = normalTexture.Single() },
                        padding = new RectOffset(0, 0, 6, 5)
                    };
                }

                settingLabel = new GUIStyle(BoltCore.Styles.nodeLabel);
                settingLabel.padding.left  = 0;
                settingLabel.padding.right = 5;
                settingLabel.wordWrap      = false;
                settingLabel.clipping      = TextClipping.Clip;
            }
Exemple #3
0
        public static EditorTexture Icon(this UnityObject obj)
        {
            var icon = (Texture2D)EditorGUIUtility.ObjectContent(obj, obj?.GetType()).image;

            if (icon != null)
            {
                return(EditorTexture.Single(icon));
            }

            return(null);
        }
Exemple #4
0
            public void Load()
            {
                variablesWindow = resources.LoadIcon("VariablesWindow.png");

                variable = resources.LoadIcon("Variable.png");

                graphVariable       = resources.LoadIcon("GraphVariable.png");
                objectVariable      = resources.LoadIcon("ObjectVariable.png");
                sceneVariable       = resources.LoadIcon("SceneVariable.png");
                applicationVariable = resources.LoadIcon("ApplicationVariable.png");
                savedVariable       = resources.LoadIcon("SavedVariable.png");
                flowVariable        = resources.LoadIcon("FlowVariable.png");

                window          = resources.LoadIcon("GraphWindow.png");
                inspectorWindow = resources.LoadIcon("GraphInspectorWindow.png");

                if (GraphWindow.active != null)
                {
                    GraphWindow.active.titleContent.image = window?[IconSize.Small];
                }

                empty = EditorTexture.Single(ColorPalette.transparent.GetPixel());

                // Messages
                questionMessage = resources.LoadIcon("Question.png");
                warningMessage  = resources.LoadIcon("Warning.png");
                successMessage  = resources.LoadIcon("Success.png");
                errorMessage    = resources.LoadIcon("Error.png");

                // States
                warningState = resources.LoadIcon("Warning.png");
                successState = resources.LoadIcon("Success.png");
                errorState   = resources.LoadIcon("Error.png");
                progress     = resources.LoadIcon("Progress.png");

                // Versioning
                upgrade   = resources.LoadIcon("Upgrade.png");
                upToDate  = resources.LoadIcon("UpToDate.png");
                downgrade = resources.LoadIcon("Downgrade.png");

                // Windows
                supportWindow      = resources.LoadIcon("SupportWindow.png");
                sidebarAnchorLeft  = resources.LoadTexture("SidebarAnchorLeft.png", CreateTextureOptions.PixelPerfect);
                sidebarAnchorRight = resources.LoadTexture("SidebarAnchorRight.png", CreateTextureOptions.PixelPerfect);

                // Configuration
                editorPref     = resources.LoadTexture("EditorPref.png", new TextureResolution[] { 12, 24 }, CreateTextureOptions.PixelPerfect);
                projectSetting = resources.LoadTexture("ProjectSetting.png", new TextureResolution[] { 12, 24 }, CreateTextureOptions.PixelPerfect);

                // Other
                @null = resources.LoadIcon("Null.png");
            }
Exemple #5
0
        public static EditorTexture Load(IResourceProvider resources, string path, TextureResolution[] resolutions, CreateTextureOptions options, bool required)
        {
            using (ProfilingUtility.SampleBlock("Load Editor Texture"))
            {
                Ensure.That(nameof(resources)).IsNotNull(resources);
                Ensure.That(nameof(path)).IsNotNull(path);
                Ensure.That(nameof(resolutions)).HasItems(resolutions);

                var set = new EditorTexture();

                // Try with explicit resolutions first
                foreach (var resolution in resolutions)
                {
                    var width = resolution.width;
                    // var height = resolution.height;

                    var personalPath     = String.Empty;
                    var professionalPath = String.Empty;

                    personalPath     = resources.GetPersonalPath(path, width);
                    professionalPath = resources.GetProfessionalPath(path, width);

                    if (resources.FileExists(personalPath))
                    {
                        var tex = resources.LoadTexture(personalPath, options);
                        set.personal.Add(width, tex);
                    }

                    if (resources.FileExists(professionalPath))
                    {
                        var tex = resources.LoadTexture(professionalPath, options);
                        set.professional.Add(width, tex);
                    }
                }

                if (set.personal.Count == 0)
                {
                    if (required)
                    {
                        Debug.LogWarning($"Missing editor texture: {path}\n{resources.DebugPath(path)}");
                    }

                    // Never return an empty set; the codebase assumes this guarantee

                    return(null);
                }

                set.textureName = path;

                return(set);
            }
        }
        public static EditorTexture Load(IResourceProvider resources, string path, TextureResolution[] resolutions, CreateTextureOptions options, bool required)
        {
            using (ProfilingUtility.SampleBlock("Load Editor Texture"))
            {
                Ensure.That(nameof(resources)).IsNotNull(resources);
                Ensure.That(nameof(path)).IsNotNull(path);
                Ensure.That(nameof(resolutions)).HasItems(resolutions);

                var set       = new EditorTexture();
                var name      = Path.GetFileNameWithoutExtension(path).PartBefore('@');
                var extension = Path.GetExtension(path);
                var directory = Path.GetDirectoryName(path);

                // Try with explicit resolutions first
                foreach (var resolution in resolutions)
                {
                    var width = resolution.width;
                    // var height = resolution.height;

                    var personalPath     = Path.Combine(directory, $"{name}@{width}x{extension}");
                    var professionalPath = Path.Combine(directory, $"{name}_Pro@{width}x{extension}");

                    if (resources.FileExists(personalPath))
                    {
                        set.personal.Add(width, resources.LoadTexture(personalPath, options));
                    }

                    if (resources.FileExists(professionalPath))
                    {
                        set.professional.Add(width, resources.LoadTexture(professionalPath, options));
                    }
                }

                if (set.personal.Count == 0)
                {
                    if (required)
                    {
                        Debug.LogWarning($"Missing editor texture: {name}\n{resources.DebugPath(path)}");
                    }

                    // Never return an empty set; the codebase assumes this guarantee

                    return(null);
                }

                return(set);
            }
        }
Exemple #7
0
        public static EditorTexture Load(IResourceProvider resources, string path, CreateTextureOptions options, bool required)
        {
            using (ProfilingUtility.SampleBlock("Load Editor Texture"))
            {
                Ensure.That(nameof(resources)).IsNotNull(resources);
                Ensure.That(nameof(path)).IsNotNull(path);

                var set       = new EditorTexture();
                var name      = Path.GetFileNameWithoutExtension(path).PartBefore('@');
                var extension = Path.GetExtension(path);
                var directory = Path.GetDirectoryName(path);

                var personalPath     = Path.Combine(directory, $"{name}{extension}");
                var professionalPath = Path.Combine(directory, $"{name}_Pro{extension}");

                var texture = resources.LoadTexture(personalPath, options);

                if (texture != null)
                {
                    set.personal.Add(texture.width, texture);
                }

                texture = resources.LoadTexture(professionalPath, options);

                if (texture != null)
                {
                    set.professional.Add(texture.width, texture);
                }

                if (set.personal.Count == 0)
                {
                    if (required)
                    {
                        Debug.LogWarning($"Missing editor texture: {name}\n{resources.DebugPath(path)}");
                    }

                    // Never return an empty set; the codebase assumes this guarantee

                    return(null);
                }

                set.textureName = path;

                return(set);
            }
        }
Exemple #8
0
        private static EditorTexture GetBuiltInUnityTypeIcon(Type type)
        {
            var icon = (Texture2D)EditorGUIUtility.ObjectContent(null, type).image;

            // Change the blank file icon to a Unity-logo file icon
            if (icon == EditorGUIUtility.FindTexture("DefaultAsset Icon"))
            {
                icon = EditorGUIUtility.FindTexture("ScriptableObject Icon");
            }

            if (icon != null)
            {
                return(EditorTexture.Single(icon));
            }

            return(null);
        }
            public void Load()
            {
                graph        = typeof(FlowGraph).Icon();
                unit         = typeof(IUnit).Icon();
                flowMacro    = resources.LoadIcon("Icons/FlowMacro.png");
                unitCategory = resources.LoadIcon("Icons/UnitCategory.png");

                var portResolutions = new[] { new TextureResolution(9, 12), new TextureResolution(12, 24) };
                var portOptions     = CreateTextureOptions.PixelPerfect;

                controlPortConnected   = resources.LoadTexture("Ports/ControlPortConnected.png", portResolutions, portOptions);
                controlPortUnconnected = resources.LoadTexture("Ports/ControlPortUnconnected.png", portResolutions, portOptions);
                valuePortConnected     = resources.LoadTexture("Ports/ValuePortConnected.png", portResolutions, portOptions);
                valuePortUnconnected   = resources.LoadTexture("Ports/ValuePortUnconnected.png", portResolutions, portOptions);
                invalidPortConnected   = resources.LoadTexture("Ports/InvalidPortConnected.png", portResolutions, portOptions);
                invalidPortUnconnected = resources.LoadTexture("Ports/InvalidPortUnconnected.png", portResolutions, portOptions);

                coroutine = resources.LoadIcon("Icons/Coroutine.png");
            }
Exemple #10
0
            public EditorTexture UnitCategory(UnitCategory category)
            {
                if (category == null)
                {
                    return(unitCategory);
                }

                if (!unitCategoryIcons.ContainsKey(category))
                {
                    var path = $"{category.name}.png";

                    EditorTexture editorTexture = LoadSharedIcon(path, false);

                    if (editorTexture == null)
                    {
                        editorTexture = unitCategory;
                    }

                    unitCategoryIcons.Add(category, editorTexture);
                }

                return(unitCategoryIcons[category]);
            }
Exemple #11
0
        private static EditorTexture GetScriptTypeIcon(string scriptName)
        {
            var scriptObject = (UnityObject)EditorGUIUtility_GetScriptObjectFromClass.Invoke(null, new object[] { scriptName });

            if (scriptObject != null)
            {
                var scriptIcon = (Texture2D)EditorGUIUtility_GetIconForObject.Invoke(null, new object[] { scriptObject });

                if (scriptIcon != null)
                {
                    return(EditorTexture.Single(scriptIcon));
                }
            }

            var scriptPath = AssetDatabase.GetAssetPath(scriptObject);

            if (scriptPath != null)
            {
                switch (Path.GetExtension(scriptPath))
                {
                case ".js":

                    return(EditorTexture.Single((Texture2D)EditorGUIUtility.IconContent("js Script Icon").image));

                case ".cs":

                    return(EditorTexture.Single((Texture2D)EditorGUIUtility.IconContent("cs Script Icon").image));

                case ".boo":

                    return(EditorTexture.Single((Texture2D)EditorGUIUtility.IconContent("boo Script Icon").image));
                }
            }

            return(null);
        }
            static Styles()
            {
                coordinatesLabel = new GUIStyle(EditorStyles.label);
                coordinatesLabel.normal.textColor  = majorGridColor;
                coordinatesLabel.fontSize          = 9;
                coordinatesLabel.normal.background = new Color(0.36f, 0.36f, 0.36f).GetPixel();
                coordinatesLabel.padding           = new RectOffset(4, 4, 4, 4);

                var nodeColorComparer = new NodeColorComparer();

                squares = new Dictionary <NodeColor, GUIStyle>(nodeColorComparer);
                hexes   = new Dictionary <NodeColor, GUIStyle>(nodeColorComparer);

                foreach (var nodeColor in nodeColors)
                {
                    var squareOff = (GUIStyle)($"flow node {(int)nodeColor}");
                    var squareOn  = (GUIStyle)($"flow node {(int)nodeColor} on");
                    var hexOff    = (GUIStyle)($"flow node hex {(int)nodeColor}");
                    var hexOn     = (GUIStyle)($"flow node hex {(int)nodeColor} on");

                    // For node styles:
                    //  - Border: 9-slice coordinates
                    //  - Padding: inner spacing from edge
                    //  - Margin: shadow / glow outside edge
                    TextureResolution[] textureResolution = { 2 };
                    var createTextureOptions = CreateTextureOptions.Scalable;

                    string path = "NodeFill";

                    EditorTexture normalTexture  = BoltCore.Resources.LoadTexture($"{path}{nodeColor}.png", textureResolution, createTextureOptions);
                    EditorTexture activeTexture  = BoltCore.Resources.LoadTexture($"{path}{nodeColor}Active.png", textureResolution, createTextureOptions);
                    EditorTexture hoverTexture   = BoltCore.Resources.LoadTexture($"{path}{nodeColor}Hover.png", textureResolution, createTextureOptions);
                    EditorTexture focusedTexture = BoltCore.Resources.LoadTexture($"{path}{nodeColor}Focused.png", textureResolution, createTextureOptions);

                    var square = new GUIStyle
                    {
                        border  = squareOff.border.Clone(),
                        margin  = new RectOffset(3, 3, 6, 9),
                        padding = new RectOffset(5, 5, 6, 6),

                        normal  = { background = normalTexture.Single() },
                        active  = { background = activeTexture.Single() },
                        hover   = { background = hoverTexture.Single() },
                        focused = { background = focusedTexture.Single() }
                    };
                    squares.Add(nodeColor, square);

                    var hex = new GUIStyle
                    {
                        border  = new RectOffset(25, 25, 23, 23),
                        margin  = new RectOffset(6, 6, 5, 7),
                        padding = new RectOffset(17, 17, 10, 10),
                        normal  = { background = hexOff.normal.background },
                        active  = { background = hexOff.normal.background },
                        hover   = { background = hexOff.normal.background },
                        focused = { background = hexOn.normal.background }
                    };
                    hexes.Add(nodeColor, hex);
                }

                var arrowResolutions = new TextureResolution[] { 32 };
                var arrowOptions     = CreateTextureOptions.Scalable;

                arrowUp    = BoltCore.Resources.LoadTexture("ArrowUp.png", arrowResolutions, arrowOptions, false);
                arrowDown  = BoltCore.Resources.LoadTexture("ArrowDown.png", arrowResolutions, arrowOptions, false);
                arrowLeft  = BoltCore.Resources.LoadTexture("ArrowLeft.png", arrowResolutions, arrowOptions, false);
                arrowRight = BoltCore.Resources.LoadTexture("ArrowRight.png", arrowResolutions, arrowOptions, false);

                lockIcon = new GUIContent(LudiqGUIUtility.newSkin ? ((GUIStyle)"IN ThumbnailSelection").onActive.background : ((GUIStyle)"Icon.Locked").onNormal.background);

                if (EditorGUIUtility.isProSkin)
                {
                    majorGridColor = new Color(0, 0, 0, majorGridColor.a * 1.5f);
                    minorGridColor = new Color(0, 0, 0, minorGridColor.a * 1.5f);
                }

                dragAndDropPreviewBackground         = new GUIStyle("TE NodeBox");
                dragAndDropPreviewBackground.margin  = new RectOffset(0, 0, 0, 0);
                dragAndDropPreviewBackground.padding = new RectOffset(6, 8, 4, 8);

                dragAndDropPreviewText                  = new GUIStyle();
                dragAndDropPreviewText.fontSize         = 11;
                dragAndDropPreviewText.normal.textColor = ColorPalette.unityForeground;
                dragAndDropPreviewText.imagePosition    = ImagePosition.TextOnly;
            }
 public static void DrawDragAndDropPreviewLabel(Vector2 position, string content, EditorTexture icon)
 {
     DrawDragAndDropPreviewLabel(position, new GUIContent(content, icon?[IconSize.Small]));
 }
Exemple #14
0
 public EditorTexture LoadIcon(string path, bool required = true)
 {
     return(EditorTexture.Load(providers, path, EditorTexture.StandardIconResolutions, CreateTextureOptions.PixelPerfect, required));
 }
Exemple #15
0
 public EditorTexture LoadTexture(string path, TextureResolution[] resolutions, CreateTextureOptions options, bool required = true)
 {
     return(EditorTexture.Load(providers, path, resolutions, options, required));
 }
Exemple #16
0
        private void OnGUI()
        {
            EditorGUI.BeginDisabledGroup(EditorApplication.isCompiling);

            scroll = GUILayout.BeginScrollView(scroll);

            LudiqGUI.BeginHorizontal();
            LudiqGUI.BeginVertical();

            foreach (var configuration in configurations)
            {
                if (configuration.Any(i => i.visible))
                {
                    if (configurations.Count > 1)
                    {
                        Header(configuration.header.Replace(label + " ", ""));
                    }

                    EditorGUI.BeginChangeCheck();

                    using (Inspector.expandTooltip.Override(true))
                    {
                        foreach (var item in configuration.Where(i => i.visible))
                        {
                            LudiqGUI.Space(2);

                            LudiqGUI.BeginHorizontal();

                            LudiqGUI.Space(4);

                            var iconPosition = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Width(Styles.iconSize), GUILayout.Height(Styles.iconSize), GUILayout.ExpandHeight(false), GUILayout.ExpandWidth(false));

                            EditorTexture icon    = null;
                            string        tooltip = null;

                            if (item is ProjectSettingMetadata)
                            {
                                icon    = BoltCore.Icons.projectSetting;
                                tooltip = "Project Setting: Shared across users, local to this project. Included in version control.";
                            }
                            else if (item is EditorPrefMetadata)
                            {
                                icon    = BoltCore.Icons.editorPref;
                                tooltip = "Editor Pref: Local to this user, shared across projects. Excluded from version control.";
                            }

                            if (icon != null)
                            {
                                using (LudiqGUI.color.Override(GUI.color.WithAlpha(0.6f)))
                                {
                                    GUI.Label(iconPosition, new GUIContent(icon[Styles.iconSize], tooltip), GUIStyle.none);
                                }
                            }

                            LudiqGUI.Space(6);

                            LudiqGUI.BeginVertical();

                            LudiqGUI.Space(-3);

                            LudiqGUI.InspectorLayout(item);

                            LudiqGUI.EndVertical();

                            LudiqGUI.EndHorizontal();
                        }
                    }

                    if (EditorGUI.EndChangeCheck())
                    {
                        configuration.Save();
                        InternalEditorUtility.RepaintAllViews();
                    }
                }
            }

            LudiqGUI.Space(8);

            if (GUILayout.Button("Reset to Defaults"))
            {
                if (EditorUtility.DisplayDialog("Reset to Defaults", "Are you sure you want to reset your preferences and project settings to default?", "Reset"))
                {
                    foreach (var configuration in configurations)
                    {
                        configuration.Reset();
                        configuration.Save();
                    }

                    InternalEditorUtility.RepaintAllViews();
                }
            }

            LudiqGUI.Space(8);
            LudiqGUI.EndVertical();
            LudiqGUI.Space(8);
            LudiqGUI.EndHorizontal();
            GUILayout.EndScrollView();
            EditorGUI.EndDisabledGroup();
        }
Exemple #17
0
 public Root(GUIContent header)
 {
     label = header.text;
     icon  = EditorTexture.Single(header.image);
 }