public void OnEndDrag(PointerEventData eventData)
    {
        if (!m_Draggable)
        {
            return;
        }

        // Play sound
        QuestionCanvas.GetInstance().PlayTickSound();

        // Temporarely move draggable object back to initial location
        ResetInstance();

        // Perform a raycast at mouse pointer position
        RaycastHit2D hit = Physics2D.Raycast(Input.mousePosition, Vector3.forward, 10.0f);

        // Check if raycast hit was a non-static question tile
        if (hit && hit.transform.gameObject.tag.Equals(TARGET_TAG))
        {
            // Get a reference to this question tile
            QuestionTile tile = hit.transform.GetComponent <QuestionTile>();

            // If non-static and not occupied, slot this value
            if (!tile.IsStatic() && !tile.IsSlotted())
            {
                transform.position = tile.transform.position;
                tile.SlotValue(GetValue());
            }
        }
    }
    // Events -------------------------------------------------------------

    public void OnBeginDrag(PointerEventData eventData)
    {
        if (!m_Draggable)
        {
            return;
        }

        // Play sound
        QuestionCanvas.GetInstance().PlayTickSound();

        // Get offset
        m_CurrentOffset = transform.position - Input.mousePosition;

        // Temporarely move object
        Vector3 tempPosition = m_CurrentOffset + Input.mousePosition;

        transform.position = m_InitialLocation;

        // Determine if there was a tile underneath
        RaycastHit2D hit = Physics2D.Raycast(Input.mousePosition, Vector3.forward, 10.0f);

        // Check if raycast hit was a non-static question tile
        if (hit && hit.transform.gameObject.tag.Equals(TARGET_TAG))
        {
            // Get a reference to this question tile
            QuestionTile tile = hit.transform.GetComponent <QuestionTile>();

            // Reset the tile
            tile.ResetInstance();
        }

        // Move object back to original position
        transform.position = tempPosition;
    }
 void Start()
 {
     index   = -1;
     boss    = FindObjectOfType <BossQuestions> ();
     qCanvas = FindObjectOfType <QuestionCanvas> ();
     panel   = FindObjectOfType <QuestionPanel> ();
     button1 = GameObject.FindGameObjectWithTag("Choice1");
     button2 = GameObject.FindGameObjectWithTag("Choice2");
     button3 = GameObject.FindGameObjectWithTag("Choice3");
     button4 = GameObject.FindGameObjectWithTag("Choice4");
 }
    // Initialization -----------------------------------------------------

    private void Awake()
    {
        // Singleton setup
        CanvasInstance = this;

        // Retreive references to indivual panels
        Transform progressPanel   = transform.Find("ProgressPanel");
        Transform questionPanel   = transform.Find("QuestionPanel");
        Transform navigationPanel = transform.Find("NavigationPanel");
        Transform dragPanel       = transform.Find("DragPanel");
        Transform finalPanel      = transform.Find("FinalPanel");

        // Init progress panel
        m_PointsValue   = progressPanel.Find("PointsValue").GetComponent <Text>();
        m_ProgressValue = progressPanel.Find("ProgressValue").GetComponent <Text>();
        m_ProgressBar   = progressPanel.Find("ProgressBar").GetComponent <Slider>();

        // Init question panel
        m_QuestionPrompt = questionPanel.Find("QuestionPrompt").GetComponent <QuestionPrompt>();
        m_QuestionBox    = questionPanel.Find("QuestionBox").GetComponent <QuestionBox>();
        m_QuestionText   = questionPanel.Find("QuestionText").GetComponent <Text>();

        // Init navigation panel

        // TODO: Disabled for the sake of demo build v0.52.
        // TODO: Currently, the exit function calls a JS close tab function.
        // TODO: However, it cannot close the tab because it did not open it.
        // TODO: This will remain disabled in scene + code until solution is found.
        //m_ExitButton = navigationPanel.Find("ExitButton").GetComponent<Button>();
        //m_ExitButton.onClick.AddListener(OnExit);
        m_ResetButton = navigationPanel.Find("ResetButton").GetComponent <Button>();
        m_ResetButton.onClick.AddListener(OnReset);
        m_CheckButton = navigationPanel.Find("CheckButton").GetComponent <Button>();
        m_CheckButton.onClick.AddListener(OnCheck);
        m_NextButton = navigationPanel.Find("NextButton").GetComponent <Button>();
        m_NextButton.onClick.AddListener(OnNext);
        m_ConsoleText      = navigationPanel.Find("ConsoleText").GetComponent <Text>();
        m_ConsoleText.text = "";

        // Disable final panel
        m_FinalScore = finalPanel.Find("FinalScoreText").GetComponent <Text>();
        finalPanel.gameObject.SetActive(false);

        // Init drag panel
        m_DraggableObjects = dragPanel.GetComponentsInChildren <DraggableObject>();

        // Init other components
        m_AudioSource = GetComponent <AudioSource>();
        m_QuizHandler = GameObject.Find("QuizHandler").GetComponent <QuizHandler>();
    }
Exemple #5
0
        public void RandomListPasses()
        {
            QuestionCanvas test   = new QuestionCanvas();
            List <int>     random = QuestionCanvas.Shuffle(toRandom);

            for (int i = 0; i < 5; i++)
            {
                if (random != toRandom)
                {
                    break;
                }
            }
            Assert.AreNotEqual(toRandom, random);
        }
    // Use this for initialization
    void Start()
    {
        qCanvas = FindObjectOfType <QuestionCanvas> ();
        panel   = FindObjectOfType <QuestionPanel> ();

        //populate array with relevant objects to show when game is paused
        showIfPaused = GameObject.FindGameObjectsWithTag("WhenPaused");
        foreach (GameObject psed in showIfPaused)
        {
            psed.SetActive(false);
        }

        //populate array with relevant objects to show when game is in play/resumed
        showIfResumed = GameObject.FindGameObjectsWithTag("WhenResumed");
        foreach (GameObject resmd in showIfResumed)
        {
            resmd.SetActive(true);
        }
    }
    // Initialization

    private void Awake()
    {
        m_Canvas = GameObject.Find("QuestionCanvas").GetComponent <QuestionCanvas>();
    }