/// <summary>
 /// Add a package
 /// </summary>
 /// <param name="package"></param>
 public void AddPackage(GaiaCompatiblePackage package)
 {
     m_packages.Add(package.m_packageName, package);
 }
Beispiel #2
0
        /// <summary>
        /// Scan for installed extensions
        /// </summary>
        public void ScanForExtensions()
        {
            #if UNITY_EDITOR
            if (EditorApplication.isCompiling)
            {
                return;
            }
            #endif

            m_extensions.Clear();

            string[]          parsedName;
            string            publisherName = "", packageName = "", packageImage = "", packageDescription = "", packageURL = "";
            MethodInfo        method;
            MethodInfo[]      methods;
            List <MethodInfo> extensionMethods;
            List <Type>       types = GetTypesInNamespace("Gaia.GX.");

            //Process installed extensions
            for (int typeIdx = 0; typeIdx < types.Count; typeIdx++)
            {
                //Get publisher and package name
                parsedName    = types[typeIdx].FullName.Split('.');
                publisherName = Regex.Replace(parsedName[2], "(\\B[A-Z])", " $1");
                packageName   = Regex.Replace(parsedName[3], "(\\B[A-Z])", " $1");

                //Grab the extension methods, update publisher and package name if necessary
                methods          = types[typeIdx].GetMethods(BindingFlags.Public | BindingFlags.Static);
                extensionMethods = new List <MethodInfo>();
                for (int methodIdx = 0; methodIdx < methods.Length; methodIdx++)
                {
                    method = methods[methodIdx];

                    if (method.Name.StartsWith("GX_"))
                    {
                        extensionMethods.Add(method);
                    }
                    else if (method.Name == "GetPublisherName")
                    {
                        publisherName = (string)method.Invoke(null, null);
                    }
                    else if (method.Name == "GetPackageName")
                    {
                        packageName = (string)method.Invoke(null, null);
                    }
                }

                //See if we can locate the publisher, if not then add them
                GaiaCompatiblePublisher publisher = null;
                if (!m_extensions.TryGetValue(publisherName, out publisher))
                {
                    publisher = new GaiaCompatiblePublisher();
                    publisher.m_publisherName       = publisherName;
                    publisher.m_compatibleFoldedOut = false;
                    publisher.m_installedFoldedOut  = false;
                    m_extensions.Add(publisherName, publisher);
                }

                //See if we can locate the extension, if not then add it
                GaiaCompatiblePackage package = publisher.GetPackage(packageName);
                if (package == null)
                {
                    package = new GaiaCompatiblePackage();
                    package.m_compatibleFoldedOut = false;
                    package.m_installedFoldedOut  = false;
                    package.m_packageName         = packageName;
                    publisher.AddPackage(package);
                }
                if (extensionMethods.Count > 0)
                {
                    package.m_isInstalled = true;
                }
                else
                {
                    package.m_isInstalled = false;
                }
                package.m_methods = new List <MethodInfo>(extensionMethods);
            }

            //Then process compatible extensions
            types = GetTypesInNamespace("Gaia.GXC.");
            for (int typeIdx = 0; typeIdx < types.Count; typeIdx++)
            {
                //Get publisher and package name
                parsedName    = types[typeIdx].FullName.Split('.');
                publisherName = Regex.Replace(parsedName[2], "(\\B[A-Z])", " $1");
                packageName   = Regex.Replace(parsedName[3], "(\\B[A-Z])", " $1");

                //Grab the extension methods, update publisher and package name if necessary
                methods = types[typeIdx].GetMethods(BindingFlags.Public | BindingFlags.Static);
                for (int methodIdx = 0; methodIdx < methods.Length; methodIdx++)
                {
                    method = methods[methodIdx];

                    if (method.Name == "GetPublisherName")
                    {
                        publisherName = (string)method.Invoke(null, null);
                    }
                    else if (method.Name == "GetPackageName")
                    {
                        packageName = (string)method.Invoke(null, null);
                    }
                    else if (method.Name == "GetPackageImage")
                    {
                        packageImage = (string)method.Invoke(null, null);
                    }
                    else if (method.Name == "GetPackageDescription")
                    {
                        packageDescription = (string)method.Invoke(null, null);
                    }
                    else if (method.Name == "GetPackageURL")
                    {
                        packageURL = (string)method.Invoke(null, null);
                    }
                }

                //See if we can locate the publisher, if not then add them
                GaiaCompatiblePublisher publisher = null;
                if (!m_extensions.TryGetValue(publisherName, out publisher))
                {
                    publisher = new GaiaCompatiblePublisher();
                    publisher.m_publisherName       = publisherName;
                    publisher.m_compatibleFoldedOut = false;
                    publisher.m_installedFoldedOut  = false;
                    m_extensions.Add(publisherName, publisher);
                }

                //See if we can locate the extension, if not then add it
                GaiaCompatiblePackage package = publisher.GetPackage(packageName);
                if (package == null)
                {
                    package = new GaiaCompatiblePackage();
                    package.m_compatibleFoldedOut = false;
                    package.m_installedFoldedOut  = false;
                    package.m_packageName         = packageName;
                    publisher.AddPackage(package);
                }
                package.m_isCompatible       = true;
                package.m_packageDescription = packageDescription;
                package.m_packageImageName   = packageImage;
                package.m_packageURL         = packageURL;
            }
        }