Example #1
0
        public static void RenderManifest(MagicLeapManifestSettings settings)
        {
            var serializedObject = settings.ToSerializedObject();

            serializedObject.UpdateIfRequiredOrScript();
            var id         = GUIUtility.GetControlID(FocusType.Passive);
            var state      = (RenderState)GUIUtility.GetStateObject(typeof(RenderState), id);
            var missingSdk = !SDKUtility.sdkAvailable;

            if (missingSdk)
            {
                EditorGUILayout.HelpBox(Messages.kCannotLocateSDK, MessageType.Error, true);
            }
            using (new EditorGUI.DisabledScope(missingSdk))
            {
                var apiLevel = serializedObject.FindProperty("m_MinimumAPILevel");
                apiLevel.intValue = PlatformLevelSelector.SelectorGUI(apiLevel.intValue);
                EditorGUILayout.LabelField("Privileges", EditorStyles.boldLabel);
                var priv_groups = serializedObject.FindProperty("m_PrivilegeGroups");
                for (int i = 0; i < priv_groups.arraySize; i++)
                {
                    var group      = priv_groups.GetArrayElementAtIndex(i);
                    var group_name = group.FindPropertyRelative("m_Name").stringValue;
                    if (!state.GroupFoldoutExpanded.TryGetValue(group_name, out var _))
                    {
                        state.GroupFoldoutExpanded[group_name] = false;
                    }
                    state.GroupFoldoutExpanded[group_name] = EditorGUILayout.BeginFoldoutHeaderGroup(state.GroupFoldoutExpanded[group_name], group_name);
                    if (state.GroupFoldoutExpanded[group_name])
                    {
                        var privs = group.FindPropertyRelative("m_Privileges");
                        for (int j = 0; j < privs.arraySize; j++)
                        {
                            var priv    = privs.GetArrayElementAtIndex(j);
                            var enabled = priv.FindPropertyRelative("m_Enabled");
                            var name    = priv.FindPropertyRelative("m_Name").stringValue;

                            var disabled = ShouldDisable(apiLevel.intValue, priv);
                            var value    = UpdateValue(name, enabled.boolValue, disabled);
                            using (new EditorGUI.DisabledScope(disabled))
                                using (new EditorGUI.IndentLevelScope())
                                    enabled.boolValue = EditorGUILayout.ToggleLeft(name, value);
                        }
                    }
                    EditorGUILayout.EndFoldoutHeaderGroup();
                }
                serializedObject.ApplyModifiedProperties();
                GUILayout.FlexibleSpace();
                EditorGUILayout.HelpBox(Messages.kShouldSynchronize, MessageType.Info, true);
                var sdkUpdateRequested = GUILayout.Button("Synchronize");
                if (sdkUpdateRequested)
                {
                    state.IsPerformingSDKUpdate  = true;
                    EditorApplication.delayCall += () => {
                        settings.RebuildPrivilegeGroups(PrivilegeParser.ParsePrivilegesFromHeader(Path.Combine(SDKUtility.sdkPath, PrivilegeParser.kPrivilegeHeaderPath)));
                        state.IsPerformingSDKUpdate = false;
                    };
                }
            }
        }
Example #2
0
        public static SettingsProvider CreateSettingsProvider()
        {
            // First parameter is the path in the Settings window.
            // Second parameter is the scope of this setting: it only appears in the Settings window for the Project scope.
            var provider = new SettingsProvider("MagicLeap/", SettingsScope.Project)
            {
                label      = "Manifest Settings",
                guiHandler = (searchContext) =>
                {
                    var settings = MagicLeapManifestSettings.GetOrCreateSettings();
                    ManifestEditorGUI.RenderManifest(settings);
                },
                // Populate the search keywords to enable smart search filtering and label highlighting:
                keywords = new HashSet <string>(new[] { "MagicLeap", "Manifest" })
            };

            return(provider);
        }
