// 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; }
// 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; }