Exemplo n.º 1
0
        LoopGridViewItem OnGetItemByRowColumn(LoopGridView gridView, int itemIndex, int row, int column)
        {
            //get the data to showing
            ItemData itemData = DataSourceMgr.Get.GetItemDataByIndex(itemIndex);

            if (itemData == null)
            {
                return(null);
            }

            /*
             * get a new item. Every item can use a different prefab,
             * the parameter of the NewListViewItem is the prefab’name.
             * And all the prefabs should be listed in ItemPrefabList in LoopGridView Inspector Setting
             */
            LoopGridViewItem item = gridView.NewListViewItem("ItemPrefab0");

            ListItem18 itemScript = item.GetComponent <ListItem18>();//get your own component

            // IsInitHandlerCalled is false means this item is new created but not fetched from pool.
            if (item.IsInitHandlerCalled == false)
            {
                item.IsInitHandlerCalled = true;
                itemScript.Init();// here to init the item, such as add button click event listener.
            }
            //update the item’s content for showing, such as image,text.
            itemScript.SetItemData(itemData, itemIndex, row, column);
            return(item);
        }
Exemplo n.º 2
0
        void ShowItemPrefabDataList(LoopGridView listView)
        {
            EditorGUILayout.PropertyField(mItemPrefabDataList, mItemPrefabListContent);
            if (mItemPrefabDataList.isExpanded == false)
            {
                return;
            }
            EditorGUI.indentLevel += 1;
            if (GUILayout.Button("Add New"))
            {
                mItemPrefabDataList.InsertArrayElementAtIndex(mItemPrefabDataList.arraySize);
                if (mItemPrefabDataList.arraySize > 0)
                {
                    SerializedProperty itemData    = mItemPrefabDataList.GetArrayElementAtIndex(mItemPrefabDataList.arraySize - 1);
                    SerializedProperty mItemPrefab = itemData.FindPropertyRelative("mItemPrefab");
                    mItemPrefab.objectReferenceValue = null;
                }
            }
            int removeIndex = -1;

            EditorGUILayout.PropertyField(mItemPrefabDataList.FindPropertyRelative("Array.size"));
            for (int i = 0; i < mItemPrefabDataList.arraySize; i++)
            {
                SerializedProperty itemData         = mItemPrefabDataList.GetArrayElementAtIndex(i);
                SerializedProperty mInitCreateCount = itemData.FindPropertyRelative("mInitCreateCount");
                SerializedProperty mItemPrefab      = itemData.FindPropertyRelative("mItemPrefab");
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PropertyField(itemData);
                if (GUILayout.Button("Remove"))
                {
                    removeIndex = i;
                }
                EditorGUILayout.EndHorizontal();
                if (itemData.isExpanded == false)
                {
                    continue;
                }
                mItemPrefab.objectReferenceValue = EditorGUILayout.ObjectField("ItemPrefab", mItemPrefab.objectReferenceValue, typeof(GameObject), true);
                mInitCreateCount.intValue        = EditorGUILayout.IntField("InitCreateCount", mInitCreateCount.intValue);
                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }
            if (removeIndex >= 0)
            {
                mItemPrefabDataList.DeleteArrayElementAtIndex(removeIndex);
            }
            EditorGUI.indentLevel -= 1;
        }
        LoopGridViewItem OnGetItemByRowColumn(LoopGridView gridView, int itemIndex, int row, int column)
        {
            ItemData itemData = DataSourceMgr.Get.GetItemDataByIndex(itemIndex);

            if (itemData == null)
            {
                return(null);
            }
            LoopGridViewItem item       = gridView.NewListViewItem("ItemPrefab0");
            ListItem19       itemScript = item.GetComponent <ListItem19>();

            if (item.IsInitHandlerCalled == false)
            {
                item.IsInitHandlerCalled = true;
                itemScript.Init();
            }
            itemScript.SetItemData(itemData, itemIndex, row, column);
            return(item);
        }
Exemplo n.º 4
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            LoopGridView tListView = serializedObject.targetObject as LoopGridView;

            if (tListView == null)
            {
                return;
            }
            ShowItemPrefabDataList(tListView);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(mGridFixedType, mGridFixedTypeContent);
            if (mGridFixedType.enumValueIndex == (int)GridFixedType.ColumnCountFixed)
            {
                EditorGUILayout.PropertyField(mGridFixedRowOrColumn, mGridFixedColumnContent);
            }
            else
            {
                EditorGUILayout.PropertyField(mGridFixedRowOrColumn, mGridFixedRowContent);
            }
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(mPadding, mPaddingContent, true);
            EditorGUILayout.PropertyField(mItemSize, mItemSizeContent);
            EditorGUILayout.PropertyField(mItemPadding, mItemPaddingContent);
            EditorGUILayout.PropertyField(mItemRecycleDistance, mItemRecycleDistanceContent);

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(mItemSnapEnable, mItemSnapEnableContent);
            if (mItemSnapEnable.boolValue == true)
            {
                EditorGUILayout.PropertyField(mItemSnapPivot, mItemSnapPivotContent);
                EditorGUILayout.PropertyField(mViewPortSnapPivot, mViewPortSnapPivotContent);
            }
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(mArrangeType, mArrangeTypeGuiContent);

            serializedObject.ApplyModifiedProperties();
        }
        private LoopGridViewItem OnGetItemByRowColumn(
            LoopGridView gridView,
            int itemIndex,
            int row,
            int column)
        {
            ItemData itemDataByIndex = DataSourceMgr.Get.GetItemDataByIndex(itemIndex);

            if (itemDataByIndex == null)
            {
                return((LoopGridViewItem)null);
            }
            LoopGridViewItem loopGridViewItem = gridView.NewListViewItem("ItemPrefab0");
            ListItem18       component        = (ListItem18)((Component)loopGridViewItem).GetComponent <ListItem18>();

            if (!loopGridViewItem.IsInitHandlerCalled)
            {
                loopGridViewItem.IsInitHandlerCalled = true;
                component.Init();
            }
            component.SetItemData(itemDataByIndex, itemIndex, row, column);
            return(loopGridViewItem);
        }