示例#1
0
 void Start()
 {
     playerAnimation = playerObj.GetComponent <AnimationStarter>();
     moving          = false;
     startPos        = movmentStick.GetScreenRect().center;
     character       = playerObj.GetComponent <CharacterController>();
 }
示例#2
0
 // Use this for initialization
 void Start()
 {
     m_Parent  = transform.parent.GetComponent <GUITexture> ();
     m_Texture = GetComponent <GUITexture> ();
     m_Width   = m_Texture.GetScreenRect().width;
     m_Height  = m_Texture.GetScreenRect().height;
     SetPosition();
 }
示例#3
0
 public void SetPosition(int column)
 {
     m_Width              = m_Texture.GetScreenRect().width;
     m_Height             = m_Texture.GetScreenRect().height;
     m_HeightOffset       = -m_Height;
     m_WidthOffset        = -m_Parent.GetComponent <GUITexture>().GetScreenRect().width / 2;
     m_WidthOffset       -= m_Number.GetScreenRect().width / 2;
     m_WidthOffset       += 100 + 100 * column;
     m_Texture.pixelInset = new Rect(m_WidthOffset, m_HeightOffset, m_Width, m_Height);
 }
示例#4
0
    protected void OnEnable()
    {
        CreateVirtualAxes();

        // Cache this component at startup instead of looking up every frame	
        gui = GetComponent<GUITexture>();

        if (gui != null)
        {
            // Store the default rect for the gui, so we can snap back to it
            defaultRect = gui.GetScreenRect();

            gui.pixelInset = defaultRect;
            transform.localScale = Vector3.zero;
        }

        transform.position = new Vector3(0.0f, 0.0f, transform.position.z);
        moveStick = true;
       
        TypeSpecificOnEnable();
       
        if (enumeratedJoysticks)
            return;
        // Collect all joysticks in the game, so we can relay finger latching messages
        joysticks = FindObjectsOfType<JoystickAbstract>();
        enumeratedJoysticks = true;
    }
示例#5
0
    // Update is called once per frame
    void Update()
    {
        if ((image.GetScreenRect().Contains(Input.mousePosition) && Input.GetMouseButtonDown(0)) || Input.GetKey(KeyCode.P))
        {
            if (scenename == "Exit")
            {
                PlayerPrefs.DeleteAll();
                Application.Quit();
            }

            GameSaver saver = GetComponent <GameSaver>();
            if (saver != null && scenename != "Test Scene")
            {
                if (saver.player != null)
                {
                    saver.SaveScene();
                }
            }
            if (scenename == "menu_main")
            {
                PlayerPrefs.DeleteAll();
            }
            Application.LoadLevel(scenename);
        }
    }
示例#6
0
    //显示最高分数和当前分数
    public void UpdateScore(float _currentScore)
    {
        //print (_currentScore);
        float _highScore = PlayerPrefs.GetFloat("score", 0);

        if (_currentScore > _highScore)
        {
            _highScore = _currentScore;
        }
        //把最高分数存储本地
        PlayerPrefs.SetFloat("score", _highScore);

        this.currentScore.text = _currentScore + "";
        this.highScore.text    = _highScore + "";

        if (Input.GetMouseButtonDown(0) && GameManager.instance.GameState == GameManager.GAMESTATE_END)
        {
            //屏幕左上角为原点,一个是宽度,一个是高度,形成长方形
            Rect    rect     = start.GetScreenRect();
            Vector3 mousePos = Input.mousePosition;
            if (mousePos.x > rect.x &&
                mousePos.x < (rect.x + rect.width) &&
                mousePos.y > rect.y &&
                mousePos.y < (rect.y + rect.height))
            {
                //这两个都可以重新。但是最好是用manager
                SceneManager.LoadScene("StartScene");
                //Application.LoadLevel(0);
            }
        }
    }
    // Update is called once per frame
    protected override void Update()
    {
        base.Update();


        if (IsCaptured())
        {
            //Enable stats
            ColliderBlock.GetComponent <Collider>().isTrigger    = false;
            ColliderBlock.GetComponent <Rigidbody>().isKinematic = true;
            //ColliderBlock.light.enabled = true;


            //Get the position
            Rect    boardrect   = Board.GetScreenRect(MainCamera);
            Vector3 screenpoint = new Vector3(boardrect.x + (boardrect.width / 2.0f), boardrect.y + (boardrect.height / 2.0f));
            screenpoint.z = 14.0f;

            //Get teh position
            Vector3 position = MainCamera.ScreenToWorldPoint(screenpoint);

            //Set the forward fo the finger.
            ColliderBlock.transform.forward  = MainCamera.transform.forward;
            ColliderBlock.transform.position = position;
            //ColliderBlock.light.transform.position = position;
        }
        else
        {
            //Turn off the stuff
            //ColliderBlock.collider.isTrigger = true;
            //ColliderBlock.rigidbody.isKinematic = true;
            //ColliderBlock.light.enabled = false;
        }
    }
    void Update()
    {
        if (disabled)
        {
            if (disabledTexture != null)
            {
                myGUITexture.texture = disabledTexture;
            }
            return;
        }
        if (!Selected)
        {
            if (myGUITexture.GetScreenRect().Contains(Input.mousePosition))
            {
                // Was left mouse button pressed while howevering over us
                if (Input.GetMouseButtonDown(0))
                {
                    // grow the image
                    myGUITexture.texture = pressedTexture;

                    // send the onbutton message
                    scene.OnButtonSelect(name);
                    Selected = true;

                    // don't allow button to be repressed.
                    if (waitTime > 0.0f)
                    {
                        Invoke("Unselect", waitTime);
                    }
                }
            }
        }
    }
    protected void OnEnable()
    {
        CreateVirtualAxes();

        // Cache this component at startup instead of looking up every frame
        gui = GetComponent <GUITexture>();

        if (gui != null)
        {
            // Store the default rect for the gui, so we can snap back to it
            defaultRect = gui.GetScreenRect();

            gui.pixelInset       = defaultRect;
            transform.localScale = Vector3.zero;
        }

        transform.position = new Vector3(0.0f, 0.0f, transform.position.z);
        moveStick          = true;

        TypeSpecificOnEnable();

        if (enumeratedJoysticks)
        {
            return;
        }
        // Collect all joysticks in the game, so we can relay finger latching messages
        joysticks           = FindObjectsOfType <JoystickAbstract>();
        enumeratedJoysticks = true;
    }
    public void UpdateScore(float nowScore)
    {
        float highScore = PlayerPrefs.GetFloat("score", 0);

        if (nowScore > highScore)
        {
            highScore = nowScore;
        }

        PlayerPrefs.SetFloat("score", highScore);

        this.nowScore.text  = nowScore + "";
        this.highScore.text = highScore + "";

        if (Input.GetMouseButtonDown(0) && GameManager._intance.GameState == GameManager.GAMESTATE_END)
        {
            Rect    rect     = startTexture.GetScreenRect();
            Vector3 mousePos = Input.mousePosition;

            if (mousePos.x > rect.x &&
                mousePos.x < rect.x + rect.width &&
                mousePos.y > rect.y &&
                mousePos.y < rect.y + rect.height
                )
            {
                Application.LoadLevel(0);
            }
        }
    }
示例#11
0
    void Update()
    {
        // set up the proper button aspect
        float   aspect        = Camera.main.aspect;
        Vector3 startingScale = myTransform.localScale;

        startingScale.y        = startingScale.x * aspect;
        myTransform.localScale = startingScale;

        if (!Selected)
        {
            if (myGUITexture.GetScreenRect().Contains(Input.mousePosition))
            {
                // Was left mouse button pressed while howevering over us
                if (Input.GetMouseButtonDown(0))
                {
                    // grow the image
                    myTransform.localScale += hoverVector;

                    // send the onbutton message
                    scene.OnButtonSelect(name);
                    Selected = true;

                    // don't allow button to be repressed.
                    if (waitTime > 0.0f)
                    {
                        Invoke("Unselect", waitTime);
                    }
                }
            }
        }
    }
示例#12
0
 // Use this for initialization
 void Start()
 {
     maxDrillBarWidth = drillProgressbar.GetScreenRect().width;
     //TODO constructor runs everytime on openscene
     mainCamera.transform.LookAt(transform);
     startRound();
     wheel = GameObject.Find("wheel");
 }
示例#13
0
    private void SetPosition()
    {
        if (m_Left)
        {
            m_PixelInsetX = -m_Parent.GetScreenRect().width / 2 - m_Width;
        }
        else
        {
            m_PixelInsetX = m_Parent.GetScreenRect().width / 2;
        }
        m_PixelInsetY = -m_Height / 2;
        GetComponent <GUITexture> ().guiTexture.pixelInset = new Rect(m_PixelInsetX, m_PixelInsetY, m_Width, m_Height);
        Vector3 tempVec = new Vector3();

        tempVec.z = 10;
        m_Texture.transform.position = tempVec;
    }
示例#14
0
    private void SetPosition()
    {
        float TempHeightOffset = 0;
        float TempWidthOffset  = -m_Parent.GetScreenRect().width / 2;

        TempWidthOffset += 100 + (m_MyNumber * 100);
        Vector2 TempVec = new Vector2(TempWidthOffset, TempHeightOffset);

        m_Text.pixelOffset = TempVec;
    }
示例#15
0
 // Update is called once per frame
 void Update()
 {
     Movement();
     if (Input.GetMouseButtonDown(0))
     {
         if (level1 != null && text_level1.GetScreenRect().Contains(Input.mousePosition))
         {
             Debug.Log("Application.loadlevel(insertlevel)");
         }
     }
 }
 // Update is called once per frame
 void Update()
 {
     changePictures();
     changeButtonSet();
     if (Input.GetMouseButtonDown(0))
     {
         if (gTexture.GetScreenRect().Contains(Input.mousePosition))
         {
             playerMovement.directionChange(gameObject.name);
         }
     }
 }
示例#17
0
    void Update()
    {
        if (myGUITexture.GetScreenRect().Contains(Input.mousePosition))
        {
            // Was left mouse button pressed while howevering over us
            if (Input.GetMouseButtonDown(0))
            {
                mainBoardImage.texture = myGUITexture.texture;

                // send the onbutton message
                scene.SetLevelToLoad(name);
            }
        }
    }
示例#18
0
    protected override bool Colliding(VCTouchWrapper tw)
    {
        // hit test against a collider if we have one
        if (_collider != null)
        {
            return(AABBContains(tw.position));
        }

        // otherwise, fall back to a rect hit test on the guiTexture
        Rect r = _colliderGuiTexture.GetScreenRect();

        VCUtils.ScaleRect(ref r, hitRectScale);
        return(r.Contains(tw.position));
    }
示例#19
0
文件: HeightBar.cs 项目: BuDDi/GEA
    // Update is called once per frame
    void OnGUI()
    {
        GUITexture thisGuiTexture = this.gameObject.guiTexture;
        Rect       screenRect     = thisGuiTexture.GetScreenRect();
        //thisGuiTexture.s


        // position for overlay

        // get the right overlay (currentScalingIndex) depending on the current height of the lander and

        // Verhältnis der aktuellen Höhe zur gewählten aktuellen maximal sichtbaren Höhe
        float currentScaling          = scalings [currentScalingIndex];
        float currentMaxVisibleHeight = maxVisibleHeight * currentScaling;
        float relativeArrowYPosition  = (distanceToGround / currentMaxVisibleHeight) * screenRect.height;
        //relativeArrowYPosition += screenRect.height/2;
        //relativeArrowYPosition += 3;

        // position for arrow
        float healthBarBottomY = Screen.height - (this.transform.position.y * Screen.height) - thisGuiTexture.pixelInset.y;

        // is like scaling for the gui texture
        float arrowHeight = 20;
        float yposArrow   = healthBarBottomY - relativeArrowYPosition - (arrowHeight / 2);

        //Debug.Log("currScalingIndex: " + currentScalingIndex.ToString() + "calc YPOS: " + relativeArrowYPosition.ToString() + " ScreenRect: " + screenRect.ToString());
        float xArrow = (this.transform.position.x * Screen.width) + thisGuiTexture.pixelInset.x;
        //Debug.Log("calc yArrow: " + relativeArrowYPosition.ToString() + " calc ypos2: " + yposArrow.ToString() + " Screen height: " + Screen.height.ToString());


        float arrowWidth = 60;

        xArrow = xArrow + (screenRect.width / 2);
        //Debug.Log("calc xArrow: " + xArrow.ToString() + " ScreenWidth: " + Screen.width.ToString());
        //GUI.DrawTexture(new Rect(xArrow, ypos, arrowWidth, 30), arrowTexture);

        //Debug.Log("ScreenRect: " + screenRect.ToString());
        float yposOverlay = healthBarBottomY - screenRect.height + 5;

        //GUI.BeginGroup(screenRect);
        GUI.DrawTexture(new Rect(xArrow, yposOverlay, 25, (screenRect.height * 0.78855f)), scalingOverlays [currentScalingIndex]);
        GUI.DrawTexture(new Rect(xArrow - (arrowWidth / 2), yposArrow, arrowWidth, arrowHeight), arrowTexture);
        //GUI.EndGroup();
        // texture to use
    }
示例#20
0
 void Update()
 {
     timeSinceLastJump += Time.deltaTime;
     for (int i = 0; i < Input.touchCount; i++)
     {
         if (guiTexture.GetScreenRect().Contains(Input.touches[i].position))
         {
             Jump();
         }
     }
     if (Input.GetKeyDown(KeyCode.K))
     {
         Jump();
     }
     if (currentPower > 0)
     {
         DoJump();
     }
 }
示例#21
0
    // Use this for initialization
    void Start()
    {
        texture = GetComponent <GUITexture>();
        Rect size = texture.GetScreenRect();

        switch (scaleType)
        {
        case ScaleType.xFirst:
            size.width  = (Screen.width * screenProportion) - size.width;
            size.height = (Screen.width * screenProportion * yToxRatio) - size.height;
            break;

        case ScaleType.yFirst:
            break;
        }
        size.x             = -size.width / 2;
        size.y             = -size.height / 2;
        texture.pixelInset = size;
    }
示例#22
0
    protected override bool Colliding(VCTouchWrapper tw)
    {
        if (!tw.Active)
        {
            return(false);
        }

        // first try and hitTest against a collider if we have one
        if (_collider != null)
        {
            return(AABBContains(tw.position));
        }

        // otherwise, fall back to a rect hit test on the guiTexture (this is what most people will want)
        Rect r = _movingPartGuiTexture.GetScreenRect();

        VCUtils.ScaleRect(ref r, hitRectScale);
        return(r.Contains(tw.position));
    }
示例#23
0
    // Use this for initialization
    void Start()
    {
        maxAmmo = 10;
        ammo    = maxAmmo;

        maxBarWidth = progressbar.GetScreenRect().width;

        bulletpool = new ArrayList();


        for (int i = 0; i < 10; i++)
        {
            bulletpool.Add(Instantiate(bullet, this.transform.position, this.transform.rotation));
        }

        axelshaft = GameObject.Find("gunaxelshaft");
        antenna   = GameObject.Find("antenna");

        //power up fx
        iTween.RotateBy(axelshaft, new Vector3(0f, 0.03f, 0f), 6f);
        iTween.ColorTo(antenna, new Color(1, 1, 1, 1), 6);
    }
示例#24
0
    protected void Update()
    {
        // Handle mouse input
        if (!MiddleVR.VRClusterMgr.IsClient())
        {
            if (!m_IgnorePhysicalMouseInput)
            {
                Vector2 mouseHit    = new Vector2(0, 0);
                bool    hasMouseHit = false;

                GUITexture guiTexture = gameObject.GetComponent <GUITexture>();

                if (m_MouseInteractionsIn2D && guiTexture != null)
                {
                    // GUITexture mouse input
                    Rect r = guiTexture.GetScreenRect();

                    if (Input.mousePosition.x >= r.x && Input.mousePosition.x < (r.x + r.width) &&
                        Input.mousePosition.y >= r.y && Input.mousePosition.y < (r.y + r.height))
                    {
                        float x = (Input.mousePosition.x - r.x) / r.width;
                        float y = (Input.mousePosition.y - r.y) / r.height;

                        mouseHit    = new Vector2(x, y);
                        hasMouseHit = true;
                    }
                }
                else if (m_MouseInteractionsIn3D && gameObject.GetComponent <Renderer>() != null)
                {
                    // 3D object mouse input
                    mouseHit = GetClosestMouseHit();

                    if (mouseHit.x != -1 && mouseHit.y != -1)
                    {
                        hasMouseHit = true;
                    }
                }

                if (hasMouseHit)
                {
                    bool isMouseButtonPressed = Input.GetMouseButton(0);

                    if (!m_IsVirtualMouseButtonPressed && isMouseButtonPressed)
                    {
                        SetVirtualMousePosition(mouseHit);
                        SetVirtualMouseButtonPressed();
                    }
                    else if (m_IsVirtualMouseButtonPressed && !isMouseButtonPressed)
                    {
                        SetVirtualMouseButtonReleased();
                        SetVirtualMousePosition(mouseHit);
                    }
                    else
                    {
                        SetVirtualMousePosition(mouseHit);
                    }
                }
            }

            m_IgnorePhysicalMouseInput = false;
        }

        // Handle texture update
        if (m_Image.HasChanged())
        {
            using (vrImageFormat format = m_Image.GetImageFormat())
            {
                if ((uint)m_Texture.width != format.GetWidth() || (uint)m_Texture.height != format.GetHeight())
                {
#if VRWEBVIEW_UNITY_FREE
                    m_PixelsHandle.Free();
#endif
                    m_Texture.Resize((int)format.GetWidth(), (int)format.GetHeight());
                    m_Texture.Apply(false, false);
#if VRWEBVIEW_UNITY_FREE
                    m_PixelsHandle.Free();
                    m_Pixels       = m_Texture.GetPixels32(0);
                    m_PixelsHandle = GCHandle.Alloc(m_Pixels, GCHandleType.Pinned);
#else
                    MiddleVR_CancelCopyBufferToTexture(m_NativeTexturePtr);
                    m_NativeTexturePtr = m_Texture.GetNativeTexturePtr();
#endif
                }

                if (format.GetWidth() > 0 && format.GetHeight() > 0)
                {
#if VRWEBVIEW_UNITY_FREE
                    m_Image.GetReadBufferData(m_PixelsHandle.AddrOfPinnedObject());
                    m_Texture.SetPixels32(m_Pixels, 0);
                    m_Texture.Apply(false, false);
#else
                    MiddleVR_AsyncCopyBufferToTexture(m_Image.GetReadBuffer(), m_NativeTexturePtr, format.GetWidth(), format.GetHeight());
                    GL.IssuePluginEvent(MVR_RENDEREVENT_COPYBUFFERSTOTEXTURES);
#endif
                }
            }
        }
    }
示例#25
0
    // Update is called once per frame
    void Update()
    {
        if (IsCompleted())
        {
            image.enabled = false;
        }
        if (image.GetScreenRect().Contains(Input.mousePosition) && Input.GetMouseButtonDown(0))
        {
            string uppKlarade = string.Empty;
            if (QuestTargetName == "Diskontenten")
            {
                uppKlarade = QuestProgress.dissenComp.ToString() + "/" + QuestProgress.dissenMax.ToString();
            }
            if (QuestTargetName == "Frans Suell")
            {
                uppKlarade = uppKlarade = QuestProgress.fransComp.ToString() + "/" + QuestProgress.fransMax.ToString();
            }
            if (QuestTargetName == "Gripen")
            {
                uppKlarade = QuestProgress.gripenComp.ToString() + "/" + QuestProgress.gripenMax.ToString();
            }
            if (QuestTargetName == "Lejonet")
            {
                uppKlarade = QuestProgress.lejonetComp.ToString() + "/" + QuestProgress.lejonetMax.ToString();
            }
            if (QuestTargetName == "Lilla Torg")
            {
                uppKlarade = QuestProgress.lillaTorgComp.ToString() + "/" + QuestProgress.lillaTorgMax.ToString();
            }
            if (QuestTargetName == "Malmö Hus")
            {
                uppKlarade = QuestProgress.slottetComp.ToString() + "/" + QuestProgress.slottetMax.ToString();
            }
            if (QuestTargetName == "Oskar")
            {
                uppKlarade = QuestProgress.oskarComp.ToString() + "/" + QuestProgress.oskarMax.ToString();
            }
            if (QuestTargetName == "Residenten")
            {
                uppKlarade = QuestProgress.residentenComp.ToString() + "/" + QuestProgress.residentenMax.ToString();
            }
            if (QuestTargetName == "St. Gertrud")
            {
                uppKlarade = QuestProgress.gertrudComp.ToString() + "/" + QuestProgress.gertrudMax.ToString();
            }
            if (QuestTargetName == "St. Knut")
            {
                uppKlarade = QuestProgress.knutComp.ToString() + "/" + QuestProgress.knutMax.ToString();
            }
            if (QuestTargetName == "St. Petri Kyrka")
            {
                uppKlarade = QuestProgress.kyrkanComp.ToString() + "/" + QuestProgress.kyrkanMax.ToString();
            }
            if (QuestTargetName == "Svanen")
            {
                uppKlarade = QuestProgress.svanenComp.ToString() + "/" + QuestProgress.svanenMax.ToString();
            }
            if (QuestTargetName == "Claus Mårtensson")
            {
                uppKlarade = QuestProgress.clausComp.ToString() + "/" + QuestProgress.clausMax.ToString();
            }

            DeselectAll();
            isselected    = true;
            image.texture = selected;
            beskrivningsbox.GetComponent <MapText>().SetText(QuestTargetName + " " + uppKlarade);
        }
    }
示例#26
0
    public void makeMeny()
    {
        if (numberofmeny == 0)
        {
            Background                     = new GameObject("BackGround");
            bgTexture                      = (GUITexture)Background.AddComponent(typeof(GUITexture));
            bgTexture.texture              = backgroundTexture;
            bgTexture.transform.position   = new Vector3(0.5f, 0.5f, 0);
            bgTexture.transform.localScale = new Vector3(0.75f, 0.75f, 0);

            Button1                             = new GameObject("Button1");
            button1Texture                      = (GUITexture)Button1.AddComponent(typeof(GUITexture));
            button1Texture.texture              = backgroundTexture;
            button1Texture.transform.position   = new Vector3(0.8f, 0.25f, 1);
            button1Texture.transform.localScale = new Vector3(0.1f, 0.1f, 0);
            rect = new Rect(Button1.transform.position.x, Button1.transform.position.y, 100, 100);
            button1Texture.color = Color.black;

            AnimalPic          = new GameObject("AnimalPic");
            gui_animal_texture = (GUITexture)AnimalPic.AddComponent(typeof(GUITexture));
            gui_animal_texture.transform.position   = new Vector3(0.3f, 0.6f, 1);
            gui_animal_texture.transform.localScale = new Vector3(0.25f, 0.4f, 0);
            gui_animal_texture.texture = backgroundTexture;
            gui_animal_texture.color   = Color.red;

            BuyButton        = new GameObject("BuyButton");
            buyButtonTexture = (GUITexture)BuyButton.AddComponent(typeof(GUITexture));
            buyButtonTexture.transform.position   = new Vector3(0.8f, 0.4f, 1);
            buyButtonTexture.transform.localScale = new Vector3(0.1f, 0.1f, 0);
            buyButtonTexture.texture = backgroundTexture;
            buyButtonTexture.color   = Color.black;

            info     = new GameObject("info");
            infotext = (GUIText)info.AddComponent(typeof(GUIText));
            infotext.transform.position   = new Vector3(0.2f, 0.35f, 1);
            infotext.transform.localScale = new Vector3(0.1f, 0.1f, 0);
            infotext.color = Color.black;
            infotext.text  = string_infotext;

            stats     = new GameObject("stats");
            statstext = (GUIText)stats.AddComponent(typeof(GUIText));
            statstext.transform.position   = new Vector3(0.7f, 0.8f, 1);
            statstext.transform.localScale = new Vector3(0.1f, 0.1f, 0);
            statstext.color = Color.black;
            statstext.text  = string_statstext;

            numberofmeny++;
        }
        if (numberofmeny <= 1)
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (button1Texture.GetScreenRect().Contains(Input.mousePosition))
                {
                    Destroy(Background);
                    Destroy(Button1);
                    Destroy(AnimalPic);
                    Destroy(BuyButton);
                    Destroy(info);
                    Destroy(stats);
                    showMenybool = false;
                    numberofmeny--;
                    Debug.Log("Exit");
                }
                if (buyButtonTexture.GetScreenRect().Contains(Input.mousePosition))
                {
                    Debug.Log("Köpknapp");
                }
            }
        }
    }
