private UnitButtonManager EnsureUnit(UnitEntityData unit, int index, ref bool isDirty)
        {
            if (!_unitButtonDic.TryGetValue(unit, out UnitButtonManager button))
            {
                if (!_unitButtonTemplate)
                {
                    _unitButtonTemplate = UnitButtonManager.CreateObject();
                    _unitButtonTemplate.gameObject.SetActive(false);
                    DontDestroyOnLoad(_unitButtonTemplate.gameObject);
                }

                button = Instantiate(_unitButtonTemplate);
                button.transform.SetParent(_unitButtons.transform, false);
                button.transform.localPosition = new Vector3(0f, -(UNIT_BUTTON_HEIGHT + UNIT_BUTTON_SPACE) * index, 0f);
                button.gameObject.SetActive(true);
                button.Index    = index;
                button.Unit     = unit;
                button.OnClick += HandleClickUnitButton;
                button.OnEnter += HandleEnterUnitButton;
                button.OnExit  += HandleExitUnitButton;

                _unitButtonDic.Add(unit, button);
                isDirty = true;
            }
            else if (button.Index != index)
            {
                button.Index = index;
                isDirty      = true;
            }
            return(button);
        }
 private void RemoveUnit(UnitButtonManager unitButton)
 {
     _unitButtonDic.Remove(unitButton.Unit);
     unitButton.SafeDestroy();
 }