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


C# MonoBehaviour.GetComponent方法代码示例

本文整理汇总了C#中MonoBehaviour.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# MonoBehaviour.GetComponent方法的具体用法?C# MonoBehaviour.GetComponent怎么用?C# MonoBehaviour.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MonoBehaviour的用法示例。


在下文中一共展示了MonoBehaviour.GetComponent方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RegisterUnknownObject

    // Called by OnNetworkInstantiate
    public void RegisterUnknownObject( MonoBehaviour _obj )
    {
        if ( _obj.GetComponent<NetworkView>() == null )
        {
            DebugConsole.Warning( "Cannot add NetworkOwnerControl without a NetworkView (" + _obj.gameObject.name + ")", _obj );
            return;
        }

        NetworkView view = _obj.GetComponent<NetworkView>();
        NetworkViewID id = view.viewID;

        if ( this.map.ContainsKey( _obj.GetComponent<NetworkView>().viewID ) )
        {
            DebugConsole.Warning( "NetworkViewID " + id + " aleady exists as " + _obj.gameObject.name,
                             this.map[id].gameObject );
            DebugConsole.Warning( "Cannot set " + id + " to " + _obj.gameObject.name, _obj.gameObject );
            return;
        }

        if ( view.isMine ) // If it is mine, tell everyone else about it
        {
            int ownerID = Common.MyNetworkID();
            GameNetworkManager.instance.SendSetViewIDMessage( ownerID, id );
            _obj.GetComponent<NetworkOwnerControl>().ownerID = ownerID;
        }
        else // If it isn't mine, store this away and wait for the RPC
        {
            this.map.Add( id, view );
        #if UNITY_EDITOR
            this.debugList.Add( view );
        #endif
        }
    }
开发者ID:marshl,项目名称:Leviathan2,代码行数:34,代码来源:NetworkOwnerManager.cs

示例2: WaitForAnimationState

    public WaitForAnimationState(MonoBehaviour animatorSibling, string stateName)
    {
        //Debug.LogError("WaitForAnimationState CTOR");

        animator = animatorSibling.GetComponent<Animator>();
        this.stateName = stateName;
        this.stateHash = Animator.StringToHash(stateName);
    }
开发者ID:rmarx,项目名称:Blood,代码行数:8,代码来源:WaitForAnimationState.cs

示例3: Init

 public void Init(MonoBehaviour parent)
 {
     this.parent = parent;
     parentRB = parent.GetComponent<Rigidbody2D> ();
     forward = false;
     rightMove = false;
     leftMove = false;
     lastMoveVector = parent.transform.up;
 }
开发者ID:ZloyHolodec,项目名称:SpaceGunner,代码行数:9,代码来源:Mover.cs

示例4: AIBaseState

    public AIBaseState(MonoBehaviour p)
    {
        parent = p;
        agent = parent.GetComponent<NavMeshAgent>();

        selectExecutor = new SelectTargetExecutor();
        selectExecutor.Init(this);
        moveExecutor = new MoveActionExecutor();
        moveExecutor.Init(this);
        lookatExecutor = new LookatActionExecutor();
        lookatExecutor.Init(this);

    }
开发者ID:ChromaTeamUPC,项目名称:ChromaVirus,代码行数:13,代码来源:AIBaseState.cs

示例5: MicIn

    public MicIn(MonoBehaviour _parent, float _sensitivity)
    {
        sensitivity = _sensitivity;
        parent = _parent;
        loudness = 0;

        parent.GetComponent<AudioSource>().clip = Microphone.Start(null, true, 1, 48000);

        parent.GetComponent<AudioSource>().loop = false; // Set the AudioClip to loop
        parent.GetComponent<AudioSource>().mute = false; // Mute the sound, we don't want the player to hear it

        parent.GetComponent<AudioSource>().bypassEffects = true;
        parent.GetComponent<AudioSource>().bypassReverbZones = true; //also important, remmoves reverb so no feedback loops
        parent.GetComponent<AudioSource>().spatialBlend = 0.0f;
        parent.GetComponent<AudioSource>().reverbZoneMix = 0.0f;

        while (!(Microphone.GetPosition(null) > 0)) { } //this seems to fix the latency issue. i know its bad code, fuck off.

        parent.GetComponent<AudioSource>().Play(); //play the audio source!
        parent.InvokeRepeating("PlayAudioSource", 1.0f, 1.0f);
    }
