Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active October 18, 2015 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/486d168a1d8da771c8cb to your computer and use it in GitHub Desktop.
Save tsubaki/486d168a1d8da771c8cb to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
public class AddContent : MonoBehaviour {
// 要素を追加するコンテント
[SerializeField] RectTransform content;
// 生成する要素
[SerializeField] RectTransform originalElement;
[SerializeField] Text elementOriginalText;
// テキスト入力フィールド
[SerializeField] InputField input;
void Awake()
{
originalElement.gameObject.SetActive (false);
}
public void OnSubmit()
{
// 入力フィールドを元に複製元のデータを改変
// 入力フィールドは初期化する
elementOriginalText.text = input.text;
input.text = string.Empty;
// content以下にoriginalElementを複製
var element = GameObject.Instantiate<RectTransform> (originalElement);
element.SetParent (content, false);
element.SetAsFirstSibling ();
element.gameObject.SetActive (true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment