Exemple #1
0
    void Awake()
    {
#if !UNITY_EDITOR
        try
        {
#endif

#if UNITY_EDITOR
        try
        {
#endif
        scroll = gameObject.GetComponent <UIScrollViewSimple>();

#if UNITY_EDITOR
    }
    catch (Exception ex)
    {
        Logger.Error(ex.ToString());
    }
#endif

#if !UNITY_EDITOR
    }
    catch (Exception ex)
    {
        Logger.Error(ex.ToString());
    }
#endif
    }
    /// <summary>
    /// Create a plane on which we will be performing the dragging.
    /// </summary>

    void OnPress(bool pressed)
    {
        //硬编码,如果在引导中限制滚动
        if (null != GuideManager.Instance && GuideManager.Instance.IsGuiding())
        {
            return;
        }

        // If the scroll view has been set manually, don't try to find it again
        if (mAutoFind && mScroll != scrollView)
        {
            mScroll   = scrollView;
            mAutoFind = false;
        }

        if (scrollView && enabled && NGUITools.GetActive(gameObject))
        {
            scrollView.Press(pressed);

            if (!pressed && mAutoFind)
            {
                scrollView = NGUITools.FindInParents <UIScrollViewSimple>(mTrans);
                mScroll    = scrollView;
            }
        }
    }
Exemple #3
0
    /// <summary>
    /// Advance toward the target position.
    /// </summary>

    protected virtual void AdvanceTowardsPosition()
    {
        float delta = RealTime.deltaTime;

        bool    trigger = false;
        Vector3 before  = mTrans.localPosition;
        Vector3 after   = NGUIMath.SpringLerp(before, before + target, strength, delta);
        Vector3 offset  = after - before;

        target = target - offset;
        //bool isLast = false;
        if (target.sqrMagnitude < 0.01f)
        {
            after   = target;
            enabled = false;
            trigger = true;
            //isLast = true;
        }
        UIScrollViewSimple tempScrollViewSimple = mTrans.GetComponent <UIScrollViewSimple>();

        if (tempScrollViewSimple != null)
        {
            tempScrollViewSimple.MoveRelative(offset, true);
            //if (isLast)
            //{
            //    if (tempScrollViewSimple.centerOnChild != null)
            //    {
            //        tempScrollViewSimple.centerOnChild.Recenter();
            //    }
            //}
        }
        else
        {
            mTrans.localPosition = after;
            Vector2 cr = mPanel.clipOffset;
            cr.x -= offset.x;
            cr.y -= offset.y;
            mPanel.clipOffset = cr;
        }

        if (mDrag != null)
        {
            mDrag.UpdateScrollbars(false);
        }
        if (tempScrollViewSimple != null)
        {
            tempScrollViewSimple.UpdateScrollbars(false);
        }

        if (trigger && onFinished != null)
        {
            current = this;
            onFinished();
            current = null;
        }
    }
