unity隐藏侧边栏效果
下面展示一些 内联代码片 。 public RectTransform mainUI; public Button showHideBtn; //public RepeatButton dragBtn; private bool m_isShow; public Sprite[] sideIcon;
// Use this for initialization
void Start()
{
m_isShow = true;
showHideBtn.GetComponent<Image>().sprite = sideIcon[0];
showHideBtn.onClick.AddListener(ShowHide);
}
void ShowHide()
{
Vector3 vec3Tmp = mainUI.anchoredPosition;
if (m_isShow)
{
showHideBtn.GetComponent<Image>().sprite = sideIcon[1];
mainUI.DOAnchorPos(new Vector2(-vec3Tmp.x, vec3Tmp.y), 1.0f);
m_isShow = false;
}
else
{
showHideBtn.GetComponent<Image>().sprite = sideIcon[0];
mainUI.DOAnchorPos(new Vector2(-vec3Tmp.x, vec3Tmp.y), 1.0f);
m_isShow = true;
}
}
|