示例#1
0
        private void DrawVariable(Rect rect, IList list, int index)
        {
            var name       = _pool.Names[index];
            var variable   = _pool.Variables[index];
            var definition = _pool.Definitions[index];

            var labelRect = RectHelper.TakeWidth(ref rect, _labelWidth);

            labelRect = RectHelper.TakeHeight(ref labelRect, EditorGUIUtility.singleLineHeight);
            var editRect = RectHelper.TakeLeadingIcon(ref labelRect);

            if (GUI.Button(editRect, _editButton.Content, GUIStyle.none))
            {
                _editPopup.Setup(this, index);
                PopupWindow.Show(editRect, _editPopup);
            }

            EditorGUI.LabelField(labelRect, name);

            using (var changes = new EditorGUI.ChangeCheckScope())
            {
                var value = VariableValueDrawer.Draw(rect, GUIContent.none, variable, definition, true);

                if (changes.changed)
                {
                    _pool.SetVariable(index, value);
                }
            }
        }
示例#2
0
        private void DrawVariable(Rect rect, IList list, int index)
        {
            var name       = _variables.GetVariableName(index);
            var value      = _variables.GetVariableValue(index);
            var definition = _variables.Schema != null && index < _variables.Schema.Count ? _variables.Schema[index] : VariableDefinition.Create("", VariableType.Empty);

            using (var changes = new EditorGUI.ChangeCheckScope())
            {
                if (_variables.Owner != null)
                {
                    var variableRect = new Rect(rect.x, rect.y, rect.width - EditorGUIUtility.singleLineHeight, rect.height);
                    var buttonRect   = new Rect(variableRect.xMax, rect.y, EditorGUIUtility.singleLineHeight, rect.height);

                    value = VariableValueDrawer.Draw(variableRect, new GUIContent(name), value, definition);

                    if (_variables.Schema != null)
                    {
                        if (GUI.Button(buttonRect, _refreshButton.Content, GUIStyle.none))
                        {
                            value = _variables.Schema[index].Generate(_variables.Owner).Value;
                        }
                    }
                }
                else
                {
                    value = VariableValueDrawer.Draw(rect, new GUIContent(name), value, definition);
                }

                if (changes.changed)
                {
                    _variables.SetVariableValue(index, value);
                }
            }
        }
示例#3
0
        private static void DrawDefaultValue(Rect rect, ref ValueDefinition definition)
        {
            var value = definition.Initializer.Execute(null, null); // context isn't necessary since the object that would be the context is currently drawing

            if (value.IsEmpty)                                      // If the initializer hasn't been set, use the default value.
            {
                value = VariableHandler.CreateDefault(definition.Type, definition.Constraint);
            }

            DrawIndentedLabel(ref rect, _defaultLabel);

            using (var changes = new EditorGUI.ChangeCheckScope())
            {
                value = VariableValueDrawer.Draw(rect, GUIContent.none, value, definition, true);

                if (changes.changed)
                {
                    switch (definition.Type)
                    {
                    case VariableType.Bool: definition.Initializer.SetStatement(value.Bool ? "true" : "false"); break;

                    case VariableType.Float: definition.Initializer.SetStatement(value.Float.ToString()); break;

                    case VariableType.Int: definition.Initializer.SetStatement(value.Int.ToString()); break;

                    case VariableType.Int2: definition.Initializer.SetStatement(string.Format("Vector2Int({0}, {1})", value.Int2.x, value.Int2.y)); break;

                    case VariableType.Int3: definition.Initializer.SetStatement(string.Format("Vector3Int({0}, {1}, {2})", value.Int3.x, value.Int3.y, value.Int3.z)); break;

                    case VariableType.IntRect: definition.Initializer.SetStatement(string.Format("RectInt({0}, {1}, {2}, {3})", value.IntRect.x, value.IntRect.y, value.IntRect.width, value.IntRect.height)); break;

                    case VariableType.IntBounds: definition.Initializer.SetStatement(string.Format("BoundsInt({0}, {1}, {2}, {3}, {4}, {5})", value.IntBounds.x, value.IntBounds.y, value.IntBounds.z, value.IntBounds.size.x, value.IntBounds.size.y, value.IntBounds.size.z)); break;

                    case VariableType.Vector2: definition.Initializer.SetStatement(string.Format("Vector2({0}, {1})", value.Vector2.x, value.Vector2.y)); break;

                    case VariableType.Vector3: definition.Initializer.SetStatement(string.Format("Vector3({0}, {1}, {2})", value.Vector3.x, value.Vector3.y, value.Vector3.z)); break;

                    case VariableType.Vector4: definition.Initializer.SetStatement(string.Format("Vector4({0}, {1}, {2}, {3})", value.Vector4.x, value.Vector4.y, value.Vector4.z, value.Vector4.w)); break;

                    case VariableType.Quaternion: var euler = value.Quaternion.eulerAngles; definition.Initializer.SetStatement(string.Format("Quaternion({0}, {1}, {2})", euler.x, euler.y, euler.z)); break;

                    case VariableType.Rect: definition.Initializer.SetStatement(string.Format("Rect({0}, {1}, {2}, {3})", value.Rect.x, value.Rect.y, value.Rect.width, value.Rect.height)); break;

                    case VariableType.Bounds: definition.Initializer.SetStatement(string.Format("Bounds({0}, {1})", value.Bounds.center, value.Bounds.extents)); break;

                    case VariableType.Color: definition.Initializer.SetStatement(string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", Mathf.RoundToInt(value.Color.r * 255), Mathf.RoundToInt(value.Color.g * 255), Mathf.RoundToInt(value.Color.b * 255), Mathf.RoundToInt(value.Color.a * 255))); break;

                    case VariableType.String: definition.Initializer.SetStatement("\"" + value.String + "\""); 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;
            }
        }
示例#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);
                    }
                }
            }
        }
示例#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;
            }
        }
        protected override void Draw(Rect rect, int index)
        {
            var name       = _proxy.GetName(index);
            var value      = Store.GetVariable(name);
            var definition = ValueDefinition.Create(VariableType.Empty);

            if (value.IsEmpty)
            {
                EditorGUI.LabelField(rect, name, EmptyText);
            }
            else
            {
                if (value.HasStore)
                {
                    if (DrawStoreView(ref rect))
                    {
                        Selected     = value.Store;
                        SelectedName = name;
                    }
                }

                using (var changes = new EditorGUI.ChangeCheckScope())
                {
                    var labelRect = RectHelper.TakeWidth(ref rect, _labelWidth);
                    labelRect = RectHelper.TakeHeight(ref labelRect, EditorGUIUtility.singleLineHeight);

                    EditorGUI.LabelField(labelRect, name);
                    value = VariableValueDrawer.Draw(rect, GUIContent.none, value, definition, false);

                    if (changes.changed)
                    {
                        Store.SetVariable(name, value);
                    }
                }
            }
        }