本文整理汇总了C#中IGameObject.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# IGameObject.GetComponent方法的具体用法?C# IGameObject.GetComponent怎么用?C# IGameObject.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGameObject
的用法示例。
在下文中一共展示了IGameObject.GetComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnitySphereCollider
public UnitySphereCollider(IGameObject obj)
: base(obj)
{
collider = obj.GetComponent<SphereCollider>();
if (null == collider) {
throw new NullReferenceException("Object " + obj.Name + " expected to have a SphereCollider but none was found");
}
}
示例2: UnityAudioListener
public UnityAudioListener(IGameObject parent)
: base(parent)
{
AudioListener listener = parent.GetComponent<AudioListener>();
if (null == listener) {
throw new NullReferenceException("Object " + parent.Name + " expected to have an AudioListener but none was found");
}
}
示例3: UnityLight
public UnityLight(IGameObject obj)
: base(obj)
{
light = obj.GetComponent<Light>();
if (null == light) {
throw new NullReferenceException("Object " + obj.Name + " expected to have Light but none was found");
}
}
示例4: UnityButton
public UnityButton(IGameObject obj)
: base(obj)
{
btn = obj.GetComponent<Button>();
if (null == btn) {
throw new NullReferenceException("Object " + obj.Name + " expected to have a UnityEngine.UI.Button but none was found");
}
}
示例5: UnityAudioSource
public UnityAudioSource(IGameObject obj)
: base(obj)
{
this.source = obj.GetComponent<AudioSource>();
if (this.source == null) {
throw new NullReferenceException("Object " + obj.Name + " expected to have an AudioSource but none was found");
}
source.rolloffMode = AudioRolloffMode.Linear;
}
示例6: UnityNavmeshAgent
public UnityNavmeshAgent(IGameObject obj)
: base(obj)
{
this.obj = obj;
this.agent = obj.GetComponent<NavMeshAgent>();
if (null == this.agent) {
throw new NullReferenceException("Object " + obj.Name + " expected to have a NavMeshAgent but none was found");
}
}
示例7: OnGameObjectAdded
protected void OnGameObjectAdded(IGameObject newObject)
{
//Register the score component if the IGameObject has one.
var component = newObject.GetComponent<IScoreComponent>();
if (component != null)
{
scores.Add(newObject.GUID, component);
}
}
示例8: OnGameObjectDestroyed
private void OnGameObjectDestroyed(IGameObject gameObject)
{
var collisionComponent = gameObject.GetComponent<IPhysicsComponent>();
if (collisionComponent != null)
{
for (int i = 0; i < collisionComponent.NumBodies; i++)
PhysicsWorld.RemoveBody(collisionComponent.GetBody(i));
}
}
示例9: OnGameObjectAdded
private void OnGameObjectAdded(IGameObject newObject)
{
var collisionComponent = newObject.GetComponent<IPhysicsComponent>();
if (collisionComponent != null)
{
//Subscribe to the collision event for each body.
for (int i = 0; i < collisionComponent.NumBodies; i++)
collisionComponent.GetBody(i).OnCollision += OnCollision;
}
}
示例10: OnGameObjectAddedHandler
private void OnGameObjectAddedHandler(IGameObject newObject)
{
var physicsComponent = newObject.GetComponent<IPhysicsComponent>();
if (physicsComponent != null)
{
newObject.OnDestroyed += OnGameObjectDestroyed;
//Subscribe to the collision event for each body.
for (int i = 0; i < physicsComponent.NumBodies; i++)
physicsComponent.GetBody(i).OnCollision += OnCollision;
}
}
示例11: OnGameObjectAdded
private void OnGameObjectAdded(IGameObject gameObject)
{
//If it's an enemy, and has an IHealthComponent let's watch for its death!
if (!gameObject.Layer.ToLowerInvariant().Equals("enemylayer"))
return;
var healthComp = gameObject.GetComponent<IHealthComponent>();
if (healthComp != null)
{
healthComp.OnHealthDepleted += OnEnemyHealthDepleted;
}
}
示例12: RegisterObject
private void RegisterObject(IGameObject theObject)
{
//Link ourselves to the OnMove event for the game object itself, and the OnDestroyed event for the collision component.
theObject.OnMove += OnMove;
var collisionComponent = theObject.GetComponent<ICollisionComponent>();
collisionTree.Insert(collisionComponent);
//Add an entry to the current collision dictionary...
currentCollisions.Add(theObject.GUID, listPool.New());
currentCollisions[theObject.GUID].Source = collisionComponent;
currentCollisions[theObject.GUID].Destroyed = false;
//..and the collision event dictionaries
onCollisionEventListeners.Add(theObject.GUID, null);
onCollisionStoppedEventListeners.Add(theObject.GUID, null);
}
示例13: RegisterObject
private void RegisterObject(IGameObject theObject)
{
//Link ourselves to the OnMove and OnDestroyed events
theObject.OnMove += OnMove;
theObject.OnDestroyed += OnGameObjectDestroyed;
collisionTree.AddObject(theObject.GetComponent<ICollisionComponent>());
collisionEvents.Add(theObject.GUID, null);
}
示例14: OnGameObjectDestroyed
private void OnGameObjectDestroyed(IGameObject gameObject)
{
ICollisionComponent collisionComponent = gameObject.GetComponent<ICollisionComponent>();
if (collisionComponent != null)
collisionTree.RemoveObject(collisionComponent);
if (collisionEvents.ContainsKey(gameObject.GUID))
collisionEvents.Remove(gameObject.GUID);
gameObject.OnMove -= OnMove;
gameObject.OnDestroyed -= OnGameObjectDestroyed;
}
示例15: OnGameObjectAdded
private void OnGameObjectAdded(IGameObject newObject)
{
if (newObject.GetComponent<ICollisionComponent>() != null)
RegisterObject(newObject);
}