本文整理汇总了C#中UnityEngine.GameObject.GetSafeComponent方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.GetSafeComponent方法的具体用法?C# GameObject.GetSafeComponent怎么用?C# GameObject.GetSafeComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.GameObject
的用法示例。
在下文中一共展示了GameObject.GetSafeComponent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FadeChange
/// <summary>
/// フェードアウト⇒フェードインでシーンを切り替える
/// </summary>
public void FadeChange(string sceneName, float fadeTime = 1.0f)
{
if (fadeState != FadeState.NONE)
{
Debug.LogError("シーン遷移実行中に不正にシーンを切り替えようとしました");
return;
}
this.sceneName = sceneName;
this.fadeTime = fadeTime;
// Canvasを生成
Canvas canvas;
canvasObject = new GameObject();
canvasObject.name = "FadeMaskCanvas";
canvas = canvasObject.AddComponent<Canvas>();
canvas.pixelPerfect = true;
canvas.renderMode = RenderMode.ScreenSpaceCamera;
canvas.sortingOrder = forGround;
canvas.gameObject.AddComponent<CanvasScaler>();
// 最前面に表示するマスクを生成
GameObject imageObject = new GameObject();
imageObject.name = "MaskImage";
imageObject.transform.SetParent(canvas.transform);
imageObject.GetSafeComponent<RectTransform>().anchoredPosition3D = Vector3.zero;
imageObject.GetComponent<RectTransform>().sizeDelta = new Vector2(Screen.width, Screen.height);
maskImage = imageObject.AddComponent<Image>();
maskImage.sprite = Resources.Load<Sprite>("Sprites/FadeFilter");
maskImage.color = new Color(0.0f, 0.0f, 0.0f, 0.0f);
fadeState = FadeState.FadeOut;
iTween.ValueTo(gameObject, iTween.Hash("from", 0.0f, "to", 1.0f, "time", this.fadeTime, "onupdate", "FadeAlpha"));
}
示例2: AddToggle
/// <summary>
/// Adds the toggle to toggleUI.
/// </summary>
/// <param name="go">The go.</param>
/// <param name="callback">The callback.</param>
void AddToggle(GameObject go, EventDelegate.Callback callback)
{
UIToggle toggle = go.GetSafeComponent<UIToggle>();
EventDelegate.Add(toggle.onChange, callback);
}