Exemple #4
0
        private void OnEnable()
        {
#if !UNITY_EDITOR
            try
            {
#endif
            foreach (var system in WorshipAnimation)
            {
                system.gameObject.SetActive(false);
            }

            if (hasRemoveBinding)
            {
                EventDispatcher.Instance.AddEventListener(RankNotifyLogic.EVENT_TYPE, OnRankNotifyLogic);
                EventDispatcher.Instance.AddEventListener(CloseUiBindRemove.EVENT_TYPE, OnCloseUiBindRemove);
                EventDispatcher.Instance.AddEventListener(RankRefreshModelView.EVENT_TYPE, OnRankRefreshModelView);
                EventDispatcher.Instance.AddEventListener(RankScrollViewMoveEvent.EVENT_TYPE, OnScrollViewMoveEvent);
                var controllerBase = UIManager.Instance.GetController(UIConfig.RankUI);
                if (controllerBase == null)
                {
                    return;
                }
                Binding.SetBindDataSource(controllerBase.GetDataModel(""));
//              var controller = UIManager.Instance.GetController(UIConfig.ShareFrame);
//              Binding.SetBindDataSource(controller.GetDataModel(""));
                DataModel = controllerBase.GetDataModel("") as RankDataModel;
                Binding.SetBindDataSource(DataModel);
                if (ModelRoot.Character)
                {
                    ModelRoot.Character.gameObject.SetActive(true);
                }
            }
            hasRemoveBinding = true;
            ScrollView       = gameObject.GetComponentInChildren <UIScrollViewSimple>();
            if (IsFirst)
            {
                if (DataModel != null && ScrollView != null)
                {
                    if (DataModel.CurrentSelect > 5)
                    {
                        ScrollView.SetLookIndex(DataModel.CurrentSelect);
                    }
                }
                IsFirst = false;
            }
#if !UNITY_EDITOR
        }

        catch (Exception ex)
        {
            Logger.Error(ex.ToString());
        }
#endif
        }
    /// <summary>
    /// Find the scroll view to work with.
    /// </summary>

    void FindScrollView()
    {
        // If the scroll view is on a parent, don't try to remember it (as we want it to be dynamic in case of re-parenting)
        UIScrollViewSimple sv = NGUITools.FindInParents <UIScrollViewSimple>(mTrans);

        if (scrollView == null || (mAutoFind && sv != scrollView))
        {
            scrollView = sv;
            mAutoFind  = true;
        }
        else if (scrollView == sv)
        {
            mAutoFind = true;
        }
        mScroll = scrollView;
    }
    /// <summary>
    /// Automatically find the scroll view if possible.
    /// </summary>

    void OnEnable()
    {
        mTrans = transform;

        // Auto-upgrade
        if (scrollView == null && draggablePanel != null)
        {
            scrollView     = draggablePanel;
            draggablePanel = null;
        }

        if (mStarted && (mAutoFind || mScroll == null))
        {
            FindScrollView();
        }
    }
Exemple #7
0
        private void Awake()
        {
#if !UNITY_EDITOR
            try
            {
#endif

            btn_AutoMatchStop = transform.FindChildRecursive("AutoMatchStop").GetComponent <UIButton>();
            if (null != btn_AutoMatchStop)
            {
                EventDelegate.Add(btn_AutoMatchStop.onClick,
                                  new EventDelegate(() => { onclickbtn_AutoMatchStop(btn_AutoMatchStop.gameObject); }));
            }

            //世界喊话
            //btn_WorldSpeak = transform.FindChildRecursive("WorldSpeak").GetComponent<UIButton>();
            //if (null != btn_WorldSpeak) EventDelegate.Add(btn_WorldSpeak.onClick,
            //     new EventDelegate(() => { onclickbtn_WorldSpeak(btn_WorldSpeak.gameObject); }));

            //队伍状态
            btn_TeamState = transform.FindChildRecursive("TeamState").GetComponent <UIButton>();
            if (null != btn_TeamState)
            {
                EventDelegate.Add(btn_TeamState.onClick,
                                  new EventDelegate(() => { onclickbtn_TeamState(btn_TeamState.gameObject); }));
            }

            TeamMemberState = transform.FindChildRecursive("TeamMemberState").GetComponent <UIButton>();
            if (null != TeamMemberState)
            {
                EventDelegate.Add(TeamMemberState.onClick,
                                  new EventDelegate(() => { onclickbtn_TeamState(TeamMemberState.gameObject); }));
            }


            btn_AutoMatch = transform.FindChildRecursive("AutoMatch").GetComponent <UIButton>();
            if (null != btn_AutoMatch)
            {
                EventDelegate.Add(btn_AutoMatch.onClick,
                                  new EventDelegate(() => { onclickbtn_AutoMatch(btn_AutoMatch.gameObject); }));
            }
            obj_CD = transform.FindChildRecursive("CD").gameObject;
            if (null != obj_CD)
            {
                obj_CD.SetActive(false);
                WorldSpeakLable = obj_CD.transform.parent.FindChild("Label").gameObject;
                if (WorldSpeakLable != null)
                {
                    WorldSpeakLable.gameObject.SetActive(true);
                }
            }
            lb_CD      = transform.FindChildRecursive("CDtime").GetComponent <UILabel>();
            ScrollView = MainScroll.GetComponentInChildren <UIScrollViewSimple>();

#if !UNITY_EDITOR
        }

        catch (Exception ex)
        {
            Logger.Error(ex.ToString());
        }
#endif
        }
