public override IEnumerator Execute(UTContext context)
    {
        var theScene = scene.EvaluateIn(context);

        if (theScene.Contains("*"))
        {
            var finalList = UTFileUtils.CalculateFileset(new string[] { theScene }, new string[0]);
            if (finalList.Length != 1)
            {
                throw new UTFailBuildException("Scene wildcard " + theScene + " yielded " +
                                               finalList.Length + " results but should yield exactly one scene.", this);
            }
            UTFileUtils.FullPathToProjectPath(finalList);
            theScene = finalList[0];
        }

        theScene = UTFileUtils.FullPathToProjectPath(theScene);

        if (UTPreferences.DebugMode)
        {
            Debug.Log("Opening scene: " + theScene, this);
        }
        var result = EditorApplication.OpenScene(theScene);

        if (!result)
        {
            throw new UTFailBuildException("Scene " + theScene + " could not be opened.", this);
        }
        yield return("");
    }
Beispiel #2
0
    public override System.Collections.IEnumerator Execute(UTContext context)
    {
        var theBaseDirectory = baseDirectory.EvaluateIn(context);

        if (string.IsNullOrEmpty(theBaseDirectory))
        {
            theBaseDirectory = UTFileUtils.ProjectAssets;
        }

        if (!Directory.Exists(theBaseDirectory))
        {
            throw new UTFailBuildException("The base directory " + theBaseDirectory + " does not exist.", this);
        }

        theBaseDirectory = UTFileUtils.NormalizeSlashes(theBaseDirectory);
        var theIncludes = EvaluateAll(includes, context);
        var theExcludes = EvaluateAll(excludes, context);

        var theFiles = UTFileUtils.CalculateFileset(theBaseDirectory, theIncludes, theExcludes, UTFileUtils.FileSelectionMode.Files);

        var now = DateTime.Now;

        foreach (var file in theFiles)
        {
            FileInfo src = new FileInfo(file);
            src.LastWriteTime = now;
            yield return("");
        }
    }
    /// <summary>
    /// Builds a file set.
    /// </summary>
    public string[] BuildFileSet(string baseFolder, string[] includes, string[] excludes, bool includeDirectories, bool includeFiles)
    {
        if (!includeDirectories && !includeFiles)
        {
            throw new ArgumentException("Please set at least one of the includeDirectories and includeFiles parameters to true.");
        }

        UTFileUtils.FileSelectionMode mode;
        if (includeDirectories)
        {
            if (includeFiles)
            {
                mode = UTFileUtils.FileSelectionMode.FilesAndFolders;
            }
            else
            {
                mode = UTFileUtils.FileSelectionMode.Folders;
            }
        }
        else
        {
            mode = UTFileUtils.FileSelectionMode.Files;
        }

        return(UTFileUtils.CalculateFileset(baseFolder, includes, excludes, mode));
    }
	public override IEnumerator Execute (UTContext context)
	{
		string  finalout = context["CurPrefabFile"] as string;
		//HandleMat(context["foreachfile"]);
		//Debug.Log(UTFileUtils.FullPathToProjectPath(finalout), this);
		HandlePrefab(UTFileUtils.FullPathToProjectPath(finalout));
		yield return "";
	}
Beispiel #5
0
    public override IEnumerator Execute(UTContext context)
    {
        string finalout = context["CurAssAssetbundleBanshenxiang"] as string;

        //HandleMat(context["foreachfile"]);
        //Debug.Log(UTFileUtils.FullPathToProjectPath(finalout), this);
        HandleAssetbundleBanshenxiang(UTFileUtils.FullPathToProjectPath(finalout));
        yield return("");
    }
Beispiel #6
0
    public override IEnumerator Execute(UTContext context)
    {
        string finalout = context["AndroidHighRes"] as string;

        Debug.Log("finalout = " + finalout);
        //HandleMat(context["foreachfile"]);
        //Debug.Log(UTFileUtils.FullPathToProjectPath(finalout), this);
        HandleSetAndroidNormalRes(UTFileUtils.FullPathToProjectPath(finalout));
        yield return("");
    }
Beispiel #7
0
    public override IEnumerator Execute(UTContext context)
    {
        var pathToInstance = assetPath.EvaluateIn(context);

        pathToInstance = UTFileUtils.FullPathToProjectPath(pathToInstance);

        var theAsset = AssetDatabase.LoadMainAssetAtPath(pathToInstance);

        Selection.activeObject = theAsset;

        yield return("");
    }
Beispiel #8
0
    public override IEnumerator Execute(UTContext context)
    {
        var theRealIncludes = EvaluateAll(includes, context);
        var theRealExcludes = EvaluateAll(excludes, context);

        var fileSet = UTFileUtils.CalculateFileset(theRealIncludes, theRealExcludes);

        UTFileUtils.FullPathToProjectPath(fileSet);


        if (fileSet.Length == 0)
        {
            Debug.LogWarning("The list of scenes is empty.");
        }


        var doAppend = append.EvaluateIn(context);

        EditorBuildSettingsScene[] sceneArray;
        var offset = 0;

        if (doAppend)
        {
            if (fileSet.Length > 0)
            {
                var oldArray = EditorBuildSettings.scenes;
                var newArray = new EditorBuildSettingsScene[oldArray.Length + fileSet.Length];
                Array.Copy(oldArray, newArray, oldArray.Length);
                offset     = oldArray.Length;
                sceneArray = newArray;
            }
            else
            {
                sceneArray = new EditorBuildSettingsScene[0];
            }
        }
        else
        {
            sceneArray = new EditorBuildSettingsScene[fileSet.Length];
        }

        for (int i = 0; i < fileSet.Length; i++)
        {
            var scene = new EditorBuildSettingsScene(fileSet [i], true);
            sceneArray [offset + i] = scene;
        }

        EditorBuildSettings.scenes = sceneArray;
        yield return("");
    }
