示例#1
0
    void Start()
    {
        if (widgetForBlinkConfirmation != null)
        {
            _initBlinkColor = widgetForBlinkConfirmation.color;
        }


        _cycler = cyclerPanel.gameObject.GetComponent(typeof(IPCycler)) as IPCycler;

        _dragContents      = pickerColliderObject.GetComponent(typeof(IPDragScrollView)) as IPDragScrollView;
        _pickerInteraction = pickerColliderObject.GetComponent(typeof(IPUserInteraction)) as IPUserInteraction;

        _pickerCollider = pickerColliderObject.GetComponent(typeof(BoxCollider)) as BoxCollider;
        _thisCollider   = gameObject.GetComponent(typeof(BoxCollider)) as BoxCollider;

        _clipRangeTween = cyclerPanel.gameObject.GetComponent(typeof(TweenPanelClipRange)) as TweenPanelClipRange;
        _softnessTween  = cyclerPanel.gameObject.GetComponent(typeof(TweenPanelClipSoftness)) as TweenPanelClipSoftness;

        _scaleTween = pickerBackground.gameObject.GetComponent(typeof(TweenHeight)) as TweenHeight;

        cyclerPanel.baseClipRegion = _clipRangeTween.from;
        cyclerPanel.clipSoftness   = _softnessTween.from;
        pickerBackground.height    = ( int )_scaleTween.from;

        _dragContents.enabled   = false;
        _pickerCollider.enabled = false;
    }
    private float _trueSpacing;     // Spacing adjusted according to cycler direction

    #region Player mode methods

    public void Init()
    {
        //Prevent multiple Init in the same frame - for compound pickers
        if (_initFrame == Time.frameCount)
        {
            return;
        }
        _initFrame = Time.frameCount;

        //Cache NGUI components
        _draggablePanel = gameObject.GetComponent(typeof(UIScrollView)) as UIScrollView;
        _panel          = gameObject.GetComponent(typeof(UIPanel)) as UIPanel;

        //Make sure the parent is active before getting collider
        NGUITools.SetActive(transform.parent.gameObject, true);

        //Look for a collider, and if one is found, add user interaction scripts
        if (_pickerCollider == null)
        {
            _pickerCollider = transform.parent.GetComponentInChildren(typeof(BoxCollider)) as BoxCollider;
        }

        if (_pickerCollider != null)
        {
            dragPanelContents            = _pickerCollider.gameObject.AddComponent(typeof(IPDragScrollView)) as IPDragScrollView;
            dragPanelContents.scrollView = _draggablePanel;

            userInteraction        = _pickerCollider.gameObject.AddComponent(typeof(IPUserInteraction)) as IPUserInteraction;
            userInteraction.cycler = this;
            userInteraction.restrictWithinPicker = restrictDragToPicker;
        }
        else
        {
            Debug.Log("Could not get collider");
        }

        //Add and subscribe to the recenter component
        _uiCenterOnChild                = gameObject.AddComponent(typeof(UICenterOnChild)) as UICenterOnChild;
        _uiCenterOnChild.enabled        = false;
        _uiCenterOnChild.springStrength = recenterSpringStrength;
        _uiCenterOnChild.onFinished     = PickerStopped;

        //Check if the ScrollWheelEvents singleton is in the scene
        ScrollWheelEvents.CheckInstance();

        _draggablePanel.movement = _isHorizontal ? UIScrollView.Movement.Horizontal : UIScrollView.Movement.Vertical;

        //Iniitialize a bunch of variables
        _resetPosition = _panel.cachedTransform.localPosition;

        //was clipRange
        _panelPrevPos = SignificantPosVector(_panel.cachedTransform);

        _transformJumpDelta = -_trueSpacing * NbOfTransforms;         //how much should the cycled transforms move when re-cycling (incrementing) ?

        CenterWidgetIndex   = NbOfTransforms / 2;
        LeftWidgetIndex     = 0;
        _decrementThreshold = _panelPrevPos;
        _incrementThreshold = _panelPrevPos + _trueSpacing;
        _deltaPos           = 0f;

        RecenterTargetWidgetIndex = 0;

        _isInitialized = true;
    }