本文整理汇总了C#中UnityEngine.GameObject.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.GetType方法的具体用法?C# GameObject.GetType怎么用?C# GameObject.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.GameObject
的用法示例。
在下文中一共展示了GameObject.GetType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBooleanMethodsFrom
public List<MethodInfo> GetBooleanMethodsFrom(GameObject gameObject)
{
List<MethodInfo> booleanMethods = new List<MethodInfo> ();
//GameObject boolean methods
foreach(MethodInfo mo in gameObject.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public)) {
if(mo.GetParameters().Length==0
&& mo.ReturnType == typeof(Boolean)) {
booleanMethods.Add(mo);
}
}
//Component of gameObject boolean methods
Component[] comps = gameObject.GetComponents<Component>();
foreach (Component comp in comps) {
if(comp==null)
continue;
MethodInfo[] methods = comp.GetType ().GetMethods (BindingFlags.Instance | BindingFlags.Public);
foreach(MethodInfo mi in methods) {
if(mi.GetParameters().Length==0
&& mi.ReturnType == typeof(Boolean))
booleanMethods.Add (mi);
}
}
return booleanMethods;
}
示例2: GetGamePropertyValue
private object GetGamePropertyValue(GameObject game)
{
if (game == null) return null;
Dictionary<string, object> objectInfo = new Dictionary<string, object>();
objectInfo.Add("type", game.GetType().FullName);
objectInfo.Add("id", GetID(game));
objectInfo.Add("tag", game.tag);
objectInfo.Add("name", game.name);
objectInfo.Add("layer", game.layer);
objectInfo.Add("isStatic", game.isStatic);
objectInfo.Add("hideFlags", game.hideFlags.ToString());
return objectInfo;
}
示例3: PrintUnityGameObject
private void PrintUnityGameObject(GameObject o, IndentedTextWriter writer, Func<GameObject, bool> gameObjectFilter, Func<Component, bool> componentFilter) {
if (o == null) {
writer.WriteLine("(null)");
return;
}
writer.WriteLine("{0} : {1}", o.GetType(), o.name);
if (_visited.ContainsKey(o)) {
writer.Write(" (already dumped)");
return;
}
writer.Indent++;
writer.WriteLine("Components:");
writer.Indent++;
_visited[o] = true;
foreach (var component in o.GetComponents(typeof (Component))) {
writer.WriteLine("[Component] {0}", component.GetType().Name);
if (!componentFilter(component)) continue;
writer.Indent++;
PrintObjectMembers(writer, component);
writer.Indent--;
}
writer.Indent--;
writer.WriteLine("Children:");
var numChildren = o.transform.childCount;
for (int i = 0; i < numChildren; i++) {
var child = o.transform.GetChild(i);
writer.Indent++;
writer.Write("{0}. [Child] ", i);
if (gameObjectFilter(child.gameObject)) {
PrintUnityGameObject(child.gameObject, writer, gameObjectFilter, componentFilter);
}
writer.Indent--;
}
writer.Indent--;
}
示例4: GetPropertyTypeFromString
private static Type GetPropertyTypeFromString(GameObject gameObj, string propertyPath)
{
if (propertyPath == "")
return gameObj.GetType();
var propsQueue = new Queue<string>(propertyPath.Split('.').Where(s => !string.IsNullOrEmpty(s)));
if (propsQueue == null) throw new ArgumentException("Incorrent property path");
Type result;
if (char.IsLower(propsQueue.Peek()[0]))
{
result = gameObj.GetType();
}
else
{
var component = gameObj.GetComponent(propsQueue.Dequeue());
if (component == null) throw new ArgumentException("Incorrent property path");
result = component.GetType();
}
while (propsQueue.Count != 0)
{
var nameToFind = propsQueue.Dequeue();
var property = result.GetProperty(nameToFind);
if (property != null)
{
result = property.PropertyType;
}
else
{
var field = result.GetField(nameToFind);
if (field == null) throw new ArgumentException("Incorrent property path");
result = field.FieldType;
}
}
return result;
}
示例5: PrintUnityGameObject
public void PrintUnityGameObject(GameObject o, int recursionDepth = 0) {
if (o == null) {
_writer.WriteLine("(null)");
return;
}
_writer.Write("{0} : {1}", o.GetType(), o.name);
if (_visited.ContainsKey(o)) {
_writer.WriteLine(" (already dumped)");
return;
}
if (recursionDepth >= _parent.MaxRecursionDepth) {
_writer.WriteLine(" (recursion depth exceeded)");
return;
}
_writer.WriteLine();
_writer.Indent++;
_writer.WriteLine($"Parent: {o.transform.parent?.name}");
_writer.WriteLine("Components:");
_writer.Indent++;
_visited[o] = true;
foreach (var component in o.Components(typeof (Component))) {
_writer.WriteLine("[Component] {0}", component.GetType().Name);
if (!_parent.ComponentFilter(component)) continue;
_writer.Indent++;
PrintObjectMembers(component);
_writer.Indent--;
}
_writer.Indent--;
_writer.WriteLine("Children:");
var numChildren = o.transform.childCount;
for (int i = 0; i < numChildren; i++) {
var child = o.transform.GetChild(i);
_writer.Write("{0}.\t [Child] ", i);
if (_parent.GameObjectFilter(child.gameObject)) {
PrintUnityGameObject(child.gameObject, recursionDepth + 1);
}
}
_writer.Indent--;
}