Exemplo n.º 1
0
        // Adds a new platform group to the set of platforms.
        public void AddPlatformGroup(string displayName)
        {
            PlatformGroup group = PlatformGroup.Create(displayName, Legacy.Platform.None);

            Platforms.Add(group.Identifier, group);
            AssetDatabase.AddObjectToAsset(group, this);

            LinkPlatform(group);
        }
Exemplo n.º 2
0
        public static PlatformGroup Create(string displayName, Legacy.Platform legacyIdentifier)
        {
            PlatformGroup group = CreateInstance <PlatformGroup>();

            group.Identifier       = GUID.Generate().ToString();
            group.displayName      = displayName;
            group.legacyIdentifier = legacyIdentifier;
            group.AffirmProperties();

            return(group);
        }
Exemplo n.º 3
0
        // Adds a new platform group to the set of platforms.
        public PlatformGroup AddPlatformGroup(string displayName, int sortOrder)
        {
            PlatformGroup group = PlatformGroup.Create(displayName, Legacy.Platform.None);

            group.DisplaySortOrder = sortOrder;

            RuntimeSettings.AddPlatform(group);
            AssetDatabase.AddObjectToAsset(group, RuntimeSettings);

            RuntimeSettings.LinkPlatform(group);

            return(group);
        }
Exemplo n.º 4
0
        // Removes a platform from the inheritance hierarchy and clears its properties, thus hiding
        // it in the UI. Also destroys the platform if it is a group.
        public void RemovePlatformProperties(Platform platform)
        {
            while (platform.Children.Count > 0)
            {
                platform.Children[platform.Children.Count - 1].Parent = platform.Parent;
            }

            if (platform is PlatformGroup)
            {
                PlatformGroup group = platform as PlatformGroup;

                group.Parent = null;
                Platforms.Remove(group.Identifier);
                DestroyImmediate(group, true);
            }
            else
            {
                platform.ClearProperties();
                platform.Parent = defaultPlatform;
            }
        }
