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


C# Image.GetComponent方法代码示例

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


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

示例1: SetHealthBar

        private void SetHealthBar(Text healthBarPercent, Image healthBar, int healthValue, int totalHealthValue)
        {
            int healthPercent = (int)(((float)healthValue / (float)totalHealthValue) * 100);
            healthBarPercent.text = (healthPercent.ToString() + "%");

            float width = (float)healthPercent;
            float height = healthBar.GetComponent<RectTransform>().rect.height;

            width = Mathf.Clamp(width, 0.0f, 100.0f);
            healthBar.GetComponent<RectTransform>().sizeDelta = new Vector2(width, height);

            if (healthPercent >= 80)
                SetColor(healthBar, colorVeryHighHealth);
            else if (healthPercent >= 60)
                SetColor(healthBar, colorHighHealth);
            else if (healthPercent >= 40)
                SetColor(healthBar, colorMediumHealth);
            else if (healthPercent >= 20)
                SetColor(healthBar, colorLowHealth);
            else
                SetColor(healthBar, colorVeryLowHealth);
        }
开发者ID:MitchLindsay,项目名称:red-havoc,代码行数:22,代码来源:UnitPreview.cs

示例2: fitImageInView

		private void fitImageInView(Image image)
		{
			var rect = image.GetComponent<RectTransform>();
			float width = image.mainTexture.width / (float)Screen.width, height = image.mainTexture.height / (float)Screen.height;
			var size = MathUtilities.FitInView(width, height, 1, 1);
			rect.anchorMin = new Vector2(-(size.x*.5f) + .5f, -(size.y*.5f) + .5f);
			rect.anchorMax = new Vector2(-(size.x*.5f) + .5f + size.x, -(size.y*.5f) + .5f + size.y);
			rect.offsetMin = Vector2.zero;
			rect.offsetMax = Vector2.zero;
		}
开发者ID:lPinchol,项目名称:Reign-Unity-Plugin,代码行数:10,代码来源:ReignScores_UnityUI.cs


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