功能需求
给列表行填充数据,可以点击按钮输出行ID
运行效果图:
打印信息:
Unity 版本:Unity 2018.3.4f1 (64-bit)
下面是代码实现:
MainTaskRowComData
using Unity.Entities;
using System;
using TMPro;
using UnityEngine.UI;
[Serializable]
public struct MainTaskRowComData : ISharedComponentData
{
//ComData
public TextMeshProUGUI txt_IndexID;
public TextMeshProUGUI txt_TaskName;
public Button btn_Edit;
public Button btn_Delete;
}
public class MainTaskRowComDataProxy : SharedComponentDataProxy<MainTaskRowComData>
{
public void On_EditClick(TextMeshProUGUI txtid)
{
UnityEngine.Debug.Log("on click:" + txtid.text);
}
}
MainTaskRow_System
using System;
using System.Collections.Generic;
using Unity.Entities;
using UnityEngine;
public class MainTaskRow_System : ComponentSystem
{
ComponentGroup m_MainGroup;
protected override void OnCreateManager()
{
//base.OnCreateManager();
//根据类型找 MainTaskRowComData
m_MainGroup = GetComponentGroup(typeof(MainTaskRowComData));
//m_MainGroup.CalculateLength() is 0
}
protected override void OnStartRunning()
{
//base.OnStartRunning();
int count = m_MainGroup.CalculateLength();
Debug.Log("row:" + count);// output count:3
var lst = m_MainGroup.GetSharedComponentDataArray<MainTaskRowComData>();
//Debug.Log("lst Length:" + lst.Length);//out put Length 3
for (int i=0;i < lst.Length;i++)
{
var row = lst[lst.Length-i-1];
//
var dbinfo = GetDBInfo(i);
int index = i + 1;
row.txt_IndexID.text = dbinfo.AutoGUID;
row.txt_TaskName.text = dbinfo.TaskName;
//
}
}
private TaskRowDBInfo GetDBInfo(int i)
{
List<TaskRowDBInfo> lst = new List<TaskRowDBInfo>();
TaskRowDBInfo row1 = new TaskRowDBInfo();
TaskRowDBInfo row2 = new TaskRowDBInfo();
TaskRowDBInfo row3 = new TaskRowDBInfo();
//
row1.AutoGUID = "id1";
row1.TaskName = "Dev 1";
row2.AutoGUID = "id2";
row2.TaskName = "Dev 2";
row3.AutoGUID = "id3";
row3.TaskName = "Dev 3";
lst.Add(row1);
lst.Add(row2);
lst.Add(row3);
//
return lst[i];
}
protected override void OnUpdate()
{
}
}
[System.Serializable]
public class TaskRowDBInfo
{
public string AutoGUID = "0";
public string TaskName = "";
}