Exemplo n.º 5
0
        // Adds any missing platforms:
        // * From the template collection
        // * From the legacy settings
        private void AddMissingPlatforms()
        {
            var newPlatforms = new List <Platform>();

            foreach (PlatformTemplate template in platformTemplates)
            {
                if (!Platforms.ContainsKey(template.Identifier))
                {
                    newPlatforms.Add(template.CreateInstance());
                }
            }

            // Ensure that the default platform exists
            if (!defaultPlatform)
            {
                defaultPlatform = CreateInstance <PlatformDefault>();
                newPlatforms.Add(defaultPlatform);
            }

            // Ensure that the Play In Editor platform exists
            if (!playInEditorPlatform)
            {
                playInEditorPlatform = CreateInstance <PlatformPlayInEditor>();
                newPlatforms.Add(playInEditorPlatform);
            }

            // Ensure that the default and Play In Editor platforms have properties
            AffirmPlatformProperties(defaultPlatform);
            AffirmPlatformProperties(playInEditorPlatform);

            // Migrate plugins if necessary
            var PluginsProperty = Platform.PropertyAccessors.Plugins;

            if (!MigratedPlatforms.Contains(defaultPlatform.LegacyIdentifier))
            {
                PluginsProperty.Set(defaultPlatform, Plugins);
            }
            else if (!PluginsProperty.HasValue(defaultPlatform))
            {
                PluginsProperty.Set(defaultPlatform, new List <string>());
            }

            // Migrate LiveUpdatePort
            if (!Platform.PropertyAccessors.LiveUpdatePort.HasValue(defaultPlatform))
            {
                Platform.PropertyAccessors.LiveUpdatePort.Set(defaultPlatform, LiveUpdatePort);
            }

            // Create a map for migrating legacy settings
            var platformMap = new Dictionary <Legacy.Platform, Platform>();

            foreach (Platform platform in Platforms.Values.Concat(newPlatforms))
            {
                if (platform.LegacyIdentifier != Legacy.Platform.None)
                {
                    platformMap.Add(platform.LegacyIdentifier, platform);
                }
            }

            Func <Legacy.Platform, Platform> AffirmPlatform = null;

            // Ensures that all of the platform's ancestors exist.
            Action <Platform> AffirmAncestors = (platform) =>
            {
                Legacy.Platform legacyParent = Legacy.Parent(platform.LegacyIdentifier);

                if (legacyParent != Legacy.Platform.None)
                {
                    platform.ParentIdentifier = AffirmPlatform(legacyParent).Identifier;
                }
            };

            // Gets the platform corresponding to legacyPlatform (or creates it if it is a group),
            // and ensures that it has properties and all of its ancestors exist.
            // Returns null if legacyPlatform is unknown.
            AffirmPlatform = (legacyPlatform) =>
            {
                Platform platform;

                if (platformMap.TryGetValue(legacyPlatform, out platform))
                {
                    platform.AffirmProperties();
                }
                else if (Legacy.IsGroup(legacyPlatform))
                {
                    PlatformGroup group = PlatformGroup.Create(Legacy.DisplayName(legacyPlatform), legacyPlatform);
                    platformMap.Add(legacyPlatform, group);
                    newPlatforms.Add(group);

                    platform = group;
                }
                else
                {
                    // This is an unknown platform
                    return(null);
                }

                AffirmAncestors(platform);

                return(platform);
            };

            // Gets the target plaform to use when migrating settings from legacyPlatform.
            // Returns null if legacyPlatform is unknown or has already been migrated.
            Func <Legacy.Platform, Platform> getMigrationTarget = (legacyPlatform) =>
            {
                if (MigratedPlatforms.Contains(legacyPlatform))
                {
                    // Already migrated
                    return(null);
                }

                return(AffirmPlatform(legacyPlatform));
            };

            var speakerModeSettings = SpeakerModeSettings.ConvertAll(
                setting => new Legacy.PlatformSetting <FMOD.SPEAKERMODE>()
            {
                Value    = (FMOD.SPEAKERMODE)setting.Value,
                Platform = setting.Platform
            }
                );

            // Migrate all the legacy settings, creating platforms as we need them via AffirmPlatform
            MigrateLegacyPlatforms(speakerModeSettings, Platform.PropertyAccessors.SpeakerMode, getMigrationTarget);
            MigrateLegacyPlatforms(SampleRateSettings, Platform.PropertyAccessors.SampleRate, getMigrationTarget);
            MigrateLegacyPlatforms(LiveUpdateSettings, Platform.PropertyAccessors.LiveUpdate, getMigrationTarget);
            MigrateLegacyPlatforms(OverlaySettings, Platform.PropertyAccessors.Overlay, getMigrationTarget);
            MigrateLegacyPlatforms(BankDirectorySettings, Platform.PropertyAccessors.BuildDirectory, getMigrationTarget);
            MigrateLegacyPlatforms(VirtualChannelSettings, Platform.PropertyAccessors.VirtualChannelCount, getMigrationTarget);
            MigrateLegacyPlatforms(RealChannelSettings, Platform.PropertyAccessors.RealChannelCount, getMigrationTarget);

            // Now we ensure that if a legacy group has settings, all of its descendants exist
            // and inherit from it (even if they have no settings of their own), so that the
            // inheritance structure matches the old system.
            // We look at all groups (not just newly created ones), because a newly created platform
            // may need to inherit from a preexisting group.
            var groupsToProcess = new Queue <Platform>(platformMap.Values.Where(
                                                           platform => platform is PlatformGroup &&
                                                           platform.LegacyIdentifier != Legacy.Platform.None &&
                                                           platform.HasAnyOverriddenProperties));

            while (groupsToProcess.Count > 0)
            {
                Platform group = groupsToProcess.Dequeue();

                // Ensure that all descendants exist
                foreach (var child in platformMap.Values)
                {
                    if (child.Active)
                    {
                        // Don't overwrite existing settings
                        continue;
                    }

                    var legacyPlatform = child.LegacyIdentifier;

                    if (legacyPlatform == Legacy.Platform.iOS || legacyPlatform == Legacy.Platform.Android)
                    {
                        // These platforms were overridden by MobileHigh and MobileLow in the old system
                        continue;
                    }

                    if (MigratedPlatforms.Contains(legacyPlatform))
                    {
                        // The user may have deleted this platform since migration, so don't mess with it
                        continue;
                    }

                    if (Legacy.Parent(legacyPlatform) == group.LegacyIdentifier)
                    {
                        child.AffirmProperties();
                        child.ParentIdentifier = group.Identifier;

                        if (child is PlatformGroup)
                        {
                            groupsToProcess.Enqueue(child as PlatformGroup);
                        }
                    }
                }
            }

            // Add all of the new platforms to the set of known platforms
            foreach (Platform platform in newPlatforms)
            {
                Platforms.Add(platform.Identifier, platform);
            }

            UpdateMigratedPlatforms();
        }
