// Start is called before the first frame update void Start() { imported = false; importerUI = importer.GetComponent <ObjectImporterUI>(); QuestionControler_class = First_question.GetComponent <I_QuestionController1>(); ActivateInformation_class = ActivateInformation.GetComponent <Imported_ActivateInformation>(); }
// Use this for initialization void Start() { if (!Application.isPlaying) { if (firstTime) { if (questionController1 != null) { //cria o importador de objetos model_importer = new GameObject("Model_Importer"); importer_UI = model_importer.AddComponent <ObjectImporterUI>(); importer_class = model_importer.AddComponent <MultiObjectImporter>(); model_importer.AddComponent <PathSettings>(); //seta as variaveis para o importador funcionar importer_class.autoLoadOnStart = true; importer_UI.first_question = questionController1.gameObject; questionController1.Active = false; //informa o question controler quem e o importador questionController1.multiobjectimporter = importer_class; //ajusta o tamanho dos vectores AdditionalElements1 e AdditionalElements3 a 2 para acrescentar alguns objetos questionController1.AdditionalElements1 = new GameObject[1]; questionController1.AdditionalElements3 = new GameObject[1]; //CRIAR INSTANCIA DO MARCADOR E ACRESCENTAR NO CAMPO DO QUESTIONCONTROLLER1 Object resourceImageTarget1Prefab = Resources.Load("ImageTarget1Prefab");//obtem o prefab do ImageTarget ImageTarget1Prefab, que está num arquivo Resources if (resourceImageTarget1Prefab != null) { //criar uma instancia do prefabs e inicializar ela GameObject marker = (GameObject)GameObject.Instantiate(resourceImageTarget1Prefab); marker.name = "ImageTarget"; //criar um objeto para poder alterar o modelo no formato do app de ajuste GameObject model_location = new GameObject(); model_location.transform.localPosition = marker.transform.localPosition; model_location.name = "model location"; model_location.transform.SetParent(marker.transform); model_location.transform.localScale = new Vector3(1, 1, 1); // acrescenta a instancias no campos automaticamente. questionController1.Marker = marker; questionController1.QuestionObjects[0] = model_location; } else { Debug.LogError("AR Educational Framework Message: The GameObject Prefab: ImageTarget1Prefab is not found in the folder Resources."); } //CRIAR INSTANCIA DO CANVAS E ACRESCENTAR NO CAMPO DO QUESTIONCONTROLLER1 Object resourceCanvasPrefab = Resources.Load("CanvasPrefab");//obtem o prefab do canvas CanvasPrefab, que está num arquivo Resources if (resourceCanvasPrefab != null) { //criar a instancia do canvas canvas = (GameObject)GameObject.Instantiate(resourceCanvasPrefab); canvas.name = "Canvas"; //CRIAR ISNTANCIA DE EVENTSYSTEM PARA O CANVAS NO CASO DE NAO TER (Um EVENTSYSTEM é criado automaticamente quando se cria um Canvas) if (GameObject.FindObjectOfType <EventSystem>() == null) { //criar eventsystem só com codigo (sem prefab) GameObject eventSystem = new GameObject("EventSystem"); eventSystem.AddComponent <EventSystem>(); eventSystem.AddComponent <StandaloneInputModule>(); } } else { Debug.LogError("AR Educational Framework Message: The GameObject Prefab: CanvasPrefab is not found in the folder Resources."); } //CRIAR TEXTOS DE ALTERNATIVA E ACRESCENTAR NOS CAMPOS DO QUESTIONCONTROLLER1 GameObject[] alternativeTexts = new GameObject[2]; for (int i = 0; i < 2; i++) { alternativeTexts[i] = new GameObject("Alternative " + (i + 1)); alternativeTexts[i].AddComponent <Text>(); alternativeTexts[i].transform.SetParent(canvas.transform); alternativeTexts[i].GetComponent <RectTransform>().sizeDelta = new Vector2(180, 30); alternativeTexts[i].GetComponent <Text>().text = "Alternative " + (i + 1); alternativeTexts[i].GetComponent <Text>().fontStyle = FontStyle.Bold; alternativeTexts[i].GetComponent <Text>().fontSize = 30; alternativeTexts[i].GetComponent <Text>().alignment = TextAnchor.MiddleCenter; alternativeTexts[i].GetComponent <Text>().horizontalOverflow = HorizontalWrapMode.Overflow; alternativeTexts[i].GetComponent <Text>().verticalOverflow = VerticalWrapMode.Overflow; alternativeTexts[i].GetComponent <Text>().color = Color.white; if (i == 0)//para o texto de alternativa1, posicionar ele { alternativeTexts[i].transform.localPosition = new Vector3(320, 30, 0); } else if (i == 1)//para o texto de alternativa2, posicionar ele { alternativeTexts[i].transform.localPosition = new Vector3(320, -10, 0); } //acrescenta os textos nos campos automaticamente. questionController1.Texts[i] = alternativeTexts[i].GetComponent <Text>(); } //CRIAR INSTANCIA DO BOTAO PARA O BOTAO RESET PERGUNTA E ACRESCENTAR NO CAMPO DO QUESTIONCONTROLLER1 Object resource1ButtonPrefab = Resources.Load("ButtonPrefab");//obtem o prefab do botao ButtonPrefab, que está num arquivo Resources if (resource1ButtonPrefab != null) { //criar uma instancia do prefabs e inicializar ela GameObject resetQuestionButton = (GameObject)GameObject.Instantiate(resource1ButtonPrefab); resetQuestionButton.name = "ResetQuestionButton"; resetQuestionButton.transform.SetParent(canvas.transform); resetQuestionButton.transform.localPosition = new Vector3(0, -95, 0); Sprite image = Resources.Load("ButtonTextures/TryAgain", typeof(Sprite)) as Sprite;//obtem a imagem para o botao if (image != null) { resetQuestionButton.GetComponent <Image>().sprite = image; resetQuestionButton.GetComponent <Image>().type = Image.Type.Simple; } else { resetQuestionButton.transform.GetChild(0).GetComponent <Text>().text = "Try Again"; Debug.LogWarning("AR Educational Framework Message: The Resource: TryAgain is not found in the folder Resources/ButtonTextures."); } //acrescenta a instancia no campo automaticamente. questionController1.ResetButton = resetQuestionButton.GetComponent <Button>(); } else { Debug.LogError("AR Educational Framework Message: The GameObject Prefab: ButtonPrefab is not found in the folder Resources."); } //CRIAR INSTANCIA DA IMAGEM PARA A IMAGEM PERGUNTA CERTA E ACRESCENTAR NO CAMPO DO QUESTIONCONTROLLER1 Sprite resource1CorrectAnswerImage = Resources.Load("CorrectAnswerImage", typeof(Sprite)) as Sprite;//obtem a imagem CorrectAnswerImage, que está num arquivo Resources if (resource1CorrectAnswerImage != null) { //criar uma elemento Image só com codigo, e apartir da imagem CorrectAnswerImage inicializando ela GameObject correctAnswerImage = new GameObject("CorrectAnswerImage"); correctAnswerImage.AddComponent <Image>(); correctAnswerImage.transform.SetParent(canvas.transform); correctAnswerImage.transform.localPosition = new Vector3(0, 25, 0); correctAnswerImage.GetComponent <Image>().sprite = resource1CorrectAnswerImage; correctAnswerImage.GetComponent <RectTransform>().sizeDelta = new Vector2(140, 140); //acrescenta a imagem no campo automaticamente. questionController1.CorrectAnswerImage = correctAnswerImage.GetComponent <Image>(); } else { Debug.LogError("AR Educational Framework Message: The Resource: CorrectAnswerImage is not found in the folder Resources."); } //CRIAR INSTANCIA DA IMAGEM PARA IMAGEM PERGUNTA ERRADA E ACRESCENTAR NO CAMPO DO QUESTIONCONTROLLER1 Sprite resourceWrongAnswerImage = Resources.Load("WrongAnswerImage", typeof(Sprite)) as Sprite;//obtem a imagem WrongAnswerImage, que está num arquivo Resources if (resourceWrongAnswerImage != null) { //criar uma elemento Image só com codigo, e apartir da imagem WrongAnswerImage inicializando ela GameObject wrongAnswerImage = new GameObject("WrongAnswerImage"); wrongAnswerImage.AddComponent <Image>(); wrongAnswerImage.transform.SetParent(canvas.transform); wrongAnswerImage.transform.localPosition = new Vector3(0, 25, 0); wrongAnswerImage.GetComponent <Image>().sprite = resourceWrongAnswerImage; wrongAnswerImage.GetComponent <RectTransform>().sizeDelta = new Vector2(140, 140); //acrescenta a imagem no campo automaticamente. questionController1.WrongAnswerImage = wrongAnswerImage.GetComponent <Image>(); } else { Debug.LogError("AR Educational Framework Message: The Resource: WrongAnswerImage is not found in the folder Resources."); } //CRIAR TEXTO DO TEMPO E ACRESCENTAR NO CAMPO DO QUESTIONCONTROLLER1 GameObject timeText = new GameObject("TimeText"); timeText.AddComponent <Text>(); timeText.transform.SetParent(canvas.transform); timeText.GetComponent <RectTransform>().sizeDelta = new Vector2(160, 30); timeText.GetComponent <Text>().text = "Time Text"; timeText.GetComponent <Text>().fontStyle = FontStyle.Bold; timeText.GetComponent <Text>().fontSize = 30; timeText.GetComponent <Text>().alignment = TextAnchor.MiddleCenter; timeText.GetComponent <Text>().horizontalOverflow = HorizontalWrapMode.Overflow; timeText.GetComponent <Text>().verticalOverflow = VerticalWrapMode.Overflow; timeText.transform.localPosition = new Vector3(320, 135, 0); timeText.GetComponent <Text>().color = Color.yellow; //acrescenta o texto no campo automaticamente. questionController1.TimeText = timeText.GetComponent <Text>(); //CRIAR INSTANCIA DO BOTAO PARA O BOTAO VER RESPOSTA DA PERGUNTA E ACRESCENTAR NO CAMPO DO QUESTIONCONTROLLER1 Object resource2ButtonPrefab = Resources.Load("ButtonPrefab");//obtem o prefab do botao ButtonPrefab, que está num arquivo Resources if (resource2ButtonPrefab != null) { //criar uma instancia do prefabs e inicializar ela GameObject answerButton = (GameObject)GameObject.Instantiate(resource2ButtonPrefab); answerButton.name = "AnswerButton"; answerButton.transform.SetParent(canvas.transform); answerButton.transform.localPosition = new Vector3(0, -65, 0); Sprite image = Resources.Load("ButtonTextures/SeeAnswer", typeof(Sprite)) as Sprite;//obtem a imagem para o botao if (image != null) { answerButton.GetComponent <Image>().sprite = image; answerButton.GetComponent <Image>().type = Image.Type.Simple; } else { answerButton.transform.GetChild(0).GetComponent <Text>().text = "See Answer"; Debug.LogWarning("AR Educational Framework Message: The Resource: SeeAnswer is not found in the folder Resources/ButtonTextures."); } //acrescenta a instancia no campo automaticamente. questionController1.AnswerButton = answerButton.GetComponent <Button>(); } else { Debug.LogError("AR Educational Framework Message: The GameObject Prefab: ButtonPrefab is not found in the folder Resources."); } //CRIAR INSTANCIA DA IMAGEM PARA A IMAGEM PEQUENA QUE INDICA A ALTERNATIVA CERTA E ACRESCENTAR NO CAMPO DO QUESTIONCONTROLLER1 Sprite resource2CorrectAnswerImage = Resources.Load("CorrectAnswerImage", typeof(Sprite)) as Sprite;//obtem a imagem CorrectAnswerImage, que está num arquivo Resources if (resource2CorrectAnswerImage != null) { //criar uma elemento Image só com codigo, e apartir da imagem CorrectAnswerImage inicializando ela GameObject correctAnswerImage2 = new GameObject("CorrectAnswerImage2"); correctAnswerImage2.AddComponent <Image>(); correctAnswerImage2.transform.SetParent(canvas.transform); correctAnswerImage2.transform.localPosition = new Vector3(320, 30, 0);//mesma posicao do texto de alternativa 1 correctAnswerImage2.GetComponent <Image>().sprite = resource2CorrectAnswerImage; correctAnswerImage2.GetComponent <RectTransform>().sizeDelta = new Vector2(32, 30); //acrescenta a instancia no campo automaticamente. questionController1.CorrectAnswerImage2 = correctAnswerImage2.GetComponent <Image>(); } else { Debug.LogError("AR Educational Framework Message: The Resource: CorrectAnswerImage is not found in the folder Resources."); } //CRIAR TEXTO DE PERGUNTA E ACRESCENTAR NO CAMPO DO QUESTIONCONTROLLER1 GameObject questionText = new GameObject("QuestionText"); questionText.AddComponent <Text>(); questionText.transform.SetParent(canvas.transform); questionText.GetComponent <RectTransform>().sizeDelta = new Vector2(200, 30); questionText.GetComponent <Text>().text = "Question Text"; questionText.GetComponent <Text>().fontStyle = FontStyle.Bold; questionText.GetComponent <Text>().fontSize = 30; questionText.GetComponent <Text>().alignment = TextAnchor.MiddleCenter; questionText.GetComponent <Text>().horizontalOverflow = HorizontalWrapMode.Overflow; questionText.GetComponent <Text>().verticalOverflow = VerticalWrapMode.Overflow; questionText.transform.localPosition = new Vector3(0, 135, 0); questionText.GetComponent <Text>().color = Color.blue; //acrescenta o texto no campo automaticamente. questionController1.AdditionalElements1[0] = questionText; //CRIAR TEXTO DE RESPOSTA E ACRESCENTAR NO CAMPO DO QUESTIONCONTROLLER1 GameObject answerText = new GameObject("AnswerText"); answerText.AddComponent <Text>(); answerText.transform.SetParent(canvas.transform); answerText.GetComponent <RectTransform>().sizeDelta = new Vector2(180, 30); answerText.GetComponent <Text>().text = "Answer Text"; answerText.GetComponent <Text>().fontStyle = FontStyle.Bold; answerText.GetComponent <Text>().fontSize = 30; answerText.GetComponent <Text>().alignment = TextAnchor.MiddleCenter; answerText.GetComponent <Text>().horizontalOverflow = HorizontalWrapMode.Overflow; answerText.GetComponent <Text>().verticalOverflow = VerticalWrapMode.Overflow; answerText.transform.localPosition = new Vector3(0, 135, 0); answerText.GetComponent <Text>().color = Color.blue; //acrescenta o texto no campo automaticamente. questionController1.AdditionalElements3[0] = answerText; } else { Debug.LogError("AR Educational Framework Message: The GameObject: " + gameObject.name + " doesn't have I_QuestionController1 component. you need to add it before add this class."); } firstTime = false; } } }
// Use this for initialization void Start() { if (!Application.isPlaying) { if (firstTime) { //cria o importador de objetos model_importer = new GameObject("Model_Importer"); importer_UI = model_importer.AddComponent <ObjectImporterUI>(); importer_class = model_importer.AddComponent <MultiObjectImporter>(); model_importer.AddComponent <PathSettings>(); importer_UI.active_info = activateInformationComponents[0]; //seta as variaveis para o importador funcionar importer_class.autoLoadOnStart = true; if (activateInformationComponents.Length > 0) { for (int i = 0; i < activateInformationComponents.Length; i++) { //CRIAR INSTANCIA DO MARCADOR1 Object resourceImageTarget1Prefab = Resources.Load("ImageTarget1Prefab"); if (resourceImageTarget1Prefab != null) { //criar instancia do marcador marker1 = (GameObject)GameObject.Instantiate(resourceImageTarget1Prefab); marker1.name = "ImageTarget"; //Informar o importador, qual e o marcador importer_UI.Marker = marker1; //criar objeto para teste Object = new GameObject(); Object.name = "model location"; //colocar objeto como filho do marcador Object.transform.SetParent(marker1.transform); //acrescenta automaticamente o marcador e seu objeto, nos campos da classe Imported_ActivateInformation activateInformationComponents[i].Marker1 = marker1; activateInformationComponents[i].MyObject = Object; for (int j = 0; j < activateInformationComponents[i].Texts3D.Length; j++) { //CRIAR O 3D TEXT DE INFORMACAO A SER ATIVADO SOBRE O OBJETO GameObject text3D = new GameObject("New Text_" + j); text3D.AddComponent <TextMesh>(); text3D.GetComponent <TextMesh>().text = "Hello World"; text3D.GetComponent <TextMesh>().anchor = TextAnchor.MiddleCenter; text3D.GetComponent <TextMesh>().alignment = TextAlignment.Center; text3D.GetComponent <TextMesh>().fontSize = 30; text3D.GetComponent <TextMesh>().font = Resources.Load("Arial", typeof(Font)) as Font; text3D.transform.localScale = new Vector3(0.12f, 0.12f, 0.12f); //ajusta posicao para ficar na mesma do objeto text3D.transform.localPosition = ObjectPosition; //ajusta posicao para aumentar 1.5 em Y text3D.transform.SetParent(Object.transform); Vector3 positionT3 = text3D.transform.localPosition; positionT3.y += 1.5f; text3D.transform.localPosition = positionT3; //acrescenta automaticamente 3D TEXT, no campo da classe Imported_ActivateInformation activateInformationComponents[i].Texts3D[j] = text3D.GetComponent <TextMesh>(); //-------------- } for (int j = 0; j < activateInformationComponents[i].Points.Length; j++) { //CRIAR O GAME OBJECT VAZIO PARA INDICAR O PONTO DE ORIGEM DA LINHA GameObject point = new GameObject("P1_" + j); //ajusta posicao para ficar na mesma do objeto point.transform.localPosition = ObjectPosition; point.transform.SetParent(Object.transform); //acrescenta automaticamente objeto vazio, no campo da classe Imported_ActivateInformation activateInformationComponents[i].Points[j] = point; //-------------- } } else { Debug.LogError("AR Educational Framework Message: The GameObject Prefab: ImageTarget1Prefab is not found in the folder Resources."); } //CRIAR INSTANCIA DO MARCADOR2 Object resourceImageTarget2Prefab = Resources.Load("ImageTarget2Prefab"); if (resourceImageTarget2Prefab != null) { GameObject marker2 = (GameObject)GameObject.Instantiate(resourceImageTarget2Prefab); marker2.name = "ImageTarget2"; Vector3 positionT = marker2.transform.localPosition; positionT.x += 1.4f; marker2.transform.localPosition = positionT; //acrescenta automaticamente o marcador, no campo da classe Imported_ActivateInformation activateInformationComponents[i].Marker2 = marker2; } else { Debug.LogError("AR Educational Framework Message: The GameObject Prefab: ImageTarget2Prefab is not found in the folder Resources."); } //OBTER A ARCAMERA ATUAL E ACRESCENTAR ELA NO campo da classe Imported_ActivateInformation, caso de nao encontrar ela, entao enviar uma mensagem de erro GameObject myARCamera = GameObject.Find("ARCamera"); if (myARCamera != null) { activateInformationComponents[i].MyARCamera = myARCamera; } else { Debug.LogError("AR Educational Framework Message: ARCamera not Found, you need have a ARCamera in the Scene before add this class."); } } } else { Debug.LogError("AR Educational Framework Message: The GameObject: " + gameObject.name + " doesn't have Imported_ActivateInformation component. you need to add it before add this class."); } firstTime = false; } } }