Пример #1
0
 void JoinServer(tk2dUIItem clickedUIItem)
 {
     HostData host = clickedUIItem.gameObject.GetComponent<HostDataContainer>().hostData;
     SetPlayerName();
     if (Network.Connect(host) == NetworkConnectionError.NoError)
         Application.LoadLevel("2DGame");
 }
    public static void FixColliderBounds( tk2dUIItem item ) {
        HashSet<Transform> ignoreItems = new HashSet<Transform>( item.editorIgnoreBounds );
        Transform root = item.transform;
        Collider collider = item.GetComponent<Collider>();
        Bounds b = GetRendererBoundsInChildren(root, ignoreItems, root, false);

        foreach (Transform t in item.editorExtraBounds) {
            if (t != null) {
                Bounds b2 = GetRendererBoundsInChildren( root, ignoreItems, t, false );
                if (b2.size != Vector3.zero) {
                    b.Encapsulate(b2);
                }
            }
        }

        BoxCollider boxCollider = collider as BoxCollider;
        if (boxCollider != null) {
            Undo.RegisterUndo(boxCollider, "Fit Collider");
            b.extents = new Vector3(b.extents.x, b.extents.y, boxCollider.extents.z);
            b.center = new Vector3(b.center.x, b.center.y, boxCollider.center.z);
            boxCollider.extents = b.extents;
            boxCollider.center = b.center;
        }

        SphereCollider sphereCollider = collider as SphereCollider;
        if (sphereCollider != null) {
            Undo.RegisterUndo(sphereCollider, "Fit Collider");
            sphereCollider.center = new Vector3(b.center.x, b.center.y, 0);
            sphereCollider.radius = Mathf.Max( b.extents.x, b.extents.y );
        }
    }
Пример #3
0
 void Clicked(tk2dUIItem clickedUIItem)
 {
     if(this.gameObject.name.Equals("Resume")){
         //Debug.Log("Resuming game...");
         pause.pauseGame();
         pause.changeCamera();
     }else if(this.gameObject.name.Equals("Main Menu")){
         //transform.Find("LevelManager").gameObject.GetComponent<LevelManager>().LoadLevelSelect();
         Application.LoadLevel("scene_title_with_level_select");
         pause.pauseGame();
     }else if(this.gameObject.name.Equals("Reset")){
         //int level = transform.Find("LevelManager").gameObject.GetComponent<LevelManager>().GetCurrentLevelNumber();
         Application.LoadLevel(Application.loadedLevelName);
         pause.pauseGame();
     }else if(this.gameObject.name.Equals("Map")){
         if(!mapping){
             mapping = true;
             resume.SetActive(false);
             reset.SetActive(false);
             menu.SetActive(false);
         }else{
             mapping = false;
             resume.SetActive(true);
             reset.SetActive(true);
             menu.SetActive(true);
         }
     }
 }
Пример #4
0
 void Clicked(tk2dUIItem clickedUIItem)
 {
     //if(!fade){
         ////Debug.Log("Clicked:" + clickedUIItem);
         //iTween.MoveTo(this.gameObject, new Vector3( 0.0f,0.0f,-1.3f), 1.5f);
     //}
 }
 private Vector3 CalculateClickWorldPos(tk2dUIItem btn)
 {
     Camera uICameraForControl = tk2dUIManager.Instance.GetUICameraForControl(base.gameObject);
     Vector2 position = btn.Touch.position;
     Vector3 vector2 = uICameraForControl.ScreenToWorldPoint(new Vector3(position.x, position.y, btn.transform.position.z - uICameraForControl.transform.position.z));
     vector2.z = btn.transform.position.z;
     return vector2;
 }
Пример #6
0
    void Start()
    {
        scriptPlayer = GameObject.Find("Monkey").GetComponent<Move>();
        UI_Component = gameObject.AddComponent<tk2dUIItem>();

        // Ajout d'un listener
        UI_Component.OnClick += ClickManager.Instance.ClickOn_Desctructible;
    }
Пример #7
0
    void Clicked(tk2dUIItem clickedUIItem)
    {
        if(transform.tag.Equals("left"))
            wheel.GetComponent<LevelSlide>().ScrollRight();

        if(transform.tag.Equals("right"))
            wheel.GetComponent<LevelSlide>().ScrollLeft();
    }
    int ItemSelected(tk2dUIItem item)
    {
        //Debug.Log(item.transform.Find("WeaponName").GetComponent<tk2dTextMesh>().text);
        int selected = testItemSelected.IndexOf(item.transform.parent);
        Debug.Log(selected);

        ScrollableArea.Value = ((float)selected + 0.5f) * scrollRate;

        selectedItem = selected;
        return selectedItem;
    }
    void levelSelectedClicked(tk2dUIItem item)
    {
        string levelName = item.name;
        Regex regex = new Regex(@"Level[0-9]+");
        Match match = regex.Match (levelName);

        PlayerPrefs.SetInt (ScoreUtils.TOTAL_SCORE, 0);
        PlayerPrefs.SetInt (ScoreUtils.LIVES, ScoreUtils.TOTAL_LIVES);

        Application.LoadLevel ("LevelBase");

        PlayerPrefs.SetString (ScoreUtils.LEVEL_USER_INIT, match.Value);
        PlayerPrefs.SetString (ScoreUtils.CURRENT_LEVEL_USER, match.Value);
    }
Пример #10
0
    void OnClick(tk2dUIItem clickedUIItem)
    {
        /* If clicked center button. */
        if (tiles[selectedLevel] == clickedUIItem.gameObject) {
            /*
             * TODO: Do checking for if the level is available.
             * */
            if (selectedLevel == 0) {
                //iTween.ShakePosition(tiles[selectedLevel], new Vector3(Random.Range(-0.9f, 0.9f), Random.Range(-0.9f, 0.9f), Random.Range(-0.9f, 0.9f)), 2.0f);
                LevelManager.LoadLevel(0);

            }

        }
    }
Пример #11
0
    void OnMuteSFX(tk2dUIItem who)
    {
        if (isSFXMute)
        {
//			print ("SFX Unmute");
            isSFXMute = false;
            who.GetComponent <tk2dSprite> ().spriteId = 0;
            GameObject.Find("tk2dUIAudioManager").GetComponent <AudioSource> ().volume = 1;
        }
        else
        {
//			print("SFX mute");
            isSFXMute = true;
            who.GetComponent <tk2dSprite> ().spriteId = 3;
            GameObject.Find("tk2dUIAudioManager").GetComponent <AudioSource> ().volume = 0;
        }
    }
Пример #12
0
    void OnMuteBGM(tk2dUIItem who)
    {
        if (isBGMMute)
        {
//			print ("BGM Unmute");
            isBGMMute = false;
            who.GetComponent <tk2dSprite> ().spriteId = 0;
            GameObject.Find("GameBGM").GetComponent <AudioSource> ().volume = 1;
        }
        else
        {
//			print("BGM mute");
            isBGMMute = true;
            who.GetComponent <tk2dSprite> ().spriteId = 3;
            GameObject.Find("GameBGM").GetComponent <AudioSource> ().volume = 0;
        }
    }
Пример #13
0
    //public void btnHomNay_OnClick()
    //{
    //setData ();
    //}


    // Use this for initialization
    void Start()
    {
        try
        {
            startPosition      = this.transform.position;
            TraTrai            = this.gameObject.transform.GetChild(0).transform;
            TraGiua            = this.gameObject.transform.GetChild(1).transform;
            TraPhai            = this.gameObject.transform.GetChild(2).transform;
            btnHomNay          = TraGiua.GetChild(0).GetChild(3).GetComponent <tk2dUIItem> ();
            btnHomNay.OnClick += setData;
            today              = DateTime.Now;
        }
        catch (System.Exception)
        {
            throw;
        }
    }
 public bool CheckIsUIItemChildOfMe(tk2dUIItem uiItem)
 {
     tk2dUIItem parentUIItem = null;
     if (uiItem != null)
     {
         parentUIItem = uiItem.parentUIItem;
     }
     while (parentUIItem != null)
     {
         if (parentUIItem == this)
         {
             return true;
         }
         parentUIItem = parentUIItem.parentUIItem;
     }
     return false;
 }
