Esempio n. 1
0
        private static void DrawError(Rect rect, Expression expression, GUIContent label, bool fullWidth)
        {
            if (expression.HasError)
            {
                RectHelper.TakeVerticalSpace(ref rect);

                if (fullWidth)
                {
                    RectHelper.TakeWidth(ref rect, RectHelper.Indent);
                }
                else if (!string.IsNullOrEmpty(label.text))
                {
                    RectHelper.TakeLabel(ref rect);
                }

                EditorGUI.HelpBox(rect, expression.CompilationResult.Message, MessageType.Error);
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
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);
                    }
                }
            }
        }