using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; using UnityEngine.UI; using UniverseLib; using UniverseLib.UI; using UniverseLib.UI.Models; using UniverseLib.UI.Widgets.ButtonList; namespace UnityExplorer.Inspectors { public class ComponentCell : ButtonCell { public Toggle BehaviourToggle; public ButtonRef DestroyButton; public Action OnBehaviourToggled; public Action OnDestroyClicked; private void BehaviourToggled(bool val) { OnBehaviourToggled?.Invoke(val, CurrentDataIndex); } private void DestroyClicked() { OnDestroyClicked?.Invoke(CurrentDataIndex); } public override GameObject CreateContent(GameObject parent) { var root = base.CreateContent(parent); // Add mask to button so text doesnt overlap on Close button //this.Button.Component.gameObject.AddComponent().showMaskGraphic = true; this.Button.ButtonText.horizontalOverflow = HorizontalWrapMode.Wrap; // Behaviour toggle var toggleObj = UIFactory.CreateToggle(UIRoot, "BehaviourToggle", out BehaviourToggle, out var behavText); UIFactory.SetLayoutElement(toggleObj, minHeight: 25, minWidth: 25); BehaviourToggle.onValueChanged.AddListener(BehaviourToggled); // put at first object toggleObj.transform.SetSiblingIndex(0); // Destroy button DestroyButton = UIFactory.CreateButton(UIRoot, "DestroyButton", "X", new Color(0.3f, 0.2f, 0.2f)); UIFactory.SetLayoutElement(DestroyButton.Component.gameObject, minHeight: 21, minWidth: 25); DestroyButton.OnClick += DestroyClicked; return root; } } }