TaskDisplayItem createItem() { int interval = Random.Range(500, 2000); int frequency = Random.Range(10, 20); GameObject newObj = GameObject.Instantiate(taskItemPrefab); TaskDisplayItem taskItem = newObj.GetComponent <TaskDisplayItem>(); if (taskItem != null) { taskItem.interval = interval; taskItem.frequency = frequency; IntervalTaskMgr.getInstance().addTask((uint)interval, frequency, taskItem.func); return(taskItem); } return(null); }
// Update is called once per frame void Update() { for (int i = 0; i < items.Count; i++) { if (items[i] != null && items[i].frequency <= 2) { IntervalTaskMgr.getInstance().removeTask(items[i].func); GameObject.Destroy(items[i].gameObject); items[i] = null; } if (items[i] == null) { TaskDisplayItem newItem = createItem(); if (newItem != null) { newItem.gameObject.name = "TaskItem" + i; items[i] = newItem; newItem.transform.SetParent(transform, false); newItem.transform.SetSiblingIndex(i); } } } }
// Use this for initialization void Start() { IntervalTaskMgr.getInstance().update(getCurTime()); }