Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
        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);
        }
        private void DrawOutput(Rect rect, IList list, int index)
        {
            var labelWidth = rect.width * 0.25f;
            var typeWidth  = rect.width * 0.25f;

            var output    = _caller.Outputs[index];
            var labelRect = RectHelper.TakeWidth(ref rect, labelWidth);
            var typeRect  = RectHelper.TakeWidth(ref rect, typeWidth);

            RectHelper.TakeHorizontalSpace(ref rect);

            EditorGUI.LabelField(labelRect, output.Name);
            output.Type = (InstructionOutputType)EditorGUI.EnumPopup(typeRect, output.Type);

            switch (output.Type)
            {
            case InstructionOutputType.Ignore: break;

            case InstructionOutputType.Reference: VariableReferenceControl.Draw(rect, output.Reference, GUIContent.none); break;
            }
        }
        private void DrawInput(Rect rect, IList list, int index)
        {
            var labelWidth = rect.width * 0.25f;
            var typeWidth  = rect.width * 0.25f;

            var input      = _caller.Inputs[index];
            var definition = _caller.GetInputDefinition(input);
            var labelRect  = RectHelper.TakeWidth(ref rect, labelWidth);
            var typeRect   = RectHelper.TakeWidth(ref rect, typeWidth);

            RectHelper.TakeHorizontalSpace(ref rect);

            EditorGUI.LabelField(labelRect, definition.Name);

            input.Type = (InstructionInputType)EditorGUI.EnumPopup(typeRect, input.Type);

            switch (input.Type)
            {
            case InstructionInputType.Reference: VariableReferenceControl.Draw(rect, input.Reference, GUIContent.none); break;

            case InstructionInputType.Value: input.Value = VariableValueDrawer.Draw(rect, GUIContent.none, input.Value, definition.Definition, true); break;
            }
        }
Esempio n. 5
0
        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);
                    }
                }
            }
        }
Esempio n. 6
0
        private void DrawInput(Rect rect, IList list, int index)
        {
            var labelWidth = rect.width * 0.25f;
            var typeWidth  = rect.width * 0.25f;

            var input     = _caller.Inputs[index];
            var labelRect = RectHelper.TakeWidth(ref rect, labelWidth);
            var typeRect  = RectHelper.TakeWidth(ref rect, typeWidth);

            RectHelper.TakeHorizontalSpace(ref rect);

            EditorGUI.LabelField(labelRect, input.Definition.Name);

            if (input.Definition.Type == VariableType.Empty)
            {
                var typeIndex = input.Type == InstructionInputType.Reference ? 6 : GetIndexForType(input.Value.Type);
                var newIndex  = EditorGUI.Popup(typeRect, typeIndex, _inputTypeOptions);

                if (newIndex != typeIndex)
                {
                    input.Type  = newIndex == 6 ? InstructionInputType.Reference : InstructionInputType.Value;
                    input.Value = VariableValue.Create(GetTypeFromIndex(newIndex));
                }
            }
            else
            {
                input.Type = (InstructionInputType)EditorGUI.EnumPopup(typeRect, input.Type);
            }

            switch (input.Type)
            {
            case InstructionInputType.Reference: VariableReferenceControl.Draw(rect, input.Reference, GUIContent.none); break;

            case InstructionInputType.Value: input.Value = VariableValueDrawer.Draw(rect, GUIContent.none, input.Value, input.Definition); break;
            }
        }