Beispiel #9
0
    public override IEnumerator Execute(UTContext context)
    {
        string finalout = context["AndroidHighRes"] as string;

        UDebug.Log("finalout = " + finalout);
        //HandleMat(context["foreachfile"]);
        //Debug.Log(UTFileUtils.FullPathToProjectPath(finalout), this);
        //string res = context ["setHighRes"].ToString();
        //Debug.Log("setHighRes = "+res);
        //if(res.Equals("True")){
        HandleSetAndroidHighRes(UTFileUtils.FullPathToProjectPath(finalout));
        //}

        yield return("");
    }
Beispiel #10
0
    public override IEnumerator Execute(UTContext context)
    {
        if (startOfSubtree == null)
        {
            Debug.LogWarning("No subtree specified.");
            yield break;
        }

        UTFileUtils.FileSelectionMode theMode = UTFileUtils.FileSelectionMode.Files;
        if (selectionMode != null)           // can happen when we migrate older automation plans which didn't have this setting.
        {
            theMode = selectionMode.EvaluateIn(context);
        }

        var theFilePropertyName = filePropertyName.EvaluateIn(context);

        if (string.IsNullOrEmpty(theFilePropertyName))
        {
            throw new UTFailBuildException("You need to specify the property which holds the current file.", this);
        }

        var theIncludes = UTAction.EvaluateAll(includes, context);
        var theExcludes = UTAction.EvaluateAll(excludes, context);

        var files = UTFileUtils.CalculateFileset(theIncludes, theExcludes, theMode);

        var theIndexPropertyName = indexPropertyName.EvaluateIn(context);
        var indexPropertySet     = !string.IsNullOrEmpty(theIndexPropertyName);

        var index = 0;

        foreach (var file in files)
        {
            context [theFilePropertyName] = file;
            if (indexPropertySet)
            {
                context [theIndexPropertyName] = index;
            }
            var enumerator = UTAutomationPlan.ExecutePath(startOfSubtree, context);
            do
            {
                yield return("");
            } while (enumerator.MoveNext());
            index++;
        }
    }
    private void SetupVariables(UTContext context)
    {
        context ["project:root"]   = UTFileUtils.ProjectRoot;
        context ["project:assets"] = UTFileUtils.ProjectAssets;

        var platform = Environment.OSVersion.Platform;

        if (Application.platform == RuntimePlatform.OSXEditor)
        {
            platform = PlatformID.MacOSX;             // seems to be some bug in Mono returning "Unix" when being on a mac.
        }

        context ["os:platform"] = platform.ToString();

        var isUnixLike = platform == PlatformID.MacOSX || platform == PlatformID.Unix;

        context ["os:pathSeparatorType"] = isUnixLike ? "Unix" : "Windows";
        context ["os:pathSeparatorChar"] = isUnixLike ? "/" : "\\";

        if (isUnixLike)
        {
            context ["user:home"] = UTFileUtils.NormalizeSlashes(Environment.GetEnvironmentVariable("HOME"));
        }
        else if (platform == PlatformID.Win32NT)
        {
            context ["user:home"] = UTFileUtils.NormalizeSlashes(Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%"));
        }
        else
        {
            Debug.Log("Unable to detect underlying os. Property 'user:home' is not available.");
        }

        context ["user:desktop"] = UTFileUtils.NormalizeSlashes(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));

        context ["unity:isUnityPro"]      = UTils.IsUnityPro;
        context ["unity:supportsAndroid"] = UTils.IsBuildTargetSupported(UnityEditor.BuildTarget.Android);
        context ["unity:supportsIos"]     = UTils.IsBuildTargetSupported(UnityEditor.BuildTarget.iOS);
        context ["unity:version"]         = Application.unityVersion;

        context ["utomate:debugMode"] = UTPreferences.DebugMode;

        context ["project:picard"] = "Make it so!";
        context ["project:worf"]   = "Torpedos ready, sir!";
        context ["project:bones"]  = "I'm a doctor, no game developer!";
    }
Beispiel #12
0
    public override IEnumerator Execute(UTContext context)
    {
        var theName = propertyName.EvaluateIn(context);

        if (string.IsNullOrEmpty(theName))
        {
            throw new UTFailBuildException("The name of the property must not be empty.", this);
        }

        // get the asset
        var pathToInstance = assetPath.EvaluateIn(context);

        pathToInstance = UTFileUtils.FullPathToProjectPath(pathToInstance);

        var theAsset = AssetDatabase.LoadMainAssetAtPath(pathToInstance);


        yield return("");
    }
    public override IEnumerator Execute(UTContext context)
    {
        var isSaveCopy  = saveCopy.EvaluateIn(context);
        var theFileName = "";

        if (isSaveCopy)
        {
            theFileName = filename.EvaluateIn(context);
            if (string.IsNullOrEmpty(theFileName))
            {
                throw new UTFailBuildException("You need to specify a file name when saving a copy of a scene.", this);
            }
            theFileName = UTFileUtils.FullPathToProjectPath(theFileName);

            UTFileUtils.EnsureParentFolderExists(UTFileUtils.CombineToPath(UTFileUtils.ProjectRoot, theFileName));
        }
        if (!EditorApplication.SaveScene(theFileName, isSaveCopy))
        {
            throw new UTFailBuildException("Saving the scene failed.", this);
        }
        yield return("");
    }
Beispiel #14
0
    public override IEnumerator Execute(UTContext context)
    {
        var theScene = scene.EvaluateIn(context);

        if (string.IsNullOrEmpty(theScene))
        {
            throw new UTFailBuildException("You need to specify a path where the scene should be saved to.", this);
        }
        theScene = UTFileUtils.FullPathToProjectPath(theScene);

        var theFullPath = UTFileUtils.CombineToPath(UTFileUtils.ProjectRoot, theScene);

        if (File.Exists(theFullPath))
        {
            throw new UTFailBuildException("There is already a file at '" + theScene + "'.", this);
        }

        UTFileUtils.EnsureParentFolderExists(theFullPath);
        EditorApplication.NewScene();
        EditorApplication.SaveScene(theScene, false);
        yield return("");
    }
