예제 #1
0
        public override void OnCleanupBuild(BuilderState state)
        {
            if (this._replacements == null)
            {
                return;
            }

            foreach (var p in this._replacements)
            {
                string path = AssetDatabase.GUIDToAssetPath(p.Key);
                if (string.IsNullOrEmpty(path))
                {
                    state.Log(string.Format("Unable to restore asset '{0}'", p.Key));
                    continue;
                }
                File.WriteAllText(path, p.Value, Encoding.UTF8);
            }

            this._replacements.Clear();
            this._replacements = null;
        }
예제 #2
0
        private void Run(BuilderState config)
        {
            string path = this.path ?? "";

            if (!Path.IsPathRooted(path))
            {
                path = Path.Combine(Environment.CurrentDirectory, path);
            }

            if (!File.Exists(path))
            {
                UnityEngine.Debug.LogWarning("Executable " + path + " doesn't exist");
                return;
            }

            string arguments = this.arguments ?? "";

            arguments = arguments.Replace("{BuildPath}", config.buildPath);

            var psi = new ProcessStartInfo();

            psi.WorkingDirectory       = Environment.CurrentDirectory;
            psi.RedirectStandardOutput = true;
            psi.UseShellExecute        = false;
            psi.FileName  = path;
            psi.Arguments = this.arguments;

            using (var p = Process.Start(psi))
            {
                string output = p.StandardOutput.ReadToEnd();
                p.WaitForExit();

                if (!string.IsNullOrEmpty(output))
                {
                    config.Log(output);
                }
            }
        }
예제 #3
0
        private void Run(string path, BuilderState config)
        {
            if (!path.StartsWith("/"))
            {
                path = Path.Combine(Environment.CurrentDirectory, path);
            }

            if (!File.Exists(path))
            {
                UnityEngine.Debug.LogWarning("Shell script " + path + " doesn't exist");
                return;
            }

            string tool = "sh";

            using (var file = File.OpenText(path))
            {
                string line = file.ReadLine();
                if (line != null && line.StartsWith("#!"))
                {
                    tool = line.Substring(2);
                }
            }

            var psi = new ProcessStartInfo();

            psi.WorkingDirectory       = Environment.CurrentDirectory;
            psi.RedirectStandardOutput = true;
            psi.FileName = tool;

            psi.Arguments = MakeArgs(
                path,

                // 0
                Path.Combine(Environment.CurrentDirectory, config.buildPath),

                // 1
                // The type of player built:
                // "dashboard", "standaloneWin32", "standaloneOSXIntel", "standaloneOSXPPC", "standaloneOSXUniversal", "webplayer"
                GetPlayerTypeString(config.buildTarget),

                // 2
                // What optimizations are applied. At the moment either "" or "strip" when Strip debug symbols is selected.
                (config.buildOptions & BuildOptions.Development) != 0 ? "strip" : "",

                // 3
                // The name of the company set in the project settings
                PlayerSettings.companyName,

                // 4
                // The name of the product set in the project settings
                PlayerSettings.productName,

                // 5
                // The default screen width of the player.
                PlayerSettings.defaultScreenWidth.ToString(),

                // 6
                // The default screen height of the player
                PlayerSettings.defaultScreenHeight.ToString()
                );

            psi.EnvironmentVariables["BUILD_VERSION"]  = config.version;
            psi.EnvironmentVariables["BUILD_BUNDLEID"] = config.bundleIdentifier;
            psi.UseShellExecute = false;

            using (var p = Process.Start(psi))
            {
                string output = p.StandardOutput.ReadToEnd();
                p.WaitForExit();

                if (!string.IsNullOrEmpty(output))
                {
                    config.Log(output);
                }
            }
        }
예제 #4
0
        public override void OnBuild(BuilderState config)
        {
            if (this.items.Count == 0)
            {
                return;
            }

            var index = new Dictionary <string, List <ReplaceInCodeItem> >();

            foreach (var item in this.items)
            {
                if (item == null || string.IsNullOrEmpty(item.replacement) || string.IsNullOrEmpty(item.guid))
                {
                    continue;
                }
                List <ReplaceInCodeItem> list;
                if (!index.TryGetValue(item.guid, out list))
                {
                    index[item.guid] = list = new List <ReplaceInCodeItem>();
                }

                list.Add(item);
            }

            foreach (var p in index)
            {
                string path = AssetDatabase.GUIDToAssetPath(p.Key);
                if (string.IsNullOrEmpty(path) || !File.Exists(path))
                {
                    config.Log(string.Format("No file found for asset '{0}'", p.Key));
                    continue;
                }

                string input  = File.ReadAllText(path);
                string output = input;
                foreach (var item in p.Value)
                {
                    string prev = output;
                    output = Regex.Replace(
                        prev,
                        string.Format(@"\/\*\+{0}\+\*\/(.*?)\/\*\-{0}\-\*\/", Regex.Escape(item.replacement)),
                        string.Format(@"/*+{0}+*/{1}/*-{0}-*/", item.replacement, item.value),
                        RegexOptions.Singleline
                        );

                    if (output == prev)
                    {
                        config.Log(string.Format("No replacement for '{0}' found in '{1}'", item.replacement, path));
                    }
                }

                if (input != output)
                {
                    if (this._replacements == null)
                    {
                        this._replacements = new Dictionary <string, string>();
                    }
                    if (!this._replacements.ContainsKey(path))
                    {
                        this._replacements.Add(p.Key, input);
                    }

                    File.WriteAllText(path, output, Encoding.UTF8);
                }
            }
        }