当前位置: 首页>>代码示例>>C#>>正文


C# IGameObject.GetComponent方法代码示例

本文整理汇总了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");
     }
 }
开发者ID:gturk,项目名称:Uniject,代码行数:8,代码来源:UnitySphereCollider.cs

示例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");
     }
 }
开发者ID:gturk,项目名称:Uniject,代码行数:8,代码来源:UnityAudioListener.cs

示例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");
     }
 }
开发者ID:gturk,项目名称:Uniject,代码行数:8,代码来源:UnityLight.cs

示例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");
     }
 }
开发者ID:gturk,项目名称:Uniject,代码行数:8,代码来源:UnityButton.cs

示例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;
 }
开发者ID:gturk,项目名称:Uniject,代码行数:9,代码来源:UnityAudioSource.cs

示例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");
     }
 }
开发者ID:gturk,项目名称:Uniject,代码行数:9,代码来源:UnityNavmeshAgent.cs

示例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);
            }
        }
开发者ID:shadercoder,项目名称:Icicle-Framework,代码行数:10,代码来源:ScoreMananger.cs

示例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));
            }
        }
开发者ID:shadercoder,项目名称:Icicle-Framework,代码行数:10,代码来源:PhysicsManager.cs

示例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;
            }
        }
开发者ID:shadercoder,项目名称:Icicle-Framework,代码行数:11,代码来源:PhysicsWorld.cs

示例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;
            }
        }
开发者ID:shadercoder,项目名称:Icicle-Framework,代码行数:13,代码来源:PhysicsManager.cs

示例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;
            }
        }
开发者ID:shadercoder,项目名称:Icicle-Framework,代码行数:13,代码来源:UIPlayerScoreBehavior.cs

示例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);
        }
开发者ID:shadercoder,项目名称:Icicle-Framework,代码行数:18,代码来源:CollisionManager.cs

示例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);
        }
开发者ID:shadercoder,项目名称:Icicle-Framework,代码行数:9,代码来源:CollisionWorld.cs

示例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;
        }
开发者ID:shadercoder,项目名称:Icicle-Framework,代码行数:13,代码来源:CollisionWorld.cs

示例15: OnGameObjectAdded

 private void OnGameObjectAdded(IGameObject newObject)
 {
     if (newObject.GetComponent<ICollisionComponent>() != null)
         RegisterObject(newObject);
 }
开发者ID:shadercoder,项目名称:Icicle-Framework,代码行数:5,代码来源:CollisionWorld.cs


注:本文中的IGameObject.GetComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。