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


C# GameObject.GetOrCreateComponent方法代码示例

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


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

示例1: Create

    public static void Create()
    {
        if ( Selection.activeGameObject != null )
        {
            GameObject path = new GameObject ( "Path" );
            path.GetOrCreateComponent<PointPath> ();
            if ( Selection.activeGameObject.transform.parent != null )
                path.transform.parent = Selection.activeGameObject.transform.parent.transform;
            path.transform.position = Selection.activeGameObject.transform.position;

            PathFollower pathFollower = Selection.activeGameObject.GetOrCreateComponent<PathFollower> ();
            pathFollower.Path = path;
        }
    }
开发者ID:apautrot,项目名称:gdp9,代码行数:14,代码来源:PathFollower.cs

示例2: CreateNinePatch

    public static void CreateNinePatch()
    {
        GameObject go = new GameObject ();
        go.name = "NinePatch";

        /* NinePatch ninePatch = */ go.GetOrCreateComponent<NinePatch> ();

        if ( Selection.activeGameObject != null )
        {
            go.transform.parent = Selection.activeGameObject.transform;
            go.transform.position = Selection.activeGameObject.transform.position;
        }
        Selection.activeObject = go;
    }
开发者ID:apautrot,项目名称:gdp9,代码行数:14,代码来源:NinePatchInspector.cs

示例3: CreateQuad

    public static void CreateQuad()
    {
        GameObject go = new GameObject ();
        go.name = "Quad";

        /* Quad quad = */ go.GetOrCreateComponent<Quad> ();

        if ( Selection.activeGameObject != null )
        {
            go.transform.parent = Selection.activeGameObject.transform;
            go.transform.position = Selection.activeGameObject.transform.position;
        }
        Selection.activeObject = go;
    }
开发者ID:apautrot,项目名称:gdp9,代码行数:14,代码来源:QuadInspector.cs

示例4: CreateTextMeshEx

    public static void CreateTextMeshEx()
    {
        GameObject go = new GameObject();
        go.name = "Text";

        TextMeshEx textMesh = go.GetOrCreateComponent<TextMeshEx> ();
        textMesh.Font = Resources.GetBuiltinResource ( typeof ( Font ), "Arial.ttf" ) as Font;

        if ( Selection.activeGameObject != null )
        {
            go.transform.parent = Selection.activeGameObject.transform;
            go.transform.position = Selection.activeGameObject.transform.position;
        }
        Selection.activeObject = go;
    }
开发者ID:apautrot,项目名称:gdp9,代码行数:15,代码来源:TextInspector.cs

示例5: Create

    static void Create()
    {
        GameObject go = new GameObject ( "PolyMesh", typeof ( MeshFilter ), typeof ( MeshRenderer ) );
        PolyMesh polyMesh = go.AddComponent<PolyMesh> ();
        CreateSquare ( polyMesh, 10 );

        MeshRenderer renderer = go.GetOrCreateComponent<MeshRenderer> ();
        Shader shader = Shader.Find ( "Sprites/Default" );
        if ( shader != null )
        {
            Material material = new Material ( shader );
            material.name = "PolyMesh Material";
            material.SetColor ( "_Color", Color.gray );
            // material.hideFlags = HideFlags.DontSave;
            renderer.material = material;
        }

        if ( Selection.activeGameObject != null )
        {
            go.transform.parent = Selection.activeGameObject.transform;
            go.transform.position = Selection.activeGameObject.transform.position;
        }
        Selection.activeObject = go;
    }
开发者ID:apautrot,项目名称:gdp9,代码行数:24,代码来源:PolyMeshEditor.cs


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