Пример #15
0
    //checks through hierarchy to find UIItem at this level or above to be used in inspector field
    public static tk2dUIItem FindAppropriateButtonInHierarchy(GameObject go)
    {
        tk2dUIItem btn = null;

        while (go != null)
        {
            btn = go.GetComponent <tk2dUIItem>();
            if (btn != null)
            {
                break;
            }

            go = go.transform.parent.gameObject;
        }

        return(btn);
    }
Пример #16
0
    public static void FixColliderBounds(tk2dUIItem item)
    {
        HashSet <Transform> ignoreItems = new HashSet <Transform>(item.editorIgnoreBounds);
        Transform           root        = item.transform;

                        #if UNITY_5
        Collider collider = item.GetComponent <Collider>();
                        #else
        Collider collider = item.collider;
                        #endif

        Bounds b = GetRendererBoundsInChildren(root, ignoreItems, root, false);

        foreach (Transform t in item.editorExtraBounds)
        {
            if (t != null)
            {
                Bounds b2 = GetRendererBoundsInChildren(root, ignoreItems, t, false);
                if (b2.size != Vector3.zero)
                {
                    b.Encapsulate(b2);
                }
            }
        }

        BoxCollider boxCollider = collider as BoxCollider;
        if (boxCollider != null)
        {
            tk2dUndo.RecordObject(boxCollider, "Fit Collider");
            b.size             = new Vector3(b.size.x, b.size.y, boxCollider.size.z);
            b.center           = new Vector3(b.center.x, b.center.y, boxCollider.center.z);
            boxCollider.size   = b.size;
            boxCollider.center = b.center;
        }

        SphereCollider sphereCollider = collider as SphereCollider;
        if (sphereCollider != null)
        {
            tk2dUndo.RecordObject(sphereCollider, "Fit Collider");
            sphereCollider.center = new Vector3(b.center.x, b.center.y, 0);
            sphereCollider.radius = 0.5f * Mathf.Max(b.size.x, b.size.y);
        }
    }
Пример #17
0
    void Handle_GameRank()
    {
        if (go_Rank == null)
        {
            go_Rank = Instantiate(Prefab_Rank) as GameObject;

            EvtR               += RankShow;
            Light               = go_Rank.transform.Find("back2").GetComponent <tk2dSprite>();
            ChangeName          = go_Rank.transform.Find("button/改名").GetComponent <tk2dUIItem>();
            ChangeName.OnClick += SettingName;
            // Debug.Log("订阅");
            Light.transform.localPosition = new Vector3(-26, -167, -103);
            go_Rank.transform.Find("button/fanhui").GetComponent <tk2dUIItem>().OnClick += Rank_BackClick;
        }
        else
        {
            go_Rank.SetActive(true);
        }
    }
Пример #18
0
    void OnClick(tk2dUIItem clickedUIItem)
    {
        /* If clicked center button. */
        if (tiles[selectedLevel] == clickedUIItem.gameObject) {
            /*
             * TODO: Do checking for if the level is available.
             * */

            //iTween.ShakePosition(tiles[selectedLevel], new Vector3(Random.Range(-0.9f, 0.9f), Random.Range(-0.9f, 0.9f), Random.Range(-0.9f, 0.9f)), 2.0f);

            Application.LoadLevel("level_select_group_" + selectedLevel);
            //Debug.Log("Loading:	level_select_group_" + selectedLevel);
        //				foreach (GameObject tile in tiles)
        //					tile.SetActive(false);
        //				transform.FindChild("LeftButton").gameObject.SetActive(false);
        //				transform.FindChild("RightButton").gameObject.SetActive(false);
                transform.gameObject.SetActive(false);
        }
    }
Пример #19
0
    /// <summary>

    /// Hover out item.

    /// Only call manually if you need to simulate touch.

    /// </summary>

    public void HoverOut(tk2dUIItem currHoverButton)

    {
        if (isHoverOver)

        {
            if (OnHoverOut != null)
            {
                OnHoverOut();
            }

            if (OnHoverOutUIItem != null)
            {
                OnHoverOutUIItem(this);
            }

            isHoverOver = false;
        }



        if (parentUIItem != null && parentUIItem.isHoverEnabled)

        {
            if (currHoverButton == null)

            {
                parentUIItem.HoverOut(currHoverButton);
            }

            else

            {
                if (!parentUIItem.CheckIsUIItemChildOfMe(currHoverButton) && currHoverButton != parentUIItem)

                {
                    parentUIItem.HoverOut(currHoverButton);
                }
            }
        }
    }
 public void CurrentOverUIItem(tk2dUIItem overUIItem)
 {
     if (overUIItem != this)
     {
         if (this.isPressed)
         {
             if (!this.CheckIsUIItemChildOfMe(overUIItem))
             {
                 this.Exit();
                 if (this.parentUIItem != null)
                 {
                     this.parentUIItem.CurrentOverUIItem(overUIItem);
                 }
             }
         }
         else if (this.parentUIItem != null)
         {
             this.parentUIItem.CurrentOverUIItem(overUIItem);
         }
     }
 }
Пример #21
0
    public void OverrideClearAllChildrenPresses(tk2dUIItem item)

    {
        if (useMultiTouch)

        {
            tk2dUIItem tempUIItem;

            for (int n = 0; n < pressedUIItems.Length; n++)

            {
                tempUIItem = pressedUIItems[n];

                if (tempUIItem != null)

                {
                    if (item.CheckIsUIItemChildOfMe(tempUIItem))

                    {
                        tempUIItem.CurrentOverUIItem(item);
                    }
                }
            }
        }

        else

        {
            if (pressedUIItem != null)

            {
                if (item.CheckIsUIItemChildOfMe(pressedUIItem))

                {
                    pressedUIItem.CurrentOverUIItem(item);
                }
            }
        }
    }
Пример #22
0
    /// <summary>
    /// Is uiItem a child of this current tk2dUIItem
    /// Only call manually if you need to simulate touch.
    /// </summary>
    public bool CheckIsUIItemChildOfMe(tk2dUIItem uiItem)
    {
        tk2dUIItem nextUIItem = null;
        bool       result     = false;

        if (uiItem != null)
        {
            nextUIItem = uiItem.parentUIItem;
        }

        while (nextUIItem != null)
        {
            if (nextUIItem == this)
            {
                result = true;
                break;
            }
            nextUIItem = nextUIItem.parentUIItem;
        }

        return(result);
    }
    public static void FixColliderBounds(tk2dUIItem item)
    {
        HashSet <Transform> ignoreItems = new HashSet <Transform>(item.editorIgnoreBounds);
        Transform           root        = item.transform;
        Collider            collider    = item.GetComponent <Collider>();
        Bounds b = GetRendererBoundsInChildren(root, ignoreItems, root, false);

        foreach (Transform t in item.editorExtraBounds)
        {
            if (t != null)
            {
                Bounds b2 = GetRendererBoundsInChildren(root, ignoreItems, t, false);
                if (b2.size != Vector3.zero)
                {
                    b.Encapsulate(b2);
                }
            }
        }

        BoxCollider boxCollider = collider as BoxCollider;

        if (boxCollider != null)
        {
            Undo.RegisterUndo(boxCollider, "Fit Collider");
            b.extents           = new Vector3(b.extents.x, b.extents.y, boxCollider.extents.z);
            b.center            = new Vector3(b.center.x, b.center.y, boxCollider.center.z);
            boxCollider.extents = b.extents;
            boxCollider.center  = b.center;
        }

        SphereCollider sphereCollider = collider as SphereCollider;

        if (sphereCollider != null)
        {
            Undo.RegisterUndo(sphereCollider, "Fit Collider");
            sphereCollider.center = new Vector3(b.center.x, b.center.y, 0);
            sphereCollider.radius = Mathf.Max(b.extents.x, b.extents.y);
        }
    }
