/// --------------------------------------------- /// Behavior Designer /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.BehaviorDesigner.Editor.Managers { using Opsive.Shared.Editor.Managers; using UnityEditor; using UnityEngine.UIElements; /// /// Shows a starting window with useful links. /// [OrderedEditorItem("Welcome", 0)] public class WelcomeScreenManager : Opsive.Shared.Editor.Managers.WelcomeScreenManager { private const string c_GraphDesignerSymbol = "GRAPH_DESIGNER"; private const string c_EditorTextureGUID = "d52eae9187aad5b41aff6dd60e49247a"; private const string c_RepositoryTextureGUID = "020153b61b65cf34f82ccc9b186cb700"; private VisualElement m_EntityHelpBoxContainer; /// /// The name of the asset. /// protected override string AssetName => AssetInfo.Name; /// /// The version of the asset. /// protected override string AssetVersion => AssetInfo.Version; /// /// Should the large documentation image be added? /// protected override bool AddLargeDocumentationImage => false; /// /// Returns the URL for the documentation page. /// /// The URL for the documentation page. protected override string GetDocumentationURL() { return "https://opsive.com/support/documentation/behavior-designer-pro/"; } /// /// Returns the URL for the videos page. /// /// The URL for the videos page. protected override string GetVideosURL() { return "https://opsive.com/videos?pid=28276"; } /// /// Returns the URL for the asset page. /// /// The URL for the asset page. protected override string GetAssetURL() { return "https://assetstore.unity.com/packages/slug/298743"; } /// /// Checks to ensure the required packages are installed. /// /// The parent VisualElement. protected override void AddHeader(VisualElement parent) { EditorApplication.update += CheckForEntities; #if !UNITY_ENTITIES m_EntityHelpBoxContainer = ManagerUtility.AddHelpBox(parent, "Behavior Designer requires the Entities package. Press the button below to install.", HelpBoxMessageType.Error, "Install", (HelpBox helpbox, Button actionButton) => { helpbox.text = "Installing the entities package. Unity will reimport after the package has been installed.\n\n" + "Restart Unity if you receive compiler errors after Unity has reimported.\n\n" + "Behavior Designer can be access from the Tools/Opsive/Behavior Designer/Editor menu."; helpbox.messageType = HelpBoxMessageType.Info; actionButton.SetEnabled(false); m_WelcomeLabel.style.display = DisplayStyle.None; UnityEditor.PackageManager.Client.Add("com.unity.entities"); }); m_WelcomeLabel.style.display = DisplayStyle.None; #else base.AddHeader(parent); #endif } /// /// Checks for the Entity package installation. /// private void CheckForEntities() { #if !GRAPH_DESIGNER && UNITY_ENTITIES AddSymbol(c_GraphDesignerSymbol); EditorApplication.update -= CheckForEntities; if (m_EntityHelpBoxContainer != null) { m_EntityHelpBoxContainer.style.display = DisplayStyle.None; m_WelcomeLabel.style.display = DisplayStyle.Flex; } #elif GRAPH_DESIGNER if (m_EntityHelpBoxContainer != null) { m_EntityHelpBoxContainer.style.display = DisplayStyle.None; m_WelcomeLabel.style.display = DisplayStyle.Flex; } #endif } /// /// Adds the specified symbol to the compiler definitions. /// /// The symbol to add. private static void AddSymbol(string symbol) { // Set on all available build targets. var buildTargets = System.Enum.GetValues(typeof(BuildTarget)) as BuildTarget[]; foreach (var buildTarget in buildTargets) { if (buildTarget is BuildTarget.NoTarget) { continue; } var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(buildTarget); if (!BuildPipeline.IsBuildTargetSupported(buildTargetGroup, buildTarget)) { continue; } #if UNITY_2023_1_OR_NEWER var namedBuildTarget = UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup); var symbols = PlayerSettings.GetScriptingDefineSymbols(namedBuildTarget); #else var symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup); #endif if (symbols.Contains(symbol)) { continue; } symbols += (";" + symbol); #if UNITY_2023_1_OR_NEWER PlayerSettings.SetScriptingDefineSymbols(namedBuildTarget, symbols); #else PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, symbols); #endif } } /// /// Adds the resource images to the parent element. /// /// The parent that the images should be added to. protected override void AddImages(VisualElement parent) { AddLargeImage(parent, c_EditorTextureGUID, () => { #if GRAPH_DESIGNER BehaviorDesignerWindow.ShowWindow(); #else UnityEngine.Debug.LogError("Error: Unable to open the Behavior Designer window. Ensure the Entities package has been installed."); #endif }); // Documentation and Videos. AddImageRow(parent, c_SmallDocumentationTextureGUID, GetDocumentationURL(), c_VideosTextureGUID, GetVideosURL()); // Repository and Downloads. AddImageRow(parent, c_RepositoryTextureGUID, "https://opsive.com/assets/behavior-designer-pro-subscription", c_DownloadsTextureGUID, IntegrationsManager.GetDownloadsLink()); // Forum and Discord. AddImageRow(parent, c_ForumTextureGUID, "https://opsive.com/forum/", c_DiscordTextureGUID, "https://discord.gg/QX6VFgc"); // Review and Showcase. AddImageRow(parent, c_ReviewTextureGUID, GetAssetURL(), c_ShowcaseTextureGUID, "https://opsive.com/showcase/"); // Professional Services. AddImageRow(parent, c_ProfessionalServicesTextureGUID, "https://opsive.com", string.Empty, string.Empty); } } }