// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved.
using System;
namespace FlaxEditor
{
partial class ScriptsBuilder
{
///
/// Compilation end event delegate.
///
/// False if compilation has failed, otherwise true.
public delegate void CompilationEndDelegate(bool success);
///
/// Compilation message events delegate.
///
/// The message.
/// The target file.
/// The target line.
public delegate void CompilationMessageDelegate(string message, string file, int line);
///
/// Occurs when compilation ends.
///
public static event CompilationEndDelegate CompilationEnd;
///
/// Occurs when compilation success.
///
public static event Action CompilationSuccess;
///
/// Occurs when compilation failed.
///
public static event Action CompilationFailed;
///
/// Occurs when compilation begins.
///
public static event Action CompilationBegin;
///
/// Occurs when compilation just started.
///
public static event Action CompilationStarted;
///
/// Occurs when user scripts reload action is called.
///
public static event Action ScriptsReloadCalled;
///
/// Occurs when user scripts reload starts.
/// User objects should be removed at this point to reduce leaks and issues. Game scripts and game editor scripts assemblies will be reloaded.
///
public static event Action ScriptsReloadBegin;
///
/// Occurs when user scripts reload is performed (just before the actual reload, scenes are serialized and unloaded). All user objects should be cleanup.
///
public static event Action ScriptsReload;
///
/// Occurs when user scripts reload ends.
///
public static event Action ScriptsReloadEnd;
///
/// Occurs when code editor starts asynchronous open a file or a solution.
///
public static event Action CodeEditorAsyncOpenBegin;
///
/// Occurs when code editor ends asynchronous open a file or a solution.
///
public static event Action CodeEditorAsyncOpenEnd;
internal enum EventType
{
CompileBegin = 0,
CompileStarted = 1,
CompileEndGood = 2,
CompileEndFailed = 3,
ReloadCalled = 4,
ReloadBegin = 5,
Reload = 6,
ReloadEnd = 7,
}
internal static void Internal_OnEvent(EventType type)
{
switch (type)
{
case EventType.CompileBegin:
CompilationBegin?.Invoke();
break;
case EventType.CompileStarted:
CompilationStarted?.Invoke();
break;
case EventType.CompileEndGood:
CompilationEnd?.Invoke(true);
CompilationSuccess?.Invoke();
break;
case EventType.CompileEndFailed:
CompilationEnd?.Invoke(false);
CompilationFailed?.Invoke();
break;
case EventType.ReloadCalled:
ScriptsReloadCalled?.Invoke();
break;
case EventType.ReloadBegin:
ScriptsReloadBegin?.Invoke();
break;
case EventType.Reload:
ScriptsReload?.Invoke();
break;
case EventType.ReloadEnd:
ScriptsReloadEnd?.Invoke();
break;
}
}
internal static void Internal_OnCodeEditorEvent(bool isEnd)
{
if (isEnd)
CodeEditorAsyncOpenEnd?.Invoke();
else
CodeEditorAsyncOpenBegin?.Invoke();
}
}
}