4.2.1
1. 改变点击的颜色设置,不使用它自带的基本点击色
private bool isok = true;
if (Input.GetButtonDown(buttonFire1))
{
if (!targetTransform.GetComponent<HighlighterFlashing>())
targetTransform.gameObject.AddComponent<HighlighterFlashing>();
Highlighter ht = targetTransform.GetComponentInParent<Highlighter>();
// ht.FlashingOn(new Color(1, 0, 0, 1), new Color(1, 0, 0, 1), 0);
isok = !isok;
if (isok)
{
ht.FlashingOn();//重载,startcolor,endcolor, fre以及延迟
}
else
{
ht.FlashingOff();
}
}
也可以直接在HighlighterFlashing这个脚本中直接修改初始的颜色值,
2. Highlighter ht = targetTransform.GetComponentInParent<Highlighter>();
ht.FlashingOn(new Color(1, 0, 0, 1), new Color(1, 0, 0, 1), 0);
当程序运行时,如果想修改初始的闪烁色值,这时修改HighlighterFlashing里的颜色值时是没有用的,只能修改脚本Highlighter 里的 ht.FlashingOn(new Color(1, 0, 0, 1), new Color(1, 0, 0, 1), 0);才能改变自身的闪烁的颜色
5.0
5.0版本的功能感觉更加完美和理解,更加一目了然,
下面修改了一点代码是相机RaycastController的点击颜色切换
private Stack<Highlighter> OnMouseClickHighlihter = new Stack<Highlighter>();
private void PerformRaycast(UpdateEvent currentEvent)
{
if (currentEvent != updateEvent) { return; }
if (cam == null) { return; }
if (onHover == null) { return; }
if (EventSystem.current.IsPointerOverGameObject())
{
return;
}
else
{
RaycastHit hitInfo;
// Create a ray from mouse coords
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
// Targeting raycast
if (Physics.Raycast(ray, out hitInfo, rayLength >= 0f ? rayLength : Mathf.Infinity, layerMask.value))
{
if (!hitInfo.collider.transform.GetComponent<Highlighter>())
hitInfo.collider.gameObject.AddComponent<Highlighter>().tweenGradient.SetKeys(new GradientColorKey[] {
new GradientColorKey { color=new Color(1,1,0),time=0.5f}, new GradientColorKey { color=new Color(0,1,0),time=1}}, new GradientAlphaKey[] {new GradientAlphaKey{alpha=255},new GradientAlphaKey{alpha=255,time=1f}
});
hitInfo.collider.transform.GetComponent<Highlighter>().overlay = true;
OnMouseEnterOrExit.OnMouseEnter(hitInfo.collider.gameObject);
if (Input.GetMouseButtonDown(0))
{
if (OnMouseClickHighlihter.Count != 0)
{
//Debug.Log("ssss");
for (int i = 0; i < OnMouseClickHighlihter.Count; i++)
{
if (OnMouseClickHighlihter.Peek())
{
OnMouseClickHighlihter.Pop().GetComponent<Highlighter>().Off();
}
}
}
OnMouseClickHighlihter.Push(hitInfo.collider.transform.GetComponent<Highlighter>());
}
onHover.Invoke(hitInfo);
}
}
}
//setkey设置颜色值以及区间值 ,overlay 开启时物体点击色能够渲染在相机最前面
hitInfo.collider.gameObject.AddComponent<Highlighter>().tweenGradient.SetKeys(new GradientColorKey[] {
new GradientColorKey { color=new Color(1,1,0),time=0.5f}, new GradientColorKey { color=new Color(0,1,0),time=1}}, new GradientAlphaKey[] {new GradientAlphaKey{alpha=255},new GradientAlphaKey{alpha=255,time=1f}
});
hitInfo.collider.transform.GetComponent<Highlighter>().overlay = true;
开启或者关闭颜色 highlighter.tween = !highlighter.tween;