Simplify code in #2202 for script type searching
This commit is contained in:
@@ -45,6 +45,21 @@ namespace FlaxEditor.Modules.SourceCodeEditing
|
||||
_checkAssembly = checkAssembly;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type matching the certain Script.
|
||||
/// </summary>
|
||||
/// <param name="script">The content item.</param>
|
||||
/// <returns>The type matching that item, or null if not found.</returns>
|
||||
public ScriptType Get(Content.ScriptItem script)
|
||||
{
|
||||
foreach (var type in Get())
|
||||
{
|
||||
if (type.ContentItem == script)
|
||||
return type;
|
||||
}
|
||||
return ScriptType.Null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the types from the all loaded assemblies (including project scripts and scripts from the plugins).
|
||||
/// </summary>
|
||||
|
||||
@@ -693,12 +693,9 @@ namespace FlaxEditor.SceneGraph.GUI
|
||||
for (int i = 0; i < _dragScriptItems.Objects.Count; i++)
|
||||
{
|
||||
var item = _dragScriptItems.Objects[i];
|
||||
// Find actors with the same content item and spawn them.
|
||||
foreach (var actorType in Editor.Instance.CodeEditing.Actors.Get())
|
||||
var actorType = Editor.Instance.CodeEditing.Actors.Get(item);
|
||||
if (actorType != ScriptType.Null)
|
||||
{
|
||||
if (actorType.ContentItem != item)
|
||||
continue;
|
||||
|
||||
var actor = actorType.CreateInstance() as Actor;
|
||||
if (actor == null)
|
||||
{
|
||||
@@ -768,10 +765,7 @@ namespace FlaxEditor.SceneGraph.GUI
|
||||
|
||||
private static bool ValidateDragScriptItem(ScriptItem script)
|
||||
{
|
||||
var actors = Editor.Instance.CodeEditing.Actors.Get();
|
||||
if (actors.Any(x => x.ContentItem == script))
|
||||
return true;
|
||||
return false;
|
||||
return Editor.Instance.CodeEditing.Actors.Get(script) != ScriptType.Null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -943,10 +943,7 @@ namespace FlaxEditor.Viewport
|
||||
|
||||
private static bool ValidateDragScriptItem(ScriptItem script)
|
||||
{
|
||||
var actors = Editor.Instance.CodeEditing.Actors.Get();
|
||||
if (actors.Any(x => x.ContentItem == script))
|
||||
return true;
|
||||
return false;
|
||||
return Editor.Instance.CodeEditing.Actors.Get(script) != ScriptType.Null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -702,13 +702,10 @@ namespace FlaxEditor.Viewport
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private static bool ValidateDragScriptItem(ScriptItem script)
|
||||
{
|
||||
var actors = Editor.Instance.CodeEditing.Actors.Get();
|
||||
if (actors.Any(x => x.ContentItem == script))
|
||||
return true;
|
||||
return false;
|
||||
return Editor.Instance.CodeEditing.Actors.Get(script) != ScriptType.Null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -203,12 +203,9 @@ namespace FlaxEditor.Viewport
|
||||
|
||||
private void Spawn(ScriptItem item, SceneGraphNode hit, ref Float2 location, ref Vector3 hitLocation, ref Vector3 hitNormal)
|
||||
{
|
||||
// Find actors with the same content item and spawn them.
|
||||
foreach (var actorType in Editor.Instance.CodeEditing.Actors.Get())
|
||||
var actorType = Editor.Instance.CodeEditing.Actors.Get(item);
|
||||
if (actorType != ScriptType.Null)
|
||||
{
|
||||
if (actorType.ContentItem != item)
|
||||
continue;
|
||||
|
||||
Spawn(actorType, hit, ref location, ref hitLocation, ref hitNormal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,13 +85,10 @@ namespace FlaxEditor.Windows.Assets
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private static bool ValidateDragScriptItem(ScriptItem script)
|
||||
{
|
||||
var actors = Editor.Instance.CodeEditing.Actors.Get();
|
||||
if (actors.Any(x => x.ContentItem == script))
|
||||
return true;
|
||||
return false;
|
||||
return Editor.Instance.CodeEditing.Actors.Get(script);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -185,12 +182,9 @@ namespace FlaxEditor.Windows.Assets
|
||||
for (int i = 0; i < _dragScriptItems.Objects.Count; i++)
|
||||
{
|
||||
var item = _dragScriptItems.Objects[i];
|
||||
// Find actors with the same content item and spawn them.
|
||||
foreach (var actorType in Editor.Instance.CodeEditing.Actors.Get())
|
||||
var actorType = Editor.Instance.CodeEditing.Actors.Get(item);
|
||||
if (actorType != ScriptType.Null)
|
||||
{
|
||||
if (actorType.ContentItem != item)
|
||||
continue;
|
||||
|
||||
var actor = actorType.CreateInstance() as Actor;
|
||||
if (actor == null)
|
||||
{
|
||||
|
||||
@@ -274,13 +274,10 @@ namespace FlaxEditor.Windows
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private static bool ValidateDragScriptItem(ScriptItem script)
|
||||
{
|
||||
var actors = Editor.Instance.CodeEditing.Actors.Get();
|
||||
if (actors.Any(x => x.ContentItem == script))
|
||||
return true;
|
||||
return false;
|
||||
return Editor.Instance.CodeEditing.Actors.Get(script) != ScriptType.Null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -468,12 +465,9 @@ namespace FlaxEditor.Windows
|
||||
for (int i = 0; i < _dragScriptItems.Objects.Count; i++)
|
||||
{
|
||||
var item = _dragScriptItems.Objects[i];
|
||||
// Find actors with the same content item and spawn them.
|
||||
foreach (var actorType in Editor.Instance.CodeEditing.Actors.Get())
|
||||
var actorType = Editor.Instance.CodeEditing.Actors.Get(item);
|
||||
if (actorType != ScriptType.Null)
|
||||
{
|
||||
if (actorType.ContentItem != item)
|
||||
continue;
|
||||
|
||||
var actor = actorType.CreateInstance() as Actor;
|
||||
if (actor == null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user