Ejemplo n.º 1
0
    public override void OnGUI(SerializedPropertyX property, GUIContent label)
    {
        shown = EditorGUILayout.Foldout(shown, label);
        if (!shown)
        {
            return;
        }

        EditorGUI.indentLevel++;
        EditorGUILayoutX.PropertyField(property["abilityCreator"]);
        if (property["abilityCreator"].Changed)
        {
            //todo assert type matches
        }
        if (property["abilityCreator"].Value == null)
        {
            property["contextCreator"].Value = null;
            return;
        }

        Type type;
        PlayerContextCreator current = property["contextCreator"].GetValue <PlayerContextCreator>();
        Type currentType             = null;

        if (current != null)
        {
            currentType = current.GetType();
        }
        SerializedPropertyX creatorProperty = property["contextCreator"];

        if (popup.DrawPopup("Context Constructor", currentType, out type))
        {
            if (type != null)
            {
                creatorProperty.Value = Activator.CreateInstance(type);
            }
            else
            {
                creatorProperty.Value = null;
            }
        }

        if (creatorProperty.Value != null)
        {
            EditorGUI.indentLevel++;
            EditorGUILayoutX.DrawProperties(creatorProperty);
            EditorGUI.indentLevel--;
        }

        EditorGUI.indentLevel--;
    }
Ejemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        PlayerSkillBook skillBook = target as PlayerSkillBook;

        if (root == null)
        {
            if (!string.IsNullOrEmpty(skillBook.source))
            {
                new AssetDeserializer(skillBook.source, false).DeserializeInto("__default__", skillBook);
            }
            root = new SerializedObjectX(target);
        }
        EditorGUILayoutX.DrawProperties(root);
        bool didChange = root.Root.ApplyModifiedProperties();

        if (didChange)
        {
            AssetSerializer serializer = new AssetSerializer();
            serializer.AddItem(target);
            serializedObject.FindProperty("source").stringValue = serializer.WriteToString();
            serializedObject.ApplyModifiedProperties();
        }
    }
    protected override void RenderBody(SerializedPropertyX property, RenderData renderData, int index)
    {
        DecisionRenderData data = renderData as DecisionRenderData;

        EditorGUI.indentLevel++;

        EditorGUILayoutX.PropertyField(property["name"]);
        EditorGUILayoutX.PropertyField(property["description"]);
        EditorGUILayoutX.PropertyField(property["weight"]);

        SerializedPropertyX action    = property["action"];
        SerializedPropertyX collector = property["contextCollector"];

        CharacterAction charAction    = action.GetValue <CharacterAction>();
        string          contextString = "<" + charAction.ContextType.Name + ">";
        string          actionString  = "Action (" + action.Type.Name + contextString + ")";

        if (action.ChildCount > 0)
        {
            data.isActionShown = EditorGUILayout.Foldout(data.isActionShown, actionString);
        }
        else
        {
            GUIContent content = new GUIContent(actionString);
            content.image = EditorGUIUtility.FindTexture("cs Script Icon");
            EditorGUILayout.LabelField(content);
            data.isActionShown = false;
        }
        if (data.isActionShown)
        {
            EditorGUI.indentLevel++;
            EditorGUILayoutX.DrawProperties(action);
            EditorGUI.indentLevel--;
        }

        data.GetContextCollectorData(charAction, collector.GetValue <ContextCollector>());
        string[] options      = data.contextCollectorNames;
        int      currentIndex = data.contextCollectorIndex;
        int      idx          = EditorGUILayout.Popup("Collector", currentIndex, options, GUILayout.Width(EditorGUIUtility.labelWidth + 300f));

        if (idx != data.contextCollectorIndex)
        {
            if (idx == 0)
            {
                collector.Value = null; //todo return an empty collector type?
            }
            else
            {
                Type newCollectorType = data.contextCollectorTypes[idx];
                collector.Value = Activator.CreateInstance(newCollectorType) as ContextCollector;
            }
        }
        if (collector.Value != null)
        {
            EditorGUI.indentLevel++;
            EditorGUILayoutX.DrawProperties(collector);
            EditorGUI.indentLevel--;
        }

        data.isEvaluatorShown = EditorGUILayout.Foldout(data.isEvaluatorShown, "Evaluator");
        if (data.isEvaluatorShown)
        {
            EditorGUI.indentLevel++;
            SerializedPropertyX evaluator      = property["evaluator"];
            SerializedPropertyX considerations = evaluator["considerations"];
            SerializedPropertyX requirements   = evaluator["requirements"];
            if (considerations.ChildCount == 0 && requirements.ChildCount == 0)
            {
                data.GetEvaluatorTemplateData(charAction.ContextType);
                int newIdx = EditorGUILayout.Popup("Set From Template", 0, data.evaluatorOptions, GUILayout.Width(EditorGUIUtility.labelWidth + 300f));
                if (newIdx != 0)
                {
                    evaluator.Value = data.evaluatorCreators[newIdx].Create();
                    data.requirementSection.SetTargetProperty(evaluator);
                    data.considerationSection.SetTargetProperty(evaluator);
                }
            }
            data.requirementSection.Render();
            data.considerationSection.Render();
            EditorGUI.indentLevel--;
        }
        EditorGUI.indentLevel--;
    }