Beispiel #15
0
    public override IEnumerator Execute(UTContext context)
    {
        var theOutputFile = outputFileName.EvaluateIn(context);

        if (string.IsNullOrEmpty(theOutputFile))
        {
            throw new UTFailBuildException("You must specify an output file name.", this);
        }

        var theBundleType = bundleType.EvaluateIn(context);

        var theFiles = new string[0];

        if (theBundleType == UTTypeOfBundle.SimpleAssetBundle || !useScenesFromBuildSettings.EvaluateIn(context))
        {
            var theIncludes = EvaluateAll(includes, context);
            var theExcludes = EvaluateAll(excludes, context);
            theFiles = UTFileUtils.CalculateFileset(theIncludes, theExcludes);

            UTFileUtils.FullPathToProjectPath(theFiles);
        }
        else
        {
            var scenes = EditorBuildSettings.scenes;
            theFiles = Array.ConvertAll <EditorBuildSettingsScene, string> (scenes, scene => scene.path);
        }

        if (UTPreferences.DebugMode)
        {
            foreach (var file in theFiles)
            {
                Debug.Log("Including: " + file, this);
            }
        }
        Debug.Log("Including " + theFiles.Length + " assets/scenes.");

        if (theBundleType == UTTypeOfBundle.StreamedScenes && theFiles.Length == 0)
        {
            throw new UTFailBuildException("No scenes have been selected. Unable to build a streamed scenes asset bundle with no scenes.", this);
        }

        var     theMainAsset  = "";
        UObject realMainAsset = null;

        UObject[] realAssets = null;

        if (theBundleType == UTTypeOfBundle.SimpleAssetBundle)
        {
            theMainAsset = mainAsset.EvaluateIn(context);
            if (!String.IsNullOrEmpty(theMainAsset))
            {
                if (theMainAsset.Contains("*"))
                {
                    var finalList = UTFileUtils.CalculateFileset(new string[] { theMainAsset }, new string[0]);
                    if (finalList.Length != 1)
                    {
                        throw new UTFailBuildException("Main asset wildcard " + theMainAsset + " yielded " +
                                                       finalList.Length + " results but should yield exactly one asset.", this);
                    }
                    theMainAsset = UTFileUtils.FullPathToProjectPath(finalList [0]);
                }

                // now get the real objects for the paths
                realMainAsset = AssetDatabase.LoadMainAssetAtPath(theMainAsset);

                if (realMainAsset == null)
                {
                    throw new UTFailBuildException("Unable to load the main asset " + theMainAsset + " from asset database.", this);
                }
            }

            realAssets = Array.ConvertAll <string, UObject> (theFiles, file => {
                var result = AssetDatabase.LoadMainAssetAtPath(file);
                if (result == null)
                {
                    throw new UTFailBuildException("Unable to load the asset " + file, this);
                }
                return(result);
            });
        }


        var theBuildTarget = targetPlatform.EvaluateIn(context);

        if (pushDependencies.EvaluateIn(context))
        {
            UTAssetDependencyStack.Push();
        }

        try {
            UTFileUtils.EnsureParentFolderExists(theOutputFile);
            if (theBundleType == UTTypeOfBundle.StreamedScenes)
            {
                Debug.Log("Building streamed scenes asset bundle.");
                var result = BuildPipeline.BuildStreamedSceneAssetBundle(theFiles, theOutputFile, theBuildTarget);
                if (!string.IsNullOrEmpty(result))
                {
                    throw new UTFailBuildException("Building streamed scene asset bundle failed. " + result, this);
                }
            }
            else
            {
                Debug.Log("Building asset bundle.");
                var realCollectDependencies      = collectDependencies.EvaluateIn(context);
                var realCompleteAssets           = completeAssets.EvaluateIn(context);
                var realDisableWriteTypeTree     = disableWriteTypeTree.EvaluateIn(context);
                var realDeterministicAssetBundle = deterministicAssetBundle.EvaluateIn(context);


                var buildOpts = (BuildAssetBundleOptions)0;

                if (realCollectDependencies)
                {
                    buildOpts |= BuildAssetBundleOptions.CollectDependencies;
                }

                if (realCompleteAssets)
                {
                    buildOpts |= BuildAssetBundleOptions.CompleteAssets;
                }

                if (realDisableWriteTypeTree)
                {
                    buildOpts |= BuildAssetBundleOptions.DisableWriteTypeTree;
                }

                if (realDeterministicAssetBundle)
                {
                    buildOpts |= BuildAssetBundleOptions.DeterministicAssetBundle;
                }

                if (!BuildPipeline.BuildAssetBundle(realMainAsset, realAssets, theOutputFile, buildOpts, theBuildTarget))
                {
                    throw new UTFailBuildException("Building asset bundle failed.", this);
                }
            }
            Debug.Log("Built asset bundle at " + theOutputFile);
        } finally {
            if (popAllDependencies.EvaluateIn(context))
            {
                UTAssetDependencyStack.PopAll();
            }
            else if (popDependencies.EvaluateIn(context))
            {
                UTAssetDependencyStack.Pop();
            }
        }
        yield return("");
    }
    public override IEnumerator Execute(UTContext context)
    {
        var theBaseDirectory = baseDirectory.EvaluateIn(context);

        if (string.IsNullOrEmpty(theBaseDirectory))
        {
            theBaseDirectory = UTFileUtils.ProjectAssets;
        }

        var theOutputFileName = outputFileName.EvaluateIn(context);

        if (string.IsNullOrEmpty(theOutputFileName))
        {
            throw new UTFailBuildException("Output file name must be set", this);
        }


        if (!theOutputFileName.EndsWith(".zip"))
        {
            Debug.LogWarning("Output filename should end with .zip.", this);
        }

        if (!appendToExistingFile.EvaluateIn(context))
        {
            if (File.Exists(theOutputFileName))
            {
                if (UTPreferences.DebugMode)
                {
                    Debug.Log("Deleting existing ZIP file: " + theOutputFileName);
                }
                File.Delete(theOutputFileName);
            }
        }

        var theIncludes = EvaluateAll(includes, context);
        var theExcludes = EvaluateAll(excludes, context);

        var fileList = UTFileUtils.CalculateFileset(theBaseDirectory, theIncludes, theExcludes, UTFileUtils.FileSelectionMode.Files);

        if (fileList.Length == 0)
        {
            throw new UTFailBuildException("There is nothing to ZIP.", this);
        }

        Debug.Log("Zipping " + fileList.Length + " files.", this);

        UTFileUtils.EnsureParentFolderExists(theOutputFileName);

        var doFlatten = flattenStructure.EvaluateIn(context);
        var theBaseFolderInZipFile = baseFolderInZIPFile.EvaluateIn(context);

        using (ZipFile zf = new ZipFile(theOutputFileName)) {
            foreach (var file in fileList)
            {
                if (UTPreferences.DebugMode)
                {
                    Debug.Log("Zipping: " + file, this);
                }
                if (doFlatten)
                {
                    zf.AddFile(file, theBaseFolderInZipFile);
                }
                else
                {
                    var relativePath = UTFileUtils.StripBasePath(UTFileUtils.GetParentPath(file), theBaseDirectory);
                    zf.AddFile(file, UTFileUtils.CombineToPath(theBaseFolderInZipFile, relativePath));
                }
                yield return("");
            }
            zf.Save();
        }

        Debug.Log("ZIP file created at " + theOutputFileName, this);
        yield return("");
    }
