Ejemplo n.º 1
0
        public void ActivateDependencies(BuildTarget platform, DependencyManager mediation)
        {
            if (dependencies.Length == 0 && depsSDK.Count == 0)
            {
                Debug.LogError(Utils.logTag + name + " have no dependencies. Please try reimport CAS package.");
                return;
            }
            if (locked)
            {
                return;
            }

            string depTagName  = platform == BuildTarget.Android ? "androidPackage" : "iosPod";
            var    destination = Utils.GetDependencyPathOrDefault(name, platform);

            EditorUtility.DisplayProgressBar("Create dependency", destination, 0.2f);

            try
            {
                var builder = new StringBuilder();
                builder.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>")
                .AppendLine("<dependencies>")
                .Append("  <").Append(depTagName).Append("s>").AppendLine();

                for (int i = 0; i < dependencies.Length; i++)
                {
                    AppendDependency(mediation, new SDK(dependencies[i], version), platform, builder);
                }

                // EDM4U have a bug.
                // Dependencies that will be added For All Targets must be at the end of the list of dependencies.
                // Otherwise, those dependencies that should not be for all targets will be tagged for all targets.
                AppendSDK(platform, mediation, builder, false);
                AppendSDK(platform, mediation, builder, true);

                builder.Append("  </").Append(depTagName).Append("s>").AppendLine()
                .AppendLine("</dependencies>");

                var replace = File.Exists(destination);
                if (!replace)
                {
                    var destDir = Path.GetDirectoryName(destination);
                    if (!Directory.Exists(destDir))
                    {
                        Directory.CreateDirectory(destDir);
                    }
                }

                File.WriteAllText(destination, builder.ToString());
                if (!replace)
                {
                    AssetDatabase.ImportAsset(destination);
                }

                Init(mediation, platform, true);
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }

            var requireItem = mediation.Find(require);

            if (requireItem != null)
            {
                requireItem.isRequired = true;
                if (!requireItem.IsInstalled())
                {
                    requireItem.ActivateDependencies(platform, mediation);
                }
            }
        }