Пример #24
0
    /// <summary>
    /// Touch press down (only call manually, if you need to simulate a touch). SentFromChild is the UIItem child it was sent from. If sentFromChild is
    /// null that means it wasn't sent from a child
    /// </summary>
    /// /// <value>
    /// return true if newly pressed
    /// </value>
    public bool Press(tk2dUITouch touch, tk2dUIItem sentFromChild) //pressed down ontop of button
    {
        if (isPressed)
        {
            return(false); //already pressed
        }
        if (!isPressed)
        {
            this.touch = touch;
            //if orginal press (not sent from child), or resgieterPressFromChildren is enabled
            if (registerPressFromChildren || sentFromChild == null)
            {
                if (enabled)
                {
                    isPressed = true;

                    if (OnDown != null)
                    {
                        OnDown();
                    }
                    if (OnDownUIItem != null)
                    {
                        OnDownUIItem(this);
                    }
                    if (SendMessageOnDownMethodName != "" && sendMessageTarget != null)
                    {
                        sendMessageTarget.SendMessage(SendMessageOnDownMethodName, SendMessageOptions.RequireReceiver);
                    }
                }
            }

            if (parentUIItem != null)
            {
                parentUIItem.Press(touch, this);
            }
        }
        return(true); //newly touched
    }
Пример #25
0
    //
    // Ranking
    //
    void RankPressed(tk2dUIItem pressed)
    {
        planet.gameObject.SetActive(false);
        arrow.gameObject.SetActive(false);
        nameSprite.gameObject.SetActive(false);
        Ranking.gameObject.SetActive(true);
        inRanking = true;
        switch (pressed.name)
        {
        case "RankSpriteAdd":
            // Call Add Ranking
            rank.gameObject.SetActive(true);
            Ranking.FindChild("RankingSpriteAdd").gameObject.SetActive(true);
            rank.gameObject.GetComponent <RankControl> ().LoadScore("Add");
            break;

        case "RankSpriteSub":
            // Call Sub Ranking
            rank.gameObject.SetActive(true);
            Ranking.FindChild("RankingSpriteSub").gameObject.SetActive(true);
            rank.gameObject.GetComponent <RankControl> ().LoadScore("Sub");
            break;

        case "RankSpriteDiv":
            // Call Div Ranking
            rank.gameObject.SetActive(true);
            Ranking.FindChild("RankingSpriteDiv").gameObject.SetActive(true);
            rank.gameObject.GetComponent <RankControl> ().LoadScore("Div");
            break;

        default:
            //Debug, suppose no excute
            print(pressed.name);
            Debug.LogError("Unable locate Ranking pressed");
            break;
        }
    }
Пример #26
0
    /// <summary>
    /// Hover over item. Return true if this was prevHover.
    /// Only call manually if you need to simulate touch.
    /// </summary>
    public bool HoverOver(tk2dUIItem prevHover)
    {
        bool       wasPrevHoverFound = false;
        tk2dUIItem nextUIItem        = null;

        if (!isHoverOver)
        {
            if (OnHoverOver != null)
            {
                OnHoverOver();
            }
            if (OnHoverOverUIItem != null)
            {
                OnHoverOverUIItem(this);
            }
            isHoverOver = true;
        }

        if (prevHover == this)
        {
            wasPrevHoverFound = true;
        }

        if (parentUIItem != null && parentUIItem.isHoverEnabled)
        {
            nextUIItem = parentUIItem;
        }

        if (nextUIItem == null)
        {
            return(wasPrevHoverFound);
        }
        else
        {
            return(nextUIItem.HoverOver(prevHover) || wasPrevHoverFound); //will return true once found
        }
    }
Пример #27
0
    /// <summary>

    /// Touch/mouse currently over UIItem. If exitting this button, but still overtop of another Button, this might be a parent. Checks if parent and

    /// does not exit.

    /// Only call manually if you need to simulate touch.

    /// </summary>

    public void CurrentOverUIItem(tk2dUIItem overUIItem)

    {
        if (overUIItem != this)

        {
            if (isPressed)

            {
                //check if overButton is child

                bool isUIItemChild = CheckIsUIItemChildOfMe(overUIItem);

                if (!isUIItemChild)

                {
                    Exit();

                    if (parentUIItem != null)

                    {
                        parentUIItem.CurrentOverUIItem(overUIItem);
                    }
                }
            }

            else

            {
                if (parentUIItem != null)

                {
                    parentUIItem.CurrentOverUIItem(overUIItem);
                }
            }
        }
    }
Пример #28
0
 //if you change the parent, call this, if isChild is false, will act as if it is true
 /// <summary>
 /// If you change the parent (in hierarchy) call this. If isChildOfAnotherUIItem is false, will act as if it is true
 /// </summary>
 public void UpdateParent()
 {
     parentUIItem = GetParentUIItem();
 }
Пример #29
0
 public void ForceUIItem(tk2dUIItem item)
 {
     forcedUIItem = item;
 }
Пример #30
0
 //if you change the parent, call this, if isChild is false, will act as if it is true
 /// <summary>
 /// If you change the parent (in hierarchy) call this. If isChildOfAnotherUIItem is false, will act as if it is true
 /// </summary>
 public void UpdateParent()
 {
     parentUIItem = GetParentUIItem();
 }
Пример #31
0
    //checks for inputs (non-multi-touch)
    private void CheckInputs()
    {
        bool isPrimaryTouchFound     = false;
        bool isSecondaryTouchFound   = false;
        bool isAnyPressBeganRecorded = false;

        primaryTouch   = new tk2dUITouch();
        secondaryTouch = new tk2dUITouch();
        resultTouch    = new tk2dUITouch();
        hitUIItem      = null;

        if (inputEnabled)
        {
            if (Input.touchCount > 0)
            {
                foreach (Touch touch in Input.touches)
                {
                    if (touch.phase == TouchPhase.Began)
                    {
                        primaryTouch            = new tk2dUITouch(touch);
                        isPrimaryTouchFound     = true;
                        isAnyPressBeganRecorded = true;
                    }
                    else if (pressedUIItem != null && touch.fingerId == firstPressedUIItemTouch.fingerId)
                    {
                        secondaryTouch        = new tk2dUITouch(touch);
                        isSecondaryTouchFound = true;
                    }
                }

                checkForHovers = false;
            }
            else
            {
                if (Input.GetMouseButtonDown(0))
                {
                    primaryTouch            = new tk2dUITouch(TouchPhase.Began, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, Vector2.zero, 0);
                    isPrimaryTouchFound     = true;
                    isAnyPressBeganRecorded = true;
                }
                else if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0))
                {
                    Vector2    deltaPosition = Vector2.zero;
                    TouchPhase mousePhase    = TouchPhase.Moved;
                    if (pressedUIItem != null)
                    {
                        deltaPosition = firstPressedUIItemTouch.position - new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                    }

                    if (Input.GetMouseButtonUp(0))
                    {
                        mousePhase = TouchPhase.Ended;
                    }
                    else if (deltaPosition == Vector2.zero)
                    {
                        mousePhase = TouchPhase.Stationary;
                    }
                    secondaryTouch        = new tk2dUITouch(mousePhase, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, deltaPosition, tk2dUITime.deltaTime);
                    isSecondaryTouchFound = true;
                }
            }
        }

        if (isPrimaryTouchFound)
        {
            resultTouch = primaryTouch;
        }
        else if (isSecondaryTouchFound)
        {
            resultTouch = secondaryTouch;
        }

        if (isPrimaryTouchFound || isSecondaryTouchFound) //focus touch found
        {
            hitUIItem = RaycastForUIItem(resultTouch.position);

            if (resultTouch.phase == TouchPhase.Began)
            {
                if (pressedUIItem != null)
                {
                    pressedUIItem.CurrentOverUIItem(hitUIItem);
                    if (pressedUIItem != hitUIItem)
                    {
                        pressedUIItem.Release();
                        pressedUIItem = null;
                    }
                    else
                    {
                        firstPressedUIItemTouch = resultTouch; //just incase touch changed
                    }
                }

                if (hitUIItem != null)
                {
                    hitUIItem.Press(resultTouch);
                }
                pressedUIItem           = hitUIItem;
                firstPressedUIItemTouch = resultTouch;
            }
            else if (resultTouch.phase == TouchPhase.Ended)
            {
                if (pressedUIItem != null)
                {
                    pressedUIItem.CurrentOverUIItem(hitUIItem);
                    pressedUIItem.UpdateTouch(resultTouch);
                    pressedUIItem.Release();
                    pressedUIItem = null;
                }
            }
            else
            {
                if (pressedUIItem != null)
                {
                    pressedUIItem.CurrentOverUIItem(hitUIItem);
                    pressedUIItem.UpdateTouch(resultTouch);
                }
            }
        }
        else //no touches found
        {
            if (pressedUIItem != null)
            {
                pressedUIItem.CurrentOverUIItem(null);
                pressedUIItem.Release();
                pressedUIItem = null;
            }
        }

        //only if hover events are enabled and only if no touch events have ever been recorded
        if (checkForHovers)
        {
            if (inputEnabled)                                                                                        //if input enabled and mouse button is not currently down
            {
                if (!isPrimaryTouchFound && !isSecondaryTouchFound && hitUIItem == null && !Input.GetMouseButton(0)) //if raycast for a button has not yet been done
                {
                    hitUIItem = RaycastForUIItem(Input.mousePosition);
                }
                else if (Input.GetMouseButton(0)) //if mouse button is down clear it
                {
                    hitUIItem = null;
                }
            }

            if (hitUIItem != null)
            {
                if (hitUIItem.isHoverEnabled)
                {
                    bool wasPrevOverFound = hitUIItem.HoverOver(overUIItem);

                    if (!wasPrevOverFound && overUIItem != null)
                    {
                        overUIItem.HoverOut(hitUIItem);
                    }
                    overUIItem = hitUIItem;
                }
                else
                {
                    if (overUIItem != null)
                    {
                        overUIItem.HoverOut(null);
                    }
                }
            }
            else
            {
                if (overUIItem != null)
                {
                    overUIItem.HoverOut(null);
                }
            }
        }

        if (isAnyPressBeganRecorded)
        {
            if (OnAnyPress != null)
            {
                OnAnyPress();
            }
        }
    }
