protected static void DrawListControls <V>(StructureControl <List <V> > control, Div container) { container.Clear(); for (int i = 0; i < control.structure.Count; i++) { int index = i; if (control.specifiedFields.Contains(typeof(V))) { FieldControl <V> fieldControl = new FieldControl <V>(control.structure[index], control.name + "list-item", "item", false, control.world); fieldControl.eventManager.AddListener <FieldControlUpdated <V> >(e => { control.structure[index] = e.control.value; control.eventManager.Raise(new StructureControlUpdated <List <V> >(control)); }); ListItemImage delButton = fieldControl.AddImage(AssetDatabase.LoadAssetAtPath <Texture>("Assets/Icons/times.png")).AddToClassList("selectable", "hoverable", "icon"); delButton.eventManager.AddListener <MouseClickEvent>(e => { control.structure.RemoveAt(index); control.eventManager.Raise(new StructureControlUpdated <List <V> >(control)); DrawListControls <V>(control, container); }); container.Add(fieldControl); } else { V structure = control.structure[index]; StructureControl <V> structureControl = new StructureControl <V>(ref structure); structureControl.eventManager.AddListener <StructureControlUpdated <V> >(e => { control.eventManager.Raise(new StructureControlUpdated <List <V> >(control)); }); } } }
protected static void DrawSetControls <V>(StructureControl <HashSet <V> > control, Div container) { container.Clear(); foreach (V item in control.structure) { if (control.specifiedFields.Contains(typeof(V))) { FieldControl <V> fieldControl = new FieldControl <V>(item, control.name + "list-item", "item", false, control.world); fieldControl.eventManager.AddListener <FieldControlUpdated <V> >(e => { control.structure.Remove(item); control.structure.Add(e.control.value); control.eventManager.Raise(new StructureControlUpdated <HashSet <V> >(control)); }); ListItemImage delButton = fieldControl.AddImage(AssetDatabase.LoadAssetAtPath <Texture>("Assets/Icons/times.png")).AddToClassList("selectable", "hoverable", "icon"); delButton.eventManager.AddListener <MouseClickEvent>(e => { control.structure.Remove(item); control.eventManager.Raise(new StructureControlUpdated <HashSet <V> >(control)); DrawSetControls <V>(control, container); }); container.Add(fieldControl); } else { V structure = item; StructureControl <V> structureControl = new StructureControl <V>(ref structure); structureControl.eventManager.AddListener <StructureControlUpdated <V> >(e => { control.eventManager.Raise(new StructureControlUpdated <HashSet <V> >(control)); }); } } }
protected void DrawDataControls() { Div container; ListItem titleItem = DrawShelf("Offsets", out container); FieldControl <Vector3> posOffsetControl = new FieldControl <Vector3>(collection[chosenKey].positionOffset, "position-offset-control", "Position Offset"); posOffsetControl.eventManager.AddListener <FieldControlUpdated <Vector3> >(e => { collection[chosenKey].positionOffset = e.control.value; eventManager.Raise <SetSceneDirtyEvent>(new SetSceneDirtyEvent(SceneManager.GetActiveScene())); }); FieldControl <Vector3> rotOffsetControl = new FieldControl <Vector3>(collection[chosenKey].rotationOffset, "rotation-offset-control", "Rotation Offset"); rotOffsetControl.eventManager.AddListener <FieldControlUpdated <Vector3> >(e => { collection[chosenKey].rotationOffset = e.control.value; eventManager.Raise <SetSceneDirtyEvent>(new SetSceneDirtyEvent(SceneManager.GetActiveScene())); }); FieldControl <Vector3> scaleOffsetControl = new FieldControl <Vector3>(collection[chosenKey].scaleOffset, "scale-offset-control", "Scale"); scaleOffsetControl.eventManager.AddListener <FieldControlUpdated <Vector3> >(e => { collection[chosenKey].scaleOffset = e.control.value; eventManager.Raise <SetSceneDirtyEvent>(new SetSceneDirtyEvent(SceneManager.GetActiveScene())); }); container.Add(posOffsetControl, rotOffsetControl, scaleOffsetControl); entryEditorScroller.Add(titleItem, container); }
protected void CreateFieldControl <U>(FieldInfo info, bool alternate = false) { FieldControl <U> el = new FieldControl <U>((U)info.GetValue(structure), this.name + "--" + info.Name, info.Name, alternate, world); el.eventManager.AddListener <FieldControlUpdated <U> >(e => { info.SetValue(structure, el.value); eventManager.Raise <StructureControlUpdated <T> >(new StructureControlUpdated <T>(this)); }); this.Add(el); }
public static void DrawControl(this FieldControl <string> control) { TextField input = control.AddTextField(control.value); control.eventManager.AddListener <ListItemInputChange>(e => { if (e.input != input) { return; } control.value = input.value; control.eventManager.Raise <FieldControlUpdated <string> >(new FieldControlUpdated <string>(control)); }); }
public static void DrawControl(this FieldControl <bool> control) { EnumField input = control.AddBoolean(control.value); control.eventManager.AddListener <ListItemInputChange>(e => { if (e.input != input) { return; } control.value = (BooleanEnum)input.value == BooleanEnum.TRUE ? true : false; control.eventManager.Raise <FieldControlUpdated <bool> >(new FieldControlUpdated <bool>(control)); }); }
public static void DrawControl(this FieldControl <GameObject> control) { ObjectField input = control.AddObjectField(typeof(GameObject), false); input.value = control.value; control.eventManager.AddListener <ListItemInputChange>(e => { if (e.input != input) { return; } control.value = (GameObject)input.value; control.eventManager.Raise <FieldControlUpdated <GameObject> >(new FieldControlUpdated <GameObject>(control)); }); }
public static void DrawControl(this FieldControl <Entity> control) { if (control.world == null) { return; } ListItemText input = control.AddEntitySelector(control.world, control.value); control.eventManager.AddListener <ListItemInputChange>(e => { if (e.input != input) { return; } control.value = (Entity)input.text; control.eventManager.Raise <FieldControlUpdated <Entity> >(new FieldControlUpdated <Entity>(control)); }); }
public static void DrawControl(this FieldControl <ushort> control) { IntegerField input = control.AddIntField(control.value); control.eventManager.AddListener <ListItemInputChange>(e => { if (e.input != input) { return; } if (input.value < 0) { input.value = 0; } if (input.value > ushort.MaxValue) { input.value = ushort.MaxValue; } control.value = (ushort)input.value; control.eventManager.Raise <FieldControlUpdated <ushort> >(new FieldControlUpdated <ushort>(control)); }); }
public FieldControlUpdated(FieldControl <T> control) { this.control = control; }