예제 #1
0
        public static void SetTypeIndex(InstructionVariable variable, int index)
        {
            var wasReference = variable.IsReference;
            var isReference  = index >= _locationOffset;

            variable.IsReference = isReference;

            if (wasReference && !isReference)
            {
                VariableReferenceDrawer.ResetLocation(variable.Reference);
            }
            else if (!wasReference && isReference)
            {
                VariableValueDrawer.SetTypeIndex(variable.Value, 0);
            }

            if (isReference)
            {
                VariableReferenceDrawer.SetLocationIndex(variable.Reference, index - _locationOffset);
            }
            else
            {
                VariableValueDrawer.SetTypeIndex(variable.Value, index);
            }
        }
예제 #2
0
        public void SetTypeIndex(SerializedProperty property, int index)
        {
            var isReferenceProperty = property.FindPropertyRelative("IsReference");
            var referenceProperty   = property.FindPropertyRelative("Reference");
            var valueProperty       = property.FindPropertyRelative("Value");

            var wasReference = isReferenceProperty.boolValue;
            var isReference  = index >= _locationOffset;

            isReferenceProperty.boolValue = isReference;

            if (wasReference && !isReference)
            {
                VariableReferenceDrawer.ResetLocation(referenceProperty);
            }
            else if (!wasReference && isReference)
            {
                VariableValueDrawer.SetTypeIndex(valueProperty, 0);
            }

            if (isReference)
            {
                VariableReferenceDrawer.SetLocationIndex(referenceProperty, index - _locationOffset);
            }
            else
            {
                VariableValueDrawer.SetTypeIndex(valueProperty, index);
            }
        }
예제 #3
0
        public static void Draw(Rect position, InstructionVariable variable, GUIContent label)
        {
            var typeNames = GetTypeNames();

            var typeWidth = position.width * 0.5f;
            var typeRect  = new Rect(position.x, position.y, typeWidth, position.height);
            var valueRect = new Rect(typeRect.xMax + 5, position.y, position.width - typeWidth - 5, position.height);

            var index = GetTypeIndex(variable);

            using (var changes = new EditorGUI.ChangeCheckScope())
            {
                index = EditorGUI.Popup(typeRect, index, typeNames);

                if (changes.changed)
                {
                    SetTypeIndex(variable, index);
                }
            }

            if (variable.IsReference)
            {
                VariableReferenceDrawer.DrawName(valueRect, variable.Reference);
            }
            else
            {
                VariableValueDrawer.DrawValue(valueRect, variable.Value, null, null);
            }
        }
예제 #4
0
 public static int GetTypeIndex(InstructionVariable variable)
 {
     if (variable.IsReference)
     {
         var index = VariableReferenceDrawer.GetLocationIndex(variable.Reference);
         return(index + _locationOffset);
     }
     else
     {
         return(VariableValueDrawer.GetTypeIndex(variable.Value));
     }
 }
예제 #5
0
        public int GetTypeIndex(SerializedProperty property)
        {
            var isReferenceProperty = property.FindPropertyRelative("IsReference");

            if (isReferenceProperty.boolValue)
            {
                var referenceProperty = property.FindPropertyRelative("Reference");
                var index             = VariableReferenceDrawer.GetLocationIndex(referenceProperty);

                return(index + _locationOffset);
            }
            else
            {
                var valueProperty = property.FindPropertyRelative("Value");
                return(VariableValueDrawer.GetTypeIndex(valueProperty));
            }
        }
예제 #6
0
        private void DrawMove(Rect rect, int index)
        {
            var creature = target as Creature;
            var move     = creature.Moves[index];

            var labelRect  = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
            var traitsRect = new Rect(rect.x + 10, labelRect.yMax + 5, rect.width - 10, EditorGUIUtility.singleLineHeight);

            EditorGUI.LabelField(labelRect, move.Ability.name);

            for (var i = 0; i < move.Traits.Count; i++)
            {
                var trait     = move.Traits.GetVariable(i);
                var traitRect = EditorGUI.PrefixLabel(traitsRect, new GUIContent(trait.Name));
                VariableValueDrawer.DrawValue(traitRect, trait, null, null);
                traitsRect.y += EditorGUIUtility.singleLineHeight + 5;
            }
        }
예제 #7
0
            public override void OnGUI(Rect rect)
            {
                var typeNames = VariableValueDrawer.GetTypeNames();

                EditorGUILayout.LabelField(_label);

                var enter = GuiFields.TextEnterField("NewName", GUIContent.none, ref _newName);

                _newType = EditorGUILayout.Popup(_newType, typeNames);
                var create = GUILayout.Button(EditorHelper.CreateContent);

                if ((enter || create) && !string.IsNullOrEmpty(_newName))
                {
                    if (CreateVariable(_newName, _newType))
                    {
                        editorWindow.Close();
                        _newName = "Name";
                    }
                }
            }