Пример #32
0
    /// <summary>
    /// Hover out item.
    /// Only call manually if you need to simulate touch.
    /// </summary>
    public void HoverOut(tk2dUIItem currHoverButton)
    {
        if (isHoverOver)
        {
            if (OnHoverOut != null) { OnHoverOut(); }
            if (OnHoverOutUIItem != null) { OnHoverOutUIItem(this); }
            isHoverOver = false;
        }

        if (parentUIItem != null && parentUIItem.isHoverEnabled)
        {
            if (currHoverButton == null)
            {
                parentUIItem.HoverOut(currHoverButton);
            }
            else
            {
                if (!parentUIItem.CheckIsUIItemChildOfMe(currHoverButton) && currHoverButton != parentUIItem)
                {
                    parentUIItem.HoverOut(currHoverButton);
                }
            }
        }

    }
Пример #33
0
    /// <summary>
    /// Is uiItem a child of this current tk2dUIItem
    /// Only call manually if you need to simulate touch.
    /// </summary>
    public bool CheckIsUIItemChildOfMe(tk2dUIItem uiItem)
    {
        tk2dUIItem nextUIItem = null;
        bool result = false;

        if (uiItem != null)
        {
            nextUIItem = uiItem.parentUIItem;
        }

        while (nextUIItem != null)
        {
            if (nextUIItem == this)
            {
                result = true;
                break;
            }
            nextUIItem = nextUIItem.parentUIItem;
        }

        return result;
    }
Пример #34
0
    /// <summary>
    /// Touch press down (only call manually, if you need to simulate a touch). SentFromChild is the UIItem child it was sent from. If sentFromChild is 
    /// null that means it wasn't sent from a child
    /// </summary>
    /// /// <value>
    /// return true if newly pressed
    /// </value>
    public bool Press(tk2dUITouch touch, tk2dUIItem sentFromChild) //pressed down ontop of button
    {
        if (isPressed)
        {
            return false; //already pressed
        }
        if (!isPressed)
        {
            this.touch = touch;
            //if orginal press (not sent from child), or resgieterPressFromChildren is enabled
            if (registerPressFromChildren || sentFromChild == null)
            {
                if (enabled)
                {
                    isPressed = true;

                    if (OnDown != null) { OnDown(); }
                    if (OnDownUIItem != null) { OnDownUIItem(this); }
                    if (SendMessageOnDownMethodName != "" && sendMessageTarget!=null) { sendMessageTarget.SendMessage(SendMessageOnDownMethodName, SendMessageOptions.RequireReceiver); }
                }
            }

            if (parentUIItem != null)
            {
                parentUIItem.Press(touch, this);
            }
        }
        return true; //newly touched
    }
Пример #35
0
    //checks for inputs (non-multi-touch)
    private void CheckInputs()
    {
        bool isPrimaryTouchFound = false;
        bool isSecondaryTouchFound = false;
        bool isAnyPressBeganRecorded = false;
        primaryTouch = new tk2dUITouch();
        secondaryTouch = new tk2dUITouch();
        resultTouch = new tk2dUITouch();
        hitUIItem = null;

        if (inputEnabled)
        {
            if (Input.touchCount > 0)
            {
                foreach (Touch touch in Input.touches)
                {
                    if (touch.phase == TouchPhase.Began)
                    {
                        primaryTouch = new tk2dUITouch(touch);
                        isPrimaryTouchFound = true;
                        isAnyPressBeganRecorded = true;
                    }
                    else if (pressedUIItem != null && touch.fingerId == firstPressedUIItemTouch.fingerId)
                    {
                        secondaryTouch = new tk2dUITouch(touch);
                        isSecondaryTouchFound = true;
                    }
                }

                checkForHovers = false;

            }
            else
            {
                if (Input.GetMouseButtonDown(0))
                {
                    primaryTouch = new tk2dUITouch(TouchPhase.Began, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, Vector2.zero, 0);
                    isPrimaryTouchFound = true;
                    isAnyPressBeganRecorded = true;
                }
                else if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0))
                {
                    Vector2 deltaPosition = Vector2.zero;
                    TouchPhase mousePhase = TouchPhase.Moved;
                    if (pressedUIItem != null)
                    {
                        deltaPosition = firstPressedUIItemTouch.position - new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                    }

                    if (Input.GetMouseButtonUp(0))
                    {
                        mousePhase = TouchPhase.Ended;
                    }
                    else if (deltaPosition == Vector2.zero)
                    {
                        mousePhase = TouchPhase.Stationary;
                    }
                    secondaryTouch = new tk2dUITouch(mousePhase, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, deltaPosition, tk2dUITime.deltaTime);
                    isSecondaryTouchFound = true;
                }
            }
        }

        if (isPrimaryTouchFound)
        {
            resultTouch = primaryTouch;
        }
        else if (isSecondaryTouchFound)
        {
            resultTouch = secondaryTouch;
        }

        if (isPrimaryTouchFound || isSecondaryTouchFound) //focus touch found
        {
            hitUIItem = RaycastForUIItem(resultTouch.position);

            if (resultTouch.phase == TouchPhase.Began)
            {
                if (pressedUIItem != null)
                {
                    pressedUIItem.CurrentOverUIItem(hitUIItem);
                    if (pressedUIItem != hitUIItem)
                    {
                        pressedUIItem.Release();
                        pressedUIItem = null;
                    }
                    else
                    {
                        firstPressedUIItemTouch = resultTouch; //just incase touch changed
                    }
                }

                if (hitUIItem != null)
                {
                    hitUIItem.Press(resultTouch);
                }
                pressedUIItem = hitUIItem;
                firstPressedUIItemTouch = resultTouch;
            }
            else if (resultTouch.phase == TouchPhase.Ended)
            {
                if (pressedUIItem != null)
                {
                    pressedUIItem.CurrentOverUIItem(hitUIItem);
                    pressedUIItem.UpdateTouch(resultTouch);
                    pressedUIItem.Release();
                    pressedUIItem = null;
                }
            }
            else
            {
                if (pressedUIItem != null)
                {
                    pressedUIItem.CurrentOverUIItem(hitUIItem);
                    pressedUIItem.UpdateTouch(resultTouch);
                }
            }
        }
        else //no touches found
        {
            if (pressedUIItem != null)
            {
                pressedUIItem.CurrentOverUIItem(null);
                pressedUIItem.Release();
                pressedUIItem = null;
            }
        }

        //only if hover events are enabled and only if no touch events have ever been recorded
        if (checkForHovers)
        {
            if (inputEnabled) //if input enabled and mouse button is not currently down
            {
                if (!isPrimaryTouchFound && !isSecondaryTouchFound && hitUIItem == null && !Input.GetMouseButton(0)) //if raycast for a button has not yet been done
                {
                    hitUIItem = RaycastForUIItem( Input.mousePosition );
                }
                else if (Input.GetMouseButton(0)) //if mouse button is down clear it
                {
                    hitUIItem = null;
                }
            }

            if (hitUIItem != null)
            {
                if (hitUIItem.isHoverEnabled)
                {
                    bool wasPrevOverFound = hitUIItem.HoverOver(overUIItem);

                    if (!wasPrevOverFound && overUIItem != null)
                    {
                        overUIItem.HoverOut(hitUIItem);
                    }
                    overUIItem = hitUIItem;
                }
                else
                {
                    if (overUIItem != null)
                    {
                        overUIItem.HoverOut(null);
                    }
                }
            }
            else
            {
                if (overUIItem != null)
                {
                    overUIItem.HoverOut(null);
                }
            }
        }

        if (isAnyPressBeganRecorded)
        {
            if (OnAnyPress != null) { OnAnyPress(); }
        }
    }
