コード例 #1
0
    ///// <summary>
    ///// 刷新物体列表
    ///// </summary>
    //public void RefleshObjectList()
    //{
    //    int childcount = currentParent.transform.childCount;
    //    for (int i = 0; i < currentType.childTypeList.Count; i++)
    //    {
    //        Transform tran = null;
    //        if (i < childcount)
    //        {
    //            tran = currentParent.transform.GetChild(i);
    //        }
    //        else
    //        {
    //            tran = InstantiateItem().transform;
    //        }
    //        if (tran)
    //        {
    //            ChildTypeItem item = tran.GetComponent<ChildTypeItem>();
    //            item.InitData(currentType.childTypeList[i]);
    //            SetToggleGroup(item.topToggle);
    //            if (childcount == 0)
    //            {
    //                item.SetContentActive(false);
    //                if (i == 0)
    //                {
    //                    //item.RefleshItems();
    //                    item.topToggle.isOn = true;
    //                    item.SetContentActive(true);
    //                }
    //            }
    //        }

    //    }

    //    for (int i = childcount - 1; i >= currentType.childTypeList.Count; i--)
    //    {
    //        Transform tran = currentParent.transform.GetChild(i);
    //        DestroyImmediate(tran.gameObject);
    //    }

    //}

    /// <summary>
    /// 刷新物体列表
    /// </summary>
    public void RefleshObjectList(List <ObjectAddList_ChildType> typeModels)
    {
        int childcount = currentParent.transform.childCount;

        for (int i = 0; i < typeModels.Count; i++)
        {
            Transform tran = null;
            if (i < childcount)
            {
                tran = currentParent.transform.GetChild(i);
            }
            else
            {
                tran = InstantiateItem().transform;
            }
            if (tran)
            {
                ChildTypeItem item = tran.GetComponent <ChildTypeItem>();
                item.InitData(typeModels[i]);
                SetToggleGroup(item.topToggle);
                if (!ObjectListSearch.Instance.isSearchShow)
                {
                    //if(childcount==0)
                    if (i == 0)
                    {
                        if (!item.topToggle.isOn)
                        {
                            item.topToggle.isOn = true;
                        }
                        else
                        {
                            StartCoroutine(item.RefleshItems());
                        }
                    }
                }
                else
                {
                    //item.SetContentActive(false);
                    if (i == 0)
                    {
                        item.topToggle.isOn = true;
                        item.topButton_OnValueChanged(true);
                        item.SetContentActive(true);
                    }
                }
            }
        }

        for (int i = childcount - 1; i >= typeModels.Count; i--)
        {
            Transform tran = currentParent.transform.GetChild(i);
            DestroyImmediate(tran.gameObject);
        }
        ObjectListSearch.Instance.SetIsSearchShow(false);
    }
コード例 #2
0
    /// <summary>
    /// 实例化预设
    /// </summary>
    /// <returns></returns>
    public GameObject InstantiateItem()
    {
        GameObject o = Instantiate(childTypeItem);

        o.transform.SetParent(currentParent.transform);
        o.transform.localScale    = Vector3.one;
        o.transform.localPosition = Vector3.zero;
        o.SetActive(true);
        ChildTypeItem item = o.GetComponent <ChildTypeItem>();

        item.SetContentActive(false);
        return(o);
    }