Exemplo n.º 1
0
    public IEnumerator TestHandleMultipleInOneFrame()
    {
        yield return(Setup());

        VoosActor actor = voosEngine.CreateActor(new Vector3(1, 2, 3), Quaternion.identity, newActor => { });

        actor.SetTint(new Color(0.1f, 0.1f, 0.1f));
        Assert.NotNull(actor);
        Assert.AreEqual(1.0, actor.transform.position.x, 1e-4);

        string brainId    = actor.GetBrainName();
        string behaviorId = behaviorSystem.GenerateUniqueId();
        string js         = @"
    export function onMoveRight() {
      const c = getTint();
      c.r += 0.1;
      setTint(c.r, c.g, c.b);
    }
    ";

        behaviorSystem.PutBehavior(behaviorId, new Behaviors.Behavior {
            javascript = js
        });
        PutTestUse(new TestUse
        {
            behaviorUri = IdToEmbeddedBehaviorUri(behaviorId),
            brainId     = brainId
        });

        // We expect x to increment by 2..
        voosEngine.EnqueueMessage(new VoosEngine.ActorMessage {
            name = "MoveRight", targetActor = actor.GetName()
        });
        voosEngine.EnqueueMessage(new VoosEngine.ActorMessage {
            name = "MoveRight", targetActor = actor.GetName()
        });

        // Let it run at least one voos update
        yield return(new WaitForEndOfFrame());

        yield return(new WaitForEndOfFrame());

        Assert.AreEqual(0.3, actor.GetTint().r, 1e-4);
    }
Exemplo n.º 2
0
    private void CheckButtonClicks()
    {
        // No button clicks while in edit mode.
        if (userMain == null || userMain.InEditMode())
        {
            return;
        }
        // Must have button down.
        if (!Input.GetMouseButtonDown(0))
        {
            return;
        }
        // Must have UI commands.
        if (currentCommands.commands == null)
        {
            return;
        }
        Vector2 mousePos = GetMousePos();

        // Let's see if that landed on any buttons.
        // Iterate backwards because the latest buttons have priority over the earlier ones.
        for (int i = currentCommands.commands.Length - 1; i >= 0; i--)
        {
            if (currentCommands.commands[i].cmd == CMD_BUTTON && currentCommands.commands[i].rect.ToUnityRect().Contains(mousePos))
            {
                // Button clicked.
                UiCommand thisCommand = currentCommands.commands[i];
                engine.EnqueueMessage(new VoosEngine.ActorMessage
                {
                    name        = string.IsNullOrEmpty(thisCommand.clickMessageName) ? "ButtonClicked" : thisCommand.clickMessageName,
                    targetActor = thisCommand.actorName,
                    argsJson    = string.IsNullOrEmpty(thisCommand.clickMessageArgJson) ? "{}" : thisCommand.clickMessageArgJson
                });
                return;
            }
        }
    }