void RegisterInternalTypes() { CryScript script; if (CryScript.TryCreate(typeof(NativeActor), out script)) { Scripts.Add(script); } if (CryScript.TryCreate(typeof(NativeEntity), out script)) { var entityRegistrationParams = new EntityRegistrationParams(); entityRegistrationParams.name = script.ScriptName; entityRegistrationParams.flags = EntityClassFlags.Default | EntityClassFlags.Invisible; #if !UNIT_TESTING NativeEntityMethods.RegisterEntityClass(entityRegistrationParams); #endif Scripts.Add(script); } }
bool TryGetEntityParams(ref IScriptRegistrationParams registrationParams, Type type) { var entityRegistrationParams = new EntityRegistrationParams(); //LoadFlowNode(ref script, true); BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; var folders = type.GetNestedTypes(flags).Where(x => x.ContainsAttribute<EditorPropertyFolderAttribute>()); var members = type.GetMembers(flags); var entityProperties = new List<object>(); EntityProperty property; members.ForEach(member => { if (TryGetProperty(member, out property)) entityProperties.Add(property); }); folders.ForEach(folder => { folder.GetMembers().ForEach(member => { if (TryGetProperty(member, out property)) { property.folder = folder.Name; entityProperties.Add(property); } }); }); entityRegistrationParams.properties = entityProperties.ToArray(); EntityAttribute entAttribute; if (type.TryGetAttribute(out entAttribute)) { entityRegistrationParams.name = entAttribute.Name; var curType = type; var entType = typeof(Entity); while (curType != entType) { if (type.TryGetAttribute(out entAttribute)) { // don't override if the type before this (or earlier) changed it. if(entityRegistrationParams.category == null) entityRegistrationParams.category = entAttribute.Category; if(entityRegistrationParams.editorHelper == null) entityRegistrationParams.editorHelper = entAttribute.EditorHelper; if(entityRegistrationParams.editorIcon == null) entityRegistrationParams.editorIcon = entAttribute.Icon; if(entityRegistrationParams.flags == EntityClassFlags.Default) entityRegistrationParams.flags = entAttribute.Flags; } curType = curType.BaseType; } } registrationParams = entityRegistrationParams; return true; }
bool TryGetEntityParams(ref IScriptRegistrationParams registrationParams, Type type) { var entityRegistrationParams = new EntityRegistrationParams(); BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; var members = type.GetMembers(flags); var entityProperties = new Dictionary<string, List<EditorProperty>>(); members.ForEach(member => TryGetEntityProperty(member, ref entityProperties)); int numProperties = entityProperties.Count; if (numProperties > 0) { var folders = new EditorPropertyFolder[numProperties]; for (int i = 0; i < numProperties; i++) { var folderPair = entityProperties.ElementAt(i); var folder = new EditorPropertyFolder(); folder.name = folderPair.Key; folder.properties = folderPair.Value.Cast<object>().ToArray(); folders[i] = folder; } entityRegistrationParams.propertyFolders = folders.Cast<object>().ToArray(); } var curType = type; bool changedFlags = false; var entType = typeof(Entity); // This should not be specific to entities, all scripts should be able to utilize this parent class attribute functionality. while (curType != entType) { EntityAttribute entAttribute; if (curType.TryGetAttribute(out entAttribute)) { // don't override if the type before this (or earlier) changed it. if (entityRegistrationParams.name == null) entityRegistrationParams.name = entAttribute.Name; if (entityRegistrationParams.category == null) entityRegistrationParams.category = entAttribute.Category; if (entityRegistrationParams.editorHelper == null) entityRegistrationParams.editorHelper = entAttribute.EditorHelper; if (entityRegistrationParams.editorIcon == null) entityRegistrationParams.editorIcon = entAttribute.Icon; if (!changedFlags) { entityRegistrationParams.flags = entAttribute.Flags; changedFlags = true; } } curType = curType.BaseType; } registrationParams = entityRegistrationParams; return true; }
internal static extern bool RegisterEntityClass(EntityRegistrationParams registerParams);
IScriptRegistrationParams TryGetEntityParams(Type type) { var entityRegistrationParams = new EntityRegistrationParams(); BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; var members = type.GetMembers(flags); var entityProperties = new Dictionary<string, List<EditorProperty>>(); members.ForEach(member => TryGetEntityProperty(member, ref entityProperties)); int numProperties = entityProperties.Count; if (numProperties > 0) { var properties = new List<object>(); foreach (var folder in entityProperties) { if (folder.Key != "Default") { properties.Add(new EditorProperty(folder.Key, null, null, EditorPropertyType.FolderBegin)); properties.AddRange(folder.Value.Cast<object>()); properties.Add(new EditorProperty(folder.Key, null, null, EditorPropertyType.FolderEnd)); } else properties.AddRange(folder.Value.Cast<object>()); } entityRegistrationParams.properties = properties.ToArray(); } var curType = type; bool changedFlags = false; var entType = typeof(Entity); // This should not be specific to entities, all scripts should be able to utilize this parent class attribute functionality. while (curType != entType) { EntityAttribute entAttribute; if (curType.TryGetAttribute(out entAttribute)) { // don't override if the type before this (or earlier) changed it. if (entityRegistrationParams.name == null) entityRegistrationParams.name = entAttribute.Name; if (entityRegistrationParams.category == null) entityRegistrationParams.category = entAttribute.Category; if (entityRegistrationParams.editorHelper == null) entityRegistrationParams.editorHelper = entAttribute.EditorHelper; if (entityRegistrationParams.editorIcon == null) entityRegistrationParams.editorIcon = entAttribute.Icon; if (!changedFlags) { entityRegistrationParams.flags = entAttribute.Flags; changedFlags = true; } } curType = curType.BaseType; } return entityRegistrationParams; }
bool TryGetEntityParams(ref IScriptRegistrationParams registrationParams, Type type) { var entityRegistrationParams = new EntityRegistrationParams(); BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; var folders = type.GetNestedTypes(flags).Where(x => x.ContainsAttribute<EditorPropertyFolderAttribute>()); var members = type.GetMembers(flags); var entityProperties = new List<object>(); EntityProperty property; members.ForEach(member => { if (TryGetEntityProperty(member, out property)) entityProperties.Add(property); }); folders.ForEach(folder => { folder.GetMembers().ForEach(member => { if (TryGetEntityProperty(member, out property)) { property.folder = folder.Name; entityProperties.Add(property); } }); }); entityRegistrationParams.properties = entityProperties.ToArray(); var curType = type; bool changedFlags = false; var entType = typeof(Entity); // This should not be specific to entities, all scripts should be able to utilize this parent class attribute functionality. while (curType != entType) { EntityAttribute entAttribute; if (curType.TryGetAttribute(out entAttribute)) { // don't override if the type before this (or earlier) changed it. if (entityRegistrationParams.name == null) entityRegistrationParams.name = entAttribute.Name; if (entityRegistrationParams.category == null) entityRegistrationParams.category = entAttribute.Category; if (entityRegistrationParams.editorHelper == null) entityRegistrationParams.editorHelper = entAttribute.EditorHelper; if (entityRegistrationParams.editorIcon == null) entityRegistrationParams.editorIcon = entAttribute.Icon; if (!changedFlags) { entityRegistrationParams.flags = entAttribute.Flags; changedFlags = true; } } curType = curType.BaseType; } registrationParams = entityRegistrationParams; return true; }