使用HighlightingSystem时的一点记录。
highlighter.tweenDuration = 1;
highlighter.tweenRepeatCount = 3; //闪烁次数
highlighter.tweenGradient.SetKeys(new GradientColorKey[] {
new GradientColorKey { color=new Color(1,0,0),time=0.5f}, new GradientColorKey { color=new Color(0,1,0),time=1f}}, new GradientAlphaKey[] {new GradientAlphaKey{alpha=255},new GradientAlphaKey{alpha=255,time=1.5f}
});
highlighter.TweenStart();//闪烁
实现点按物体高亮
实现方法:在鼠标点击时从camera中发出射线,射线打到的物体添加高亮组件并高亮,如果此物体已经有高亮组件则删除高亮组件。
if (Input.GetMouseButton(0))
{
Ray ray = Cam.ScreenPointToRay(Input.mousePosition);//鼠标的屏幕坐标转化为一条射线'
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
//print(hit.point);
var hitObj = hit.collider.gameObject;
if(hitObj.TryGetComponent<Highlighter>(out highlighter))//如果已经有高亮组件,再次点击删除(停止高亮)
{
Destroy(hitObj.GetComponent<Highlighter>());
}
else
{
highlighter = hitObj.AddComponent<Highlighter>();
//highlighter.ConstantOn(Color.red, 3f);//红色高亮 3秒到最亮
highlighter.tweenDuration = 1;
highlighter.tweenRepeatCount = 3; //闪烁次数
highlighter.tweenGradient.SetKeys(new GradientColorKey[] {
new GradientColorKey { color=new Color(1,0,0),time=0.5f},
new GradientColorKey { color=new Color(0,1,0),time=1f}},
new GradientAlphaKey[] {new GradientAlphaKey{alpha=255},
new GradientAlphaKey{alpha=255,time=1.5f}
});
highlighter.TweenStart();//闪烁
}
}
}