本文整理汇总了C#中UnityEngine.Canvas类的典型用法代码示例。如果您正苦于以下问题:C# Canvas类的具体用法?C# Canvas怎么用?C# Canvas使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Canvas类属于UnityEngine命名空间,在下文中一共展示了Canvas类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
private void Start()
{
gridRect = GetComponentInParent<RectTransform>();
gridCanvas = GetComponentInParent<Canvas>();
gridLayout = GetComponentInParent<GridLayoutGroup>();
gridRect.pivot = new Vector2(0, 0);
gridRect.position = new Vector3(terrainMesh.transform.position.x, 6.0f, terrainMesh.transform.position.z);
gridRect.anchorMin = new Vector2(terrainMesh.transform.position.x, terrainMesh.transform.position.z);
gridRect.anchorMax = new Vector2(terrainMesh.terrainData.size.x, terrainMesh.terrainData.size.z);
gridLayout.CalculateLayoutInputHorizontal();
Debug.Log(string.Format("Origin: {0}, Size: {1}, Cell size: {2}\n", gridRect.position.ToString(), gridRect.rect.size.ToString(), gridLayout.cellSize));
buttonTemplate = GetComponentInChildren<Button>();
for (int y = 0; y < gridRect.rect.y; y++)
{
for (int x = 0; x < gridRect.rect.x; x++)
{
Vector3 pos = new Vector3(x, 0, y); // * spacing;
Button b = (Button)Instantiate(buttonTemplate, pos, Quaternion.identity);
//b.gameObject.AddComponent<LayoutElement>();
//b.name = "Button " + x.ToString() + "," + y.ToString();
//b.GetComponentInChildren<Text>().text = b.name;
gridLayout.SetLayoutHorizontal();
}
}
}
示例2: Start
void Start()
{
timerText = GameObject.Find("Play Timer").GetComponent<Text>();
canvas = this.GetComponent<Canvas>();
canvas.enabled = true;
}
示例3: OnEnable
protected override void OnEnable()
{
base.OnEnable ();
current = this;
canvas = GetComponentInParent<Canvas> ();
base.Close ();
}
示例4: Start
void Start()
{
quitMenu = quitMenu.GetComponent<Canvas>();
quitMenu.enabled = false;
startText = startText.GetComponent<Button>();
exitText = exitText.GetComponent<Button>();
}
示例5: init
internal void init()
{
var cardCanvas = GameObject.Find(Constants.cardCanvas);
canvas = GameObject.Find("Canvas").gameObject.GetComponent<Canvas>();
//set up fake card model
var hoverCardModel = new CardModel()
{
playerId = -1,
};
//init the hover card that's hidden most of the time
cardService.CreateCard(hoverCardModel, cardCanvas.transform, new Vector3(10000,10000, 0));
var hoverCardGO = hoverCardModel.gameObject;
hoverCardGO.name = hoverName;
hoverCardGO.tag = "HoverCard";
//disable all colliders so you can't hover the hover
foreach (var collider in hoverCardGO.GetComponentsInChildren<BoxCollider>())
{
collider.enabled = false;
}
foreach (var collider in hoverCardGO.GetComponentsInChildren<MeshCollider>())
{
collider.enabled = false;
}
hoverCardView = hoverCardGO.AddComponent<CardView>();
hoverCardView.card = hoverCardModel;
hoverCardGO.SetActive(false);
}
示例6: Update
void Update() {
if (followObject != null) {
if (!Application.isPlaying || canvas == null) {
canvas = GetComponentInParent<Canvas>();
if (canvas == null) {
Debug.LogError("This object should be placed under a canvas", this);
}
}
if (!Application.isPlaying || cameraReference == null) {
cameraReference = worldCamera.Lookup<Camera>(this);
}
UpdateFollowObject();
bool visible = IsPossiblyVisible();
var energyBarBase = GetComponent<EnergyBarBase>();
energyBarBase.opacity = visible ? 1 : 0;
if (cameraReference != null && canvas != null) {
if (canvas.renderMode == RenderMode.WorldSpace) {
energyBarBase.transform.rotation =
Quaternion.LookRotation(energyBarBase.transform.position - cameraReference.transform.position);
} else {
energyBarBase.transform.rotation = Quaternion.identity;
}
}
} else {
FastPoolManager.GetPool(this.gameObject,false).FastDestroy(this.gameObject);
}
}
示例7: CreateAccountCanvasController
public CreateAccountCanvasController(IoCResolver resolver, Canvas canvasView)
: base(resolver, canvasView)
{
// resolve
resolver.Resolve(out _messager);
resolver.Resolve(out _user);
ResolveElement(out _usernameInputField, "username_input_field");
ResolveElement(out _passwordInputField, "password_input_field");
ResolveElement(out _passwordConfirmationInputField, "password_confirmation_input_field");
ResolveElement(out _confirmButton, "confirm_button");
ResolveElement(out _backButton, "back_button");
// initialize
ShowCanvas = false;
_usernameInputField.text = "";
_passwordInputField.text = "";
// subscribe
_onCreateAccountSelected = _messager.Subscribe<CreateAccountSelectedMessage>(message =>
{
ShowCanvas = true;
_currentAccountCreationSession = message;
_usernameInputField.text = "";
_passwordInputField.text = "";
_confirmButton.onClick.RemoveAllListeners();
_backButton.onClick.RemoveAllListeners();
_confirmButton.onClick.AddListener(RegisterAccount);
_backButton.onClick.AddListener(() => message.OnCancelled());
});
}
示例8: InitializeMainComponents
private void InitializeMainComponents()
{
canvas = Instantiate(Resources.Load<Canvas>("Prefabs/Play/Canvas"));
mainCamera = Instantiate(Resources.Load<Camera>("Prefabs/Play/MainCamera"));
Canvas = canvas;
}
示例9: Start
void Start()
{
timerBar = GameObject.Find("Card Selection Timer").transform;
canvas = this.GetComponent<Canvas>();
canvas.enabled = false;
}
示例10: UnregisterGraphicForCanvas
/// <summary>
///
/// <para>
/// Deregister the given Graphic from a Canvas.
/// </para>
///
/// </summary>
/// <param name="c">Canvas.</param><param name="graphic">Graphic to deregister.</param>
public static void UnregisterGraphicForCanvas(Canvas c, Graphic graphic)
{
IndexedSet<Graphic> indexedSet;
if ((Object) c == (Object) null || !GraphicRegistry.instance.m_Graphics.TryGetValue(c, out indexedSet))
return;
indexedSet.Remove(graphic);
}
示例11: OnHover
public void OnHover(RectTransform uiElement) {
this.uiElement = uiElement;
if (this.tempHud != null) this.tempHud.enabled = false;
if (this.animationRoot != null) this.animationRoot.SetInState();
var canvas = uiElement.root.GetComponentsInChildren<Canvas>()[0];
uiElement.root.GetComponentInChildren<Canvas>();
this.uiElementCanvas = canvas;
this.ApplyPosition();
if (this.animationRoot != null) this.animationRoot.SetResetState();
if (this.layoutRoot != null) {
this.CheckPivot(uiElement.rect.size, canvas.transform as RectTransform);
} else {
var anchor = this.root.anchoredPosition3D;
anchor.z = 0f;
this.root.anchoredPosition3D = anchor + Vector3.up * uiElement.rect.size.y * 0.5f;
}
}
示例12: ScreenPoint
public static Vector2 ScreenPoint(Camera mainCamera, Vector3 worldPosition, RectTransform parent, Canvas canvas)
{
var screenPosition = mainCamera.WorldToScreenPoint(worldPosition);
var localPosition = Vector2.zero;
RectTransformUtility.ScreenPointToLocalPointInRectangle(parent, screenPosition, canvas.worldCamera, out localPosition);
return localPosition;
}
示例13: Awake
public void Awake()
{
GameManager.Instance.CursorEnabled = false;
this.canvas = GetComponent<Canvas>();
this.eventSystem = FindObjectOfType<EventSystem>();
this.wasCancelPressed = false;
}
示例14: OnEnter
public override void OnEnter()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go != null)
{
_rt = go.GetComponent<RectTransform>();
}
GameObject goCanvas = canvas.Value;
if (goCanvas != null)
{
_canvas = goCanvas.GetComponent<Canvas>();
}
if (_canvas==null && go!=null)
{
var _ui = go.GetComponent<UnityEngine.UI.Graphic>();
if (_ui!=null)
{
_canvas = _ui.canvas;
}
}
DoAction();
if (!everyFrame)
{
Finish();
}
}
示例15: MainMenuCanvasController
public MainMenuCanvasController(IoCResolver resolver, Canvas canvasView)
: base(resolver, canvasView)
{
// resolve
resolver.Resolve(out _messager);
resolver.Resolve(out _user);
ResolveElement(out _welcomeText, "welcome_text");
ResolveElement(out _hostGameButton, "host_game_button");
ResolveElement(out _joinGameButton, "join_game_button");
ResolveElement(out _exitGameButton, "exit_game_button");
// initialize
ShowCanvas = false;
_hostGameButton.onClick.AddListener(() =>
{
_messager.Publish(new HostGameClickedMessage());
});
_exitGameButton.onClick.AddListener(() =>
{
_messager.Publish(new ExitMessage());
});
// subscribe
_onMainMenuSelected = _messager.Subscribe<MainMenuSelectedMessage>(message =>
{
ShowCanvas = true;
_welcomeText.text = String.Format(LanguageStrings.MainMenuWelcome, _user.Username);
});
}