您现在的位置是:首页 >技术教程 >【Unity】简单的边缘高亮网站首页技术教程
【Unity】简单的边缘高亮
简介【Unity】简单的边缘高亮
【Unity】简单的边缘高亮
全部文件
使用方法
方法 | 功能 |
---|---|
On() | 打开单帧高亮显示 |
On(Color color) | 打开单帧高亮显示 |
FlashingParams(Color color1, Color color2, float freq) | 闪烁的参数设置 |
FlashingOn | 打开闪烁 |
FlashingOn(Color color1, Color color2) | 从颜色1切换到颜色2 |
FlashingOn(Color color1, Color color2, float freq) | 从color1到color2按指定频率打开闪烁 |
FlashingOn(float freq) | 按规定的频率打开闪光灯 |
FlashingOff() | 关掉闪光 |
FlashingSwitch() | 切换闪光模式 |
ConstantParams(Color color) | 设置常量高亮颜色 |
ConstantOn() | 淡入持续的高光 |
ConstantOn(Color color) | 褪色在不断突出与给定的颜色 |
ConstantOff() | 淡出持续的高光 |
ConstantSwitch() | 切换不断凸显 |
ConstantOnImmediate() | 立即打开持续高亮(不褪色) |
ConstantOnImmediate(Color color) | 立即用指定的颜色打开持续高亮(不褪色) |
ConstantOffImmediate() | 立即关闭持续高亮(不淡出) |
ConstantSwitchImmediate() | 立即切换常量高亮(不淡入/淡出) |
OccluderOn() | 启用遮光板模式 |
OccluderOff() | 关闭遮光板模式 |
OccluderSwitch() | 切换遮光板模式 |
Off() | 关掉所有类型的高亮显示 |
Des() | 销毁这个HighlightableObject组件 |
Demo
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HighlightUser : MonoBehaviour
{
public enum HighType {on, ConstantOn , ConstantOnImmediate , ConstantSwitch , FlashingOn , Off }
RaycastHit hit;
Action<HighlightableObject> action;
GameObject Target;
HighType currentType;
Color CurrentColor=Color.green;
private HighType CurrentType {
get {
return currentType;
}
set
{
currentType = value;
SetAction(currentType);
}
}
private void Start()
{
CurrentType = HighType.on;
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray,out hit))
{
Target = hit.collider.gameObject;
higtObj(Target);
}
}
}
void higtObj(GameObject game)
{
HighlightableObject highlightableObject;
game.TryGetComponent<HighlightableObject>(out highlightableObject);
if (highlightableObject)
{
action(highlightableObject);
}
else
{
game.AddComponent<HighlightableObject>();
higtObj(game);
}
}
void SetAction(HighType type)
{
switch (type)
{
case HighType.on:
action = On;
break;
case HighType.ConstantOn:
action = ConstantOn;
break;
case HighType.ConstantOnImmediate:
action = ConstantOnImmediate;
break;
case HighType.ConstantSwitch:
action = ConstantSwitch;
break;
case HighType.FlashingOn:
action = FlashingOn;
break;
case HighType.Off:
action = Off;
break;
default:
break;
}
}
/// <summary>
/// 单帧高亮
/// </summary>
/// <param name="highlightableObject"></param>
private void On(HighlightableObject highlightableObject)
{
highlightableObject.On(CurrentColor);
}
/// <summary>
/// 持续高亮
/// </summary>
/// <param name="highlightableObject"></param>
private void ConstantOn(HighlightableObject highlightableObject)
{
highlightableObject.ConstantOn(CurrentColor);
}
/// <summary>
/// 立刻持续高亮
/// </summary>
/// <param name="highlightableObject"></param>
private void ConstantOnImmediate(HighlightableObject highlightableObject)
{
highlightableObject.ConstantOnImmediate(CurrentColor);
}
/// <summary>
/// 切换不断凸显
/// </summary>
/// <param name="highlightableObject"></param>
private void ConstantSwitch(HighlightableObject highlightableObject)
{
highlightableObject.ConstantSwitch();
}
/// <summary>
/// 打开闪烁
/// </summary>
/// <param name="highlightableObject"></param>
private void FlashingOn(HighlightableObject highlightableObject)
{
highlightableObject.FlashingOn(Color.yellow,Color.blue);
}
/// <summary>
/// 关闭全部高亮
/// </summary>
/// <param name="highlightableObject"></param>
private void Off(HighlightableObject highlightableObject)
{
highlightableObject.Off();
}
public void SetType(int highType)
{
CurrentType = (HighType)highType;
}
public void SetColor(int color)
{
if (color==0)
{
CurrentColor = Color.red;
}
else if (color == 1)
{
CurrentColor = Color.green;
}
else if (color == 2)
{
CurrentColor = Color.blue;
}
}
}
风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。