facebook twitter hatena line email

「Unity/UIImage」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(円のゲージ描画)
 
(同じ利用者による、間の17版が非表示)
行1: 行1:
==幅修正==
+
[[Unity/UIImage/基本]]
GameObject graph = GameObject.Find("/Canvas/Graph");
+
RectTransform textRect = graph.GetComponent<RectTransform>();
+
textRect.sizeDelta = new Vector2(1000.0f, 1000.0f);
+
  
==幅と高さ==
+
[[Unity/UIImage/Mask]]
float width = gameObject.GetComponent<RectTransform>().sizeDelta.x; //
+
float height = gameObject.GetComponent<RectTransform>().sizeDelta.y; // 高さ
+
  
==UiImage複製して配置==
+
[[Unity/UIImage/Collider2d]]
*Canvas/CopySourceImageにコピー元Image設置
+
*NewImageが新しくできるImage
+
<pre>
+
GameObject canvas = GameObject.Find("Canvas");
+
GameObject copySourceImage = GameObject.Find("Canvas/CopySourceImage");
+
GameObject newImage = new GameObject("NewImage");
+
newImage.transform.SetParent(canvas.transform, false);
+
newImage.transform.SetSiblingIndex(copySourceImage.transform.GetSiblingIndex());
+
RectTransform baseTransform = copySourceImage.transform as RectTransform;
+
RectTransform rectTransform = newImage.AddComponent<RectTransform>();
+
rectTransform.anchorMax = baseTransform.anchorMax;
+
rectTransform.anchorMin = baseTransform.anchorMin;
+
rectTransform.anchoredPosition = baseTransform.anchoredPosition;
+
rectTransform.sizeDelta = baseTransform.sizeDelta;
+
rectTransform.localScale = baseTransform.localScale;
+
rectTransform.localPosition = baseTransform.localPosition;
+
rectTransform.localRotation = baseTransform.localRotation;
+
Image img = newImage.AddComponent<Image>();
+
img.sprite = copySourceImage.GetComponent<Image>().sprite;
+
</pre>
+
  
参考:https://teratail.com/questions/42899
+
[[Unity/UIImage/Texture]]
 
+
==枠を追加==
+
以下で外枠を追加できるが、Imageを透明にするとOutlineも消えてしまう・・。
+
<pre>
+
Outline outline =imageObj.AddComponent<Outline>();
+
outline.effectColor = new Color(1, 0f, 0f, 1f);
+
</pre>
+
 
+
どこか一辺だけの場合は、以下参照すればできるかも。http://aktaat.hatenablog.com/entry/2016/10/30/085534
+
 
+
==画像ロード==
+
Resourcesの中にimage.pngを入れる
+
Sprite iconImage = Resources.Load<Sprite>("image");
+
 
+
==円のゲージ描画==
+
#Imageに丸画像を追加
+
#ImageTypeをFilledへ
+
#FillOriginをTopへ
+
#FillAmountを0~1へ
+
 
+
<pre>
+
GameObject circleObj = GameObject.Find("CircleOnImage");
+
Image circleImage = circleObj.GetComponent<Image>();
+
circleImage.fillAmount = 0.5f; // 0~1
+
</pre>
+
 
+
参考:https://clrmemory.com/programming/unity/circle-gauge-meter-p1/
+

2023年3月8日 (水) 04:29時点における最新版

Unity/UIImage/基本

Unity/UIImage/Mask

Unity/UIImage/Collider2d

Unity/UIImage/Texture