Last active
October 18, 2015 17:25
-
-
Save tsubaki/486d168a1d8da771c8cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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