Пример #36
0
 public void OnClickTranferBtn(tk2dUIItem item)
 {
     FireEvent(item.triggerEventName);
 }
    //checks for inputs (multi-touch)
    private bool CheckMultiTouchInputs()
    {
        bool claimTouches            = false;
        bool isAnyPressBeganRecorded = false;
        int  prevFingerID            = -1;
        bool wasPrevTouchFound       = false;
        bool isNewlyPressed          = false;

        touchCounter = 0;
        if (IsEnabledInputTouches)
        {
            if (Input.touchCount > 0)
            {
                foreach (Touch touch in Input.touches)
                {
                    if (touchCounter < MAX_MULTI_TOUCH_COUNT)
                    {
                        allTouches[touchCounter] = new tk2dUITouch(touch);
                        touchCounter++;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                if (Input.GetMouseButtonDown(0))
                {
                    allTouches[touchCounter] = new tk2dUITouch(TouchPhase.Began, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, Vector2.zero, 0);
                    mouseDownFirstPos        = Input.mousePosition;
                    touchCounter++;
                }
                else if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0))
                {
                    Vector2    deltaPosition = mouseDownFirstPos - new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                    TouchPhase mousePhase    = TouchPhase.Moved;

                    if (Input.GetMouseButtonUp(0))
                    {
                        mousePhase = TouchPhase.Ended;
                    }
                    else if (deltaPosition == Vector2.zero)
                    {
                        mousePhase = TouchPhase.Stationary;
                    }
                    allTouches[touchCounter] = new tk2dUITouch(mousePhase, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, deltaPosition, tk2dUITime.deltaTime);
                    touchCounter++;
                }
            }
        }

        for (int p = 0; p < touchCounter; p++)
        {
            tk2dUITouch touch = allTouches[p];

            pressedUIItems[p] = RaycastForUIItem(touch.position);
        }

        //deals with all the previous presses

        for (int f = prevPressedUIItemList.Count - 1; f >= 0; f--)
        {
            tk2dUIItem prevPressedItem = prevPressedUIItemList[f];


            if ((prevPressedItem != null) && (prevPressedItem.isActiveAndEnabled))
            {
                prevFingerID = prevPressedItem.Touch.fingerId;

                wasPrevTouchFound = false;

                for (int t = 0; t < touchCounter; t++)
                {
                    currTouch = allTouches[t];

                    if (currTouch.fingerId == prevFingerID)
                    {
                        wasPrevTouchFound = true;
                        currPressedItem   = pressedUIItems[t];

                        if (currPressedItem != null && currPressedItem.isActiveAndEnabled && prevPressedItem != null)
                        {
                            /*if (currTouch.phase == TouchPhase.Began)
                             * {
                             *      prevPressedItem.CurrentOverUIItem(currPressedItem);
                             *
                             *      if (prevPressedItem != currPressedItem)
                             *      {
                             *              prevPressedItem.Release();
                             *
                             *                      temp.Add(prevPressedItem);
                             * //									if (prevPressedUIItemList.Contains(prevPressedItem))
                             * //									{
                             * //										prevPressedUIItemList.Remove(prevPressedItem);
                             * //									}
                             * //									prevPressedItem = null;
                             *
                             *                      if (touchCounter > 1)
                             *                      {
                             *                              CustomDebug.Log("Began!");
                             *                      }
                             *      }
                             * }
                             * else */if (currTouch.phase == TouchPhase.Ended)
                            {
                                prevPressedItem.CurrentOverUIItem(currPressedItem);
                                prevPressedItem.UpdateTouch(currTouch);
                                prevPressedItem.Release();

                                if (prevPressedUIItemList.Contains(prevPressedItem))
                                {
                                    prevPressedUIItemList.Remove(prevPressedItem);
                                }
//								prevPressedItem = null;
                            }
                            else if (currTouch.phase == TouchPhase.Canceled)
                            {
                                prevPressedItem.CurrentOverUIItem(currPressedItem);
                                prevPressedItem.UpdateTouch(currTouch);
                                prevPressedItem.Release();

                                if (prevPressedUIItemList.Contains(prevPressedItem))
                                {
                                    prevPressedUIItemList.Remove(prevPressedItem);
                                }
//								prevPressedItem = null;
                            }
                            else
                            {
                                prevPressedItem.CurrentOverUIItem(currPressedItem);
                                prevPressedItem.UpdateTouch(currTouch);
                            }
                        }
                        break;
                    }
                }

                if (!wasPrevTouchFound && (prevPressedItem != null))
                {
                    prevPressedItem.CurrentOverUIItem(null);
                    prevPressedItem.Release();

                    if (prevPressedUIItemList.Contains(prevPressedItem))
                    {
                        prevPressedUIItemList.Remove(prevPressedItem);
                    }
                }
            }
            else
            {
                prevPressedUIItemList.RemoveAt(f);
            }
        }


        for (int f = 0; f < touchCounter; f++)
        {
            currPressedItem = pressedUIItems[f];
            currTouch       = allTouches[f];

            if (currTouch.phase == TouchPhase.Began)
            {
                if (currPressedItem != null && currPressedItem.isActiveAndEnabled)
                {
                    claimTouches = true;

                    isNewlyPressed = currPressedItem.Press(currTouch);

                    if (isNewlyPressed && !prevPressedUIItemList.Contains(currPressedItem))
                    {
                        prevPressedUIItemList.Add(currPressedItem);
                    }
                }

                isAnyPressBeganRecorded = true;
            }
        }

        if (isAnyPressBeganRecorded)
        {
            if (OnAnyPress != null)
            {
                OnAnyPress();
            }
        }

        return(claimTouches);
    }
