NData BUG 记录

一、collection

  如果设计如下页面

  

  页面模型如下

  

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

using MyUtils;

public class Product : EZData.Context
{
    #region Property Name
    #endregion

    #region Property Price
    #endregion

    #region Property Model
    #endregion

    #region Property PicUrl
    #endregion

    #region Property Pic //Texture2D
    #endregion

    public void SetTexture2D(Texture2D tar) {
        Pic = tar;
    }

    //set current product
    public void SetCurrentProduct() {
        Messenger.Broadcast<Product>(EventSignal.Select_Current_Product.ToString(), this);
    }
}

public class CommodityPage<T> : EZData.Context
    where T : EZData.Context
{
    //列的集合 
    #region Collection Page
    #endregion
}

public class Category<T> : EZData.Context
    where T : EZData.Context
{
    //row list
    #region Collection Table
    #endregion

    #region Property Name
    #endregion

    public void LoadTable(T[] Array, int PageNum)
    {
    }
}

public class CategroyUi : EZData.Context
{
    #region Collection CategoryList
    #endregion

    #region Property NowSelectProduct
    #endregion


    public ICategory_Product_Dao Ca_Pr_dao;

    public CategroyUi(ICategory_Product_Dao Ca_Pr_dao)
    {
        this.Ca_Pr_dao = Ca_Pr_dao;

        List<CategoryBean> mycategorylist = Ca_Pr_dao.getAllCategory();

        foreach (CategoryBean item in mycategorylist)
        {
            CategoryList.Add(new Category<Product>() { Name = item.Name });
        }

        for (int i = 0; i < mycategorylist.Count; i++)
        {
            List<ProductBean> collection = Ca_Pr_dao.getProductListByCategoryId(mycategorylist[i].Id);

            Product[] Product_collection = GetArray(collection);

            CategoryList.GetItem(i).LoadTable(Product_collection, 3);
        }

        //使用ngui master path
        //path = CategoryList.SelectedItem.Table.SelectedItem.Page.SelectedItem 
        //这样形式是不可以的,只有CategoryList.SelectedItem 是可以使用的

        
        //这里千万不要这么引用
        //比如这里引用第一行第一个的数据
        //之后你改为第一行第二个的数据
        //NowSelectProduct 引用的是第一行第一个 那么第一行第一个的数据也改为第一行第二个
        //NowSelectProduct = CategoryList.GetItem(0).Table.GetItem(0).Page.GetItem(0);

        
        
        //新new 一个 不要引用相同的
        //一定要对其最开始就进行初始化 之后改变这个类的属性 不能改变这个类的引用
        Product tmp = CategoryList.GetItem(0).Table.GetItem(0).Page.GetItem(0);
        NowSelectProduct = new Product() { Name = tmp.Name, Price = tmp.Price, Model = tmp.Model, PicUrl = tmp.PicUrl };
        Ca_Pr_dao.GetPicureByProductNameOrUrl(NowSelectProduct.Name, NowSelectProduct.PicUrl, NowSelectProduct.SetTexture2D);

        //监听当前选择的改变
        Messenger.AddListener<Product>(
            EventSignal.Select_Current_Product.ToString(), SelectCurrentProduct);
    }


    public void SelectCurrentProduct(Product cur)
    {
        //这里不能改引用 只能赋值
        NowSelectProduct.Name = cur.Name;
        NowSelectProduct.Price = cur.Price;
        NowSelectProduct.Model = cur.Model;
        NowSelectProduct.PicUrl = cur.PicUrl;
        UnityEngine.Debug.Log("SelectCurrentProduct" + NowSelectProduct.Name);
        Ca_Pr_dao.GetPicureByProductNameOrUrl(NowSelectProduct.Name, NowSelectProduct.PicUrl, NowSelectProduct.SetTexture2D);
    }

    #region 功能函数
    Product[] GetArray(List<ProductBean> collection)
    {
        int length = collection.Count;

        Product[] result = new Product[length];
        for (int i = 0; i < length; i++)
        {
            ProductBean tmp = collection[i];
            result[i] = new Product() { Name = tmp.Name, Price = tmp.Price, Model = tmp.Size, PicUrl = tmp.PicUrl};
            Ca_Pr_dao.GetPicureByProductNameOrUrl(result[i].Name, result[i].PicUrl, result[i].SetTexture2D);
        }
        return result;
    }
    #endregion
}

public class CategoryViewModel : MonoBehaviour
{
    public NguiRootContext View;
    
    public CategroyUi Context;

    public void Init(NguiRootContext View)
    {
        this.View = View;
        Context = new CategroyUi(new CategoryModel());
        View.SetContext(Context);
    }
}

 

 2、关于NguiTextBinding

  拖一个输入框如下:

  Control - Simple Input Field

    -》 Label

  附加脚本如下:

  Control - Simple Input Field

  

  Label

  

  

  ViewModel 对应如下:
  

    #region Property MessageLeave
    private readonly EZData.Property<string> _privateMessageLeaveProperty
       = new EZData.Property<string>();
    public EZData.Property<string> MessageLeaveProperty
    { get { return _privateMessageLeaveProperty; } }
    public string MessageLeave
    {
        get { return MessageLeaveProperty.GetValue(); }
        set { MessageLeaveProperty.SetValue(value); }
    }
    #endregion

    public void SendMessage() {
        Debuger.Log("LeaveMessage is :"+ MessageLeave);
    }

  void SendMessage() 绑定一个按钮,MessageLeave 绑定刚才的label,按钮点击,结果如下

  

  

  但如果只保留label:

  附加脚本如下:

  

  同样的ViewModel,结果如下

  

  可以得到绑定,无语了,这个BUG。还有我建议Text CommitBind 能不用就不用。

三、NguiTextureBinding

  这里要修改一下,如果采用material的话,那么同一个材质的图片都是一样的了。

  

原文地址:https://www.cnblogs.com/chongxin/p/3925209.html