Add Actor.HasScene and Script.HasScene
Useful in managed code to check the existence of the scene in hot paths by avoiding expensive marshalling of the Scene object.
This commit is contained in:
@@ -89,7 +89,7 @@ namespace FlaxEditor.Content
|
||||
// Cleanup it after usage
|
||||
Object.Destroy(actor, 20.0f);
|
||||
}
|
||||
else if (actor.Scene != null)
|
||||
else if (actor.HasScene)
|
||||
{
|
||||
// Create prefab with identity transform so the actor instance on a level will have it customized
|
||||
resetTransform = true;
|
||||
|
||||
@@ -291,7 +291,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
||||
if (editor.ChildrenEditors.Count == 0 || (isRefEdited && editor is CollectionEditor))
|
||||
result = CreateDiffNode(editor);
|
||||
bool isScriptEditorWithRefValue = editor is ScriptsEditor && editor.Values.HasReferenceValue;
|
||||
bool isActorEditorInLevel = editor is ActorEditor && editor.Values[0] is Actor actor && actor.IsPrefabRoot && actor.Scene != null;
|
||||
bool isActorEditorInLevel = editor is ActorEditor && editor.Values[0] is Actor actor && actor.IsPrefabRoot && actor.HasScene;
|
||||
for (int i = 0; i < editor.ChildrenEditors.Count; i++)
|
||||
{
|
||||
var childEditor = editor.ChildrenEditors[i];
|
||||
|
||||
@@ -227,7 +227,7 @@ namespace FlaxEditor.Modules
|
||||
|
||||
// When applying changes to prefab from actor in level ignore it's root transformation (see ActorEditor.ProcessDiff)
|
||||
var originalTransform = instance.LocalTransform;
|
||||
if (instance.IsPrefabRoot && instance.Scene != null)
|
||||
if (instance.IsPrefabRoot && instance.HasScene)
|
||||
instance.LocalTransform = prefab.GetDefaultInstance().Transform;
|
||||
|
||||
// Call backend
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace FlaxEditor.SceneGraph.GUI
|
||||
Visible = (actor.HideFlags & HideFlags.HideInHierarchy) == 0;
|
||||
|
||||
// Pick the correct id when inside a prefab window.
|
||||
var id = actor.HasPrefabLink && actor.Scene == null ? actor.PrefabObjectID : actor.ID;
|
||||
var id = actor.HasPrefabLink && !actor.HasScene ? actor.PrefabObjectID : actor.ID;
|
||||
if (Editor.Instance.ProjectCache.IsExpandedActor(ref id))
|
||||
{
|
||||
Expand(true);
|
||||
@@ -291,7 +291,7 @@ namespace FlaxEditor.SceneGraph.GUI
|
||||
return Style.Current.ForegroundGrey;
|
||||
}
|
||||
|
||||
if (actor.Scene != null && Editor.Instance.StateMachine.IsPlayMode && actor.IsStatic)
|
||||
if (actor.HasScene && Editor.Instance.StateMachine.IsPlayMode && actor.IsStatic)
|
||||
{
|
||||
// Static
|
||||
return color * 0.85f;
|
||||
@@ -366,7 +366,7 @@ namespace FlaxEditor.SceneGraph.GUI
|
||||
if (!IsLayoutLocked && actor)
|
||||
{
|
||||
// Pick the correct id when inside a prefab window.
|
||||
var id = actor.HasPrefabLink && actor.Scene == null ? actor.PrefabObjectID : actor.ID;
|
||||
var id = actor.HasPrefabLink && !actor.HasScene ? actor.PrefabObjectID : actor.ID;
|
||||
Editor.Instance.ProjectCache.SetExpandedActor(ref id, IsExpanded);
|
||||
}
|
||||
}
|
||||
@@ -640,8 +640,8 @@ namespace FlaxEditor.SceneGraph.GUI
|
||||
private bool ValidateDragScript(Script script)
|
||||
{
|
||||
// Reject dragging scripts not linked to scene (eg. from prefab) or in the opposite way
|
||||
var thisHasScene = Actor.Scene != null;
|
||||
var otherHasScene = script.Scene != null;
|
||||
var thisHasScene = Actor.HasScene;
|
||||
var otherHasScene = script.HasScene;
|
||||
if (thisHasScene != otherHasScene)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace FlaxEditor.SceneGraph
|
||||
private void OnActorSpawned(Actor actor)
|
||||
{
|
||||
// Skip actors from game
|
||||
if (actor.Scene != null)
|
||||
if (actor.HasScene)
|
||||
return;
|
||||
|
||||
// Check if it has parent
|
||||
|
||||
@@ -382,6 +382,15 @@ public:
|
||||
return _isActiveInHierarchy != 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets value indicating if actor is in a scene.
|
||||
/// </summary>
|
||||
API_PROPERTY(Attributes="HideInEditor, NoSerialize")
|
||||
FORCE_INLINE bool HasScene() const
|
||||
{
|
||||
return _scene != nullptr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if object is fully static on the scene, otherwise false.
|
||||
/// </summary>
|
||||
|
||||
@@ -17,6 +17,12 @@ namespace FlaxEngine
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets value indicating if the actor owning the script is in a scene.
|
||||
/// </summary>
|
||||
[HideInEditor, NoSerialize]
|
||||
public bool HasScene => Actor?.HasScene ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the world space transformation of the actors owning this script.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user