Beispiel #17
0
    public override IEnumerator Execute(UTContext context)
    {
        var realIncludes = EvaluateAll(includes, context);
        var realExcludes = EvaluateAll(excludes, context);

        var theBaseDirectory = baseDirectory != null?baseDirectory.EvaluateIn(context) : null;

        if (string.IsNullOrEmpty(theBaseDirectory))
        {
            theBaseDirectory = Application.dataPath;
        }

        if (!Directory.Exists(theBaseDirectory))
        {
            throw new UTFailBuildException("The base directory " + theBaseDirectory + " does not exist or is not a directory", this);
        }


        var fileList = UTFileUtils.CalculateFileset(theBaseDirectory, realIncludes, realExcludes, UTFileUtils.FileSelectionMode.Files);

        if (fileList.Length == 0)
        {
            throw new UTFailBuildException("No files were selected for build. Please check includes and excludes.", this);
        }

        var realOutputFile = outputFile.EvaluateIn(context);

        if (!realOutputFile.EndsWith(".dll"))
        {
            if (UTPreferences.DebugMode)
            {
                Debug.LogWarning("The output file does not end with .dll. The built DLL will not be picked up by Unity.");
            }
        }

        UTFileUtils.EnsureParentFolderExists(realOutputFile);

        if (UTPreferences.DebugMode)
        {
            foreach (var file in fileList)
            {
                Debug.Log("Compiling " + file);
            }
        }
        else
        {
            Debug.Log("Compiling " + fileList.Length + " files.");
        }

        var compiler = new CSharpCodeProvider();
        CompilerParameters parameters = new CompilerParameters();
        var doIncludeEngineDll        = true;

        if (includeEngineDll != null)           // can happen when we migrate older automation plans which didn't have this setting.
        {
            doIncludeEngineDll = includeEngineDll.EvaluateIn(context);
        }
        if (doIncludeEngineDll)
        {
            parameters.ReferencedAssemblies.Add(UnityDll());
        }
        if (includeEditorDll.EvaluateIn(context))
        {
            parameters.ReferencedAssemblies.Add(UnitEditorDll());
        }

        var realAssemblies = EvaluateAll(referencedAssemblies, context);

        foreach (var asm in realAssemblies)
        {
            parameters.ReferencedAssemblies.Add(asm);
        }

        parameters.GenerateExecutable = false;
        parameters.OutputAssembly     = realOutputFile;

        var theSymbols = defineSymbols.EvaluateIn(context);

        if (!string.IsNullOrEmpty(theSymbols))
        {
            parameters.CompilerOptions = "/define:" + theSymbols.Trim();
        }

        var theAdditionalOptions = additionalCompilerOptions.EvaluateIn(context);

        if (!string.IsNullOrEmpty(theAdditionalOptions))
        {
            parameters.CompilerOptions += " " + theAdditionalOptions.Trim();
        }

        SetPath();
        CompilerResults results = compiler.CompileAssemblyFromFile(parameters, fileList);

        if (UTPreferences.DebugMode)
        {
            var output = results.Output;
            foreach (var line in output)
            {
                Debug.Log(line);
            }
        }

        var errors    = results.Errors;
        var hadErrors = false;

        foreach (CompilerError error in errors)
        {
            if (error.IsWarning)
            {
                Debug.LogWarning(error.ToString());
            }
            else
            {
                hadErrors = true;
                Debug.LogError(error.ToString());                   // TODO link errors to file.
            }
        }
        if (hadErrors)
        {
            throw new UTFailBuildException("There were compilation errors.", this);
        }
        Debug.Log("Built " + realOutputFile + " from " + fileList.Length + " source file(s).");
        yield return("");
    }
    public override IEnumerator Execute(UTContext context)
    {
        var theExecutable = pathToExecutable.EvaluateIn(context);

        if (!System.IO.File.Exists(theExecutable))
        {
            throw new UTFailBuildException("Executable " + theExecutable + " does not exist.", this);
        }

        string[] finalFileSet;
        if (useFileset.EvaluateIn(context))
        {
            var theBasePath = basePath.EvaluateIn(context);
            if (!Directory.Exists(theBasePath))
            {
                throw new UTFailBuildException("The base path " + theBasePath + " does not exist.", this);
            }

            var theIncludes = EvaluateAll(includes, context);
            var theExcludes = EvaluateAll(excludes, context);

            var theFiles = UTFileUtils.CalculateFileset(theBasePath, theIncludes, theExcludes, UTFileUtils.FileSelectionMode.Files);

            if (relativePaths.EvaluateIn(context))
            {
                UTFileUtils.StripBasePath(theFiles, theBasePath);
            }

            if (pathSeparator.EvaluateIn(context) == PathSeparator.Windows)
            {
                UTFileUtils.SlashesToWindowsSlashes(theFiles);
            }

            finalFileSet = theFiles;
        }
        else
        {
            finalFileSet = new string[0];
        }


        if (runOncePerFile.EvaluateIn(context))
        {
            foreach (var file in finalFileSet)
            {
                if (context.CancelRequested)
                {
                    break;
                }

                currentFiles = new string[] { file };
                InvokeProgram(theExecutable, context);
                do
                {
                    yield return("");

                    if (context.CancelRequested && !currentProcess.HasExited)
                    {
                        currentProcess.Kill();
                        break;
                    }
                } while (!currentProcess.HasExited);

                CheckResult(context);
            }
        }
        else
        {
            currentFiles = finalFileSet;
            InvokeProgram(theExecutable, context);
            do
            {
                yield return("");

                if (context.CancelRequested && !currentProcess.HasExited)
                {
                    currentProcess.Kill();
                }
            } while(!currentProcess.HasExited);

            CheckResult(context);
        }
    }