Exemple #8
0
    public void Recenter()
    {
        if (mScrollView == null)
        {
            mScrollView = NGUITools.FindInParents <UIScrollViewSimple>(gameObject);

            if (mScrollView == null)
            {
                Debug.LogWarning(GetType() + " requires " + typeof(UIScrollViewSimple) + " on a parent object in order to work", this);
                enabled = false;
                return;
            }
            else
            {
                if (mScrollView)
                {
                    mScrollView.centerOnChild   = this;
                    mScrollView.onDragFinished += OnDragFinished;
                }

                if (mScrollView.horizontalScrollBar != null)
                {
                    mScrollView.horizontalScrollBar.onDragFinished += OnDragFinished;
                }

                if (mScrollView.verticalScrollBar != null)
                {
                    mScrollView.verticalScrollBar.onDragFinished += OnDragFinished;
                }
            }
        }
        if (mScrollView.panel == null)
        {
            return;
        }
        CenterOn();
//      Transform trans = transform;
//      if (trans.childCount == 0) return;
//
//      // Calculate the panel's center in world coordinates
//      Vector3[] corners = mScrollView.panel.worldCorners;
//      Vector3 panelCenter = (corners[2] + corners[0]) * 0.5f;
//
//      // Offset this value by the momentum
//      Vector3 momentum = mScrollView.currentMomentum * mScrollView.momentumAmount;
//      Vector3 moveDelta = NGUIMath.SpringDampen(ref momentum, 9f, 2f);
//      Vector3 pickingPoint = panelCenter - moveDelta * 0.01f; // Magic number based on what "feels right"
//
//      float min = float.MaxValue;
//      Transform closest = null;
//      int index = 0;
//      int ignoredIndex = 0;
//
//      // Determine the closest child
//      for (int i = 0, imax = trans.childCount, ii = 0; i < imax; ++i)
//      {
//          Transform t = trans.GetChild(i);
//          if (!t.gameObject.activeInHierarchy) continue;
//          float sqrDist = Vector3.SqrMagnitude(t.position - pickingPoint);
//
//          if (sqrDist < min)
//          {
//              min = sqrDist;
//              closest = t;
//              index = i;
//              ignoredIndex = ii;
//          }
//          ++ii;
//      }
//
//      // If we have a touch in progress and the next page threshold set
//      if (nextPageThreshold > 0f && UICamera.currentTouch != null)
//      {
//          // If we're still on the same object
//          if (mCenteredObject != null && mCenteredObject.transform == trans.GetChild(index))
//          {
//              Vector3 totalDelta = UICamera.currentTouch.totalDelta;
//              totalDelta = transform.rotation * totalDelta;
//
//              float delta = 0f;
//
//              switch (mScrollView.movement)
//              {
//                     case UIScrollViewSimple.Movement.Horizontal:
//                  {
//                      delta = totalDelta.x;
//                      break;
//                  }
//                     case UIScrollViewSimple.Movement.Vertical:
//                  {
//                      delta = totalDelta.y;
//                      break;
//                  }
//                  default:
//                  {
//                      delta = totalDelta.magnitude;
//                      break;
//                  }
//              }
//
//              if (Mathf.Abs(delta) > nextPageThreshold)
//              {
//                     UIGridSimple grid = GetComponent<UIGridSimple>();
//
//                     if (grid != null && grid.sorting != UIGridSimple.Sorting.None)
//                  {
//                      List<Transform> list = grid.GetChildList();
//
//                      if (delta > nextPageThreshold)
//                      {
//                          // Next page
//                          if (ignoredIndex > 0) closest = list[ignoredIndex - 1];
//                          else closest = (GetComponent<UIWrapContent>() == null) ? list[0] : list[list.Count - 1];
//                      }
//                      else if (delta < -nextPageThreshold)
//                      {
//                          // Previous page
//                          if (ignoredIndex < list.Count - 1) closest = list[ignoredIndex + 1];
//                          else closest = (GetComponent<UIWrapContent>() == null) ? list[list.Count - 1] : list[0];
//                      }
//                  }
//                  else Debug.LogWarning("Next Page Threshold requires a sorted UIGrid in order to work properly", this);
//              }
//          }
//      }
//      CenterOn(closest, panelCenter);
    }