mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-08-01 08:18:20 -04:00
* Move all unit tests to Engine/Tests * Fix Margin.EdgeSubtract * Fix Capsule.Contains * EnvironmentVariables.Remove if it's null * Fixed ray trace never returning startedsolid * Fix HistoryList.Navigate on empty list * Fix GameObject.WorldPosition accepting NaNs * Fix flex: initial expanding to the wrong grow/shrink * Translation.TryConvert shouldn't throw on invalid enum strings * Skip sound file tests on machines with no audio device
37 lines
760 B
C#
37 lines
760 B
C#
using System.Text.Json.Nodes;
|
|
|
|
namespace Editor;
|
|
|
|
public static class SceneEditor
|
|
{
|
|
/// <summary>
|
|
/// Is there a <see cref="Component"/> type in the clipboard?
|
|
/// </summary>
|
|
public static bool HasComponentInClipboard()
|
|
{
|
|
return IsComponentJson( EditorUtility.Clipboard.Paste() );
|
|
}
|
|
|
|
/// <summary>
|
|
/// Does this text look like a serialized <see cref="Component"/> - a json object
|
|
/// whose __type is a known component type?
|
|
/// </summary>
|
|
internal static bool IsComponentJson( string text )
|
|
{
|
|
try
|
|
{
|
|
if ( JsonNode.Parse( text ) is JsonObject jso )
|
|
{
|
|
var componentType = TypeLibrary.GetType<Component>( (string)jso["__type"] );
|
|
return componentType is not null;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// Do nothing.
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|