Пример #38
0
    bool IsResetMyItemValid(UIButtonScaler bs)
    {
        tk2dUIItem item = bs.GetComponent <tk2dUIItem>();

        return((item != null) && (bs.myItem != item));
    }
Пример #39
0
    void CreateLevel(float positionX, PhepToan vio, int thutu)
    {
        SpItemMonkey levelCreate = spPrefab.Spawn <SpItemMonkey>
                                   (
            new Vector3(positionX, startY, 70f),
            spPrefab.transform.rotation
                                   );

        levelCreate.Giatri   = vio.Ketqua;
        levelCreate.Pheptoan = "" + vio.Congthuc;
        levelCreate.setData(vio.Loai);
        levelCreate.Trangthai = true;
        levelCreate.Vitri     = thutu;



        sp = levelCreate.GetComponent <tk2dUIItem>();


        switch (thutu)
        {
        case 1:
            bt1         = levelCreate;
            sp.OnClick += onClick_sp1;
            break;

        case 2:
            bt2         = levelCreate;
            sp.OnClick += onClick_sp2;
            break;

        case 3:
            bt3         = levelCreate;
            sp.OnClick += onClick_sp3;
            break;

        case 4:
            bt4         = levelCreate;
            sp.OnClick += onClick_sp4;
            break;

        case 5:
            bt5         = levelCreate;
            sp.OnClick += onClick_sp5;
            break;

        case 6:
            bt6         = levelCreate;
            sp.OnClick += onClick_sp6;
            break;

        case 7:
            bt7         = levelCreate;
            sp.OnClick += onClick_sp7;
            break;

        case 8:
            bt8         = levelCreate;
            sp.OnClick += onClick_sp8;
            break;

        case 9:
            bt9         = levelCreate;
            sp.OnClick += onClick_sp9;
            break;

        case 10:
            bt10        = levelCreate;
            sp.OnClick += onClick_sp10;
            break;

        case 11:
            bt11        = levelCreate;
            sp.OnClick += onClick_sp11;
            break;

        case 12:
            bt12        = levelCreate;
            sp.OnClick += onClick_sp12;
            break;

        case 13:
            bt13        = levelCreate;
            sp.OnClick += onClick_sp13;
            break;

        case 14:
            bt14        = levelCreate;
            sp.OnClick += onClick_sp14;
            break;

        case 15:
            bt15        = levelCreate;
            sp.OnClick += onClick_sp15;
            break;

        case 16:
            bt16        = levelCreate;
            sp.OnClick += onClick_sp16;
            break;

        case 17:
            bt17        = levelCreate;
            sp.OnClick += onClick_sp17;
            break;

        case 18:
            bt18        = levelCreate;
            sp.OnClick += onClick_sp18;
            break;

        case 19:
            bt19        = levelCreate;
            sp.OnClick += onClick_sp19;
            break;

        case 20:
            bt20        = levelCreate;
            sp.OnClick += onClick_sp20;
            break;

        default:
            Debug.Log("Default case");
            break;
        }
        levelCreate.transform.parent = respawn.transform;
    }
Пример #40
0
    void RemoveEvent(SpItemMonkey pSP)
    {
        int        tmg    = pSP.Vitri;
        tk2dUIItem uiitem = pSP.GetComponent <tk2dUIItem>();

        switch (tmg)
        {
        case 1:
            uiitem.OnClick -= onClick_sp1;
            break;

        case 2:
            uiitem.OnClick -= onClick_sp2;
            break;

        case 3:
            uiitem.OnClick -= onClick_sp3;
            break;

        case 4:
            uiitem.OnClick -= onClick_sp4;
            break;

        case 5:
            uiitem.OnClick -= onClick_sp5;
            break;

        case 6:
            uiitem.OnClick -= onClick_sp6;
            break;

        case 7:
            uiitem.OnClick -= onClick_sp7;
            break;

        case 8:
            uiitem.OnClick -= onClick_sp8;
            break;

        case 9:
            uiitem.OnClick -= onClick_sp9;
            break;

        case 10:
            uiitem.OnClick -= onClick_sp10;
            break;

        case 11:
            uiitem.OnClick -= onClick_sp11;
            break;

        case 12:
            uiitem.OnClick -= onClick_sp12;
            break;

        case 13:
            uiitem.OnClick -= onClick_sp13;
            break;

        case 14:
            uiitem.OnClick -= onClick_sp14;
            break;

        case 15:
            uiitem.OnClick -= onClick_sp15;
            break;

        case 16:
            uiitem.OnClick -= onClick_sp16;
            break;

        case 17:
            uiitem.OnClick -= onClick_sp17;
            break;

        case 18:
            uiitem.OnClick -= onClick_sp18;
            break;

        case 19:
            uiitem.OnClick -= onClick_sp19;
            break;

        case 20:
            uiitem.OnClick -= onClick_sp20;
            break;
        }
    }
Пример #41
0
 /// <summary>
 /// Manually setting specific UIItem parent
 /// </summary>
 public void ManuallySetParent(tk2dUIItem newParentUIItem)
 {
     parentUIItem = newParentUIItem;
 }
Пример #42
0
    //checks for inputs (multi-touch)
    private void CheckMultiTouchInputs()
    {
        bool isAnyPressBeganRecorded = false;
        int prevFingerID = -1;
        bool wasPrevTouchFound = false;
        bool isNewlyPressed = false;

        touchCounter = 0;
        if (inputEnabled)
        {
            if (Input.touchCount > 0)
            {
                foreach (Touch touch in Input.touches)
                {
                    if (touchCounter < MAX_MULTI_TOUCH_COUNT)
                    {
                        allTouches[touchCounter] = new tk2dUITouch(touch);
                        touchCounter++;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                if (Input.GetMouseButtonDown(0))
                {
                    allTouches[touchCounter] = new tk2dUITouch(TouchPhase.Began, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, Vector2.zero, 0);
                    mouseDownFirstPos = Input.mousePosition;
                    touchCounter++;
                }
                else if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0))
                {
                    Vector2 deltaPosition = mouseDownFirstPos - new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                    TouchPhase mousePhase = TouchPhase.Moved;

                    if (Input.GetMouseButtonUp(0))
                    {
                        mousePhase = TouchPhase.Ended;
                    }
                    else if (deltaPosition == Vector2.zero)
                    {
                        mousePhase = TouchPhase.Stationary;
                    }
                    allTouches[touchCounter] = new tk2dUITouch(mousePhase, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, deltaPosition, tk2dUITime.deltaTime);
                    touchCounter++;
                }
            }
        }

        for (int p = 0; p < touchCounter; p++)
        {
            pressedUIItems[p] = RaycastForUIItem(allTouches[p].position);
        }
       
        //deals with all the previous presses
        for (int f=0; f<prevPressedUIItemList.Count; f++)
        {
            prevPressedItem = prevPressedUIItemList[f];
            if (prevPressedItem != null)
            {
                prevFingerID = prevPressedItem.Touch.fingerId;

                wasPrevTouchFound=false;
                for (int t = 0; t < touchCounter; t++)
                {
                    currTouch = allTouches[t];
                    if (currTouch.fingerId == prevFingerID)
                    {
                        wasPrevTouchFound=true;
                        currPressedItem = pressedUIItems[t];
                        if (currTouch.phase == TouchPhase.Began)
                        {
                            prevPressedItem.CurrentOverUIItem(currPressedItem);

                            if (prevPressedItem != currPressedItem)
                            {
                                prevPressedItem.Release();
                                prevPressedUIItemList.RemoveAt(f);
                                f--;
                            }
                        }
                        else if (currTouch.phase == TouchPhase.Ended)
                        {
                            prevPressedItem.CurrentOverUIItem(currPressedItem);
                            prevPressedItem.UpdateTouch(currTouch);
                            prevPressedItem.Release();
                            prevPressedUIItemList.RemoveAt(f);
                            f--;
                        }
                        else
                        {
                            prevPressedItem.CurrentOverUIItem(currPressedItem);
                            prevPressedItem.UpdateTouch(currTouch);
                        }
                        break;
                    }
                }

                if(!wasPrevTouchFound)
                {
                    prevPressedItem.CurrentOverUIItem(null);
                    prevPressedItem.Release();
                    prevPressedUIItemList.RemoveAt(f);
                    f--;
                }
            }
        }

        for (int f = 0; f < touchCounter; f++)
        {
            currPressedItem = pressedUIItems[f];
            currTouch = allTouches[f];
            if (currTouch.phase == TouchPhase.Began)
            {
                if (currPressedItem != null)
                {
                    isNewlyPressed = currPressedItem.Press(currTouch);
                    if (isNewlyPressed)
                    {
                        prevPressedUIItemList.Add(currPressedItem);
                    }
                }
                isAnyPressBeganRecorded = true;
            }
        }

        if (isAnyPressBeganRecorded)
        {
            if (OnAnyPress != null) { OnAnyPress(); }
        }
    }
