| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEditor;
- using UnityEditorInternal;
- namespace SuperScrollView
- {
- [CustomEditor(typeof(LoopListView))]
- public class LoopListViewEditor : Editor
- {
- SerializedProperty mStartPadding;
- SerializedProperty mEndPadding;
- SerializedProperty mSupportScrollBar;
- SerializedProperty mItemSnapEnable;
- SerializedProperty mArrangeType;
- SerializedProperty mItemPrefabDataList;
- SerializedProperty mItemSnapPivot;
- SerializedProperty mViewPortSnapPivot;
- SerializedProperty mAutoAdapterSize;
- GUIContent mStartPaddingContent = new GUIContent("StartPadding");
- GUIContent mEndPaddingContent = new GUIContent("EndPadding");
- GUIContent mSupportScrollBarContent = new GUIContent("SupportScrollBar");
- GUIContent mItemSnapEnableContent = new GUIContent("ItemSnapEnable");
- GUIContent mArrangeTypeGuiContent = new GUIContent("ArrangeType");
- GUIContent mItemPrefabListContent = new GUIContent("ItemPrefabList");
- GUIContent mItemSnapPivotContent = new GUIContent("ItemSnapPivot");
- GUIContent mViewPortSnapPivotContent = new GUIContent("ViewPortSnapPivot");
- GUIContent mAutoAdapterSizeContent = new GUIContent("AutoAdapterSize", "如果LoopListView是大小是可变的,并且需要影响到LoopListViewItem,则可勾选这个");
- protected virtual void OnEnable()
- {
- mStartPadding = serializedObject.FindProperty("mStartPadding");
- mEndPadding = serializedObject.FindProperty("mEndPadding");
- mSupportScrollBar = serializedObject.FindProperty("mSupportScrollBar");
- mItemSnapEnable = serializedObject.FindProperty("mItemSnapEnable");
- mArrangeType = serializedObject.FindProperty("mArrangeType");
- mItemPrefabDataList = serializedObject.FindProperty("mItemPrefabDataList");
- mItemSnapPivot = serializedObject.FindProperty("mItemSnapPivot");
- mViewPortSnapPivot = serializedObject.FindProperty("mViewPortSnapPivot");
- mAutoAdapterSize = serializedObject.FindProperty("mAutoAdapterSize");
- }
- void ShowItemPrefabDataList(LoopListView 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");
- SerializedProperty mItemPrefabPadding = itemData.FindPropertyRelative("mPadding");
- SerializedProperty mItemStartPosOffset = itemData.FindPropertyRelative("mStartPosOffset");
- 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);
- mItemPrefabPadding.floatValue = EditorGUILayout.FloatField("ItemPadding", mItemPrefabPadding.floatValue);
- if (listView.ArrangeType == ListItemArrangeType.TopToBottom || listView.ArrangeType == ListItemArrangeType.BottomToTop)
- {
- mItemStartPosOffset.floatValue = EditorGUILayout.FloatField("XPosOffset", mItemStartPosOffset.floatValue);
- }
- else
- {
- mItemStartPosOffset.floatValue = EditorGUILayout.FloatField("YPosOffset", mItemStartPosOffset.floatValue);
- }
- mInitCreateCount.intValue = EditorGUILayout.IntField("InitCreateCount", mInitCreateCount.intValue);
- EditorGUILayout.Space();
- EditorGUILayout.Space();
- }
- if (removeIndex >= 0)
- {
- mItemPrefabDataList.DeleteArrayElementAtIndex(removeIndex);
- }
- EditorGUI.indentLevel -= 1;
- }
- public override void OnInspectorGUI()
- {
- serializedObject.Update();
- LoopListView tListView = serializedObject.targetObject as LoopListView;
- if (tListView == null)
- {
- return;
- }
- ShowItemPrefabDataList(tListView);
- EditorGUILayout.Space();
- EditorGUILayout.PropertyField(mStartPadding, mStartPaddingContent);
- EditorGUILayout.PropertyField(mEndPadding, mEndPaddingContent);
- EditorGUILayout.PropertyField(mSupportScrollBar, mSupportScrollBarContent);
- EditorGUILayout.PropertyField(mItemSnapEnable, mItemSnapEnableContent);
- EditorGUILayout.PropertyField(mAutoAdapterSize, mAutoAdapterSizeContent);
- if (mItemSnapEnable.boolValue == true)
- {
- EditorGUILayout.PropertyField(mItemSnapPivot, mItemSnapPivotContent);
- EditorGUILayout.PropertyField(mViewPortSnapPivot, mViewPortSnapPivotContent);
- }
- EditorGUILayout.PropertyField(mArrangeType, mArrangeTypeGuiContent);
- serializedObject.ApplyModifiedProperties();
- }
- }
- }
|