forked from RealityStop/ecslite-unityeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added manual naming to the new ecslite-unityeditor
- Loading branch information
1 parent
ebd625a
commit 4d2d0cb
Showing
3 changed files
with
91 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Leopotam.EcsLite.UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Leopotam.EcsLite | ||
{ | ||
public struct UnityDebugName | ||
{ | ||
public string DisplayName; | ||
|
||
public bool changed; | ||
} | ||
|
||
public static class UnityDebugNamingExt | ||
{ | ||
/// <summary> | ||
/// Creates a new entity. If running inside the unity editor, the passed name will be used | ||
/// in the debug hierarchy. (In builds, this is ignored) | ||
/// </summary> | ||
public static int NewEntity(this EcsWorld world, string entityName) | ||
{ | ||
int result = world.NewEntity(); | ||
#if UNITY_EDITOR | ||
ref UnityDebugName nameComponent = ref world.GetPool<UnityDebugName>().Add(result); | ||
nameComponent.DisplayName = entityName; | ||
nameComponent.changed = true; | ||
#endif | ||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the debug name shown for an entity in the debug hierarchy, if running | ||
/// inside the unity editor. (In builds, this is ignored) | ||
/// </summary> | ||
public static void UpdateEntityName(this EcsWorld world, int entity, string entityName) | ||
{ | ||
#if UNITY_EDITOR | ||
var pool = world.GetPool<UnityDebugName>(); | ||
ref UnityDebugName nameComponent = ref pool.GetOrCreate(entity); | ||
nameComponent.DisplayName = entityName; | ||
nameComponent.changed = true; | ||
#endif | ||
} | ||
|
||
|
||
private static ref T GetOrCreate<T>(this EcsPool<T> self, int entity) where T : struct | ||
{ | ||
if (!self.Has(entity)) | ||
{ | ||
return ref self.Add(entity); | ||
} | ||
|
||
return ref self.Get(entity); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.