Пример #43
0
 /// <summary>
 /// Will remove parent and act as if isChildOfAnotherUIItem is false
 /// </summary>
 public void RemoveParent()
 {
     parentUIItem = null;
 }
Пример #44
0
 public void OverrideClearAllChildrenPresses(tk2dUIItem item)
 {
     if (useMultiTouch)
     {
         tk2dUIItem tempUIItem;
         for (int n = 0; n < pressedUIItems.Length; n++)
         {
             tempUIItem = pressedUIItems[n];
             if (tempUIItem!=null)
             {
                 if (item.CheckIsUIItemChildOfMe(tempUIItem))
                 {
                     tempUIItem.CurrentOverUIItem(item);
                 }
             }
         }
     }
     else
     {
         if (pressedUIItem != null)
         {
             if (item.CheckIsUIItemChildOfMe(pressedUIItem))
             {
                 pressedUIItem.CurrentOverUIItem(item);
             }
         }
     }
 }
Пример #45
0
 /// <summary>
 /// Touch/mouse currently over UIItem. If exitting this button, but still overtop of another Button, this might be a parent. Checks if parent and
 /// does not exit.
 /// Only call manually if you need to simulate touch.
 /// </summary>
 public void CurrentOverUIItem(tk2dUIItem overUIItem)
 {
     if (overUIItem != this)
     {
         if (isPressed)
         {
             //check if overButton is child
             bool isUIItemChild = CheckIsUIItemChildOfMe(overUIItem);
             if (!isUIItemChild)
             {
                 Exit();
                 if (parentUIItem != null)
                 {
                     parentUIItem.CurrentOverUIItem(overUIItem);
                 }
             }
         }
         else
         {
             if (parentUIItem != null)
             {
                 parentUIItem.CurrentOverUIItem(overUIItem);
             }
         }
     }
 }
Пример #46
0
	void Awake() {
		uiItem = GetComponent<tk2dUIItem>();
	}
Пример #47
0
    /// <summary>
    /// Hover over item. Return true if this was prevHover.
    /// Only call manually if you need to simulate touch.
    /// </summary>
    public bool HoverOver(tk2dUIItem prevHover)
    {
        bool wasPrevHoverFound = false;
        tk2dUIItem nextUIItem = null;
        if (!isHoverOver)
        {
            if (OnHoverOver != null) { OnHoverOver(); }
            if (OnHoverOverUIItem != null) { OnHoverOverUIItem(this); }
            isHoverOver = true;
        }

        if (prevHover == this)
        {
            wasPrevHoverFound = true;
        }

        if (parentUIItem != null && parentUIItem.isHoverEnabled)
        {
            nextUIItem = parentUIItem;
        }

        if (nextUIItem == null)
        {
            return wasPrevHoverFound;
        }
        else
        {
            return nextUIItem.HoverOver(prevHover) || wasPrevHoverFound; //will return true once found
        }
    }
Пример #48
0
    void Handle_GameRank()
    {
        if (go_Rank==null)
        {
            go_Rank = Instantiate(Prefab_Rank) as GameObject;

            EvtR += RankShow;
            Light = go_Rank.transform.FindChild("back2").GetComponent<tk2dSprite>();
            ChangeName = go_Rank.transform.FindChild("button/改名").GetComponent<tk2dUIItem>();
            ChangeName.OnClick += SettingName;
           // Debug.Log("订阅");
            Light.transform.localPosition = new Vector3(-26, -167, -103);
            go_Rank.transform.FindChild("button/fanhui").GetComponent<tk2dUIItem>().OnClick += Rank_BackClick;
        }
        else
        {
            go_Rank.SetActive(true);
        }
    }
Пример #49
0
    //
    // Ranking
    //
    void RankPressed(tk2dUIItem pressed)
    {
        planet.gameObject.SetActive(false);
        arrow.gameObject.SetActive(false);
        nameSprite.gameObject.SetActive(false);
        NameText.gameObject.SetActive(false);
        ExperienceText.gameObject.SetActive(false);
        ItemList.gameObject.SetActive(false);

        if (!FB.IsLoggedIn)
        {
            Ranking.gameObject.SetActive(true);
            rank.gameObject.SetActive(true);
            ScrollView.gameObject.SetActive(false);
            FacebookRanking.gameObject.SetActive(false);

            switch (pressed.name)
            {
            case "AddSprite":
                // Call Add Ranking
                rank.gameObject.GetComponent <RankControl>().LoadScore("Add");
                AddRankingsprite.gameObject.SetActive(false);
                SubRankingsprite.gameObject.SetActive(true);
                DivRankingsprite.gameObject.SetActive(true);
                break;

            case "SubSprite":
                // Call Sub Ranking
                rank.gameObject.GetComponent <RankControl>().LoadScore("Sub");
                AddRankingsprite.gameObject.SetActive(true);
                SubRankingsprite.gameObject.SetActive(false);
                DivRankingsprite.gameObject.SetActive(true);
                break;

            case "DivSprite":
                // Call Div Ranking
                rank.gameObject.GetComponent <RankControl>().LoadScore("Div");
                AddRankingsprite.gameObject.SetActive(true);
                SubRankingsprite.gameObject.SetActive(true);
                DivRankingsprite.gameObject.SetActive(false);
                break;

            default:
                //Debug, suppose no excute
                print(pressed.name);
                Debug.Log("Unable locate Ranking pressed");
                //第一次進rank才不會沒load到東西
                rank.gameObject.GetComponent <RankControl>().LoadScore("Add");
                break;
            }
        }
        else
        {
            // When FB is logged in.
            rank.gameObject.SetActive(false);
            ScrollView.gameObject.SetActive(true);
            Ranking.gameObject.SetActive(false);
            FacebookRanking.gameObject.SetActive(true);

            FacebookLogin fb = GameObject.Find("GameManager").GetComponent <FacebookLogin>();
            fb.info(FB.IsLoggedIn);
        }
    }
Пример #50
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        bool changeOccurred = false;

        EditorGUIUtility.LookLikeControls(180);
        tk2dUIItem btn = (tk2dUIItem)target;

        bool newIsChildOfAnotherMenuBtn = EditorGUILayout.Toggle("Child of Another UIItem?", btn.InternalGetIsChildOfAnotherUIItem());

        if (newIsChildOfAnotherMenuBtn != btn.InternalGetIsChildOfAnotherUIItem())
        {
            changeOccurred = true;
            btn.InternalSetIsChildOfAnotherUIItem(newIsChildOfAnotherMenuBtn);
        }

        btn.registerPressFromChildren = EditorGUILayout.Toggle("Register Events From Children", btn.registerPressFromChildren);

        btn.isHoverEnabled = EditorGUILayout.Toggle("Is Hover Events Enabled?", btn.isHoverEnabled);

        GUILayout.Label("Send Message", EditorStyles.boldLabel);
        EditorGUI.indentLevel++;

        GameObject newSendMessageTarget = EditorGUILayout.ObjectField("Target", btn.sendMessageTarget, typeof(GameObject), true, null) as GameObject;

        if (newSendMessageTarget != btn.sendMessageTarget)
        {
            changeOccurred        = true;
            btn.sendMessageTarget = newSendMessageTarget;
        }
        if (btn.sendMessageTarget != null && EditorUtility.IsPersistent(btn.sendMessageTarget))
        {
            changeOccurred        = true;
            btn.sendMessageTarget = null;
        }
        if (btn.sendMessageTarget != null)
        {
            btn.SendMessageOnDownMethodName    = EditorGUILayout.TextField("On Down Method Name", btn.SendMessageOnDownMethodName);
            btn.SendMessageOnUpMethodName      = EditorGUILayout.TextField("On Up Method Name", btn.SendMessageOnUpMethodName);
            btn.SendMessageOnClickMethodName   = EditorGUILayout.TextField("On Clicked Method Name", btn.SendMessageOnClickMethodName);
            btn.SendMessageOnReleaseMethodName = EditorGUILayout.TextField("On Release Method Name", btn.SendMessageOnReleaseMethodName);
        }
        EditorGUI.indentLevel--;

        if (btn.collider != null)
        {
            GUILayout.Label("Collider", EditorStyles.boldLabel);
            EditorGUI.indentLevel++;

            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Automatic Fit");
            if (GUILayout.Button("Fit", GUILayout.MaxWidth(100)))
            {
                tk2dUIItemBoundsHelper.FixColliderBounds(btn);
            }
            GUILayout.EndHorizontal();

            ArrayProperty("Extra Bounds", extraBoundsProp);
            ArrayProperty("Ignore Bounds", ignoreBoundsProp);

            EditorGUI.indentLevel--;
        }

        serializedObject.ApplyModifiedProperties();
        if (GUI.changed || changeOccurred)
        {
            EditorUtility.SetDirty(btn);
        }
    }
Пример #51
0
    //checks for inputs (multi-touch)
    private void CheckMultiTouchInputs()
    {
        bool isAnyPressBeganRecorded = false;
        int  prevFingerID            = -1;
        bool wasPrevTouchFound       = false;
        bool isNewlyPressed          = false;

        touchCounter = 0;
        if (inputEnabled)
        {
            if (Input.touchCount > 0)
            {
                foreach (Touch touch in Input.touches)
                {
                    if (touchCounter < MAX_MULTI_TOUCH_COUNT)
                    {
                        allTouches[touchCounter] = new tk2dUITouch(touch);
                        touchCounter++;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                if (Input.GetMouseButtonDown(0))
                {
                    allTouches[touchCounter] = new tk2dUITouch(TouchPhase.Began, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, Vector2.zero, 0);
                    mouseDownFirstPos        = Input.mousePosition;
                    touchCounter++;
                }
                else if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0))
                {
                    Vector2    deltaPosition = mouseDownFirstPos - new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                    TouchPhase mousePhase    = TouchPhase.Moved;

                    if (Input.GetMouseButtonUp(0))
                    {
                        mousePhase = TouchPhase.Ended;
                    }
                    else if (deltaPosition == Vector2.zero)
                    {
                        mousePhase = TouchPhase.Stationary;
                    }
                    allTouches[touchCounter] = new tk2dUITouch(mousePhase, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, deltaPosition, tk2dUITime.deltaTime);
                    touchCounter++;
                }
            }
        }

        for (int p = 0; p < touchCounter; p++)
        {
            pressedUIItems[p] = RaycastForUIItem(allTouches[p].position);
        }

        //deals with all the previous presses
        for (int f = 0; f < prevPressedUIItemList.Count; f++)
        {
            prevPressedItem = prevPressedUIItemList[f];
            if (prevPressedItem != null)
            {
                prevFingerID = prevPressedItem.Touch.fingerId;

                wasPrevTouchFound = false;
                for (int t = 0; t < touchCounter; t++)
                {
                    currTouch = allTouches[t];
                    if (currTouch.fingerId == prevFingerID)
                    {
                        wasPrevTouchFound = true;
                        currPressedItem   = pressedUIItems[t];
                        if (currTouch.phase == TouchPhase.Began)
                        {
                            prevPressedItem.CurrentOverUIItem(currPressedItem);

                            if (prevPressedItem != currPressedItem)
                            {
                                prevPressedItem.Release();
                                prevPressedUIItemList.RemoveAt(f);
                                f--;
                            }
                        }
                        else if (currTouch.phase == TouchPhase.Ended)
                        {
                            prevPressedItem.CurrentOverUIItem(currPressedItem);
                            prevPressedItem.UpdateTouch(currTouch);
                            prevPressedItem.Release();
                            prevPressedUIItemList.RemoveAt(f);
                            f--;
                        }
                        else
                        {
                            prevPressedItem.CurrentOverUIItem(currPressedItem);
                            prevPressedItem.UpdateTouch(currTouch);
                        }
                        break;
                    }
                }

                if (!wasPrevTouchFound)
                {
                    prevPressedItem.CurrentOverUIItem(null);
                    prevPressedItem.Release();
                    prevPressedUIItemList.RemoveAt(f);
                    f--;
                }
            }
        }

        for (int f = 0; f < touchCounter; f++)
        {
            currPressedItem = pressedUIItems[f];
            currTouch       = allTouches[f];
            if (currTouch.phase == TouchPhase.Began)
            {
                if (currPressedItem != null)
                {
                    isNewlyPressed = currPressedItem.Press(currTouch);
                    if (isNewlyPressed)
                    {
                        prevPressedUIItemList.Add(currPressedItem);
                    }
                }
                isAnyPressBeganRecorded = true;
            }
        }

        if (isAnyPressBeganRecorded)
        {
            if (OnAnyPress != null)
            {
                OnAnyPress();
            }
        }
    }
Пример #52
0
 public void ResetForcedUIItem()
 {
     forcedUIItem = null;
 }
Пример #53
0
 private void OnHardButtonClick(tk2dUIItem tk2dUiItem)
 {
     AppController.GetInstance().Difc = 1;
     SceneManager.LoadScene(Constants.SCENE_GAME);
 }
Пример #54
0
 private Vector3 CalculateClickWorldPos(tk2dUIItem btn)
 {
     Vector2 pos = btn.Touch.position;
     Camera viewingCamera = tk2dUIManager.Instance.GetUICameraForControl( gameObject );
     Vector3 worldPos = viewingCamera.ScreenToWorldPoint(new Vector3(pos.x, pos.y, btn.transform.position.z - viewingCamera.transform.position.z));
     worldPos.z = btn.transform.position.z;
     return worldPos;
 }
Пример #55
0
 private Vector3 CalculateClickWorldPos(tk2dUIItem btn)
 {
     Vector2 pos = btn.Touch.position;
     Vector3 worldPos = tk2dUIManager.Instance.UICamera.ScreenToWorldPoint(new Vector3(pos.x, pos.y, btn.transform.position.z - tk2dUIManager.Instance.UICamera.transform.position.z));
     worldPos.z = btn.transform.position.z;
     return worldPos;
 }
Пример #56
0
 /// <summary>
 /// Will remove parent and act as if isChildOfAnotherUIItem is false
 /// </summary>
 public void RemoveParent()
 {
     parentUIItem = null;
 }
Пример #57
0
 void OnEnable()
 {
     uiItem = GetComponent<tk2dUIItem>();
     uiItem.OnClickUIItem += Clicked;
 }
Пример #58
0
 // Update is called once per frame
 void Update()
 {
     tk2dUIItem uiNormal = transform.GetComponent<tk2dUIItem>();
     uiNormal.OnDown += HideRenderer;
     uiNormal.OnUp += ShowRenderer;
 }
Пример #59
0
 void Clicked(tk2dUIItem clickedUIItem)
 {
     Debug.Log("Clicked:" + clickedUIItem);
 }
Пример #60
0
 /// <summary>
 /// Manually setting specific UIItem parent
 /// </summary>
 public void ManuallySetParent(tk2dUIItem newParentUIItem)
 {
     parentUIItem = newParentUIItem;
 }