Ejemplo n.º 1
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);
    }