コード例 #1
0
    /**
     * OnGUI should be called when you want the GUI to update.  This will
     * handle button presses and OnClick actions.
     */
    public override void OnGUI(GameObject gameObject)
    {
        CalculateField();

        // If the pressed timer is reset and the GUI Button is clicked
        if (pressedTimer == 0 && GUI.Button(this.field, this.text, this.guiStyle))
        {
            SoundUtil.getInstance().buttonPlay(gameObject);
            this.isClicked = true;
            Event.current.Use();
        }

        // Are we clicked?
        if (this.isClicked)
        {
            // Increment the timer
            pressedTimer++;

            Texture2D temp = this.guiStyle.normal.background;
            this.guiStyle.normal.background = clickedTexture;

            // Render the clicked texture
            GUI.Button(this.field, this.text, this.guiStyle);

            // Do the associated action if it is defined
            if (this.action != null && pressedTimer == 1)
            {
                this.action();
            }

            // Reset the timer when it hits 100
            if (pressedTimer == 100)
            {
                pressedTimer   = 0;
                this.isClicked = false;
            }

            this.guiStyle.normal.background = temp;
        }

        // Are we pressed?
        if (this.pressed)
        {
            Texture2D temp = this.guiStyle.normal.background;
            this.guiStyle.normal.background = clickedTexture;

            // Render the clicked texture
            GUI.Button(this.field, this.text, this.guiStyle);

            this.guiStyle.normal.background = temp;
        }

        base.OnGUI(gameObject);
    }
コード例 #2
0
    public override void OnGUI(GameObject gameObject)
    {
        // No need to call base
        // base.OnGUI (gameObject);

        Rect parentField = GetParentField();

        float margin = parentField.width * 0.05f;

        for (int i = 0; i < lessons.Count; i++)
        {
            Rect cR        = new Rect(margin, i * (this.buttonHeight + GUILessonList.bufferSize), parentField.width - 2 * margin, this.buttonHeight);
            Rect imageRect = new Rect(
                parentField.width - 2 * margin,
                i * (this.buttonHeight + GUILessonList.bufferSize) + this.buttonHeight * 0.25f,
                this.buttonHeight * 0.5f,
                this.buttonHeight * 0.5f);

            Texture tImage = GUIStyles.GetInstance().COMPLETED_SWATCH;
            Lesson  lesson = lessons[i];
            switch (lesson.GetCompletedness())
            {
            case Lesson.COMPLETEDNESS.COMPLETE:
                tImage = GUIStyles.GetInstance().COMPLETED_SWATCH;
                break;

            case Lesson.COMPLETEDNESS.IN_PROGRESS:
                tImage = GUIStyles.GetInstance().IN_PROGRESS;
                break;

            default:
                tImage = GUIStyles.GetInstance().NOT_COMPLETED;
                break;
            }


            if (GUI.Button(cR, lesson.GetLessonName(), this.guiStyle))
            {
                SoundUtil.getInstance().buttonPlay(gameObject);

                FlowControl.SetLesson(lesson.GetSceneName());
                Application.LoadLevel("Lesson_Loader");
            }

            // TODO show whether completed or not
            GUI.Label(imageRect, tImage);
        }
    }
コード例 #3
0
    bool Touched()
    {
        bool    clickDetected;
        Vector3 touchPosition = Vector3.zero;

        // Detect click and calculate touch position
        if (isTouchDevice)
        {
            clickDetected = (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended);
            if (clickDetected)
            {
                touchPosition = Input.GetTouch(0).position;
            }
        }
        else
        {
            clickDetected = (Input.GetMouseButtonDown(0));
            touchPosition = Input.mousePosition;
        }

        // Detect clicks
        if (clickDetected)
        {
            // Check if the GameObject is clicked by casting a
            // Ray from the main camera to the touched position.
            Ray ray = Camera.main.ScreenPointToRay
                          (touchPosition);
            RaycastHit hit;
            // Cast a ray of distance 100, and check if this
            // collider is hit.
            if (GetComponent <Collider>().Raycast(ray, out hit, 100.0f))
            {
                SoundUtil.getInstance().buttonPlay(gameObject);
                return(true);
            }
        }

        return(false);
    }