internal void AddAPIKey(string apiKey)
    {
        XmlNode newMetadata = this.CreateNode(XmlNodeType.Element, "meta-data", null);

        var          settings = FritzConfiguration.GetSerializedSettings();
        XmlAttribute nameAttr = CreateAndroidAttribute("name", "fritz_api_key");
        XmlAttribute valAttr  = CreateAndroidAttribute("value", apiKey);

        newMetadata.Attributes.Append(nameAttr);
        newMetadata.Attributes.Append(valAttr);

        ApplicationElement.AppendChild(newMetadata);
    }
    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        // If needed, add condition checks on whether you need to run the modification routine.
        // For example, specific configuration/app options enabled

        var androidManifest = new AndroidManifest(GetManifestPath(basePath));

        FritzConfiguration config = FritzConfiguration.GetOrCreateSettings();

        androidManifest.AddAPIKey(config.androidAPIKey);

        // Add your XML manipulation routines

        androidManifest.Save();
    }
示例#3
0
    public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath)
    {
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }

        string sourcePath   = "Runtime/iOS/Source/";
        string sourceFolder = Path.Combine(PACKAGE_PATH, sourcePath);
        string libraryPath  = "Libraries/ai.fritz.vision/Runtime/iOS/Source/";
        string plistPath    = Path.Combine(sourceFolder, "Fritz-Info.plist");
        string xcodePath    = Path.Combine(buildPath, libraryPath, "Fritz-Info.plist");

        PlistDocument plist = new PlistDocument();

        plist.ReadFromFile(plistPath);

        // TODO: Pull out API Key specification here, until then, set configuration in Source/Fritz-Info.plist file.
        FritzConfiguration config = FritzConfiguration.GetOrCreateSettings();

        plist.root.SetString("apiKey", config.iOSAPIKey);
        File.WriteAllText(xcodePath, plist.WriteToString());

        var projPath = buildPath + "/Unity-Iphone.xcodeproj/project.pbxproj";
        var proj     = new PBXProject();

        proj.ReadFromFile(projPath);

        var targetGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName());

        string plistGuid = proj.AddFile(xcodePath, Path.Combine(libraryPath, "Fritz-Info.plist"));

        proj.AddFileToBuild(targetGuid, plistGuid);

        proj.WriteToFile(projPath);

        // Update Info with Camera usage description
        string        infoPath  = Path.Combine(buildPath, "Info.plist");
        PlistDocument infoPlist = new PlistDocument();

        infoPlist.ReadFromFile(infoPath);
        infoPlist.root.SetString("NSCameraUsageDescription", "For ML Camera Usage");
        File.WriteAllText(infoPath, infoPlist.WriteToString());
    }
示例#4
0
    public static SettingsProvider CreateFritzConfigProvider()
    {
        // First parameter is the path in the Settings window.
        // Second parameter is the scope of this setting: it only appears in the Project Settings window.
        var provider = new SettingsProvider("Project/Fritz", SettingsScope.Project)
        {
            // By default the last token of the path is used as display name if no label is provided.
            label = "Fritz",

            // Create the SettingsProvider and initialize its drawing (IMGUI) function in place:
            guiHandler = (searchContext) =>
            {
                var settings = FritzConfiguration.GetSerializedSettings();

                EditorGUILayout.HelpBox(apiKeyMessage, MessageType.Info);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Register", GUILayout.Width(smallButtonSize)))
                {
                    Application.OpenURL(fritzSignup);
                }
                if (GUILayout.Button("Login", GUILayout.Width(smallButtonSize)))
                {
                    Application.OpenURL(fritzLogin);
                }
                GUILayout.EndHorizontal();

                EditorGUILayout.LabelField("iOS", EditorStyles.boldLabel);

                string bundleID = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS);
                EditorGUILayout.LabelField("iOS Bundle ID", bundleID);
                EditorGUILayout.PropertyField(settings.FindProperty("iOSAPIKey"), new GUIContent("Fritz iOS API Key"));

                EditorGUILayout.PropertyField(settings.FindProperty("sdkVersion"), new GUIContent("SDK Version"));

                if (GUILayout.Button("Download", GUILayout.Width(mediumButtonSize)))
                {
                    var sdkVersion = settings.FindProperty("sdkVersion").stringValue;
                    var download   = new DownloadFramework(sdkVersion);
                    download.Download();
                }

                var property = settings.FindProperty("frameworks");
                for (int i = 0; i < property.arraySize; i++)
                {
                    var element = property.GetArrayElementAtIndex(i);
                    EditorGUILayout.PropertyField(element);
                }

                // Android Section
                EditorGUILayout.LabelField("Android", EditorStyles.boldLabel);

                string packageId = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.Android);
                EditorGUILayout.LabelField("Android Application ID", packageId);
                EditorGUILayout.PropertyField(settings.FindProperty("androidAPIKey"), new GUIContent("Fritz Android API Key"));

                settings.ApplyModifiedProperties();
            },

            // Populate the search keywords to enable smart search filtering and label highlighting:
            keywords = new HashSet <string>(new[] { "Pose", "Fritz" })
        };

        return(provider);
    }