Beispiel #19
0
    public override IEnumerator Execute(UTContext context)
    {
        var theOutputFileName = outputFileName.EvaluateIn(context);

        if (string.IsNullOrEmpty(theOutputFileName))
        {
            throw new UTFailBuildException("Output file name must be set", this);
        }

        if (!theOutputFileName.EndsWith(".unitypackage"))
        {
            Debug.LogWarning("Output filename should end with .unitypackage.", this);
        }

        var theIncludes = EvaluateAll(includes, context);
        var theExcludes = EvaluateAll(excludes, context);

        var fileList = UTFileUtils.CalculateFileset(theIncludes, theExcludes);

        UTFileUtils.FullPathToProjectPath(fileList);

        var theFinalList = new List <string>();

        theFinalList.AddRange(fileList);

        var doIncludeProjectSettings = includeProjectSettings.EvaluateIn(context);

        if (doIncludeProjectSettings == IncludeProjectSettingsMode.Some)
        {
            var theSettingsIncludes = EvaluateAll(settingsIncludes, context);
            var theSettingsExcludes = EvaluateAll(settingsExcludes, context);

            var settingsFileList = UTFileUtils.CalculateFileset(UTFileUtils.ProjectSettings, theSettingsIncludes, theSettingsExcludes, UTFileUtils.FileSelectionMode.Files);
            UTFileUtils.FullPathToProjectPath(settingsFileList);
            theFinalList.AddRange(settingsFileList);
        }

        if (theFinalList.Count == 0 && doIncludeProjectSettings != IncludeProjectSettingsMode.All)
        {
            throw new UTFailBuildException("There is nothing to export.", this);
        }

        if (UTPreferences.DebugMode)
        {
            foreach (var entry in theFinalList)
            {
                Debug.Log("Exporting: " + entry, this);
            }
        }

        Debug.Log("Exporting " + theFinalList.Count + " files.", this);

        ExportPackageOptions flags = ExportPackageOptions.Default;

        var doIncludeDependencies = includeDependencies.EvaluateIn(context);

        if (doIncludeDependencies)
        {
            flags = flags | ExportPackageOptions.IncludeDependencies;
        }

        if (doIncludeProjectSettings == IncludeProjectSettingsMode.All)
        {
            flags = flags | ExportPackageOptions.IncludeLibraryAssets;
        }

        UTFileUtils.EnsureParentFolderExists(theOutputFileName);
        AssetDatabase.ExportPackage(theFinalList.ToArray(), theOutputFileName, flags);
        Debug.Log("Package exported to " + theOutputFileName, this);
        yield return("");
    }
 /// <summary>
 /// Builds a file set.
 /// </summary>
 public string[] BuildFileSet(string baseFolder, string[] includes, string[] excludes, bool includeDirectories)
 {
     return(UTFileUtils.CalculateFileset(baseFolder, includes, excludes,
                                         includeDirectories ? UTFileUtils.FileSelectionMode.FilesAndFolders : UTFileUtils.FileSelectionMode.Files));
 }
 /// <summary>
 /// Combines the given path segments into a path.
 /// </summary>
 public string CombinePath(params string[] parts)
 {
     return(UTFileUtils.CombineToPath(parts));
 }
 /// <summary>
 /// Converts the given full path to a path relative to the project's assets folder.
 /// </summary>
 public string ToAssetsRelativePath(string path)
 {
     return(UTFileUtils.StripBasePath(path, Application.dataPath));
 }
 /// <summary>
 /// Converts the given full path to a path relative to the project's root folder.
 /// </summary>
 public string ToProjectRelativePath(string path)
 {
     return(UTFileUtils.FullPathToProjectPath(path));
 }
    public override IEnumerator Execute(UTContext context)
    {
        var theBaseDirectory = baseDirectory.EvaluateIn(context);

        if (string.IsNullOrEmpty(theBaseDirectory))
        {
            theBaseDirectory = UTFileUtils.ProjectRoot;
        }


        if (!Directory.Exists(theBaseDirectory))
        {
            throw new UTFailBuildException("The base directory " + theBaseDirectory + " does not exist.", this);
        }

        theBaseDirectory = UTFileUtils.NormalizeSlashes(theBaseDirectory);

        var theTargetDirectory = targetDirectory.EvaluateIn(context);

        if (string.IsNullOrEmpty(theTargetDirectory))
        {
            throw new UTFailBuildException("You must specify a target directory.", this);
        }
        theTargetDirectory = UTFileUtils.NormalizeSlashes(theTargetDirectory);

        var theIncludes = EvaluateAll(includes, context);
        var theExcludes = EvaluateAll(excludes, context);
        var doFlatten   = flattenStructure.EvaluateIn(context);

        var theFiles  = UTFileUtils.CalculateFileset(theBaseDirectory, theIncludes, theExcludes, UTFileUtils.FileSelectionMode.Files);
        var theCopies = UTFileUtils.Repath(theFiles, theBaseDirectory, theTargetDirectory, doFlatten);

        Debug.Log("Copying " + theFiles.Length + " files to " +
                  theTargetDirectory + (doFlatten ? " and flattening " : " and preserving ") + " the directory structure.", this);

        var doOverwrite = overwriteExisting.EvaluateIn(context);
        var doOnlyNewer = onlyIfNewer.EvaluateIn(context);

        for (int i = 0; i < theFiles.Length; i++)
        {
            context.LocalProgress = ((float)i) / ((float)theFiles.Length);
            FileInfo src    = new FileInfo(theFiles[i]);
            FileInfo target = new FileInfo(theCopies[i]);
            if (!doOverwrite && target.Exists)
            {
                if (UTPreferences.DebugMode)
                {
                    Debug.Log("File " + theCopies[i] + " exists. Not overwriting it.");
                }
                continue;
            }
            if (doOverwrite && doOnlyNewer && src.LastWriteTime.CompareTo(target.LastWriteTime) <= 0)
            {
                if (UTPreferences.DebugMode)
                {
                    Debug.Log("File " + theFiles[i] + " is not newer than " + theCopies[i] + ". Not copying it.", this);
                }
                continue;
            }
            if (UTPreferences.DebugMode)
            {
                Debug.Log("Copying " + theFiles[i] + " to " + theCopies[i], this);
            }
            UTFileUtils.EnsureParentFolderExists(theCopies[i]);
            src.CopyTo(theCopies[i], doOverwrite);
            yield return("");
        }
    }
