public ConsoleObjectList(IConsoleObject consoleObject, params IConsoleObject[] consoleObjects) { ConsoleObjectGroup = new List <IConsoleObject> { consoleObject }; ConsoleObjectGroup.AddRange(consoleObjects); }
public void AddConsoleObject(IConsoleObject text, params IConsoleObject[] texts) { if (Text.Count > 0) { Text[Text.Count - 1].ConsoleObjectGroup.Add(text); } else { Text.Add(new ConsoleObjectList(text)); } Text[Text.Count - 1].ConsoleObjectGroup.AddRange(texts); }
public void UnregisterConsole(IConsoleObject o) { if (o == null) { return; } Type type = o.GetType(); if (mConsoleInfos.TryGetValue(type, out var consoleInfo)) { consoleInfo.Remove(o); } }
/// <summary> /// if RegisterToConsole called, the UnregisterFromConsole must call at the end of this object lifecircle /// </summary> /// <param name="o">object</param> public static void UnregisterFromConsole(this IConsoleObject o) { #if UNITY_EDITOR if (!Application.isPlaying) { return; } #endif #if LOKI_CONSOLE if (o is ConsoleManager) { ((ConsoleManager)o).UnregisterConsole(o); return; } ConsoleManager consoleMgr = ConsoleManager.Get(); if (consoleMgr != null) { consoleMgr.UnregisterConsole(o); } #endif }
public void RegisterConsole(IConsoleObject o) { ProfilingUtility.BeginSample("RegisterConsole_", o.statID); DoRegister(o); ProfilingUtility.EndSample(); }
private void DoRegister(IConsoleObject o) { Type type = o.GetType(); if (!mConsoleInfos.TryGetValue(type, out var consoleInfo)) { consoleInfo = new List <IConsoleObject>(); mConsoleInfos.Add(type, consoleInfo); } consoleInfo.Union(o); if (mSearchedType.Add(type)) { var reflectTypeInfo = GlobalReflectionCache.FindOrAdd(type); var methods = reflectTypeInfo.FindMethods <ConsoleMethodAttribute>(); foreach (var m in methods) { var attr = m.GetCustomAttribute <ConsoleMethodAttribute>(); MethodInfo validate = null; if (!string.IsNullOrEmpty(attr.validate)) { validate = type.GetMethod(attr.validate); } if (validate != null) { if (validate.IsStatic != m.IsStatic) { DebugUtility.LogError(LoggerTags.Console, "The Method [{0}] and the validate [{1}] must be the same modifier (ex. static)", m.Name, validate.Name); continue; } if (validate.DeclaringType != typeof(bool)) { DebugUtility.LogError(LoggerTags.Console, "The Validate [{0}] must return bool (true or false)", validate.Name); continue; } } string cmd = attr.aliasName; if (string.IsNullOrEmpty(cmd)) { cmd = string.Concat(type.FullName, ".", m.Name); } if (!mCommandInfos.TryGetValue(cmd, out var cmdGroup)) { cmdGroup = new List <ConsoleCommand>(); mCommandInfos.Add(cmd, cmdGroup); } else { if (cmdGroup.FindIndex(command => command.owner == type) >= 0) { DebugUtility.LogError(LoggerTags.Engine, "The command is existed, it is not allowed : {0}", string.Concat(type.FullName, ".", m.Name)); continue; } } ConsoleCommand entry; entry.owner = type; entry.attribute = attr; entry.validate = validate; entry.memberInfo = m; entry.cmd = cmd; cmdGroup.Add(entry); } var fieldsOrProperties = reflectTypeInfo.FindMembers <ConsoleMemberAttribute>(); foreach (var m in fieldsOrProperties) { var attr = m.GetCustomAttribute <ConsoleMemberAttribute>(); MethodInfo validate = null; if (!string.IsNullOrEmpty(attr.validate)) { validate = type.GetMethod(attr.validate); } if (validate != null) { bool memberIsStatic = false; if (m.MemberType == MemberTypes.Field) { memberIsStatic = ((FieldInfo)m).IsStatic; } else if (m.MemberType == MemberTypes.Property) { memberIsStatic = ((PropertyInfo)m).IsStatic(); } if (validate.IsStatic != memberIsStatic) { DebugUtility.LogError(LoggerTags.Console, "The Field [{0}] and the validate [{1}] must be the same modifier (ex. static)", m.Name, validate.Name); continue; } if (validate.DeclaringType != typeof(bool)) { DebugUtility.LogError(LoggerTags.Console, "The Validate [{0}] must return bool (true or false)", validate.Name); continue; } } string cmd = attr.aliasName; if (string.IsNullOrEmpty(cmd)) { cmd = string.Concat(type.FullName, ".", m.Name); } if (!mCommandInfos.TryGetValue(cmd, out var cmdGroup)) { cmdGroup = new List <ConsoleCommand>(); mCommandInfos.Add(cmd, cmdGroup); } else { if (cmdGroup.FindIndex(command => command.owner == type) >= 0) { DebugUtility.LogError(LoggerTags.Engine, "The command is existed, it is not allowed : {0}", string.Concat(type.FullName, ".", m.Name)); continue; } } ConsoleCommand entry; entry.owner = type; entry.attribute = attr; entry.validate = validate; entry.memberInfo = m; entry.cmd = cmd; cmdGroup.Add(entry); } } }
public void AddLineConsoleObject(IConsoleObject text, params IConsoleObject[] texts) { Text.Add(new ConsoleObjectList(text)); Text[Text.Count - 1].ConsoleObjectGroup.AddRange(texts); }
public void AddObjekt(IConsoleObject consobjekt) { listObjects.Add(consobjekt); }