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


C# GameObject.EnsureComponent方法代码示例

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


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

示例1: Add

    public GameObject Add(string textureName, Func<bool> isEnabled = null, Action onClick = null)
    {
        GameObject go = new GameObject();
        UITexture buttonTexture = go.EnsureComponent<UITexture>();

        if (onClick != null)
        {
            DaemonButton button = go.EnsureComponent<DaemonButton>();
            UIButton buttonUI = go.EnsureComponent<UIButton>();
            buttonUI.disabledColor = disabledColor;
            BoxCollider buttonBoxCollider = go.EnsureComponent<BoxCollider>();
            if (isEnabled != null)
            {
                go.EnsureComponent<IsEnabled>().Predicate = isEnabled;
                bool enabled = isEnabled();
                buttonUI.isEnabled = enabled;
                //buttonBoxCollider.enabled = enabled;
            }
            buttonBoxCollider.isTrigger = true;
            buttonTexture.ResizeCollider();

            button.click += onClick;
        }

        buttonTexture.mainTexture = Resources.Load<Texture2D>("Textures/" + textureName);
        buttonTexture.autoResizeBoxCollider = true;
        buttonTexture.depth = 10;
        _gameObjects.Add(go);
        return go;
    }
开发者ID:TreyWheeler,项目名称:ProjectLilith,代码行数:30,代码来源:PositionButtons.cs

示例2: Start

 // Use this for initialization
 void Start()
 {
     cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
     cube.transform.parent = this.gameObject.transform;
     cube.transform.localPosition = new Vector3(0, 3f, 0);
     cube.transform.localScale = new Vector3(1, .25f, 0f);
     cube.RemoveComponent<BoxCollider>();
     cube.GetComponent<MeshRenderer>().material.color = new Color(.6f, 0f, 0f, .5f);
     cube.GetComponent<MeshRenderer>().material.shader = Shader.Find("Transparent/Cutout/Soft Edge Unlit");
     cube.transform.localRotation = new Quaternion();
     cube.EnsureComponent<LookAtCamera>();
 }
开发者ID:TreyWheeler,项目名称:ProjectLilith,代码行数:13,代码来源:HealthArch.cs

示例3: Start

    // Use this for initialization
    void Start()
    {
        this.transform.rotation = Random.rotation;

        if (Target == null)
            Target = GameObject.FindGameObjectWithTag("Player");

        TargetRotationHelper = new GameObject("RotationHelper");
        TargetRotationHelper.transform.parent = this.transform;
        TargetRotationHelper.EnsureComponent<lookatPlayer>();

        //this.EnsureComponent<ImpactDamage>().Damage = Damage;

        this.EnsureComponent<Rigidbody>();
        rigidbody.useGravity = false;
    }
开发者ID:RoyM33,项目名称:Dawkter-s-Dungeon,代码行数:17,代码来源:ChaosMissleBehavior.cs

示例4: Start

    void Start()
    {
        GameObject outline = new GameObject();
        outline.transform.parent = this.gameObject.transform;
        outline.transform.localPosition = Vector3.zero;
        outline.name = Name;

        _sprite = outline.EnsureComponent<UISprite>();
        _sprite.atlas = Resources.Load<GameObject>("GUI/Atlas").GetComponent<UIAtlas>();
        _sprite.spriteName = "Radiance";
        _sprite.type = UISprite.Type.Filled;
        _sprite.fillDirection = UISprite.FillDirection.Radial360;
        _sprite.invert = Clockwise;
        _sprite.transform.localScale = new Vector3(1, 1, 1);
        _sprite.width = Diameter;
        _sprite.height = Diameter;
        _sprite.depth = Depth;
        _sprite.color = Color;

        _totalPerimeterPercentage = (DegreeEnd - DegreeStart) / 360f;
    }
开发者ID:TreyWheeler,项目名称:ProjectLilith,代码行数:21,代码来源:EnergyIconOutline.cs


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