void CmdQuitGame()
 {
     if (!SubmitFinalQuestionScript.isListening)
     {
         QuitGameScript.TaskOnClick();
     }
 }
 void RpcQuitGame()
 {
     if (!isServer)
     {
         if (!SubmitFinalQuestionScript.isListening)               //So this isn't done twice
         {
             QuitGameScript.TaskOnClick();
         }
     }
 }
示例#3
0
    //This method can be called from the EventListener script using the GameObject that was clicked on as input:
    public static void replaceTag(GameObject obj, bool clickedImage)
    {
        //Find tag with this object:
        for (int i = 0; i < tags.Length; i++)
        {
            if (obj.name == tags[i].text.name)
            {
                if (inTutorial)
                {
                    if (tutorialWordsIndex < tutorialWords.Length)
                    {
                        tags [i].isChangingColor = true;

                        tags [i].setText(tutorialWords [tutorialWordsIndex]);
                    }
                    else
                    {
                        tags [i].setText("");
                    }
                }
                else
                {
                    if (sequenceIndex < wordBank.Count)
                    {
                        tags [i].isChangingColor = true;
                        tags [i].text.color      = Color.clear;

                        tags [i].setText(wordBank [SEQUENCE [imageIndex, sequenceIndex]]);
                        sequenceIndex++;
                    }
                    else
                    {
                        if (clickedImage)
                        {
                            tags [i].isChangingColor = true;
                            tags [i].text.color      = Color.clear;
                            tags [i].setText("");
                        }
                        else
                        {
                            //Do nothing so you can't throw away tags when there's nothing to replace them
                        }
                    }
                }
            }
        }
        if (clickedImage || (skipTaggingTutorialStep && inPracticeLevel) || (skipTaggingTutorialStep && continueAfterOtherQuit))           //If they're the trasher, the practice level should turn over tags left.
        //Handle tags remaining label, image turnover, here:
        {
            if (numTagsRemaining > 2)               //Plural "tags remaining" vs singular "tag remaining" (minor detail):
            {
                numTagsRemaining--;

                if (skipTaggingTutorialStep && inPracticeLevel)
                {
                }
                else
                {
                    tagsRemainingText.text = numTagsRemaining + " Tags Left";
                }
            }
            else
            {
                numTagsRemaining--;
                if (numTagsRemaining == 1)
                {
                    if (!(skipTaggingTutorialStep && inPracticeLevel))
                    {
                        tagsRemainingText.text = numTagsRemaining + " Tag Left";
                    }
                }
                else
                {
                    if (imageIndex == imageMaterials.Length - 1)                       //On last image, then quit:
                    {
                        QuitGameScript.quitGame();
                    }
                    if (!inTutorial)
                    {
                        if (!inPracticeLevel)                           //Are we not in the practice level:
                        {
                            DataCollector.Flush();
                        }
                        if (!skipTaggingTutorialStep)                           //Only set these if you're the tagger:
                        {
                            Transform lastTag = tagSphere.transform.GetChild(tagSphere.transform.childCount - 1);

                            positionLastTag = lastTag.localPosition;
                            rotationLastTag = lastTag.localRotation.eulerAngles;
                            scaleLastTag    = lastTag.localScale;
                        }

                        if (ClickAction.cursorTag != null)
                        {
                            Destroy(ClickAction.cursorTag);
                            ClickAction.cursorTag       = null;
                            PlayerScript.holdingTag     = "";
                            PlayerScript.trashedTagText = "";
                            ClickAction.state.setSelected(null);
                        }

                        foreach (Transform t in tagSphere.transform)
                        {
                            Destroy(t.gameObject, 0.08f);
                        }

                        for (int i = 0; i < ClickAction.trashedTags.Count; i++)
                        {
                            Destroy(ClickAction.trashedTags [i]);
                        }
                        ClickAction.trashedTags.Clear();

                        numTagsRemaining       = 5;
                        tagsRemainingText.text = numTagsRemaining + " Tags Left";
                        imageIndex++;
                        tagSphere.GetComponent <Renderer> ().material = imageMaterials [imageIndex];
                        sequenceIndex = 0;
                        for (int tagsIndex = 0; tagsIndex < tags.Length; tagsIndex++)
                        {
                            tags [tagsIndex].setText(wordBank [SEQUENCE [imageIndex, sequenceIndex]]);
                            tags [tagsIndex].text.color = Color.black;

                            sequenceIndex++;
                        }
                        if (inPracticeLevel)
                        {
                            practiceLevelText.SetActive(false);
                            welcomeText.text = "You have completed the practice level.\nPress any button to " +
                                               "begin data collection.";
                            welcomeScreen.SetActive(true);
                            inScreenBeforeExperiment = true;
                            inPracticeLevel          = false;
                        }
                    }
                }
            }
        }
    }
