• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# UnityEngine.Canvas类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中UnityEngine.Canvas的典型用法代码示例。如果您正苦于以下问题:C# Canvas类的具体用法?C# Canvas怎么用?C# Canvas使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Canvas类属于UnityEngine命名空间,在下文中一共展示了Canvas类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
                }
            }
        }
开发者ID:LowEnergyCycle,项目名称:TUBSCOM,代码行数:30,代码来源:CombatGrid.cs


示例2: Start

        void Start()
        {
            timerText = GameObject.Find("Play Timer").GetComponent<Text>();
            canvas = this.GetComponent<Canvas>();

            canvas.enabled = true;
        }
开发者ID:JonathanHunter,项目名称:CardNinjas,代码行数:7,代码来源:CardTimer.cs


示例3: OnEnable

 protected override void OnEnable()
 {
     base.OnEnable ();
     current = this;
     canvas = GetComponentInParent<Canvas> ();
     base.Close ();
 }
开发者ID:gloowa,项目名称:mstest,代码行数:7,代码来源:UITooltip.cs


示例4: Start

 void Start()
 {
     quitMenu = quitMenu.GetComponent<Canvas>();
     quitMenu.enabled = false;
     startText = startText.GetComponent<Button>();
     exitText = exitText.GetComponent<Button>();
 }
开发者ID:TKey530,项目名称:ProjectYore,代码行数:7,代码来源:MainMenu.cs


示例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);
        }
开发者ID:dshook,项目名称:centauri-tac,代码行数:32,代码来源:HoverCardView.cs


示例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);
		}
    }
开发者ID:andrewstarnes,项目名称:wwtd2,代码行数:31,代码来源:EnergyBarFollowObject.cs


示例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());
            });
        }
开发者ID:TeaAlligator,项目名称:dicey-dice,代码行数:35,代码来源:CreateAccountCanvasController.cs


示例8: InitializeMainComponents

        private void InitializeMainComponents()
        {
            canvas = Instantiate(Resources.Load<Canvas>("Prefabs/Play/Canvas"));
            mainCamera = Instantiate(Resources.Load<Camera>("Prefabs/Play/MainCamera"));

            Canvas = canvas;
        }
开发者ID:Rupini,项目名称:Hexocracy,代码行数:7,代码来源:GameInstance.cs


示例9: Start

        void Start()
        {
            timerBar = GameObject.Find("Card Selection Timer").transform;
            canvas = this.GetComponent<Canvas>();

            canvas.enabled = false;
        }
开发者ID:szhangGT,项目名称:CardNinjas,代码行数:7,代码来源:SelectionTimer.cs


示例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);
 }
开发者ID:NetherDrk,项目名称:Eternal-Empire,代码行数:15,代码来源:GraphicRegistry.cs


示例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;

			}

		}
开发者ID:Cyberbanan,项目名称:Unity3d.UI.Windows,代码行数:29,代码来源:LayoutTipWindowType.cs


示例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;
		}
开发者ID:hiroki-kitahara,项目名称:Brilliant,代码行数:7,代码来源:RectTransformUtilityExtensions.cs


示例13: Awake

 public void Awake()
 {
     GameManager.Instance.CursorEnabled = false;
     this.canvas = GetComponent<Canvas>();
     this.eventSystem = FindObjectOfType<EventSystem>();
     this.wasCancelPressed = false;
 }
开发者ID:Dawnwoodgames,项目名称:LotsOfTowers,代码行数:7,代码来源:PauseMenu.cs


示例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();
			}		
		}
开发者ID:OmegaDEVAU,项目名称:Simulator,代码行数:30,代码来源:RectTransformPixelAdjustRect.cs


示例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);
            });
        }
开发者ID:TeaAlligator,项目名称:dicey-dice,代码行数:32,代码来源:MainMenuCanvasController.cs


示例16: Start

        protected override void Start()
        {
            base.Start();

            _parentCanvas = GetComponentInParent<Canvas>();
            if ( _parentCanvas != null )
                _parentCanvasRectTransform = _parentCanvas.transform as RectTransform;
        }
开发者ID:moto2002,项目名称:Kathulhu-Framework,代码行数:8,代码来源:UITooltip.cs


示例17: Awake

 private void Awake()
 {
     m_rectTransform = GetComponent<RectTransform>();
     SiblingGraphics.SetActive(true);
     m_parentCanvas = GetComponentInParent<Canvas>();
     m_itemsControl = GetComponentInParent<ItemsControl>();
     AwakeOverride();
 }
开发者ID:WilliamRADFunk,项目名称:vedic,代码行数:8,代码来源:ItemDropMarker.cs


示例18: GetCanvasRect

 public Rect GetCanvasRect(RectTransform t, Canvas c)
 {
   t.GetWorldCorners(this.m_WorldCorners);
   Transform component = c.GetComponent<Transform>();
   for (int index = 0; index < 4; ++index)
     this.m_CanvasCorners[index] = component.InverseTransformPoint(this.m_WorldCorners[index]);
   return new Rect(this.m_CanvasCorners[0].x, this.m_CanvasCorners[0].y, this.m_CanvasCorners[2].x - this.m_CanvasCorners[0].x, this.m_CanvasCorners[2].y - this.m_CanvasCorners[0].y);
 }
开发者ID:NetherDrk,项目名称:Eternal-Empire,代码行数:8,代码来源:RectangularVertexClipper.cs


示例19: Awake

        void Awake()
        {
            _win = this.GetComponent<Canvas>();
            _label = this.GetComponentInChildren<Text>();
            _win.enabled = false;

            _yes = GameObject.Find("Yes").GetComponent<Button>();
        }
开发者ID:sabrinagreenlee,项目名称:JaneBound,代码行数:8,代码来源:ConfirmationWindow.cs


示例20: FindCanvas

        private void FindCanvas()
        {
            if (!canvas)
                canvas = FindObjectOfType<Canvas>();

            if (!canvas)
                throw new InvalidOperationException("You need a canvas in your scene, or add code to create one here.");
        }
开发者ID:devmelon,项目名称:Answers,代码行数:8,代码来源:UIBuilder.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UnityEngine.CanvasGroup类代码示例发布时间:2022-05-26
下一篇:
C# UnityEngine.Camera类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap