/******************************************************************************
*
* Logs:
* 2017-2-10 mx Initial version:Added API SwithHightlightAPI()
*
*
******************************************************************************/
using HighlightingSystem;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 将此脚本挂载到需要高亮的物体上
/// required package: Highlighting System
/// </summary>
public class HighlightObject : MonoBehaviour
{
protected Highlighter h;
public enum HighlightType
{
Once,//变化一次
Constant,//持续
Flash//闪烁
}
public Color highlightColor = Color.red;
void Awake()
{
h = gameObject.AddComponent<Highlighter>();
if (Camera.main.GetComponent<HighlightingRenderer>() == null)
{
Camera.main.gameObject.AddComponent<HighlightingRenderer>();
}
}
/// <summary>
/// API:修改物体是否开启高亮
/// </summary>
/// <param name="showHightlight">是否开启高亮</param>
public void SwithHightlight(bool showHightlight)
{
SwithHightlight(showHightlight, HighlightType.Once);
}
/// <summary>
/// API:修改物体是否开启高亮
/// </summary>
/// <param name="showHightlight">是否开启高亮</param>
/// <param name="type">高亮类型</param>
public void SwithHightlight(bool showHightlight, HighlightType type)
{
switch (type)
{
case HighlightType.Once:
if (showHightlight)
h.ConstantOnImmediate(highlightColor);
else
h.ConstantOffImmediate();
break;
case HighlightType.Constant:
if (showHightlight)
h.ConstantOn(highlightColor);
else
h.ConstantOff();
break;
case HighlightType.Flash:
if (showHightlight)
h.FlashingOn(highlightColor, new Color(0, 0, 0, 0));
else
h.FlashingOff();
break;
}
}
#region 测试:QWE键控制高亮类型
void Update()
{
if (Input.GetKeyDown(KeyCode.Q))
{
SwithHightlight(true);
}
else if (Input.GetKeyUp(KeyCode.Q))
{
SwithHightlight(false);
}
if (Input.GetKeyDown(KeyCode.W))
{
SwithHightlight(true, HighlightType.Constant);
}
else if (Input.GetKeyUp(KeyCode.W))
{
SwithHightlight(false, HighlightType.Constant);
}
if (Input.GetKeyDown(KeyCode.E))
{
SwithHightlight(true, HighlightType.Flash);
}
else if (Input.GetKeyUp(KeyCode.E))
{
SwithHightlight(false, HighlightType.Flash);
}
}
#endregion
}
高亮显示脚本
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- IDEA默认对properties文件是进行关键字检查造成 setting里面搜索 ”Unused“ 或者 "In...