Esempio n. 1
0
        /// <summary>
        /// 创建随机行数据
        /// </summary>
        /// <returns></returns>
        private RowDataEntity CreatRandomRowEntity()
        {
            RowDataEntity rentity = new RowDataEntity();

            rentity.age    = UnityEngine.Random.Range(10, 100).ToString();
            rentity.id     = "BVRP-" + UnityEngine.Random.Range(10, 100).ToString();
            rentity.name   = "Student";
            rentity.clazz  = "BBRR";
            rentity.status = "Good";
            return(rentity);
        }
Esempio n. 2
0
        /// <summary>
        /// 处理添加行业务逻辑
        /// </summary>
        /// <param name="evt"></param>
        public override void ProcessLogic(PropertyMessage evt)
        {
            //忽略初始化事件
            if (evt.OldValue == evt.NewValue)
            {
                return;
            }

            if (evt.PropertyName.Equals("addClicked"))
            {
                //随机创建行数据并添加到数据表
                TableViewModel tvm = gameObject.GetComponentInParent <TableViewModel>();
                if (tvm != null)
                {
                    TableEntity   entity  = (TableEntity)tvm.DataEntity;
                    RowDataEntity rentity = CreatRandomRowEntity();
                    entity.rowData.Add(rentity);
                }
                return;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 处理删除数据行事件
        /// </summary>
        /// <param name="evt"></param>
        public override void ProcessLogic(PropertyMessage evt)
        {
            //MVVM初始化事件特点是OldValue==NewValue,
            //这里表示不处理初始化事件
            if (evt.OldValue == evt.NewValue)
            {
                return;
            }

            if (evt.PropertyName.Equals("removeClicked"))
            {
                //获取表实体并在表中删除行数据
                RowDataEntity  rentity = (RowDataEntity)GetComponent <RowDataViewModel>().DataEntity;
                TableViewModel tvm     = gameObject.GetComponentInParent <TableViewModel>();
                if (tvm != null)
                {
                    TableEntity entity = (TableEntity)tvm.DataEntity;
                    entity.rowData.Remove(rentity);
                }

                return;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 处理数据表格业务逻辑
        /// </summary>
        /// <param name="evt"></param>
        public override void ProcessLogic(PropertyMessage evt)
        {
            //当数据恢复后触发更新界面显示
            if (evt.PropertyName.Equals("isLoaded"))
            {
                //获取Entity
                TableEntity entity = (TableEntity)(gameObject.
                                                   GetComponent <TableViewModel>().DataEntity);

                //生成数据行UI并重新绑定实体对象
                foreach (RowDataEntity row in entity.rowData)
                {
                    //加载行预制体
                    GameObject newRow = (GameObject)Resources.Load("Prefabs/ImageRowData");
                    newRow = Instantiate(newRow);
                    GameObject goContent = GameObject.Find("ScrollViewTableData/Viewport/Content");
                    if (goContent != null)
                    {
                        newRow.transform.parent = goContent.transform;
                    }

                    //重新绑定数据实体
                    RowDataViewModel rdvm = newRow.GetComponent <RowDataViewModel>();
                    rdvm.Rebinding(row);
                }
                return;
            }

            //当有行实体对象添加到表格实体的rowData中,
            //加载行预制体并重新绑定实体对象
            if (evt.PropertyName.Equals("rowData#Add"))
            {
                var info = evt.TargetObject.GetType().GetField("rowData").GetCustomAttribute <NoStorage>();
                if (info != null)
                {
                    Debug.Log("就是我!!!");
                }
                //给新创建的实体对象编号
                RowDataEntity entity = (RowDataEntity)evt.NewValue;

                //加载行预制体
                GameObject newRow = (GameObject)Resources.Load("Prefabs/ImageRowData");
                newRow = Instantiate(newRow);
                GameObject goContent = GameObject.Find("ScrollViewTableData/Viewport/Content");
                if (goContent != null)
                {
                    newRow.transform.parent = goContent.transform;
                }

                //重新绑定数据实体
                RowDataViewModel rdvm = newRow.GetComponent <RowDataViewModel>();
                rdvm.Rebinding(entity);

                return;
            }

            //当表格实体的rowData数据发生删除事件时,执行预制体销毁
            if (evt.PropertyName.Equals("rowData#Remove"))
            {
                //销毁预制体
                GameObject         goContent = GameObject.Find("ScrollViewTableData/Viewport/Content");
                RowDataViewModel[] rvms      = goContent.GetComponentsInChildren <RowDataViewModel>();
                foreach (RowDataViewModel rvm in rvms)
                {
                    RowDataEntity rentity = (RowDataEntity)rvm.DataEntity;
                    if (ReferenceEquals(rentity, evt.OldValue))
                    {
                        Destroy(rvm.gameObject, 0.1f);
                    }
                }
            }
        }