本文整理汇总了C#中MonoBehaviour.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# MonoBehaviour.GetType方法的具体用法?C# MonoBehaviour.GetType怎么用?C# MonoBehaviour.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MonoBehaviour
的用法示例。
在下文中一共展示了MonoBehaviour.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TraceRecursively
static void TraceRecursively( MonoBehaviour _mono, GameObject _obj)
{
if( null == _obj)
return;
Transform parent = _obj.transform.parent;
string log = "{R}" + _mono.GetType();
while( true)
{
if( parent == null)
break;
bool concur = false;
foreach( KeyValuePair<MonoBehaviour, GameObject> pair in s_dicObj)
{
if( pair.Value == parent.gameObject)
{
concur = true;
break;
}
}
if( concur == false)
log = "< [ INVALID ] " + parent.name + " >/" + log;
else
log = "(" + parent.name + ")/" + log;
parent = parent.parent;
}
}
示例2: Process
public static void Process(MonoBehaviour obj)
{
var type = obj.GetType();
var fileds = type.GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic);
foreach(var filed in fileds)
{
var attribute = filed.GetCustomAttributes(typeof(ControlAttribute), true);
if (attribute.Length == 0)
continue;
var controlAttribute = attribute[0] as ControlAttribute;
if (controlAttribute == null)
continue;
if (!string.IsNullOrEmpty(controlAttribute.Name))
{
var control = GetControl(obj.gameObject, controlAttribute.Name, filed.FieldType);
filed.SetValue(obj, control);
continue;
}
if (!string.IsNullOrEmpty(controlAttribute.FullPath))
{
var control = GetControlByFullPath(obj.gameObject, controlAttribute.FullPath, filed.FieldType);
filed.SetValue(obj, control);
continue;
}
}
}
示例3: SendWithDelay
public IEnumerator SendWithDelay(MonoBehaviour sender)
{
yield return new WaitForSeconds(delay);
if (receiver)
receiver.SendMessage(action);
else
Debug.LogWarning("No receiver of signal \"" + action + "\" on object " + sender.name + " (" + sender.GetType().Name + ")", sender);
}
示例4: SerializeComponent
private ComponentData SerializeComponent( MonoBehaviour component )
{
if( component != null )
{
ComponentData componentData = new ComponentData( component.GetType(), JsonUtility.ToJson( component ) );
DestroyImmediate( component );
return componentData;
}
return null;
}
示例5: AddToInventory
public bool AddToInventory(MonoBehaviour item) {
if (ItemInInventory(item))
return false;
inventory.Add(item);
Debug.Log ("Adding a " + item.GetType().ToString() + " to inventory");
UpdateSelectables();
return true;
}
示例6: logObjName
public static string logObjName(MonoBehaviour objx )
{
GameObject obj = objx.gameObject;
string objName = string.Format("{0}/{1} ",obj.name, objx.GetType().Name);
while (obj.transform && obj.transform.parent)
{
obj = obj.transform.parent.gameObject;
objName = string.Format("{0}/{1}", obj.name, objName);
}
return objName;
}
示例7: Start
void Start()
{
EventPool eventPool = GameObject.FindObjectOfType<EventPool>();
GameEvent playerFoundEvent;
eventPool.GetEventFromPool("Player Found", out playerFoundEvent);
playerFoundEvent.onHandleEvent += EventZoom;
currentCamera = cameras[0];
cameraType = currentCamera.GetType();
cameraName.text = cameraType.ToString();
description.text = "This camera follows the player rigidly and can zoom in and out\npress up/down arrows to increase/decrease";
}
示例8: ExamMonoBehaviour
/// <summary>
/// Exams the component to see if there is something not supported.
/// Currently check List only.
/// </summary>
/// <param name="com">The component.</param>
/// <returns>An error list.</returns>
static List<string> ExamMonoBehaviour(MonoBehaviour com)
{
List<string> lstProblem = new List<string>();
//StringBuilder sbProblem = new StringBuilder();
MonoBehaviour behaviour = com as MonoBehaviour;
//Type type = behaviour.GetType();
FieldInfo[] fields = JSSerializerEditor.GetMonoBehaviourSerializedFields(behaviour);
for (var i = 0; i < fields.Length; i++)
{
FieldInfo field = fields[i];
Type fieldType = field.FieldType;
if (fieldType.IsArray)
{
fieldType = fieldType.GetElementType();
}
// ! List is not supported
//
if (fieldType.IsGenericType)
{
lstProblem.Add(new StringBuilder().AppendFormat("{0} {1}.{2} serialization not supported.", fieldType.Name, com.GetType().Name, field.Name).ToString());
//continue;
}
// if this MonoBehaviour refer to another MonoBehaviour (A)
// A must be export or compiled to JavaScript as well
if (typeof(MonoBehaviour).IsAssignableFrom(fieldType))
{
if (!JSSerializerEditor.WillTypeBeAvailableInJavaScript(fieldType))
{
lstProblem.Add(new StringBuilder().AppendFormat("{0} {1}.{2} not available in JavaScript.", fieldType.Name, com.GetType().Name, field.Name).ToString());
}
}
//more to exam
}
return lstProblem;
}
示例9: Open
public void Open(MonoBehaviour scriptToUse, string _dropdownMenu = null)
{
ClearButtons();
script = scriptToUse;
isOpen = true;
if(_dropdownMenu == null){
_dropdownMenu = scriptToUse.GetType().Name;
}
SetButtons(_dropdownMenu);
if(UIManager.UICamera) {
transform.position = UIManager.MainToUICameraPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition));
} else {
transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition + Camera.main.transform.forward * 0.9f);
}
}
示例10: PropertyCopier
public PropertyCopier(MonoBehaviour pPrototype, System.Type pAttribute)
{
prototype = pPrototype;
prototypeType = pPrototype.GetType();
List<PropertyInfo> lOut = new List<PropertyInfo>();
var lMembers =prototypeType.GetMembers();
foreach (var lMember in lMembers)
{
var lAttributes =
lMember.GetCustomAttributes(pAttribute, false);
if (lAttributes.Length > 0)
{
lOut.Add((PropertyInfo)lMember);
}
}
copyList = lOut.ToArray();
}
示例11: EventResponseWrapper
/// <summary>
/// Creates a new instance of EventResponseWrapper, tying the given EventResponder to the specified Event.
/// </summary>
/// <param name="targetComponent">The MonoBehaviour that contains the event to which the EventResponder will be bound.</param>
/// <param name="eventName">The string-name of the Event on the target MonoBehaviour.</param>
/// <param name="responder">The EventResponder object that will be hooked into the specified event.</param>
public EventResponseWrapper(MonoBehaviour targetComponent, string eventName, EventResponder responder)
{
this.targetComponentTypeName = targetComponent.GetType().Name;
this.eventName = eventName;
this.responder = responder;
}
示例12: ExportScript
public void ExportScript(MonoBehaviour monoBehaviour)
{
Debug.Log("Start script export of " + monoBehaviour.GetType());
assets.ExportScript(monoBehaviour.GetType(), false, true);
}
示例13: SendMessage
// ------------------------------------------------------------------
// Desc:
// ------------------------------------------------------------------
protected void SendMessage( MonoBehaviour _sender )
{
if ( receiver ) {
receiver.SendMessage(action);
}
else
Debug.LogWarning ( "No receiver of signal \"" + action
+ "\" on object " + _sender.name
+ " (" + _sender.GetType().Name + ")",
_sender );
}
示例14: GetCachedMethod
private MethodInfo GetCachedMethod(MonoBehaviour monob, PhotonNetworkingMessage methodType)
{
Type type = monob.GetType();
if (!this.cachedMethods.ContainsKey(type))
{
Dictionary<PhotonNetworkingMessage, MethodInfo> newMethodsDict = new Dictionary<PhotonNetworkingMessage, MethodInfo>();
this.cachedMethods.Add(type, newMethodsDict);
}
// Get method type list
Dictionary<PhotonNetworkingMessage, MethodInfo> methods = this.cachedMethods[type];
if (!methods.ContainsKey(methodType))
{
// Load into cache
Type[] argTypes;
if (methodType == PhotonNetworkingMessage.OnPhotonSerializeView)
{
argTypes = new Type[2];
argTypes[0] = typeof(PhotonStream);
argTypes[1] = typeof(PhotonMessageInfo);
}
else if (methodType == PhotonNetworkingMessage.OnPhotonInstantiate)
{
argTypes = new Type[1];
argTypes[0] = typeof(PhotonMessageInfo);
}
else
{
Debug.LogError("Invalid PhotonNetworkingMessage!");
return null;
}
MethodInfo metInfo = monob.GetType().GetMethod(methodType + string.Empty, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, argTypes, null);
if (metInfo != null)
{
methods.Add(methodType, metInfo);
}
}
if (methods.ContainsKey(methodType))
{
return methods[methodType];
}
else
{
return null;
}
}
示例15: CopyBehaviour
static void CopyBehaviour(MonoBehaviour behaviour, JSSerializer serizlizer)
{
lstAnalyze.Clear();
lstString.Clear();
lstObjs.Clear();
// GameObject go = behaviour.gameObject;
//Type type = behaviour.GetType();
FieldInfo[] fields = GetMonoBehaviourSerializedFields(behaviour);
foreach (FieldInfo field in fields)
{
AddAnalyze(field.FieldType, field.Name, field.GetValue(behaviour));
}
TraverseAnalyze();
for (var i = 0; i < lstAnalyze.Count; i++)
{
lstAnalyze[i].Alloc(serizlizer);
}
serizlizer.jsClassName = JSNameMgr.GetTypeFullName(behaviour.GetType());
serizlizer.arrString = lstString.ToArray();
serizlizer.arrObject = lstObjs.ToArray();
}