private void AddDefaultPlayerControlsToPlayerBrain()
    {
        string controlsUri = BehaviorSystem.IdToBuiltinBehaviorUri("Player Controls");

        Behaviors.PropertyAssignment speedProp = new Behaviors.PropertyAssignment {
            propertyName = "Speed", valueJson = "{\"value\":5}"
        };
        if (!behaviors.HasBrain("Player"))
        {
            behaviors.PutBrain("Player", new Behaviors.Brain());
        }
        var playerBrain = behaviors.GetBrain("Player");

        playerBrain.AddUse(new Behaviors.BehaviorUse
        {
            id                  = behaviors.GenerateUniqueId(),
            behaviorUri         = controlsUri,
            propertyAssignments = new Behaviors.PropertyAssignment[] { speedProp }
        });

        if (!behaviors.HasBrain("e04de2718a594fc0afd2cb55bd4fa8dc"))
        {
            behaviors.PutBrain("e04de2718a594fc0afd2cb55bd4fa8dc", new Behaviors.Brain());
        }
        var playerInstBrain = behaviors.GetBrain("e04de2718a594fc0afd2cb55bd4fa8dc");

        playerInstBrain.AddUse(new Behaviors.BehaviorUse
        {
            id                  = behaviors.GenerateUniqueId(),
            behaviorUri         = controlsUri,
            propertyAssignments = new Behaviors.PropertyAssignment[] { speedProp }
        });
    }
Exemple #2
0
    public void PropertyValueJson()
    {
        PropertyAssignment before = new PropertyAssignment();

        before.propertyName = "health";
        before.SetValue <int>(42);

        string             json  = JsonUtility.ToJson(before);
        PropertyAssignment after = JsonUtility.FromJson <PropertyAssignment>(json);

        Assert.AreEqual(42, after.GetValue <int>());
        Assert.AreEqual("health", after.propertyName);
    }
Exemple #3
0
    public void BuildPropertyBlockJson()
    {
        PropertyAssignment health = new PropertyAssignment();

        health.propertyName = "health";
        health.SetValue <int>(42);

        PropertyAssignment friend = new PropertyAssignment();

        friend.propertyName = "friend";
        friend.SetValue <string>("alice");

        PropertyAssignment[] all = new PropertyAssignment[] { health, friend };

        string json = PropertyAssignment.BuildPropertyBlockJson(all);

        Debug.Log(json);

        TestPropertyBlock after = JsonUtility.FromJson <TestPropertyBlock>(json);

        Assert.AreEqual(42, after.health.value);
        Assert.AreEqual("alice", after.friend.value);
    }