Exemplo n.º 6
0
        private void DisplayPlatform(Platform platform)
        {
            if (!platform.Active)
            {
                return;
            }

            var label = new System.Text.StringBuilder();

            label.AppendFormat("<b>{0}</b>", platform.DisplayName);

            if (!platform.IsIntrinsic && platform.Children.Count > 0)
            {
                IEnumerable <string> children = platform.Children
                                                .Where(child => child.Active)
                                                .Select(child => child.DisplayName);

                if (children.Any())
                {
                    label.Append(" (");
                    label.Append(string.Join(", ", children.ToArray()));
                    label.Append(")");
                }
            }

            EditorGUILayout.BeginHorizontal();

            bool expand = true;

            if (platform.IsIntrinsic)
            {
                GUIStyle style = new GUIStyle(GUI.skin.label);
                style.richText = true;

                EditorGUILayout.LabelField(label.ToString(), style);
            }
            else
            {
                expand = false;

                if (expandPlatform.ContainsKey(platform.Identifier))
                {
                    expand = expandPlatform[platform.Identifier];
                }

                GUIStyle style = new GUIStyle(GUI.skin.FindStyle("Foldout"));
                style.richText = true;

                expand = EditorGUILayout.Foldout(expand, new GUIContent(label.ToString()), style);

                expandPlatform[platform.Identifier] = expand;

                if (GUILayout.Button("Delete", GUILayout.ExpandWidth(false)))
                {
                    // This avoids modifying the parent platform's children list while we're iterating over it
                    pendingPlatformDelete = platform;
                }
            }

            EditorGUILayout.EndHorizontal();

            if (expand)
            {
                Settings settings = target as Settings;

                EditorGUI.indentLevel++;

                PlatformGroup group = platform as PlatformGroup;

                if (group != null)
                {
                    group.displayName = EditorGUILayout.DelayedTextField("Name", group.displayName);
                }

                DisplayPlatformParent(platform);

                DisplayTriStateBool("Live Update", platform, Platform.PropertyAccessors.LiveUpdate);

                if (platform.IsLiveUpdateEnabled)
                {
                    if (platform.IsIntrinsic)
                    {
                        EditorGUILayout.BeginHorizontal();
                        settings.LiveUpdatePort = ushort.Parse(EditorGUILayout.TextField("Live Update Port", settings.LiveUpdatePort.ToString()));
                        if (GUILayout.Button("Reset", GUILayout.ExpandWidth(false)))
                        {
                            settings.LiveUpdatePort = 9264;
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    else
                    {
                        GUIStyle style = new GUIStyle(GUI.skin.label);
                        style.richText = true;

                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.PrefixLabel(" ");
                        GUILayout.Label(string.Format("Live update will listen on port <b>{0}</b>", settings.LiveUpdatePort), style);
                        EditorGUILayout.EndHorizontal();
                    }
                }

                DisplayTriStateBool("Debug Overlay", platform, Platform.PropertyAccessors.Overlay);
                DisplaySampleRate("Sample Rate", platform);

                if (settings.HasPlatforms)
                {
                    bool prevChanged = GUI.changed;
                    DisplayBuildDirectory("Bank Platform", platform);
                    hasBankSourceChanged |= !prevChanged && GUI.changed;

                    DisplaySpeakerMode("Speaker Mode", platform);
                }

                if (!(platform is PlatformPlayInEditor))
                {
                    DisplayInt("Virtual Channel Count", platform, Platform.PropertyAccessors.VirtualChannelCount, 1, 2048);
                    DisplayInt("Real Channel Count", platform, Platform.PropertyAccessors.RealChannelCount, 1, 256);
                    DisplayPlugins(platform);
                }

                if (!platform.IsIntrinsic)
                {
                    foreach (Platform child in platform.Children)
                    {
                        DisplayPlatform(child);
                    }
                }

                EditorGUI.indentLevel--;
            }
        }