【发布时间】:2018-11-26 08:49:50
【问题描述】:
我想在我的统一 UI 中的输入字段中添加一个简单的搜索动画。
这是我的 InputField,我的想法是,当我选择它时,它应该慢慢扩展,当我取消选择它时,它应该收缩回正常形式。
这是此输入字段的矩形变换组件。我添加了输入字段和事件触发器组件和一个动画器。我创建了两个名为 SearchAnimation 和 DeselectAnimation 的动画,并将它们添加到名为“SearchController”的 AnimationController 中。 这就是我设计 SearchController 的方式: 我将 defaultState 和 SearchAnimation 之间的转换设置为监听 SelectBool 和 DeselectBool(名称已经描述了它的用途)。
然后我将以下脚本添加到我的输入字段中,以便根据事件触发器设置这两个布尔值:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class OnClickScript : MonoBehaviour {
Animator anim;
void Start()
{
anim = GetComponent<Animator>();
}
public void OnSelect()
{
anim.SetBool("SelectBool", true);
anim.SetBool("DeselectBool", false);
GetComponent<RectTransform>().sizeDelta = new Vector2(450, 50);
GetComponent<RectTransform>().localPosition.Set(-275, 0, 0);
}
public void OnDeselect()
{
anim.SetBool("DeselectBool", true);
anim.SetBool("SelectBool", false);
GetComponent<RectTransform>().sizeDelta = new Vector2(200, 50);
GetComponent<RectTransform>().localPosition.Set(-130, 0, 0);
}
}
但在播放动画后,输入字段会被设置回其初始大小和位置。我该如何解决这个问题?
【问题讨论】:
标签: unity3d