public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUILayout.PropertyField(debug);

        if (!serializedObject.isEditingMultipleObjects)
        {
            GUIStyle bold = new GUIStyle(EditorStyles.boldLabel);
            EditorGUILayout.LabelField(
                "Attributes (" + attributes.arraySize + ")", bold
                );

            EditorGUI.indentLevel++;
            EditorGUIUtility.labelWidth = 64;

            EntityComponent component = serializedObject.targetObject
                                        as EntityComponent;

            for (int i = 0; i < attributes.arraySize; ++i)
            {
                SerializedProperty label
                    = attributes.GetArrayElementAtIndex(i).FindPropertyRelative("label");
                SerializedProperty state
                    = attributes.GetArrayElementAtIndex(i).FindPropertyRelative("state");

                EditorGUILayout.BeginHorizontal();

                EditorGUILayout.LabelField(label.stringValue);
                component.instances[i].State
                    = EditorGUILayout.Slider(state.floatValue, 0, 1);

                EditorGUILayout.EndHorizontal();

                NormalizedAttribute prototype = component.instances[i].Prototype
                                                as NormalizedAttribute;

                if (prototype.transform != Transformations.Linear())
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUI.BeginDisabledGroup(true);

                    EditorGUILayout.LabelField("  (Transformed)");
                    NormalizedAttribute.TransformedInstance instance
                        = component.instances[i]
                          as NormalizedAttribute.TransformedInstance;
                    EditorGUILayout.Slider(instance.TransformedState, 0, 1);

                    EditorGUI.EndDisabledGroup();
                    EditorGUILayout.EndHorizontal();
                }
            }
        }

        serializedObject.ApplyModifiedProperties();
    }
Exemple #2
0
    void Awake()
    {
        // Initialize environment
        Universe.root = new Universe();
        SimpleRepo repo = new SimpleRepo();

        // Attributes
        trollFactor = new NormalizedAttribute(
            () => Random.Range(0, 1f)
            );
        anger = new NormalizedAttribute(() => 0);

        repo.RegisterAttribute(trollFactor);
        repo.RegisterAttribute(anger);

        trollFactor.SetDebugLabel("Troll Factor");
        anger.SetDebugLabel("Anger");

        // Users
        User[] users =
        {
            new User("Julian"),
            new User("Andy"),
            new User("Mike")
        };

        foreach (User user in users)
        {
            user.Repository = repo;
        }

        // Effects
        annoy = new Effect();
        annoy.Modifiers.Add(new FloatModifier(anger, .2f));
        repo.effects.Add(annoy);
        annoy.SetDebugLabel("Annoy");

        incite = new Effect();
        incite.Modifiers.Add(new FloatModifier(anger, .4f));
        repo.effects.Add(incite);
        incite.SetDebugLabel("Anger");

        calm = new Effect();
        calm.Modifiers.Add(new FloatModifier(anger, -.1f));
        repo.effects.Add(calm);
        calm.SetDebugLabel("Calm Down");

        // Interactions
        start = new Interaction(0);
        flame = new Interaction(1);
        quit  = new Interaction(0);

        repo.RegisterInteraction(start);
        repo.RegisterInteraction(flame);
        repo.RegisterInteraction(quit);

        start.SetDebugLabel("Start Thread");
        flame.SetDebugLabel("Flame");
        quit.SetDebugLabel("Ragequit");

        // Attribution
        foreach (User user in users)
        {
            user.Subscribe();
            Universe.root.entities.Add(user);
        }

        // Unity hooks
        ComponentManager hook = GetComponent <ComponentManager>();

        hook.Hook("Universe.root", Universe.root);
        hook.Hook <SimpleRepoComponent>("simple-repo", repo);
    }