RayCast检测
using System. Collections ;
using System. Collections. Generic ;
using UnityEngine ;
using UnityEngine. UI ;
#if UNITY_EDITOR
using UnityEditor ;
#endif
namespace LargeScreen
{
public class NoDrawImage : Graphic
{
protected override void OnPopulateMesh ( VertexHelper vh)
{
vh. Clear ( ) ;
}
#if UNITY_EDITOR
[ CustomEditor ( typeof ( NoDrawImage ) ) ]
public class GraphicCastEditor : Editor
{
public override void OnInspectorGUI ( ) { }
}
#endif
}
}
图片旋转
using System. Collections ;
using System. Collections. Generic ;
using UnityEngine ;
namespace LargeScreen
{
[ DisallowMultipleComponent ]
public class TransFormXYZRotate : MonoBehaviour
{
private float fToatZ = 0 ;
bool bForward = false ;
public float fRotateSpeed = 150f ;
[ SerializeField ]
private float XAngle = 60f ;
private float YAngle = 0f ;
void Update ( )
{
ScoreRotate ( ) ;
}
private void ScoreRotate ( )
{
fToatZ += Time. deltaTime * fRotateSpeed;
if ( fToatZ > 360f )
{
fToatZ = 0f ;
}
if ( bForward)
{
transform. localEulerAngles = new Vector3 ( XAngle, YAngle, fToatZ) ;
}
else
{
transform. localEulerAngles = new Vector3 ( XAngle, YAngle, - fToatZ) ;
}
}
}
}
事件触发
using UnityEngine ;
using System. Collections ;
using UnityEngine. EventSystems ;
using UnityEngine. UI ;
public class UEvent : EventTrigger
{
public delegate void VoidDelegate ( ) ;
public delegate void VoidDelegateG ( GameObject go) ;
public delegate void VoidDelegate_ ( GameObject go, PointerEventData data) ;
public delegate void VoidHoverDelegate ( GameObject go, bool bHover) ;
public VoidHoverDelegate OnHover;
public VoidDelegateG onClick;
public VoidDelegateG onDoubleClick;
public VoidDelegate onDown;
public VoidDelegate onEnter;
public VoidDelegate onExit;
public VoidDelegate onUp;
public VoidDelegateG onSelect;
public VoidDelegate onUpdateSelect;
public VoidDelegate_ onClick_;
public VoidDelegate_ onUp_;
public VoidDelegate_ onEnter_;
public VoidDelegate_ onExit_;
static public UEvent Get ( GameObject go)
{
UEvent listener = go. GetComponent < UEvent> ( ) ;
if ( listener == null ) listener = go. AddComponent < UEvent> ( ) ;
if ( go. GetComponent < MaskableGraphic> ( ) )
{
go. GetComponent < MaskableGraphic> ( ) . raycastTarget = true ;
}
return listener;
}
static public UEvent Get ( Transform transform)
{
UEvent listener = transform. GetComponent < UEvent> ( ) ;
if ( listener == null ) listener = transform. gameObject. AddComponent < UEvent> ( ) ;
return listener;
}
public override void OnPointerClick ( PointerEventData eventData)
{
if ( eventData. button == PointerEventData. InputButton. Left && eventData. clickCount == 2 )
{
if ( onDoubleClick != null )
{
onDoubleClick ( gameObject) ;
}
}
else if ( eventData. clickCount == 1 )
{
if ( onClick != null ) onClick ( gameObject) ;
if ( onClick_ != null ) onClick_ ( gameObject, eventData) ;
}
}
public override void OnPointerDown ( PointerEventData eventData)
{
if ( onDown != null ) onDown ( ) ;
}
public override void OnPointerEnter ( PointerEventData eventData)
{
if ( OnHover != null ) OnHover ( gameObject, true ) ;
}
public override void OnPointerExit ( PointerEventData eventData)
{
if ( OnHover != null ) OnHover ( gameObject, false ) ;
}
public override void OnPointerUp ( PointerEventData eventData)
{
if ( onUp != null ) onUp ( ) ;
if ( onUp_ != null ) onUp_ ( gameObject, eventData) ;
}
public override void OnSelect ( BaseEventData eventData)
{
if ( onSelect != null ) onSelect ( gameObject) ;
}
public override void OnUpdateSelected ( BaseEventData eventData)
{
if ( onUpdateSelect != null ) onUpdateSelect ( ) ;
}
}
呼吸效果
using System. Collections ;
using System. Collections. Generic ;
using UnityEngine ;
using DG. Tweening ;
using UnityEngine. UI ;
public class BreathLight : MonoBehaviour
{
public Image[ ] breathLights;
void Start ( )
{
breathLights = this . transform. GetComponentsInChildren < Image> ( true ) ;
for ( int index = 0 ; index < breathLights. Length; index++ )
{
breathLights[ index] . DOFade ( 0 , 2f ) . SetDelay ( index) . SetLoops ( - 1 , LoopType. Yoyo) ;
}
}
}
读取CSV配置文件
#region 配置数据解析和处理接口
Dictionary< string , MenuNodeData> PathConfigDataDic = new Dictionary< string , MenuNodeData> ( ) ;
private void InitPathCfg ( )
{
if ( PathConfigDataDic == null )
{
PathConfigDataDic = new Dictionary< string , MenuNodeData> ( ) ;
}
if ( PathConfigDataDic. Count > 0 )
{
return ;
}
string [ ] paths = File. ReadAllLines ( Application. streamingAssetsPath + "/Path.csv" ) ;
for ( int i = 1 ; i < paths. Length; i++ )
{
string [ ] split = paths[ i] . Split ( ',' ) ;
MenuNodeData item = new MenuNodeData ( ) ;
item. id = int . Parse ( split[ 0 ] ) ;
item. key = split[ 1 ] . Trim ( ) ;
item. name = split[ 2 ] . Trim ( ) ;
item. path = split[ 3 ] . Trim ( ) ;
item. imgPath = split[ 4 ] . Trim ( ) ;
PathConfigDataDic. Add ( item. key, item) ;
}
}
public MenuNodeData GetPathCfgByKey ( string key)
{
InitPathCfg ( ) ;
MenuNodeData cfg = null ;
PathConfigDataDic. TryGetValue ( key, out cfg) ;
return cfg;
}
public class MenuNodeData
{
public int id;
public string key;
public string name;
public string path;
public string imgPath;
}
开启和杀掉进程
#region 开启和杀掉进程
public void StartProgramInvoke ( string path)
{
KillProgram ( CurProgramPath) ;
CurProgramPath = path;
CancelInvoke ( "StartProgramByPath" ) ;
Invoke ( "StartProgramByPath" , 0.5f ) ;
}
private void StartProgramByPath ( )
{
if ( string . IsNullOrEmpty ( CurProgramPath) )
{
return ;
}
ProcessStartInfo startInfo = new ProcessStartInfo ( ) ;
startInfo. FileName = @CurProgramPath;
startInfo. Arguments = "" ;
Process pro = Process. Start ( startInfo) ;
}
private void KillProgram ( string path)
{
if ( string . IsNullOrEmpty ( path) )
{
return ;
}
string appName = Path. GetFileNameWithoutExtension ( path) ;
Process[ ] allProgresse = Process. GetProcessesByName ( appName) ;
foreach ( Process closeProgress in allProgresse)
{
if ( closeProgress. ProcessName. Equals ( appName) )
{
closeProgress. Kill ( ) ;
closeProgress. WaitForExit ( ) ;
break ;
}
}
}
#endregion
帧率和分辨率设置
private void InitSetting ( )
{
Application. targetFrameRate = 55 ;
Screen. SetResolution ( 3080 , 1080 , true ) ;
}