Beispiel #25
0
    public override IEnumerator Execute(UTContext context)
    {
        var theProjectPath = projectPath.EvaluateIn(context);

        if (!Directory.Exists(theProjectPath))
        {
            throw new UTFailBuildException("Project path " + theProjectPath + " does not exist.", this);
        }


        if (UTFileUtils.IsBelow(UTFileUtils.ProjectRoot, theProjectPath))
        {
            throw new UTFailBuildException("You cannot run uTomate externally on the current project. Use the Sub-Plan node if you want to run a plan as part of a plan.", this);
        }

        var thePlanName  = planName.EvaluateIn(context);
        var theDebugMode = debugMode.EvaluateIn(context);

        var theProperties = EvaluateAll(properties, context);

        StringBuilder sb = new StringBuilder();

        foreach (var prop in theProperties)
        {
            sb.Append(" -prop ").Append(UTExecutableParam.Quote(prop));
        }

        Process process = new Process();

        process.StartInfo.FileName  = UTils.GetEditorExecutable();
        process.StartInfo.Arguments = "-projectPath " + UTExecutableParam.Quote(theProjectPath) +
                                      " -executeMethod UTExternalRunner.RunPlan -plan " + UTExecutableParam.Quote(thePlanName) +
                                      " -debugMode " + theDebugMode + sb.ToString();
        if (UTPreferences.DebugMode)
        {
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute        = false;
            process.OutputDataReceived += (sender, args) => UDebug.Log("[Unity]" + args.Data);
            UDebug.Log("Executing: " + process.StartInfo.FileName + " with arguments " + process.StartInfo.Arguments);
        }

        try {
            if (!process.Start())
            {
                throw new UTFailBuildException("Unable to start Unity3D.", this);
            }
            if (UTPreferences.DebugMode)
            {
                process.BeginOutputReadLine();
            }
        } catch (Win32Exception e) {
            throw new UTFailBuildException("Unable to start process " + e.Message, this);
        }
        do
        {
            yield return("");

            if (context.CancelRequested && !process.HasExited)
            {
                process.Kill();
                break;
            }
        } while(!process.HasExited);

        if (!context.CancelRequested && failOnError.EvaluateIn(context))
        {
            if (process.ExitCode != 0)
            {
                throw new UTFailBuildException("Plan " + thePlanName + " failed or was cancelled.", this);
            }
        }
    }
    public override IEnumerator Execute(UTContext context)
    {
        var theOutput = outputFileName.EvaluateIn(context);

        if (string.IsNullOrEmpty(theOutput))
        {
            throw new UTFailBuildException("You must specify an output file name.", this);
        }

        if (theOutput.StartsWith(Application.dataPath))
        {
            throw new UTFailBuildException("Building a player inside the assets folder will break the build. Please place it somewhere else.", this);
        }


        var theTarget = targetPlatform.EvaluateIn(context);

        if (addPlatformExtension.EvaluateIn(context))
        {
            theOutput += GetPlatformExtension(theTarget);
            UTFileUtils.EnsureParentFolderExists(theOutput);
        }

#if UNITY_4_1
        // workaround for UNITY_4_1 offering StandaloneOSXUniversal but not being able to build for it.
        if (theTarget == BuildTarget.StandaloneOSXUniversal)
        {
            theTarget = BuildTarget.StandaloneOSXIntel;
        }
#endif

        var useBuildSettings = useScenesFromBuildSettings.EvaluateIn(context);

        string[] scenes;
        if (!useBuildSettings)
        {
            // get them from includes/excludes
            var theIncludes = EvaluateAll(includes, context);
            var theExcludes = EvaluateAll(excludes, context);

            var fileSet = UTFileUtils.CalculateFileset(theIncludes, theExcludes);
            if (fileSet.Length == 0)
            {
                throw new UTFailBuildException("The file set yielded no scenes to include into the player.", this);
            }

            scenes = fileSet;
        }
        else
        {
            var scenesFromEditor = EditorBuildSettings.scenes;
            if (scenesFromEditor.Length == 0)
            {
                throw new UTFailBuildException("There are no scenes set up in the editor build settings.", this);
            }
            var active = Array.FindAll(scenesFromEditor, scene => scene.enabled);
            scenes = Array.ConvertAll(active, scene => scene.path);
        }

        if (UTPreferences.DebugMode)
        {
            foreach (var entry in scenes)
            {
                Debug.Log("Adding scene: " + entry, this);
            }
        }

        BuildOptions buildOptions = BuildOptions.None;
        if (developmentBuild.EvaluateIn(context))
        {
            buildOptions |= BuildOptions.Development;
        }

        if (runTheBuiltPlayer.EvaluateIn(context))
        {
            buildOptions |= BuildOptions.AutoRunPlayer;
        }

        if (showTheBuiltPlayer.EvaluateIn(context))
        {
            buildOptions |= BuildOptions.ShowBuiltPlayer;
        }

        if (buildStreamedScenes.EvaluateIn(context))
        {
            buildOptions |= BuildOptions.BuildAdditionalStreamedScenes;
        }

        if (acceptExternalModifications.EvaluateIn(context))
        {
            buildOptions |= BuildOptions.AcceptExternalModificationsToPlayer;
        }

        if (connectWithProfiler.EvaluateIn(context))
        {
            buildOptions |= BuildOptions.ConnectWithProfiler;
        }

        if (allowDebugging.EvaluateIn(context))
        {
            buildOptions |= BuildOptions.AllowDebugging;
        }

        if (uncompressedAssetBundle.EvaluateIn(context))
        {
            buildOptions |= BuildOptions.UncompressedAssetBundle;
        }

        if (theTarget == BuildTarget.WebPlayer || theTarget == BuildTarget.WebPlayerStreamed)
        {
            if (offlineDeployment.EvaluateIn(context))
            {
                buildOptions |= BuildOptions.WebPlayerOfflineDeployment;
            }
            if (deployOnline.EvaluateIn(context))
            {
                //buildOptions |= BuildOptions.DeployOnline;
            }
        }

        if (theTarget == BuildTarget.iOS)
        {
            if (symlinkLibraries.EvaluateIn(context))
            {
                buildOptions |= BuildOptions.SymlinkLibraries;
            }
        }


        Debug.Log("Building " + ObjectNames.NicifyVariableName(theTarget.ToString()) + " player including " + scenes.Length + " scenes to " + theOutput);
        yield return("");

        if (pushDependencies.EvaluateIn(context))
        {
            UTAssetDependencyStack.Push();
        }
        try {
            // build the player.
            var result = BuildPipeline.BuildPlayer(scenes, theOutput, theTarget, buildOptions);
            if (!string.IsNullOrEmpty(result))
            {
                throw new UTFailBuildException("Building the player failed. " + result, this);
            }
        }
        finally {
            if (popAllDependencies.EvaluateIn(context))
            {
                UTAssetDependencyStack.PopAll();
            }
            else if (popDependencies.EvaluateIn(context))
            {
                UTAssetDependencyStack.Pop();
            }
        }
    }
