// TODO HEIDI 1/27 fill this in so we can display the sentence an NPC is saying over their head! public void FromScratch(Expression expr, Vector3 position) { this.expression = expr; this.arguments = new ExpressionPiece[expr.GetNumArgs()]; this.gameObject.transform.position = position; GameObject tabletop = GameObject.Find("Workspace"); this.gameObject.transform.position = new Vector3(0, 0, 0); // this.gameObject.transform.SetParent = this.parent.transform; if (arguments.Length > 0) { this.heightInUnits = 2; } int currentXInUnits = 1; for (int i = 0; i < arguments.Length; i++) { Expression argExpression = expr.GetArg(i); if (argExpression == null) { this.widthInUnits++; currentXInUnits++; } else { GameObject exprPiece = Resources.Load("Piece") as GameObject; GameObject exprPieceInstance = Instantiate(exprPiece, new Vector2(0, 0), Quaternion.identity) as GameObject; ExpressionPiece exprPieceScript = exprPieceInstance.GetComponent <ExpressionPiece>(); // exprPieceScript.gameObject.parent = this; exprPieceScript.FromScratch(argExpression, new Vector3(currentXInUnits * PIXELS_PER_UNIT, PIXELS_PER_UNIT)); arguments[i] = exprPieceScript; currentXInUnits += arguments[i].widthInUnits; this.widthInUnits += exprPieceScript.widthInUnits; this.heightInUnits = (arguments[i].heightInUnits + 1 > this.heightInUnits) ? arguments[i].heightInUnits + 1 : this.heightInUnits; } } }
public IEnumerator ShowSpeechBubble(Expression expr) { GameObject exprPiece = Resources.Load("Piece") as GameObject; GameObject exprPieceInstance = Instantiate(exprPiece, new Vector2(0, 0), Quaternion.identity) as GameObject; exprPieceInstance.name = "LIONKING"; ExpressionPiece exprPieceScript = exprPieceInstance.GetComponent <ExpressionPiece>(); exprPieceScript.FromScratch(expr, new Vector3(0, 0, 0)); exprPieceScript.transform.SetParent(GameObject.Find("ResponseCanvas").transform); Camera cam; if (controller.is2D) { cam = GameObject.Find("Main Camera").GetComponent <Camera>(); exprPieceScript.transform.position = cam.WorldToScreenPoint(this.transform.position); exprPieceScript.transform.position = new Vector3(exprPieceScript.transform.position.x, exprPieceScript.transform.position.y + (exprPieceScript.heightInUnits * ExpressionPiece.PIXELS_PER_UNIT / 2) + 16); } else { cam = GameObject.Find("FirstPersonCharacter").GetComponent <Camera>(); exprPieceScript.transform.position = cam.WorldToScreenPoint(this.transform.position); exprPieceScript.transform.position = new Vector3(exprPieceScript.transform.position.x, exprPieceScript.transform.position.y + (exprPieceScript.heightInUnits * ExpressionPiece.PIXELS_PER_UNIT / 2)); } exprPieceScript.SetVisual(exprPieceScript.GenerateVisual()); Destroy(exprPieceInstance, 2.0f); yield return(new WaitForSeconds(2.0f)); }