Dropdown打开下拉菜单会以“Template”为模板创建一个Dropdown List,在“Template”上添加一个脚本在Start()中执行下拉框打开时的操作,在OnDestroy()中执行下拉框收起时的操作即可。
效果代码如下用于控制Arrow旋转可以根据自己的想法进行修改:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;/// <summary>
/// 控制Dropdown中的Arrow效果,脚本挂在Template上
/// </summary>
public class DropdownArrowCtr : MonoBehaviour
{public RectTransform arrow;// Start is called before the first frame updatevoid Start(){if (this.name == "Dropdown List"){arrow.eulerAngles = new Vector3(0, 0, 180);}}private void OnDestroy(){if (this.name == "Dropdown List"){arrow.eulerAngles = Vector3.zero;}}
}