Beispiel #27
0
    public override IEnumerator Execute(UTContext context)
    {
        DeletionType theDeletionType = deletionType.EvaluateIn(context);
        var          doDryRun        = dryRun.EvaluateIn(context);

        if (theDeletionType == DeletionType.SingleFileOrFolder)
        {
            var theSingleFileOrFolder = fileOrFolder.EvaluateIn(context);
            if (string.IsNullOrEmpty(theSingleFileOrFolder))
            {
                throw new UTFailBuildException("You need to specify the name of the file or folder to be deleted.", this);
            }
            if (doDryRun)
            {
                Debug.Log("[Dry Run] Would delete " + theSingleFileOrFolder);
            }
            else
            {
                FileAttributes attributes;
                try {
                    attributes = File.GetAttributes(theSingleFileOrFolder);
                }
                catch (DirectoryNotFoundException) {
                    if (UTPreferences.DebugMode)
                    {
                        Debug.Log("File " + theSingleFileOrFolder + " already deleted.");
                    }
                    yield break;
                }
                if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    if (UTPreferences.DebugMode)
                    {
                        Debug.Log("Deleting directory " + theSingleFileOrFolder);
                    }
                    Directory.Delete(theSingleFileOrFolder, true);
                }
                else
                {
                    if (UTPreferences.DebugMode)
                    {
                        Debug.Log("Deleting file " + theSingleFileOrFolder);
                    }
                    File.Delete(theSingleFileOrFolder);
                }
            }
        }
        else
        {
            var theBaseDirectory = baseDirectory.EvaluateIn(context);
            if (string.IsNullOrEmpty(theBaseDirectory))
            {
                theBaseDirectory = UTFileUtils.ProjectRoot;
            }
            if (!Directory.Exists(theBaseDirectory))
            {
                Debug.Log("Base directory " + theBaseDirectory + " does not exist. Skipping delete action.");
            }
            else
            {
                theBaseDirectory = UTFileUtils.NormalizeSlashes(theBaseDirectory);

                var theIncludes = EvaluateAll(includes, context);
                var theExcludes = EvaluateAll(excludes, context);

                var theStuff = UTFileUtils.CalculateFileset(theBaseDirectory, theIncludes, theExcludes, UTFileUtils.FileSelectionMode.FilesAndFolders);


                Debug.Log("Deleting " + theStuff.Length + " files & directories.");

                for (int i = 0; i < theStuff.Length; i++)
                {
                    context.LocalProgress = ((float)i) / ((float)theStuff.Length);

                    var stuff  = theStuff [i];
                    var exists = File.Exists(stuff) || Directory.Exists(stuff);
                    if (!exists)
                    {
                        Debug.LogWarning(stuff + " does no longer exist. Check if your fileset can be simplified.");
                        // maybe was a subfolder of a directory that got deleted before.
                        continue;
                    }
                    var attributes = File.GetAttributes(stuff);
                    if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        if (doDryRun)
                        {
                            Debug.Log("[Dry Run] Would delete directory " + stuff);
                        }
                        else
                        {
                            if (UTPreferences.DebugMode)
                            {
                                Debug.Log("Deleting directory " + stuff);
                            }
                            Directory.Delete(stuff, true);
                        }
                    }
                    else
                    {
                        if (doDryRun)
                        {
                            Debug.Log("[Dry Run] Would delete file" + stuff);
                        }
                        else
                        {
                            if (UTPreferences.DebugMode)
                            {
                                Debug.Log("Deleting file " + stuff);
                            }
                            File.Delete(stuff);
                        }
                    }
                    yield return("");
                }
            }
        }
    }
    public override IEnumerator Execute(UTContext context)
    {
        var files = UTFileUtils.CalculateFileset(EvaluateAll(includes, context), EvaluateAll(excludes, context));

        UTFileUtils.FullPathToProjectPath(files);          // repath them to be relative to project root

        var doAmend   = amend.EvaluateIn(context);
        var theLabels = EvaluateAll(labels, context);

        Debug.Log("The labels: " + string.Join(", ", theLabels));

        if (doAmend && theLabels.Length == 0)
        {
            Debug.LogWarning("Amend is set to true but no labels are specified. This will effectively change nothing.");
            yield break;
        }

        Debug.Log("Updating the labels of " + files.Length + " assets.");

        foreach (var file in files)
        {
            if (file.EndsWith(".meta"))
            {
                Debug.LogWarning("File set contains a meta file: " + file + ". Please exclude meta files from the fileset.", this);
                continue;
            }
            var      asset       = AssetDatabase.LoadAssetAtPath(file, typeof(UObject));
            string[] finalLabels = theLabels;

            if (doAmend)
            {
                var currentLabels = AssetDatabase.GetLabels(asset);
                var knownLabels   = new HashSet <string> (currentLabels);
                foreach (var aLabel in theLabels)
                {
                    if (!knownLabels.Contains(aLabel))
                    {
                        knownLabels.Add(aLabel);
                    }
                }
                finalLabels = new string[knownLabels.Count];
                knownLabels.CopyTo(finalLabels);
            }
            if (UTPreferences.DebugMode)
            {
                Debug.Log("Setting labels of " + file + " to [" + string.Join(", ", finalLabels) + "]", this);
            }

            if (finalLabels.Length == 0)
            {
                AssetDatabase.ClearLabels(asset);
            }
            else
            {
                AssetDatabase.SetLabels(asset, finalLabels);
            }
            EditorUtility.SetDirty(asset);
            yield return("");
        }

        AssetDatabase.SaveAssets();         // save asset changes.
        Debug.Log("Assets successfully updated.");
    }
    public override System.Collections.IEnumerator Execute(UTContext context)
    {
        if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebPlayer ||
            EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebPlayerStreamed)
        {
            Debug.LogWarning("You have currently set the build target to 'Web Player'. This may cause interference with actions that access the internet. If you get an error message about cross domain policy from this action, switch the target to 'PC and Mac Standalone' and try again.");
        }

        var theNexusUrl = nexusUrl.EvaluateIn(context);

        if (string.IsNullOrEmpty(theNexusUrl))
        {
            throw new UTFailBuildException("You need to specify the nexus URL", this);
        }

        var theRepoId = repositoryId.EvaluateIn(context);

        if (string.IsNullOrEmpty(theRepoId))
        {
            throw new UTFailBuildException("You need to specify the repository id.", this);
        }


        var theUserName = userName.EvaluateIn(context);
        var thePassword = password.EvaluateIn(context);

        var theGroupId = groupId.EvaluateIn(context);

        if (string.IsNullOrEmpty(theGroupId))
        {
            throw new UTFailBuildException("You need to specify the group id.", this);
        }

        var theArtifactId = artifactId.EvaluateIn(context);

        if (string.IsNullOrEmpty(theArtifactId))
        {
            throw new UTFailBuildException("You need to specify the artifact id.", this);
        }

        var theVersion = version.EvaluateIn(context);

        if (string.IsNullOrEmpty(theVersion))
        {
            throw new UTFailBuildException("You need to specify the version.", this);
        }


        var thePackaging = packaging.EvaluateIn(context);

        if (string.IsNullOrEmpty(thePackaging))
        {
            throw new UTFailBuildException("You need to specify the packaging.", this);
        }

        var theExtension  = extension.EvaluateIn(context);
        var theClassifier = classifier.EvaluateIn(context);

        var theOutputFileName = outputFileName.EvaluateIn(context);

        if (string.IsNullOrEmpty(theOutputFileName))
        {
            throw new UTFailBuildException("You need to specify the output file name.", this);
        }

        if (Directory.Exists(theOutputFileName))
        {
            throw new UTFailBuildException("The specified output file " + theOutputFileName + " is a directory.", this);
        }

        UTFileUtils.EnsureParentFolderExists(theOutputFileName);

        // TODO: ignore SSL certs if required
        using (var wc = new WebClient()) {
            if (!string.IsNullOrEmpty(theUserName))
            {
                wc.Credentials = new NetworkCredential(theUserName, thePassword);
            }


            Uri uri = new Uri(theNexusUrl + "/service/local/artifact/maven/content?" +
                              "g=" + Uri.EscapeUriString(theGroupId) +
                              "&a=" + Uri.EscapeUriString(theArtifactId) +
                              "&v=" + Uri.EscapeUriString(theVersion) +
                              "&r=" + Uri.EscapeUriString(theRepoId) +
                              "&p=" + Uri.EscapeUriString(thePackaging) +
                              (!string.IsNullOrEmpty(theClassifier) ? "&c=" + Uri.EscapeUriString(theClassifier) : "") +
                              (!string.IsNullOrEmpty(theExtension) ? "&e=" + Uri.EscapeUriString(theExtension) : ""));


            downloadFinished          = false;
            error                     = false;
            wc.DownloadFileCompleted += delegate(object sender, AsyncCompletedEventArgs e) {
                downloadFinished = true;
                error            = e.Error != null;
                if (error)
                {
                    Debug.LogError("An error occured while downloading. " + e.Error.Message, this);
                }
            };

            wc.DownloadFileAsync(uri, theOutputFileName);

            do
            {
                yield return("");

                if (context.CancelRequested)
                {
                    wc.CancelAsync();
                }
            } while(!downloadFinished);

            if (!error && !context.CancelRequested)
            {
                Debug.Log("Successfully downloaded artifact to " + theOutputFileName + ".", this);
            }

            if (context.CancelRequested)
            {
                File.Delete(theOutputFileName);
            }
        }
    }