示例#4
0
    public void OnPointerClick(PointerEventData eventData)
    {
        // OnClick code goes here ...
        GameObject objectClicked = eventData.pointerCurrentRaycast.gameObject; // get the object that was pressed

        if (eventData.button != PointerEventData.InputButton.Left)             // Ensure the left button was pressed (OR THE FALCON BUTTON)
        {
            return;
        }

        if (objectClicked.tag == "Tag") // A tag was pressed
        {
            if (MakeWordBank.inTutorial && MakeWordBank.stepOfTutorial != 4 && MakeWordBank.stepOfTutorial != 8)
            {
                return;
            }
            if (MakeWordBank.stepOfTutorial == 8 && MakeWordBank.timeSpentOnStep8 <= 0.25f)
            {
                return;                 //prevents glitch
            }

            if (objectClicked.GetComponentInChildren <Text> ().color == Color.red)
            {
                return;                 //Prevents trasher from clicking on a tag the tagger has selected in multiplayer
            }
            if (objectClicked.GetComponent <Text>() != null && objectClicked.GetComponent <Text>().color == Color.red)
            {
                return;
            }

            Debug.Log(objectClicked.name); // Name of the object
            GameObject currentTag = state.getSelected();

            if (currentTag != null && currentTag.GetComponent <Text>() != null)
            {
                currentTag.GetComponent <Text>().color = Color.black; // Reset the color of the previously selected tag
            }
            state.setSelected(objectClicked);

            //if (MakeWordBank.trasherPanel.transform.localPosition.y >= 3000) { //If the player doesn't have a panel blocking putting tags on the image:
            objectClicked.GetComponentInChildren <Text> ().color = Color.red;
            for (int i = 0; i < MakeWordBank.tags.Length; i++)
            {
                if (objectClicked.GetComponentInChildren <Text> ().text.Equals(MakeWordBank.tags [i].getText()))
                {
                    MakeWordBank.tags [i].isChangingColor = false;
                }
            }
            //}

            if (cursorTag != null)
            {
                Destroy(cursorTag);
            }

            //Make tag that follows cursor:
            cursorTag = Instantiate(state.getSelected().transform.parent.gameObject, canvas.transform);
            cursorTag.transform.LookAt(Vector3.zero);
            //cursorTag.transform.Rotate (new Vector3 (0f, 0f, -3f));
            cursorTag.layer = 5;             //UI Layer
            if (cursorSphere != null)
            {
                cursorSphere.GetComponent <MeshRenderer>().enabled = false;
            }
            //cursorTag.name = currentTag.GetComponent<Text> ().name;
            //cursorTag.transform.localScale = new Vector3 (8.8f, 3.188f, 0.001f);
        }
        else if (objectClicked.tag == "QuitButton" && !MakeWordBank.inTutorial)         // Quit button clicked by falcon
        {
            QuitGameScript.TaskOnClick();
        }
        else if (objectClicked.tag == "Bin") // The bin was pressed, so we move the tag to the bin
        {
            Debug.Log("Bin Clicked");
            GameObject currentTag = state.getSelected();
            if (currentTag != null)
            {
                if (MakeWordBank.sequenceIndex < MakeWordBank.wordBank.Count)
                {
                    if (!MakeWordBank.inPracticeLevel && !MakeWordBank.inTutorial)
                    {
                        DataCollector.AddTag(currentTag.transform.parent.name);
                    }
                    GameObject newTrashedTag = Instantiate(state.getSelected().transform.parent.gameObject, canvas.transform);
                    newTrashedTag.transform.localScale
                        = new Vector3(newTrashedTag.transform.localScale.x / 2.0f, newTrashedTag.transform.localScale.y / 2.5f, newTrashedTag.transform.localScale.z);
                    newTrashedTag.transform.GetChild(0).GetComponent <Text> ().color = Color.black;
                    newTrashedTag.transform.tag             = "TrashedTag";
                    newTrashedTag.transform.GetChild(0).tag = "TrashedTag";
                    int verticalBump = 0;
                    if (trashedTags.Count >= 14 && trashedTags.Count < 28)
                    {
                        verticalBump = 168;                         //To prevent overlap
                    }
                    else if (trashedTags.Count >= 28 && trashedTags.Count < 42)
                    {
                        verticalBump = 606;
                    }
                    else if (trashedTags.Count >= 42)
                    {
                        verticalBump = 774;
                    }

                    int horizontalBump = 0;
                    if (trashedTags.Count >= 14 && trashedTags.Count < 28)
                    {
                        horizontalBump = 50;
                    }
                    else if (trashedTags.Count >= 28 && trashedTags.Count < 42)
                    {
                        horizontalBump = 0;
                    }
                    else if (trashedTags.Count >= 42)
                    {
                        horizontalBump = 50;
                    }
                    newTrashedTag.transform.position = canvas.transform.TransformPoint(new Vector2(320 + horizontalBump, -55 - 12 * trashedTags.Count + verticalBump)) + Vector3.back * -0.25f;
                    newTrashedTag.transform.LookAt(newTrashedTag.transform.position + Vector3.back * newTrashedTag.transform.position.z * -1);
                    trashedTags.Add(newTrashedTag);
                    trashedTags[trashedTags.Count - 1].layer = 5;                     //UI
                }
                MakeWordBank.replaceTag(currentTag, false);
                currentTag.GetComponentInChildren <Text>().color = Color.clear;
                currentTag.GetComponent <Text>().color           = Color.clear; // Reset the color of the previously selected tag
            }
            if (cursorTag != null)
            {
                Destroy(cursorTag);
                cursorTag = null;
                if (cursorSphere != null)
                {
                    cursorSphere.GetComponent <MeshRenderer>().enabled = true;
                }
            }
            state.setSelected(null);
        }
        else if (objectClicked.tag == "Image") // The image area was pressed, so here we cast a tag onto the sphere
        {
            Debug.Log("Image Clicked");
            GameObject currentTag = state.getSelected();
            if (currentTag != null && !currentTag.transform.parent.name.Equals(""))    // TODO: Check if a tag is currently selected and that the tag isn't blank
            {
                Vector3 cursorPosition = state.getCursorPosition();                    // Use the cursor position to cast a ray onto the sphere
                Ray     ray            = Camera.main.ScreenPointToRay(cursorPosition); // The ray that will be casted onto the sphere

                // In the following two lines, since the sphere collider is outside the sphere
                // We move the point of the ray well outside of the sphere, then invert the direction
                // This way, we cast ray to the same point of the sphere, but from the outside rather than the inside
                ray.origin    = ray.GetPoint(100);
                ray.direction = -ray.direction;

                RaycastHit hit; // The raycast

                Debug.DrawRay(ray.origin, ray.direction, Color.red, 5);
                if (Physics.Raycast(ray, out hit))
                {
                    Destroy(cursorTag);
                    cursorTag = null;
                    if (cursorSphere != null)
                    {
                        cursorSphere.GetComponent <MeshRenderer>().enabled = true;
                    }
                    GameObject newObject = Instantiate(tagPrefab, hit.point * 0.95f, Quaternion.identity); // Create the new object using the tagPrefab
                    newObject.transform.LookAt(Vector3.zero);                                              // Make it face the center of the sphere
                    newObject.transform.localScale = new Vector3(0.25f, 0.1f, 0.00001f);
                    newObject.name             = currentTag.transform.parent.name;                         // CHANGE THIS LATER
                    newObject.transform.parent = sphere.transform;
                    newObject.GetComponent <Renderer>().material = new Material(Shader.Find("Diffuse"));

                    // Create the object which will hold the TextMesh
                    GameObject textContainer = new GameObject();
                    textContainer.transform.parent = newObject.transform;

                    // Create the text mesh to be rendered over the plane
                    TextMesh text = textContainer.AddComponent <TextMesh> ();
                    text.text                       = currentTag.transform.parent.name;
                    text.fontSize                   = 20;
                    text.alignment                  = TextAlignment.Center;
                    text.anchor                     = TextAnchor.MiddleCenter;
                    text.name                       = currentTag.transform.parent.name + "_Text";
                    text.transform.parent           = textContainer.transform;
                    text.transform.localScale       = new Vector3(-0.075f, 0.25f, 0.25f);
                    text.transform.localPosition    = Vector3.zero;
                    text.transform.localEulerAngles = Vector3.zero;
                    if (!MakeWordBank.inTutorial && !MakeWordBank.inPracticeLevel)
                    {
                        DataCollector.AddTag(currentTag.transform.parent.name, newObject.transform.position);
                    }

                    //int diff = MakeWordBank.sequenceIndex; //This is just a convoluted way to find out if the image turned over so the trashed tag prefabs can be deleted
                    MakeWordBank.replaceTag(currentTag, true);
                    currentTag.GetComponentInChildren <Text>().color = Color.clear;
                    state.setSelected(null);
                    //diff -= MakeWordBank.sequenceIndex;
                    //if (diff > 0) { //Means image turned over:
                    //	for (int i = 0; i < trashedTags.Count; i++) {
                    //		Destroy (trashedTags [i]);
                    //	}
                    //	trashedTags.Clear();
                    //}


                    // ---- Below is old code used to create the tag whereever the click happened. It isn't being used now but may be useful later
                    // --------------------------------------------------------------------------------------------------------------------------
                    //GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.tag, hit.point * 0.95f, Quaternion.identity);
                    //gameObject.transform.LookAt(Vector3.zero);
                    //gameObject.name = "Tag " + this.tags.Count;
                    //gameObject.transform.localScale = new Vector3(20f, 5f, 1f);
                    //this.tag.GetComponent<MeshRenderer>().shadowCastingMode = ShadowCastingMode.Off;
                    //gameObject.AddComponent(typeof(Tag));
                    //gameObject.transform.parent = this.tagContainer.transform;
                    //this.tags.Add(gameObject);
                    //this.keycam.transform.position = Vector3.zero;
                    //this.keycam.transform.LookAt(this.ray.point);
                    //this.keycam.transform.position = Vector3.MoveTowards(this.keycam.transform.position, this.ray.point, Vector3.Distance(this.keycam.transform.position, this.ray.point) * 0.8f);
                    //this.startTag(gameObject);
                }
            }
        }
    }