Beispiel #1
0
    private void CleanUp()
    {
        UTils.ClearAsyncProgressBar();
        var cancelled = context.CancelRequested;
        var failed    = context.Failed;

        context    = null;
        enumerator = null;

        var endTime  = DateTime.Now;
        var duration = endTime - startTime;

        if (!cancelled && !failed)           // recording cancelled runs will greatly diminish the accuracy of the statistics, so don't record them
        {
            UTStatistics.RecordRuntime(plan, (float)duration.TotalSeconds);
        }
        plan = null;
        Debug.Log("Automation finished in " + FormatTime(duration, false) + ".");
        if (cancelled)
        {
            Debug.LogWarning("Run was canceled by user.");
        }
        if (failed)
        {
            Debug.LogError("Run failed with error.");
        }

        if (OnRunnerFinished != null)
        {
            OnRunnerFinished(cancelled, failed);
        }

        // now check if the player settings were modified by an action, in this case we don't reset them
        var newBackgroundSetting = PlayerSettings.runInBackground;

        Application.runInBackground = false;

        // and reset it back if it wasn't so we don't f**k up what was set before..
        if (newBackgroundSetting == playerSettingsRunInBackgroundValue)
        {
            // not modified by an action, in this case reset it
            PlayerSettings.runInBackground = playerSettingsRunInBackgroundValue;
        }

        if (reloadOfAssembliesLocked)
        {
            Debug.Log("Releasing assembly reload lock now.");
            EditorApplication.UnlockReloadAssemblies();
        }
        AssetDatabase.Refresh();          // make sure updates are shown in the editor.
    }
Beispiel #2
0
    /// <summary>
    /// Clears the unused entries in the automation plan asset located at the given path. This is necessary
    /// because we support undo/redo with the visual editor and therefore don't delete automation plan entries
    /// when they are removed from the graphical view. The unused entries are cleared when the plan is saved.
    /// </summary>
    /// <param name='path'>
    /// Path.
    /// </param>
    /// <seealso cref="UTSaveInterceptor"/>
    public static void ClearUnusedEntriesIn(string path)
    {
        var asset = AssetDatabase.LoadMainAssetAtPath(path);

        if (asset is UTAutomationPlan)
        {
            var     plan      = (UTAutomationPlan)asset;
            UTGraph graph     = null;
            var     allAssets = AssetDatabase.LoadAllAssetsAtPath(path);
            var     entries   = new List <UTAutomationPlanEntry> ();
            foreach (var anAsset in allAssets)
            {
                if (anAsset is UTGraph)
                {
                    graph = (UTGraph)anAsset;
                }
                if (anAsset is UTAutomationPlanEntry)
                {
                    entries.Add((UTAutomationPlanEntry)anAsset);
                }
            }

            var deps = EditorUtility.CollectDependencies(new UObject[] { plan, graph });
            foreach (var dep in deps)
            {
                if (dep is UTAutomationPlanEntry)
                {
                    entries.Remove((UTAutomationPlanEntry)dep);
                }
            }

            if (UTPreferences.DebugMode && entries.Count > 0)
            {
                Debug.Log("Clearing " + entries.Count + " leaked entries from " + plan.name + ". This message is harmless.");
            }
            foreach (var entry in entries)
            {
                ScriptableObject.DestroyImmediate(entry, true);
            }

            UTStatistics.CleanUp();
        }
    }
Beispiel #3
0
    /// <summary>
    /// Requests to run a certain plan. Only one plan can run at a time.
    /// </summary>
    /// <param name='plan'>
    /// The plan to run.
    /// </param>
    /// <param name='context'>
    /// Context in which the plan should run.
    /// </param>
    public void RequestRun(UTAutomationPlan plan, UTContext context)
    {
#if UTOMATE_DEMO
        // when developing utomate demo locally we want to allow our own plans, so we set another flag which
        // removes this restriction for us.
#if !UTOMATE_DEVELOPMENT_MODE
        if (UTomate.CheckPlanCountExceeded())
        {
            return;
        }
#endif
#endif

        if (IsRunning)
        {
            throw new InvalidOperationException("The runner is currently busy. Use IsRunning to check if the runner is busy, before invoking this.");
        }
        this.plan    = plan;
        this.context = context;
        float expectedTimeInSeconds = 0;
        this.planWasRunBefore     = UTStatistics.GetExpectedRuntime(plan, out expectedTimeInSeconds);
        this.expectedTime         = TimeSpan.FromSeconds(expectedTimeInSeconds);
        UTPreferences.LastRunPlan = plan.name;
        planLookupDone            = false;

        if (OnRunnerStarted != null)
        {
            OnRunnerStarted();
        }
        // save all changes to assets before run.
        AssetDatabase.SaveAssets();
        EditorApplication.SaveAssets();

        // keep stuff running in background
        // this will overwrite playersettings implicitely, therefore we store the previous value here..
        playerSettingsRunInBackgroundValue = PlayerSettings.runInBackground;
        Application.runInBackground        = true;
        // and set it back here... so we don't f**k up the settings that were set before running utomate.
        PlayerSettings.runInBackground = playerSettingsRunInBackgroundValue;
        this.reloadOfAssembliesLocked  = false;
    }
Beispiel #4
0
    private void DrawRunner()
    {
        GUILayout.Label("Runner", UTEditorResources.TitleStyle);

        var lastPlan = UTomateRunner.Instance.LastPlan;

        if (lastPlan != null && !UTomateRunner.Instance.IsRunning)
        {
            Rect boxRect = EditorGUILayout.BeginHorizontal(UTEditorResources.RunAgainBoxStyle);
            EditorGUI.HelpBox(boxRect, "Last executed plan: " + lastPlan.name, MessageType.None);
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(UTEditorResources.RunAgainIcon, UTEditorResources.RunAgainButtonStyle))
            {
                UTomate.Run(lastPlan);
            }
            EditorGUILayout.EndHorizontal();
        }
        EditorGUILayout.Space();

        UTomateRunner.Instance.DrawGUI();

        if (!UTomateRunner.Instance.IsRunning)
        {
            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();
            GUI.enabled = UTStatistics.HasStatistics();
            if (GUILayout.Button("Clear plan statistics"))
            {
                UTStatistics.Clear();
            }
            GUI.enabled = true;
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
        else
        {
            Repaint();
        }
    }