private void DrawRule(Rect rect, IList list, int index) { var rule = _ruleOverrideTile.Rules[index]; var overrideRule = _ruleOverrideTile.OverrideTile.Rules[index]; var width = EditorGUIUtility.singleLineHeight * 3 + RectHelper.VerticalSpace * 2; var referenceRect = RectHelper.TakeLine(ref rect); var isReferenceRect = RectHelper.TakeWidth(ref referenceRect, referenceRect.width * 0.5f - RectHelper.HorizontalSpace); RectHelper.TakeHorizontalSpace(ref referenceRect); var matrixRect = RectHelper.TakeWidth(ref rect, width); RectHelper.TakeHorizontalSpace(ref rect); DrawRuleMatrix(_ruleOverrideTile.OverrideTile, matrixRect, overrideRule); rule.UseReference = EditorGUI.Toggle(isReferenceRect, _isReferenceContent.Content, rule.UseReference); if (rule.UseReference) { rule.Tile.Sprite = null; rule.Reference = EditorGUI.ObjectField(referenceRect, _referenceContent, rule.Reference, typeof(TileBase), false) as TileBase; if (rule.Reference == _ruleOverrideTile) { rule.Reference = null; } } else { rule.Tile = TileTransformInfoControl.Draw(rect, GUIContent.none, rule.Tile); rule.Reference = null; } }
public override void Draw(Rect position, GUIContent label) { var moneyRect = RectHelper.TakeLine(ref position); _inventory.Money = EditorGUI.IntField(moneyRect, _moneyLabel.Content, _inventory.Money); _listControl.Draw(position, _itemsLabel.Content); }
private void DrawDoor(Rect rect, IList list, int index) { var door = _building.Doors[index]; var nameRect = RectHelper.TakeLine(ref rect); RectHelper.TakeWidth(ref rect, RectHelper.LeftMargin); var positionRect = RectHelper.TakeLine(ref rect); var orderRect = RectHelper.TakeLine(ref rect); var spriteRect = RectHelper.TakeLine(ref rect); var openARect = RectHelper.TakeLine(ref rect); var closeARect = RectHelper.TakeLine(ref rect); var openSRect = RectHelper.TakeLine(ref rect); var closeSRect = RectHelper.TakeLine(ref rect); door.GameObject.name = EditorGUI.TextField(nameRect, door.GameObject.name); var position = EditorGUI.Vector2Field(positionRect, _accessoryPositionContent, door.Bounds.position); door.OrderOffset = door.Renderer.sortingOrder = EditorGUI.IntSlider(orderRect, _orderOffsetContent, door.Renderer.sortingOrder, 0, _MaxOrderOffset); door.Renderer.sprite = EditorGUI.ObjectField(spriteRect, _spriteContent, door.Renderer.sprite, typeof(Sprite), false) as Sprite; door.Door.OpenAnimation = EditorGUI.ObjectField(openARect, _openAnimationContent, door.Door.OpenAnimation, typeof(AnimationClip), false) as AnimationClip; door.Door.CloseAnimation = EditorGUI.ObjectField(closeARect, _closeAnimationContent, door.Door.CloseAnimation, typeof(AnimationClip), false) as AnimationClip; door.Door.OpenSound = EditorGUI.ObjectField(openSRect, _openSoundContent, door.Door.OpenSound, typeof(AudioClip), false) as AudioClip; door.Door.CloseSound = EditorGUI.ObjectField(closeSRect, _closeSoundContent, door.Door.CloseSound, typeof(AudioClip), false) as AudioClip; UpdatePartTransform(door, position); }
public static ValueDefinition Draw(Rect position, GUIContent label, ValueDefinition definition, VariableInitializerType initializer, TagList tags, bool showConstraintLabel, ref bool isExpanded) { var tag = definition.Tag; var constraint = definition.Constraint; var hasInitializer = HasInitializer(definition.Type, initializer); var hasConstraint = HasConstraint(definition.Type, definition.Constraint, definition.IsConstraintLocked); var hasTag = HasTags(tags); var typeRect = RectHelper.TakeLine(ref position); if (label != GUIContent.none) { var labelRect = RectHelper.TakeWidth(ref typeRect, RectHelper.CurrentLabelWidth); EditorGUI.LabelField(labelRect, label); } var type = DrawType(typeRect, definition.IsTypeLocked, definition.Type); if (hasConstraint) { var constraintHeight = GetConstraintHeight(definition.Type, definition.Constraint); var constraintRect = RectHelper.TakeHeight(ref position, constraintHeight); DrawConstraint(constraintRect, type, definition.IsConstraintLocked, ref constraint, showConstraintLabel); } if (hasInitializer && definition.Initializer != null) { if (initializer == VariableInitializerType.Expression) { var initializerHeight = ExpressionControl.GetFoldoutHeight(definition.Initializer, isExpanded, true, 2, 3); var initializerRect = RectHelper.TakeHeight(ref position, initializerHeight); RectHelper.TakeVerticalSpace(ref position); DrawInitializer(initializerRect, ref definition, ref isExpanded); } else if (initializer == VariableInitializerType.DefaultValue) { var initializerRect = RectHelper.TakeLine(ref position); DrawDefaultValue(initializerRect, ref definition); } } if (hasTag) { var tagRect = RectHelper.TakeLine(ref position); tag = DrawTag(tagRect, tag, tags); } return(ValueDefinition.Create(type, constraint, tag, definition.Initializer, definition.IsTypeLocked, definition.IsConstraintLocked)); }
private void DrawNode(Rect rect, SerializedProperty property, int index) { var element = property.GetArrayElementAtIndex(index); var positionRect = RectHelper.TakeLine(ref rect); var delayRect = RectHelper.TakeLine(ref rect); var directionRect = RectHelper.TakeLine(ref rect); GUI.enabled = index != 0; EditorGUI.PropertyField(positionRect, element.FindPropertyRelative(nameof(Path.NodeData.Position))); GUI.enabled = true; EditorGUI.PropertyField(delayRect, element.FindPropertyRelative(nameof(Path.NodeData.Delay))); EditorGUI.PropertyField(directionRect, element.FindPropertyRelative(nameof(Path.NodeData.Direction))); }
public static void Draw(Rect position, Expression expression, GUIContent label) { var rect = RectHelper.TakeLine(ref position); EditorGUI.LabelField(rect, label); using (new InvalidScope(!expression.HasError)) { using (var changes = new EditorGUI.ChangeCheckScope()) { var statement = EditorGUI.TextArea(position, expression.Statement); if (changes.changed) { expression.SetStatement(statement); } } } }
public override void OnGUI(Rect position) { var rect = RectHelper.Inset(position, 5.0f); var nameRect = RectHelper.TakeLine(ref rect); var buttonRect = RectHelper.TakeTrailingHeight(ref rect, EditorGUIUtility.singleLineHeight); RectHelper.TakeTrailingHeight(ref rect, RectHelper.VerticalSpace); var isExpanded = false; _name = EditorGUI.TextField(nameRect, _name); _definition = ValueDefinitionControl.Draw(rect, GUIContent.none, _definition, VariableInitializerType.None, null, false, ref isExpanded); if (GUI.Button(buttonRect, "Apply")) { _control.ApplyDefinition(_index, _name, _definition); editorWindow.Close(); } }
private static void DrawStringConstraint(Rect rect, ref VariableConstraint constraint) { if (!(constraint is StringVariableConstraint stringConstraint)) { stringConstraint = new StringVariableConstraint { Values = new string[] { } }; constraint = stringConstraint; } var remove = -1; for (var i = 0; i < stringConstraint.Values.Length; i++) { if (i != 0) { RectHelper.TakeVerticalSpace(ref rect); } var item = stringConstraint.Values[i]; var itemRect = RectHelper.TakeLine(ref rect); var removeRect = RectHelper.TakeTrailingIcon(ref itemRect); stringConstraint.Values[i] = EditorGUI.TextField(itemRect, item); if (GUI.Button(removeRect, _removeButton.Content, GUIStyle.none)) { remove = i; } } var addRect = RectHelper.TakeTrailingIcon(ref rect); if (GUI.Button(addRect, _addButton.Content, GUIStyle.none)) { ArrayUtility.Add(ref stringConstraint.Values, string.Empty); } if (remove >= 0) { ArrayUtility.RemoveAt(ref stringConstraint.Values, remove); } }
public override void Draw(Rect position, GUIContent label) { var stringFormatRect = RectHelper.TakeLine(ref position); var formattingRect = RectHelper.TakeLine(ref position); var formatRect = RectHelper.TakeLine(ref position); var valueFormatRect = RectHelper.TakeLine(ref position); var previewValueRect = RectHelper.TakeLine(ref position); var previewRect = RectHelper.TakeLine(ref position); _formatter.Format = EditorGUI.TextField(stringFormatRect, _stringFormatLabel.Content, _formatter.Format); _formatter.Formatting = (BindingFormatter.FormatType)EditorGUI.EnumPopup(formattingRect, _formattingLabel.Content, _formatter.Formatting); if (_formatter.Formatting != BindingFormatter.FormatType.None) { if (_formatter.Formatting == BindingFormatter.FormatType.Time) { _formatter.TimeFormatting = (BindingFormatter.TimeFormatType)EditorGUI.EnumPopup(formatRect, _timeFormattingLabel.Content, _formatter.TimeFormatting); _formatter.ValueFormat = _formatter.TimeFormatting == BindingFormatter.TimeFormatType.Custom ? EditorGUI.TextField(valueFormatRect, _valueFormatLabel.Content, _formatter.ValueFormat) : TimeFormats[(int)_formatter.TimeFormatting]; } else if (_formatter.Formatting == BindingFormatter.FormatType.Number) { _formatter.NumberFormatting = (BindingFormatter.NumberFormatType)EditorGUI.EnumPopup(formatRect, _numberFormattingLabel.Content, _formatter.NumberFormatting); _formatter.ValueFormat = _formatter.NumberFormatting == BindingFormatter.NumberFormatType.Custom ? EditorGUI.TextField(valueFormatRect, _valueFormatLabel.Content, _formatter.ValueFormat) : NumberFormats[(int)_formatter.NumberFormatting]; } if ((_formatter.Formatting == BindingFormatter.FormatType.Time && _formatter.TimeFormatting != BindingFormatter.TimeFormatType.Custom) || (_formatter.Formatting == BindingFormatter.FormatType.Number && _formatter.NumberFormatting != BindingFormatter.NumberFormatType.Custom)) { EditorGUI.LabelField(valueFormatRect, _valueFormatLabel.Content, new GUIContent(_formatter.ValueFormat)); } _preview = EditorGUI.FloatField(previewValueRect, _previewContent, _preview); try { var preview = _formatter.GetFormattedString(_preview); EditorGUI.LabelField(previewRect, " ", preview); } catch { EditorGUI.LabelField(previewRect, " ", "Invalid Format"); } } }
private static void DrawListConstraint(Rect rect, ref VariableConstraint constraint) { if (!(constraint is ListVariableConstraint listConstraint)) { listConstraint = new ListVariableConstraint { ItemType = VariableType.Empty, ItemConstraint = null }; constraint = listConstraint; } var typeRect = RectHelper.TakeLine(ref rect); listConstraint.ItemType = (VariableType)EditorGUI.EnumPopup(typeRect, listConstraint.ItemType); if (HasConstraint(listConstraint.ItemType, listConstraint.ItemConstraint, false)) { DrawConstraint(rect, listConstraint.ItemType, false, ref listConstraint.ItemConstraint, false); } }
private void DrawAccessory(Rect rect, IList list, int index) { var accessory = _building.Accessories[index]; var nameRect = RectHelper.TakeLine(ref rect); RectHelper.TakeWidth(ref rect, RectHelper.LeftMargin); var orderRect = RectHelper.TakeLine(ref rect); var positionRect = RectHelper.TakeLine(ref rect); var spriteRect = RectHelper.TakeLine(ref rect); var animationRect = RectHelper.TakeLine(ref rect); var animationLabelRect = RectHelper.TakeLabel(ref animationRect); var animationToggleRect = RectHelper.TakeLeadingIcon(ref animationRect); accessory.GameObject.name = EditorGUI.TextField(nameRect, accessory.GameObject.name); var position = EditorGUI.Vector2Field(positionRect, _accessoryPositionContent, accessory.Bounds.position); accessory.OrderOffset = accessory.Renderer.sortingOrder = EditorGUI.IntSlider(orderRect, _orderOffsetContent, accessory.Renderer.sortingOrder, 0, _MaxOrderOffset); accessory.Renderer.sprite = EditorGUI.ObjectField(spriteRect, _spriteContent, accessory.Renderer.sprite, typeof(Sprite), false) as Sprite; EditorGUI.LabelField(animationLabelRect, _animationsContent); var hasAnimations = accessory.Animation != null; var selectedHasAnimations = EditorGUI.Toggle(animationToggleRect, hasAnimations); if (selectedHasAnimations && !hasAnimations) { AddAnimations(accessory); } else if (!selectedHasAnimations && hasAnimations) { RemoveAnimations(accessory); } if (selectedHasAnimations) { accessory.Animation.Animation = EditorGUI.ObjectField(animationRect, accessory.Animation.Animation, typeof(AnimationClip), false) as AnimationClip; } UpdatePartTransform(accessory, position); }
private static TileTransformInfo Draw(Rect position, GUIContent label, Sprite sprite, int rotation, bool horizontal, bool vertical) { var rect = EditorGUI.PrefixLabel(position, label); var spriteRect = RectHelper.TakeWidth(ref rect, Height); RectHelper.TakeHorizontalSpace(ref rect); var rotationRect = RectHelper.TakeLine(ref rect); var horizontalRect = RectHelper.TakeLine(ref rect); var verticalRect = RectHelper.TakeLine(ref rect); var info = new TileTransformInfo { Sprite = EditorGUI.ObjectField(spriteRect, sprite, typeof(Sprite), false) as Sprite, Rotation = EditorGUI.IntPopup(rotationRect, _rotationContent.Content, rotation, _rotationsContent, TileTransformInfo.Rotations), FlipHorizontal = EditorGUI.Toggle(horizontalRect, _flipHorizontalContent.Content, horizontal), FlipVertical = EditorGUI.Toggle(verticalRect, _flipVerticalContent.Content, vertical) }; return(info); }
public override void OnGUI(Rect rect) { rect = RectHelper.Inset(rect, 5.0f); var nameRect = RectHelper.TakeLine(ref rect); var buttonRect = RectHelper.TakeTrailingHeight(ref rect, EditorGUIUtility.singleLineHeight); RectHelper.TakeTrailingHeight(ref rect, RectHelper.VerticalSpace); Name = EditorGUI.TextField(nameRect, Name); var valid = !string.IsNullOrEmpty(Name) && !Store.Map.ContainsKey(Name); using (new EditorGUI.DisabledScope(!valid)) { if (GUI.Button(buttonRect, "Add")) { Store.AddVariable(Name, VariableValue.Empty); editorWindow.Close(); } } }
public override void Draw(Rect position, SerializedProperty property, GUIContent label) { var labelRect = RectHelper.TakeLine(ref position); var typeRect = RectHelper.TakeLine(ref position); var repeatRect = RectHelper.TakeLine(ref position); var absoluteRect = RectHelper.TakeLine(ref position); var pathfindingRect = RectHelper.TakeLine(ref position); EditorGUI.LabelField(labelRect, label, EditorStyles.boldLabel); EditorGUI.PropertyField(typeRect, _type); EditorGUI.PropertyField(repeatRect, _repeatCount); EditorGUI.PropertyField(absoluteRect, _absolute); EditorGUI.PropertyField(pathfindingRect, _usePathfinding); if (_usePathfinding.boolValue) { EditorGUI.PropertyField(RectHelper.TakeLine(ref position), _findAlternate); } _nodesControl.Draw(position, _nodesContent.Content); }
private void DrawTrainer(Trainer trainer) { if (trainer && trainer.Roster != null && trainer.Roster.Creatures != null) { EditorGUILayout.LabelField("Roster"); var rosterRect = EditorGUILayout.GetControlRect(false, RectHelper.LineHeight * trainer.Roster.Creatures.Count); RectHelper.TakeIndent(ref rosterRect); foreach (var creature in trainer.Roster.Creatures) { var rect = RectHelper.TakeLine(ref rosterRect); var icon = RectHelper.TakeLeadingIcon(ref rect); if (GUI.Button(icon, _editCreatureButton.Content, GUIStyle.none)) { Selection.activeObject = creature; } GUI.Label(rect, creature.Name); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var target = PropertyHelper.GetObject <VariableValueSource>(property); var typeRect = RectHelper.TakeLine(ref position); RectHelper.TakeLabel(ref position); using (new EditObjectScope(property.serializedObject)) { using (new UndoScope(property.serializedObject.targetObject, false)) { target.Type = (VariableSourceType)EnumDisplayDrawer.Draw(typeRect, label, (int)target.Type, typeof(VariableSourceType), EnumDisplayType.Buttons, false, 50); if (target.Type == VariableSourceType.Value) { if (!target.Definition.IsTypeLocked) { var variableRect = RectHelper.TakeWidth(ref position, position.width * 0.5f); RectHelper.TakeHorizontalSpace(ref position); var definitionType = (VariableType)EditorGUI.EnumPopup(variableRect, target.Definition.Type); if (definitionType != target.Definition.Type) { target.Definition = ValueDefinition.Create(definitionType, target.Definition.Constraint, target.Definition.Tag, target.Definition.Initializer, false, false); target.Value = target.Definition.Generate(null); } } target.Value = VariableValueDrawer.Draw(position, GUIContent.none, target.Value, target.Definition, true); } else if (target.Type == VariableSourceType.Reference) { VariableReferenceControl.Draw(position, target.Reference, GUIContent.none); } } } }
private static VariableValue DrawStore(Rect rect, VariableValue value, StoreVariableConstraint constraint, bool drawStores) { if (drawStores) { var names = value.Store.GetVariableNames(); var remove = string.Empty; var first = true; var empty = ValueDefinition.Create(VariableType.Empty); foreach (var name in names) { if (!first) { RectHelper.TakeVerticalSpace(ref rect); } var index = constraint?.Schema != null?constraint.Schema.GetIndex(name) : -1; var definition = index >= 0 ? constraint.Schema[index].Definition : empty; var item = value.Store.GetVariable(name); var height = GetHeight(item, definition, true); var itemRect = RectHelper.TakeHeight(ref rect, height); var labelRect = RectHelper.TakeWidth(ref itemRect, _storeLabelWidth); labelRect = RectHelper.TakeLine(ref labelRect); EditorGUI.LabelField(labelRect, name); if (constraint?.Schema == null && value.Store is VariableStore) { var removeRect = RectHelper.TakeTrailingIcon(ref itemRect); if (GUI.Button(removeRect, _removeStoreButton.Content, GUIStyle.none)) { remove = name; } } item = Draw(itemRect, GUIContent.none, item, definition, true); value.Store.SetVariable(name, item); first = false; } if (constraint?.Schema == null && value.Store is VariableStore store) { var addRect = RectHelper.TakeTrailingIcon(ref rect); if (GUI.Button(addRect, _addStoreButton.Content, GUIStyle.none)) { AddToStorePopup.Store = store; AddToStorePopup.Name = ""; PopupWindow.Show(addRect, AddToStorePopup.Instance); } if (!string.IsNullOrEmpty(remove)) { (value.Store as VariableStore).RemoveVariable(remove); } } } else { EditorGUI.LabelField(rect, value.Store.ToString()); } return(value); }