public BitActionSwitchItemDrawer(BitActionSwitchWindowViewModel viewModel, GameObject targetAvatar, BitActionSwitchGroup bitActionSwitchGroup, BitActionSwitchItem bitActionSwitchItem) { this.viewModel = viewModel; this.targetAvatar = targetAvatar; this.bitActionSwitchGroup = bitActionSwitchGroup; this.bitActionSwitchItem = bitActionSwitchItem; this.gameObjectRegisterUi = new GameObjectRegisterUi(viewModel, bitActionSwitchItem); this.customAnimRegisterUi = new CustomAnimRegisterUi(bitActionSwitchItem); }
private void OnEnable() { this.viewModel = new BitActionSwitchWindowViewModel(); this.bitActionSwitch = (Scripts.BitActionSwitch) this.target; this.viewModel.BitActionSwitch = this.bitActionSwitch; this.reorderableList = new ReorderableList(this.bitActionSwitch.bitActionSwitchGroups, typeof(BitActionSwitchGroup), false, true, true, true) { elementHeight = 54, drawElementCallback = this.DrawElement, drawHeaderCallback = DrawHeader, }; this.bitActionSwitchGroupDrawers = this.bitActionSwitch.bitActionSwitchGroups.Select(x => new BitActionSwitchGroupDrawer(this.viewModel, this.viewModel.AvatarDescriptor == null ? null : this.viewModel.AvatarDescriptor.gameObject, x)).ToList(); this.reorderableList.onAddCallback += list => { this.Add(); }; this.reorderableList.onRemoveCallback += list => { this.bitActionSwitch.bitActionSwitchGroups.RemoveAt(list.index); this.bitActionSwitchGroupDrawers.RemoveAt(list.index); if (list.index >= list.list.Count - 1) { list.index = list.list.Count - 1; } }; this.reorderableList.elementHeightCallback += index => this.bitActionSwitchGroupDrawers[index].GetElementHeight(); if (this.viewModel.BitActionSwitch.bitActionSwitchGroups.Count == 0) { this.Add(); } this.reorderableList.onCanRemoveCallback = list => list.count > 1; }
public GameObjectRegisterUi(BitActionSwitchWindowViewModel viewModel, BitActionSwitchItem bitActionSwitchItem) { this.bitActionSwitchItem = bitActionSwitchItem; this.reorderableList = new ReorderableList(bitActionSwitchItem.gameObjects, typeof(GameObject), true, false, true, true); this.reorderableList.drawHeaderCallback += rect => { EditorGUI.LabelField(rect, L10n.Tr("Target Game Objects")); }; this.reorderableList.drawElementCallback += (rect, index, active, focused) => { var toggleFieldRect = rect; toggleFieldRect.width = 16f; toggleFieldRect.height = EditorGUIUtility.singleLineHeight + 2; var objectFieldRect = rect; objectFieldRect.x += toggleFieldRect.width + 2; objectFieldRect.y += 1; objectFieldRect.width -= toggleFieldRect.width + 2; objectFieldRect.height = EditorGUIUtility.singleLineHeight; if (bitActionSwitchItem.gameObjects[index] != null) { EditorCustomGUI.Toggle(toggleFieldRect, "", bitActionSwitchItem.gameObjects[index].activeSelf, x => bitActionSwitchItem.gameObjects[index].SetActive(x)); } EditorCustomGUI.ObjectField(objectFieldRect, "", bitActionSwitchItem.gameObjects[index], true, true, x => { bitActionSwitchItem.gameObjects[index] = x; }, () => viewModel.IsErrorRegisterGameObject(bitActionSwitchItem.gameObjects[index])); }; this.reorderableList.onAddCallback += list => bitActionSwitchItem.gameObjects.Add(null); }
public BitActionSwitchGroupDrawer(BitActionSwitchWindowViewModel viewModel, GameObject targetAvatar, BitActionSwitchGroup bitActionSwitchGroup) { this.viewModel = viewModel; this.bitActionSwitchGroup = bitActionSwitchGroup; this.reorderableList = new ReorderableList(bitActionSwitchGroup.bitActionSwitchItems, typeof(BitActionSwitchItem), true, true, true, true) { elementHeight = 54, drawElementCallback = this.DrawElement, drawHeaderCallback = this.DrawHeader, }; this.bitActionSwitchItemDrawers = bitActionSwitchGroup.bitActionSwitchItems .Select(x => new BitActionSwitchItemDrawer(viewModel, targetAvatar, this.bitActionSwitchGroup, x)).ToList(); this.reorderableList.onAddCallback += list => this.AddItem(targetAvatar, bitActionSwitchGroup); this.reorderableList.onRemoveCallback += list => { bitActionSwitchGroup.bitActionSwitchItems.RemoveAt(list.index); this.bitActionSwitchItemDrawers.RemoveAt(list.index); if (list.index >= list.list.Count - 1) { list.index = list.list.Count - 1; } }; this.reorderableList.elementHeightCallback += index => this.bitActionSwitchItemDrawers[index].GetElementHeight(); this.reorderableList.onReorderCallbackWithDetails += (list, index, newIndex) => { this.bitActionSwitchItemDrawers.ShiftElement(index, newIndex); }; this.reorderableList.onCanRemoveCallback = list => list.count > 1; }