示例#1
0
    void OnEnable()
    {
        if (!InputComponent)
        {
            InputComponent = GetComponent <ScrollMenuInput>();
        }
        if (!InputComponent.enabled)
        {
            InputComponent.enabled = true;
        }
        //set menu to first item selected and reset all positions
        SelectedIndexContinuous = SelectedIndex = MinDisplayedIndex = 0;
        ResetMenuItemsToStart();

        //calculate values used for offsets
        int bufferSize        = (PoolSize - DisplaySize) / 2;
        int ActionIndexOffset = MinDisplayedIndex - bufferSize;

        //Disable extra actions so they don't display
        for (int i = 0; i < PoolSize; i++)
        {
            transform.GetChild(i).gameObject.SetActive(i < AvailableActions.List.Count + bufferSize);
            int ActionIndex = i + ActionIndexOffset;
            if (ActionIndex < AvailableActions.List.Count && ActionIndex >= 0)
            {
                transform.GetChild(i).GetComponent <MenuAction>().action = AvailableActions.List[ActionIndex];
            }
        }

        //Move the pointer to the start of the list
        SetPointerIconPosition();
        ParentHolder = GetComponentInParent <ScrollMenuHolder>();
    }
 void Start()
 {
     InputComponent = GetComponentInChildren <ScrollMenuInput>(true);
 }