facebook twitter hatena line email

「Unity/UIImage」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(幅修正)
(UiImage複製して配置)
行8: 行8:
 
*NewImageが新しくできるImage
 
*NewImageが新しくできるImage
 
<pre>
 
<pre>
        GameObject canvas = GameObject.Find("Canvas");
+
GameObject canvas = GameObject.Find("Canvas");
        GameObject copySourceImage = GameObject.Find("Canvas/CopySourceImage");
+
GameObject copySourceImage = GameObject.Find("Canvas/CopySourceImage");
        GameObject newImage = new GameObject("NewImage");
+
GameObject newImage = new GameObject("NewImage");
        newImage.transform.SetParent(canvas.transform, false);
+
newImage.transform.SetParent(canvas.transform, false);
        newImage.transform.SetSiblingIndex(copySourceImage.transform.GetSiblingIndex());
+
newImage.transform.SetSiblingIndex(copySourceImage.transform.GetSiblingIndex());
        RectTransform baseTransform = copySourceImage.transform as RectTransform;
+
RectTransform baseTransform = copySourceImage.transform as RectTransform;
        RectTransform rectTransform = newImage.AddComponent<RectTransform>();
+
RectTransform rectTransform = newImage.AddComponent<RectTransform>();
        rectTransform.anchorMax = baseTransform.anchorMax;
+
rectTransform.anchorMax = baseTransform.anchorMax;
        rectTransform.anchorMin = baseTransform.anchorMin;
+
rectTransform.anchorMin = baseTransform.anchorMin;
        rectTransform.anchoredPosition = baseTransform.anchoredPosition;
+
rectTransform.anchoredPosition = baseTransform.anchoredPosition;
        rectTransform.sizeDelta = baseTransform.sizeDelta;
+
rectTransform.sizeDelta = baseTransform.sizeDelta;
        rectTransform.localScale = baseTransform.localScale;
+
rectTransform.localScale = baseTransform.localScale;
        rectTransform.localPosition = baseTransform.localPosition;
+
rectTransform.localPosition = baseTransform.localPosition;
        rectTransform.localRotation = baseTransform.localRotation;
+
rectTransform.localRotation = baseTransform.localRotation;
        Image img = newImage.AddComponent<Image>();
+
Image img = newImage.AddComponent<Image>();
        img.sprite = copySourceImage.GetComponent<Image>().sprite;
+
img.sprite = copySourceImage.GetComponent<Image>().sprite;
 
</pre>
 
</pre>
  
 
参考:https://teratail.com/questions/42899
 
参考:https://teratail.com/questions/42899

2020年5月15日 (金) 18:07時点における版

幅修正

GameObject graph = GameObject.Find("/Canvas/Graph");
RectTransform textRect = graph.GetComponent<RectTransform>();
textRect.sizeDelta = new Vector2(1000.0f, 1000.0f);

UiImage複製して配置

  • Canvas/CopySourceImageにコピー元Image設置
  • NewImageが新しくできるImage
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;

参考:https://teratail.com/questions/42899