コード例 #1
0
        /// <summary>
        /// Finds the path of a directory relative to the project folder.
        /// </summary>
        /// <param name="directoryPathToSearch">
        /// The subtree's root path to search in.
        /// </param>
        /// <param name="directoryName">
        /// The name of the directory to search for.
        /// </param>
        internal static bool FindRelativeDirectory(string directoryPathToSearch, string directoryName, out string path)
        {
            string absolutePath;

            if (FindDirectory(directoryPathToSearch, directoryName, out absolutePath))
            {
                path = MixedRealityToolkitFiles.GetAssetDatabasePath(absolutePath);
                return(true);
            }

            path = string.Empty;
            return(false);
        }
        /// <summary>
        /// Ensure that a link.xml file exists in the MixedRealityToolkit.Generated folder.
        /// This file is used to control the Unity linker's byte code stripping of MRTK assemblies.
        /// </summary>
        public static void EnsureLinkXml()
        {
            string generatedFolder = MixedRealityToolkitFiles.MapRelativeFolderPathToAbsolutePath(MixedRealityToolkitModuleType.Generated, "");
            string linkXmlPath     = Path.Combine(generatedFolder, "link.xml");

            if (File.Exists(linkXmlPath))
            {
                bool xmlUpdated = false;

                // Update to ensure Unity's okay ignoring missing assemblies
                XmlDocument doc = new XmlDocument();
                doc.Load(linkXmlPath);

                XmlNodeList assemblyNodes = doc.SelectNodes(@"/linker/assembly");

                if (assemblyNodes != null)
                {
                    XmlAttribute newAttr = doc.CreateAttribute("ignoreIfMissing");
                    newAttr.Value = "1";

                    foreach (XmlNode assembly in assemblyNodes)
                    {
                        XmlNode fullname        = assembly.Attributes.GetNamedItem("fullname");
                        XmlNode ignoreIfMissing = assembly.Attributes.GetNamedItem("ignoreIfMissing");
                        if (ignoreIfMissing == null && fullname.InnerText.StartsWith("Microsoft.MixedReality.Toolkit"))
                        {
                            assembly.Attributes.SetNamedItem(newAttr);
                            xmlUpdated = true;
                        }
                    }
                }

                if (xmlUpdated)
                {
                    Debug.Log($"The link.xml file in {MixedRealityToolkitFiles.GetGeneratedFolder} was updated to include \"ignoreIfMissing\" tags.\n" +
                              "This is required in Unity 2021 or later for legacy XR assemblies that are no longer used and is okay if this project is on an earlier version.");
                    doc.Save(linkXmlPath);
                }

                return;
            }

            // Create a default link.xml with an initial set of assembly preservation rules.
            using (StreamWriter writer = new StreamWriter(linkXmlPath))
            {
                writer.WriteLine(defaultLinkXmlContents);
                Debug.Log($"A link.xml file was created in {MixedRealityToolkitFiles.GetGeneratedFolder}.\n" +
                          "This file is used to control preservation of MRTK code during linking. It is recommended to add link.xml (and link.xml.meta) to source control.");
            }
        }
コード例 #3
0
        /// <summary>
        /// Ensure that a link.xml file exists in the MixedRealityToolkit.Generated folder.
        /// This file is used to control the Unity linker's byte code stripping of MRTK assemblies.
        /// </summary>
        public static void EnsureLinkXml()
        {
            string generatedFolder = MixedRealityToolkitFiles.MapRelativeFolderPathToAbsolutePath(MixedRealityToolkitModuleType.Generated, "");
            string linkXmlPath     = Path.Combine(generatedFolder, "link.xml");

            if (File.Exists(linkXmlPath))
            {
                // Do not touch the existing file.
                return;
            }

            // Create a default link.xml with an initial set of assembly preservation rules.
            using (StreamWriter writer = new StreamWriter(linkXmlPath))
            {
                writer.WriteLine(defaultLinkXmlContents);
                Debug.Log($"A link.xml file was created in {MixedRealityToolkitFiles.GetGeneratedFolder}. \n" +
                          "This file is used to control preservation of MRTK code during linking. It is recommended to add link.xml (and link.xml.meta) to source control.");
            }
        }
コード例 #4
0
        private static void SetIconTheme()
        {
            if (!MixedRealityToolkitFiles.AreFoldersAvailable)
            {
                Debug.LogError("Unable to find the Mixed Reality Toolkit's directory!");
                return;
            }

            var icons     = MixedRealityToolkitFiles.GetFiles("StandardAssets/Icons");
            var icon      = new Texture2D(2, 2);
            var iconColor = new Color32(4, 165, 240, 255);

            for (int i = 0; i < icons.Length; i++)
            {
                icons[i] = icons[i].Replace("/", "\\");
                if (icons[i].Contains(".meta"))
                {
                    continue;
                }

                var imageData = File.ReadAllBytes(icons[i]);
                icon.LoadImage(imageData, false);

                var pixels = icon.GetPixels32();
                for (int j = 0; j < pixels.Length; j++)
                {
                    pixels[j].r = iconColor.r;
                    pixels[j].g = iconColor.g;
                    pixels[j].b = iconColor.b;
                }

                icon.SetPixels32(pixels);
                File.WriteAllBytes(icons[i], icon.EncodeToPNG());
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
        }
コード例 #5
0
 internal static string MakePathRelativeToProject(string absolutePath) => MixedRealityToolkitFiles.GetAssetDatabasePath(absolutePath);