示例#1
0
    // Sets up a trigger between TinkerTexts and SceneObjects.
    private void loadTrigger(Trigger trigger)
    {
        switch (trigger.type)
        {
        case TriggerType.CLICK_TINKERTEXT_SCENE_OBJECT:
            // It's possible this sceneObject was not added because we found that it
            // overlapped with a previous object. This is fine, just skip it.
            if (!this.sceneObjects.ContainsKey(trigger.args.sceneObjectId))
            {
                return;
            }
            SceneObjectManipulator manip =
                this.sceneObjects[trigger.args.sceneObjectId]
                .GetComponent <SceneObjectManipulator>();
            TinkerText tinkerText = this.tinkerTexts[trigger.args.textId]
                                    .GetComponent <TinkerText>();
            Action action = manip.Highlight(Constants.SCENE_OBJECT_HIGHLIGHT_COLOR);
            tinkerText.AddClickHandler(action);
            manip.AddClickHandler(tinkerText.Highlight());
            break;

        default:
            Logger.LogError("Unknown TriggerType: " + trigger.type);
            break;
        }
    }
    // Highlight the given game object.
    // Just an example, probably need to pass more information, like
    // the position to highlight, what color, more extendable basically.
    //
    // Question: Return true on success, or should throw errors on failure?
    //
    // Make a specific type of GameObject that knows how to highlight itself?

    //private static Action HighlightAction(GameObject obj, string arg) {
    //    Logger.Log("Highlighted!" + arg);
    //    return MakeAction(obj, HighlightAction, )
    //}

    // Transform an action that takes a parameter into one that doesn't.
    private static Action MakeAction(
        SceneObjectManipulator target,
        Action <SceneObjectManipulator, object[]> action, params object[] args)
    {
        return(() =>
        {
            action(target, args);
        });
    }
    // Adds a SceneObject to the story scene.
    private void loadSceneObject(SceneObject sceneObject)
    {
        // TODO: handle multiple objects per label. For now, only allow one.
        // Idea: allow multiple as long as the boxes don't overlap.
        if (this.sceneObjects.ContainsKey(sceneObject.id))
        {
            return;
        }
        GameObject newObj =
            Instantiate((GameObject)Resources.Load("Prefabs/SceneObject"));

        newObj.transform.SetParent(this.graphicsPanel.transform, false);
        newObj.GetComponent <RectTransform>().SetAsLastSibling();
        // Set the position.
        SceneObjectManipulator manip =
            newObj.GetComponent <SceneObjectManipulator>();
        Position pos = sceneObject.position;

        manip.id    = sceneObject.id;
        manip.label = sceneObject.label;
        Logger.Log("x, y " + storyImageX.ToString() + " " + storyImageY.ToString());
        manip.MoveToPosition(
            new Vector3(this.storyImageX + pos.left * this.imageScaleFactor,
                        this.storyImageY - pos.top * this.imageScaleFactor)
            )();
        manip.ChangeSize(
            new Vector2(pos.width * this.imageScaleFactor,
                        pos.height * this.imageScaleFactor)
            )();
        // Add a dummy handler to check things.
        manip.AddClickHandler(() =>
        {
            Logger.Log("SceneObject clicked " +
                       manip.label);
        });
        // TODO: if sceneObject.inText is false, set up whatever behavior we
        // want for these words.
        if (!sceneObject.inText)
        {
            manip.AddClickHandler(() =>
            {
                Logger.Log("Not in text! " + manip.label);
            });
        }
        // Name the GameObject so we can inspect in the editor.
        newObj.name = sceneObject.label;
        this.sceneObjects[sceneObject.id] = newObj;
    }
    // Sets up a trigger between TinkerTexts and SceneObjects.
    private void loadTrigger(Trigger trigger)
    {
        switch (trigger.type)
        {
        case TriggerType.CLICK_TINKERTEXT_SCENE_OBJECT:
            SceneObjectManipulator manip =
                this.sceneObjects[trigger.args.sceneObjectId]
                .GetComponent <SceneObjectManipulator>();
            TinkerText tinkerText = this.tinkerTexts[trigger.args.textId]
                                    .GetComponent <TinkerText>();
            Action action = manip.Highlight(new Color(0, 1, 1, 60f / 255));
            tinkerText.AddClickHandler(action);
            break;

        default:
            Logger.LogError("Unknown TriggerType: " +
                            trigger.type.ToString());
            break;
        }
    }
示例#5
0
    // Adds a SceneObject to the story scene.
    private void loadSceneObject(SceneObject sceneObject)
    {
        // Allow multiple scene objects per label as long as we believe that they are referring to
        // different objects.
        if (this.sceneObjectsLabelToId.ContainsKey(sceneObject.label))
        {
            // Check for overlap.
            foreach (int existingObject in this.sceneObjectsLabelToId[sceneObject.label])
            {
                if (Util.RefersToSameObject(
                        sceneObject.position,
                        this.sceneObjects[existingObject].GetComponent <SceneObjectManipulator>().position))
                {
                    Logger.Log("Detected overlap for object " + sceneObject.label);
                    return;
                }
            }
        }
        // Save this id under its label.
        if (!this.sceneObjectsLabelToId.ContainsKey(sceneObject.label))
        {
            this.sceneObjectsLabelToId[sceneObject.label] = new List <int>();
        }
        this.sceneObjectsLabelToId[sceneObject.label].Add(sceneObject.id);

        GameObject newObj =
            Instantiate((GameObject)Resources.Load("Prefabs/SceneObject"));

        newObj.transform.SetParent(this.graphicsPanel.transform, false);
        newObj.GetComponent <RectTransform>().SetAsLastSibling();
        // Set the position.
        SceneObjectManipulator manip =
            newObj.GetComponent <SceneObjectManipulator>();
        Position pos = sceneObject.position;

        manip.id       = sceneObject.id;
        manip.label    = sceneObject.label;
        manip.position = pos;
        manip.MoveToPosition(
            new Vector3(this.storyImageX + pos.left * this.imageScaleFactor,
                        this.storyImageY - pos.top * this.imageScaleFactor)
            )();
        manip.ChangeSize(
            new Vector2(pos.width * this.imageScaleFactor,
                        pos.height * this.imageScaleFactor)
            )();
        // Add a dummy handler to check things.
        manip.AddClickHandler(() =>
        {
            Logger.Log("SceneObject clicked " +
                       manip.label);
        });
        // Add a click handler to send a ROS message.
        manip.AddClickHandler(
            this.rosManager.SendSceneObjectTappedAction(sceneObject.id, sceneObject.label));
        // Add additional click handlers if the scene object's label is not in the story text.
        if (!sceneObject.inText)
        {
            manip.AddClickHandler(() =>
            {
                Logger.Log("Not in text! " + manip.label);
                this.showPopupText(manip.label, manip.position);
            });
        }
        // Name the GameObject so we can inspect in the editor.
        newObj.name = sceneObject.label;
        this.sceneObjects[sceneObject.id] = newObj;
    }