void OnEnable()
    {
        TabbedPanel _tabbedPanel = (TabbedPanel)target;

        if (_sheetList == null)
        {
            _sheetList    = _tabbedPanel._sheetList;
            _currentSheet = _sheetList.First();
        }

        if (_tabList == null)
        {
            _tabList = _tabbedPanel._tabsList;
        }

        _toggleStates = new List <bool>(_sheetList.Count);
        for (int i = 0; i < _sheetList.Count; i++)
        {
            if (i != 0)
            {
                _toggleStates.Add(false);
            }
            else
            {
                _toggleStates.Add(true);
            }
        }
    }
Пример #2
0
    void Awake()
    {
        //_sheetPrefab = GameObject.Find("Sheet");
        //todo this needs to be done at runtime or in the editor
        Debug.Assert(_tabsList.Count == _sheetList.Count, "Sheets count and Tabs count must match.");
        for (int i = 0; i < _tabsList.Count; i++)
        {
            Tab         tab   = _tabsList[i];
            TabbedSheet sheet = _sheetList[i];
            tab.OnTabClick.AddListener(HandleSheetOnTabClickEvent);
            tab.Label = sheet.name;
            if (i > 0)
            {
                sheet.gameObject.SetActive(false);
            }
            else
            {
                sheet.gameObject.SetActive(true);
            }
        }
        _currentSelected = _sheetList.First();

        foreach (RectTransform child in GetComponentsInChildren <RectTransform>())
        {
            if (child.name == "Tabs Parent")
            {
                _tabsParent = child;
            }
            else if (child.name == "Sheets Parent")
            {
                _sheetsParent = child;
            }
        }
    }
    void Sheet(TabbedSheet sheet)
    {
        Image  backgroundImage  = sheet.gameObject.GetComponent <Image>();
        Sprite backgroundSprite = backgroundImage.sprite;
        Color  backgroundColor  = backgroundImage.color;
        int    sheetIndex       = _sheetList.IndexOf(sheet);
        Tab    tab            = _tabList[sheetIndex];
        Text   tabText        = tab.GetComponentInChildren <Text>();
        bool   isCurrentSheet = sheet == _currentSheet;


        float prevWidth = EditorGUIUtility.labelWidth;

        EditorGUIUtility.labelWidth = 65;
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.BeginVertical(new GUIStyle()
        {
            fixedWidth = 25, alignment = TextAnchor.MiddleCenter
        });

        bool currentState = _toggleStates[sheetIndex];
        bool newState     = EditorGUILayout.Toggle(currentState);

        if (newState != currentState)
        {
            if (!isCurrentSheet)
            {
                _toggleStates[sheetIndex] = newState;
                _toggleStates[_sheetList.IndexOf(_currentSheet)] = false;
                _currentSheet = sheet;
            }
        }

        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical();
        if (!isCurrentSheet)
        {
            GUI.enabled = false;
        }

        tabText.text = EditorGUILayout.TextField("Name:", tabText.text);

        tab.name = tabText.text;

        //Background image
        EditorGUILayout.LabelField("Background Image");
        EditorGUI.indentLevel++;
        EditorGUILayout.BeginHorizontal();

        backgroundSprite = EditorGUILayout.ObjectField("Sprite", backgroundSprite, typeof(Sprite), true) as Sprite;

        backgroundColor = EditorGUILayout.ColorField("Color", backgroundColor);

        EditorGUILayout.EndHorizontal();
        EditorGUI.indentLevel--;


        EditorGUILayout.EndVertical();

        EditorGUILayout.EndHorizontal();
        EditorGUIUtility.labelWidth = prevWidth;
        GUI.enabled = true;
    }