Example #3
0
        public static SettingsProvider CreateSettingsProvider()
        {
            // First parameter is the path in the Settings window.
            // Second parameter is the scope of this setting: it only appears in the Settings window for the Project scope.
            var provider = new SettingsProvider("MagicLeap/", SettingsScope.Project)
            {
                label = "Manifest Settings",
                // activateHandler is called when the user clicks on the Settings item in the Settings window.
                activateHandler = (searchContext, rootElement) =>
                {
                    rootElement.Add(new ManifestEditor {
                        settingsAsset = MagicLeapManifestSettings.GetOrCreateSettings()
                    });
                },
                // Populate the search keywords to enable smart search filtering and label highlighting:
                keywords = new HashSet <string>(new[] { "Number", "Some String" })
            };

            return(provider);
        }
 void OnEnable()
 {
     rootVisualElement.Add(new ManifestEditor {
         settingsAsset = MagicLeapManifestSettings.GetOrCreateSettings()
     });
 }
        private void MergeToCustomManifest(MagicLeapManifestSettings ctx, string path)
        {
            try
            {
                XDocument customManifest = GetManifestTemplate();
                customManifest.Declaration = new XDeclaration("1.0", "utf-8", null);

                // Find "manifest, ml:package" attribute and set to PlayerSettings.applicationIdentifier
                XElement manifestElement = customManifest.Element("manifest");
                if (manifestElement != null)
                {
                    manifestElement.SetAttributeValue(kML + "package", PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.Lumin));
                    manifestElement.SetAttributeValue(kML + "version_code", PlayerSettings.Lumin.versionCode);
                    manifestElement.SetAttributeValue(kML + "version_name", PlayerSettings.Lumin.versionName);
                }

                // Find "application, ml:visible_name" attribute and set to PlayerSettings.productName
                XElement applicationElement = (from node in customManifest.Descendants("application")
                                               select node).SingleOrDefault();
                if (applicationElement != null)
                {
                    applicationElement.SetAttributeValue(kML + "visible_name", PlayerSettings.productName);

                    XAttribute minAPILevelAttribute = applicationElement.Attribute(kML + kMinAPILevelAttributeName);

                    // When the minimum API level is not specified, it is assumed to be 1 by the package manager.
                    if (minAPILevelAttribute == null)
                    {
                        applicationElement.SetAttributeValue(kML + kMinAPILevelAttributeName, ctx.minimumAPILevel);
                    }
                    else
                    {
                        minAPILevelAttribute.Value = ctx.minimumAPILevel.ToString();
                    }
                }

                // Find "component, ml:visible_name" attribute and set to PlayerSettings.productName
                // Find "component, ml:binary_name" attribute and set to "bin/Player.elf"
                IEnumerable <XElement> componentElements = from node in customManifest.Descendants("component")
                                                           where (string)node.Attribute(kML + "name") == ".fullscreen"
                                                           select node;

                if (Enumerable.Count(componentElements) > 1)
                {
                    Debug.LogError("Custom Manifest contained more than one component with name \".fullscreen\". Only one .fullscreen component is allowed.");
                    throw new System.Exception();
                }

                XElement componentElement = componentElements.FirstOrDefault();

                if (componentElement != null)
                {
                    componentElement.SetAttributeValue(kML + "name", ".fullscreen");
                    componentElement.SetAttributeValue(kML + "visible_name", PlayerSettings.productName);
                    componentElement.SetAttributeValue(kML + "binary_name", "bin/Player.elf");
                    componentElement.SetAttributeValue(kML + "type", PlayerSettings.Lumin.isChannelApp ? "ScreensImmersive" : "Fullscreen");

                    // Find "icon, model_folder" and set to "Icon/Model"
                    // Find or Add "icon, portal_folder" and set to "Icon/Portal"
                    XElement iconElement = (from node in componentElement.Descendants("icon")
                                            select node).SingleOrDefault();
                    if (iconElement != null)
                    {
                        iconElement.SetAttributeValue(kML + "model_folder", "Icon/Model");
                        iconElement.SetAttributeValue(kML + "portal_folder", "Icon/Portal");
                    }
                }

                SetPrivileges(applicationElement, ctx.requiredPermissions.ToArray());

                var dir = Path.GetDirectoryName(path);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                customManifest.Save(path);
            }
            catch (System.Exception e)
            {
                throw new Exception(kManifestFailureError, e);
            }
        }