开发者ID:miintz,项目名称:SeeingSoundwaves,代码行数:21,代码来源:MicIn.cs

示例6: BindSimpleField

    /// <summary>
    /// Initializes the specified field of component given then information in bindAttribute.
    /// </summary>
    /// <param name="field">Field to bind</param>
    /// <param name="bindAttribute">Information about how to bind it</param>
    /// <param name="component">Object with the field</param>
    private static void BindSimpleField(FieldInfo field, BindAttribute bindAttribute, MonoBehaviour component)
    {
        Object target = null;
        switch (bindAttribute.Scope)
        {
            case BindingScope.GameObject:
                target = component.GetComponent(field.FieldType);
                break;

            case BindingScope.GameObjectOrChildren:
                target = component.GetComponentInChildren(field.FieldType);
                break;

            case BindingScope.Global:
                target = FindObjectOfType(field.FieldType);
                break;
        }

        if (target == null)
            switch (bindAttribute.IfNotFound)
            {
                case BindingDefault.Exception:
                    throw new Exception("No target to bind to");

                case BindingDefault.Create:
                    target = component.gameObject.AddComponent(field.FieldType);
                    break;

                case BindingDefault.Ignore:
                    break;
            }

        field.SetValue(component, target);
    }
开发者ID:tzamora,项目名称:superteam,代码行数:40,代码来源:BindingBehaviour.cs

示例7: getVerticesContour

    // Считывание вершин MeshFilter-а в контур кватернионов с корректировкой значений (если требуется)
    List<Quaternion> getVerticesContour(MonoBehaviour gameObject, Vector3 correctionVect = new Vector3())
    {
        MeshFilter viewedModelFilter = (MeshFilter)gameObject.GetComponent("MeshFilter");
        Mesh viewedModel = viewedModelFilter.mesh;
        Vector3[] vertices = viewedModel.vertices;

        List<Quaternion> contour = new List<Quaternion> ();
        for (int i = 0; i < vertices.Length; ++i) {
            Vector3 vertex = gameObject.transform.TransformPoint(vertices[i]);
            Quaternion quaternion = new Quaternion(vertex.x + correctionVect.x,
                                                   vertex.y + correctionVect.y,
                                                   vertex.z + correctionVect.z,
                                                   0.0f);
            contour.Add(quaternion);
        }

        return contour;
    }
开发者ID:hedunky,项目名称:quaternions,代码行数:19,代码来源:Plane2.cs

示例8: bossDefeated

 public void bossDefeated(MonoBehaviour bossObject)
 {
     Destroy(bossObject.GetComponent("EnemyMover_Boss"));
     Application.LoadLevel(0);
 }
开发者ID:jcsinck,项目名称:colt,代码行数:5,代码来源:EnemySpawner.cs

示例9: GetToBeInjectedObject

 public UnityEngine.Object GetToBeInjectedObject(MonoBehaviour target)
 {
     return target.GetComponent(ComponentType.Name);
 }
开发者ID:joaokucera,项目名称:unity-attributes,代码行数:4,代码来源:IInjectionPolicy.cs

示例10: EnableBehaviorAfterTime

    /// <summary>
    ///   Enables behavior after some time.
    /// </summary>
    private IEnumerator EnableBehaviorAfterTime(MonoBehaviour b, float time)
    {
        // wait
        yield return new WaitForSeconds(time);

        // check
        if (b)

          // enable if not picked
          if (!b.GetComponent<Pickable>().Picked)
        b.enabled = true;
    }
开发者ID:thecocce,项目名称:HellCourtJam,代码行数:15,代码来源:Picking.cs

示例11: moveButtonTo

    private void moveButtonTo(MonoBehaviour button, Hexagon hexagon, Vector3 offset)
    {
        var rectTransform = button.GetComponent<RectTransform>();
        if (hexagon != null && !(userInteractionState == UserInteractionState.StartedDragging || userInteractionState == UserInteractionState.StartedMoving))
        {
            var screenPoint = Camera.main.WorldToScreenPoint(hexagon.transform.position);

            rectTransform.transform.position = screenPoint + offset;
            rectTransform.localScale = new Vector3(1, 1, 1);
        }
        else
        {
            rectTransform.localScale = new Vector3(0, 0, 0);
        }
    }
开发者ID:YannickLange,项目名称:ForestGame,代码行数:15,代码来源:UserInteraction.cs


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