public override void OnEnable() { bsl = target as BiomeSwitchList; switchDatas = bsl.switchDatas; reorderableSwitchDataList = new ReorderableList(bsl.switchDatas, typeof(BiomeSwitchData), true, true, true, true); reorderableSwitchDataList.elementHeight = EditorGUIUtility.singleLineHeight * 2 + 4; //padding reorderableSwitchDataList.drawElementCallback = DrawElementCallback; reorderableSwitchDataList.drawHeaderCallback = (rect) => { EditorGUI.LabelField(rect, "switches"); }; reorderableSwitchDataList.onReorderCallback += (ReorderableList l) => { if (bsl.OnBiomeDataReordered != null) { bsl.OnBiomeDataReordered(); } }; reorderableSwitchDataList.onAddCallback += (ReorderableList l) => { BiomeSwitchData bsd = new BiomeSwitchData(bsl.sampler, bsl.samplerName); BiomeSwitchData lastSwitch = switchDatas.Last(); bsd.min = lastSwitch.min + (lastSwitch.max - lastSwitch.min) / 2; switchDatas.Add(bsd); if (bsl.OnBiomeDataAdded != null) { bsl.OnBiomeDataAdded(bsd); } }; reorderableSwitchDataList.onRemoveCallback += (ReorderableList l) => { if (switchDatas.Count > 1) { switchDatas.RemoveAt(l.index); if (bsl.OnBiomeDataRemoved != null) { bsl.OnBiomeDataRemoved(); } } }; //add at least one biome switch: if (switchDatas.Count == 0) { switchDatas.Add(new BiomeSwitchData(bsl.sampler, bsl.samplerName)); } }
void DrawElementCallback(Rect rect, int index, bool isActive, bool selected) { BiomeSwitchData elem = switchDatas[index]; rect.y += 2; int floatFieldSize = 70; int colorFieldSize = 20; int nameFieldSize = (int)rect.width - colorFieldSize - 2; float lineHeight = EditorGUIUtility.singleLineHeight; Rect nameRect = new Rect(rect.x, rect.y, nameFieldSize, EditorGUIUtility.singleLineHeight); Rect colorFieldRect = new Rect(rect.x + nameFieldSize + 4, rect.y - 2, colorFieldSize, colorFieldSize); Rect minRect = new Rect(rect.x, rect.y + lineHeight + 2, floatFieldSize, EditorGUIUtility.singleLineHeight); Rect maxRect = new Rect(rect.x + floatFieldSize, rect.y + lineHeight + 2, floatFieldSize, EditorGUIUtility.singleLineHeight); EditorGUIUtility.labelWidth = 25; EditorGUI.BeginChangeCheck(); { float oldMin = elem.min; float oldMax = elem.max; bool first = index == 0; bool last = index == reorderableSwitchDataList.count - 1; PWGUI.ColorPicker(colorFieldRect, ref elem.color, false, true); elem.name = EditorGUI.TextField(nameRect, elem.name); EditorGUI.BeginDisabledGroup(first); elem.min = EditorGUI.FloatField(minRect, "min", elem.min); EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(last); elem.max = EditorGUI.FloatField(maxRect, "max", elem.max); EditorGUI.EndDisabledGroup(); if (last) { elem.max = bsl.relativeMax; } if (first) { elem.min = bsl.relativeMin; } elem.min = Mathf.Max(elem.min, bsl.relativeMin); elem.max = Mathf.Min(elem.max, bsl.relativeMax); //affect up/down cell value if (elem.min != oldMin && index > 0) { switchDatas[index - 1].max = elem.min; } if (elem.max != oldMax && index + 1 < switchDatas.Count) { switchDatas[index + 1].min = elem.max; } } if (EditorGUI.EndChangeCheck() && bsl.OnBiomeDataModified != null) { bsl.OnBiomeDataModified(elem); } EditorGUIUtility.labelWidth = 0; switchDatas[index] = elem; }