private float GetOutputHeight(int index)
        {
            var output     = _caller.Outputs[index];
            var definition = _caller.GetOutputDefinition(output);

            switch (output.Type)
            {
            case InstructionOutputType.Reference: return(VariableReferenceControl.GetHeight());

            default: return(EditorGUIUtility.singleLineHeight);
            }
        }
        private float GetInputHeight(int index)
        {
            var input      = _caller.Inputs[index];
            var definition = _caller.GetInputDefinition(input);

            switch (input.Type)
            {
            case InstructionInputType.Reference: return(VariableReferenceControl.GetHeight());

            case InstructionInputType.Value: return(VariableValueDrawer.GetHeight(input.Value, definition.Definition, true));

            default: return(EditorGUIUtility.singleLineHeight);
            }
        }
        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;
            }
        }
示例#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;
            }
        }