示例#27
0
    private void OnEnable()
    {
        // set axes to use
        useX = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyHorizontal);
        useY = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyVertical);

        // create new axes based on axes to use
        if (useX)
        {
            horizontalVirtualAxis = new CrossPlatformInput.VirtualAxis(horizontalAxisName);
        }
        if (useY)
        {
            verticalVirtualAxis = new CrossPlatformInput.VirtualAxis(verticalAxisName);
        }

        // Cache this component at startup instead of looking up every frame
        gui = GetComponent <GUITexture>();

        if (gui != null)
        {
            // Store the default rect for the gui, so we can snap back to it
            defaultRect = gui.GetScreenRect();
        }

        transform.position = new Vector3(0.0f, 0.0f, transform.position.z);
        moveStick          = true;
        if (inputMode == InputMode.TouchPadPositional || inputMode == InputMode.TouchPadRelativePositional || inputMode == InputMode.TouchPadSwipe)
        {
            touchPad         = true;
            getTouchZoneRect = true;
            if (gui == null)
            {
                // no GUI on this object, so no stick to move
                moveStick = false;
            }
            else
            {
                if (touchZone == null)
                {
                    // marked as a touchpad, but no touchzone gui assigned, so this object's
                    // GUI is the touchzone, and no stick to move:
                    touchZone = gui;
                    moveStick = false;
                }
                else
                {
                    // touchpad, plus we have GUI on this object and a separate touchzone,
                    // so we do have a stick to move.
                    moveStick = true;
                }
            }
        }
        else
        {
            touchPad = false;

            // This is an offset for touch input to match with the top left
            // corner of the GUI
            guiTouchOffset.x = defaultRect.width * 0.5f;
            guiTouchOffset.y = defaultRect.height * 0.5f;

            // Cache the center of the GUI, since it doesn't change
            guiCenter.x = defaultRect.x + guiTouchOffset.x;
            guiCenter.y = defaultRect.y + guiTouchOffset.y;

            // Let's build the GUI boundary, so we can clamp joystick movement
            guiBoundary.min.x = defaultRect.x - guiTouchOffset.x;
            guiBoundary.max.x = defaultRect.x + guiTouchOffset.x;
            guiBoundary.min.y = defaultRect.y - guiTouchOffset.y;
            guiBoundary.max.y = defaultRect.y + guiTouchOffset.y;

            moveStick = true;
        }

        if (gui != null)
        {
            gui.pixelInset       = defaultRect;
            transform.localScale = Vector3.zero;
        }
    }
    private void OnEnable()
    {
	
        // set axes to use
		useX = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyHorizontal);
		useY = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyVertical);

        // create new axes based on axes to use
		if (useX) {
			horizontalVirtualAxis = new CrossPlatformInput.VirtualAxis(horizontalAxisName);
		}
		if (useY) {
			verticalVirtualAxis = new CrossPlatformInput.VirtualAxis(verticalAxisName);
		} 

        // Cache this component at startup instead of looking up every frame	
        gui = GetComponent<GUITexture>();

		if (gui != null)
		{
	        // Store the default rect for the gui, so we can snap back to it
			defaultRect = gui.GetScreenRect();
		}

        transform.position = new Vector3(0.0f, 0.0f , transform.position.z);
		moveStick = true;
		if (inputMode == InputMode.TouchPadPositional || inputMode == InputMode.TouchPadRelativePositional || inputMode == InputMode.TouchPadSwipe) {
			touchPad = true;
			getTouchZoneRect = true;
            if (gui == null)
			{
				// no GUI on this object, so no stick to move
				moveStick = false;

			} else {
				if (touchZone == null) {
					// marked as a touchpad, but no touchzone gui assigned, so this object's
					// GUI is the touchzone, and no stick to move:
					touchZone = gui;
					moveStick = false;

				} else {
					// touchpad, plus we have GUI on this object and a separate touchzone,
					// so we do have a stick to move.
					moveStick = true;

				}
			} 

		} else {
			touchPad = false;

            // This is an offset for touch input to match with the top left
            // corner of the GUI
            guiTouchOffset.x = defaultRect.width*0.5f;
            guiTouchOffset.y = defaultRect.height*0.5f;

            // Cache the center of the GUI, since it doesn't change
            guiCenter.x = defaultRect.x + guiTouchOffset.x;
            guiCenter.y = defaultRect.y + guiTouchOffset.y;

            // Let's build the GUI boundary, so we can clamp joystick movement
            guiBoundary.min.x = defaultRect.x - guiTouchOffset.x;
            guiBoundary.max.x = defaultRect.x + guiTouchOffset.x;
            guiBoundary.min.y = defaultRect.y - guiTouchOffset.y;
            guiBoundary.max.y = defaultRect.y + guiTouchOffset.y;

			moveStick = true;
        }

		if (gui != null)
		{
			gui.pixelInset = defaultRect;
			transform.localScale = Vector3.zero;
		}
    }
示例#29
0
 void Start()
 {
     rotating = false;
     startPos = rotationStick.GetScreenRect().center;
 }