예제 #8
0
        public static string[] GetTypeNames()
        {
            if (_typeNames == null)
            {
                var valueTypeNames         = VariableValueDrawer.GetTypeNames();
                var referenceLocationNames = VariableReferenceDrawer.GetLocationNames();

                _typeNames      = new string[valueTypeNames.Length + referenceLocationNames.Length];
                _locationOffset = valueTypeNames.Length;

                for (var i = 0; i < valueTypeNames.Length; i++)
                {
                    _typeNames[i] = "Value/" + valueTypeNames[i];
                }

                for (var i = 0; i < referenceLocationNames.Length; i++)
                {
                    _typeNames[_locationOffset + i] = "Reference/" + referenceLocationNames[i];
                }
            }

            return(_typeNames);
        }
예제 #9
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var typeNames           = GetTypeNames();
            var nameProperty        = property.FindPropertyRelative("Name");
            var isReferenceProperty = property.FindPropertyRelative("IsReference");

            var nameWidth = position.width * 0.3f;
            var typeWidth = position.width * 0.3f;
            var nameRect  = new Rect(position.x, position.y, nameWidth, position.height);
            var typeRect  = new Rect(nameRect.xMax + 5, position.y, typeWidth, position.height);
            var valueRect = new Rect(typeRect.xMax + 5, position.y, position.width - nameWidth - typeWidth - 10, position.height);

            var index = GetTypeIndex(property);

            EditorGUI.PropertyField(nameRect, nameProperty, GUIContent.none);

            using (var changes = new EditorGUI.ChangeCheckScope())
            {
                index = EditorGUI.Popup(typeRect, index, typeNames);

                if (changes.changed)
                {
                    SetTypeIndex(property, index);
                }
            }

            if (isReferenceProperty.boolValue)
            {
                var referenceProperty = property.FindPropertyRelative("Reference");
                VariableReferenceDrawer.DrawName(valueRect, referenceProperty);
            }
            else
            {
                var valueProperty = property.FindPropertyRelative("Value");
                VariableValueDrawer.DrawValue(valueRect, valueProperty);
            }
        }
예제 #10
0
        private void DrawSkill(Rect rect, int index)
        {
            var skill  = _species.Skills[index];
            var inputs = _inputLists[index];

            var labelRect       = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
            var conditionRect   = new Rect(rect.x + 10, labelRect.yMax + 5, rect.width - 10, EditorGUIUtility.singleLineHeight);
            var limitRect       = new Rect(rect.x + 10, conditionRect.yMax + 5, rect.width * 0.75f, EditorGUIUtility.singleLineHeight);
            var limitAmountRect = new Rect(limitRect.xMax + 5, limitRect.y, rect.width - limitRect.width - 15, limitRect.height);
            var instructionRect = new Rect(rect.x + 10, limitRect.yMax + 5, rect.width - 10, EditorGUIUtility.singleLineHeight);
            var inputsRect      = new Rect(rect.x + 10, instructionRect.yMax + 5, rect.width - 10, EditorGUIUtility.singleLineHeight);

            EditorGUI.LabelField(labelRect, skill.Name, EditorStyles.boldLabel);

            using (var changes = new EditorGUI.ChangeCheckScope())
            {
                conditionRect = EditorGUI.PrefixLabel(conditionRect, new GUIContent("Condition"));
                var condition = EditorGUI.DelayedTextField(conditionRect, skill.Condition.Statement);

                if (changes.changed)
                {
                    skill.Condition.Statement = condition;
                    skill.UpdateTriggers();
                }
            }

            var limitIndex = EditorGUI.Popup(limitRect, "Learn Limit", skill.LearnLimit == 0 ? 2 : (skill.LearnLimit == 1 ? 0 : 1), _limits);

            if (limitIndex == 0)
            {
                skill.LearnLimit = 1;
            }
            else if (limitIndex == 1)
            {
                if (skill.LearnLimit == 0 || skill.LearnLimit == 1)
                {
                    skill.LearnLimit = 10;
                }

                skill.LearnLimit = EditorGUI.IntField(limitAmountRect, skill.LearnLimit);
            }
            else if (limitIndex == 2)
            {
                skill.LearnLimit = 0;
            }

            using (var changes = new EditorGUI.ChangeCheckScope())
            {
                instructionRect = EditorGUI.PrefixLabel(instructionRect, new GUIContent("Instruction"));
                skill.Instruction.Instruction = InstructionDrawer.Draw(instructionRect, null, skill.Instruction.Instruction, GUIContent.none);

                if (changes.changed && skill.Instruction.Instruction != null)
                {
                    RefreshInputs(inputs, skill.Instruction);
                }
            }

            for (var i = 0; i < skill.Instruction.Inputs.Count; i++)
            {
                var input     = skill.Instruction.Inputs[i];
                var inputRect = EditorGUI.PrefixLabel(inputsRect, new GUIContent(input.Name));
                VariableValueDrawer.DrawValue(inputRect, input, inputs.Inputs[i].Type, inputs.Inputs[i].ParentType);
                inputsRect.y += EditorGUIUtility.singleLineHeight + 5;
            }
        }