本文整理汇总了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;
}
示例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>();
}
示例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;
}
示例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;
}