using UnityEngine;
using System.Collections;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using System.Collections.Generic;
using UnityEngine .UI ;
public class DistrictBgEvent { //门户小界面按钮功能
private EventTrigger m_eventTrigger;
public string pathDistrictBg;
public GameObject PanelName;
private bool m_state = true ;
private bool m_state_2 = true;
private bool m_toggleState = false ;
// Use this for initialization //初始化
public void StartInit(GameObject Obj,string path)
{
if (PanelName.name == "mainPanel(Clone)" || PanelName.name == "mainControllerPanel(Clone)")
{
Enter(Obj, path, "Gwh", "管委会");
}
else
{
if (pathDistrictBg == "LeftBar/districtBg/mainconbg/")
{ Enter(Obj, path, "Gwh", "管委会");
}
else
{ Exit(Obj, path, "Gwh", "管委会"); } }
Exit(Obj, path, "Gjq", "高教区");
Exit(Obj, path, "Jmq", "居民区");
Exit(Obj, path, "Gyq", "工业区");
Exit(Obj, path, "Yfq", "研发区");
Exit(Obj, path, "Syq", "商业区"); m_state = true;
m_state_2 = true;
m_toggleState = false ; } //鼠标进入事件
public void MouseInit(GameObject Obj,string path) { AddTriggersListener(Obj.transform.Find(path + "LeftBtn/Gwh").gameObject, EventTriggerType.PointerEnter, GwhEnter);
AddTriggersListener(Obj.transform.Find(path + "LeftBtn/Gjq").gameObject, EventTriggerType.PointerEnter, GjqEnter);
AddTriggersListener(Obj.transform.Find(path + "LeftBtn/Jmq").gameObject, EventTriggerType.PointerEnter, JmqEnter);
AddTriggersListener(Obj.transform.Find(path + "LeftBtn/Gyq").gameObject, EventTriggerType.PointerEnter, GyqEnter);
AddTriggersListener(Obj.transform.Find(path + "LeftBtn/Yfq").gameObject, EventTriggerType.PointerEnter, YfqEnter);
AddTriggersListener(Obj.transform.Find(path + "LeftBtn/Syq").gameObject, EventTriggerType.PointerEnter, SyqEnter); if (PanelName.name == "mainPanel(Clone)" || PanelName.name == "mainControllerPanel(Clone)")
{ }
else
{
AddTriggersListener(Obj.transform.FindChild("TopBarBg/districtBg").gameObject, EventTriggerType.PointerEnter, OnPointerEnter_2);
AddTriggersListener(Obj.transform.FindChild("TopBarBg/districtBg").gameObject, EventTriggerType.PointerExit, OnPointerExit_2); AddTriggersListener(Obj.transform.FindChild(path + "RightBtn/Gwh").gameObject, EventTriggerType.PointerEnter, OnPointerEnter);
AddTriggersListener(Obj.transform.FindChild(path + "RightBtn/Gwh").gameObject, EventTriggerType.PointerExit, OnPointerExit); AddTriggersListener(Obj.transform.FindChild(path + "RightBtn/Gjq").gameObject, EventTriggerType.PointerEnter, OnPointerEnter);
AddTriggersListener(Obj.transform.FindChild(path + "RightBtn/Gjq").gameObject, EventTriggerType.PointerExit, OnPointerExit); AddTriggersListener(Obj.transform.FindChild(path + "RightBtn/Jmq").gameObject, EventTriggerType.PointerEnter, OnPointerEnter);
AddTriggersListener(Obj.transform.FindChild(path + "RightBtn/Jmq").gameObject, EventTriggerType.PointerExit, OnPointerExit); AddTriggersListener(Obj.transform.FindChild(path + "RightBtn/Gyq").gameObject, EventTriggerType.PointerEnter, OnPointerEnter);
AddTriggersListener(Obj.transform.FindChild(path + "RightBtn/Gyq").gameObject, EventTriggerType.PointerExit, OnPointerExit); AddTriggersListener(Obj.transform.FindChild(path + "RightBtn/Yfq").gameObject, EventTriggerType.PointerEnter, OnPointerEnter);
AddTriggersListener(Obj.transform.FindChild(path + "RightBtn/Yfq").gameObject, EventTriggerType.PointerExit, OnPointerExit); AddTriggersListener(Obj.transform.FindChild(path + "RightBtn/Syq").gameObject, EventTriggerType.PointerEnter, OnPointerEnter);
AddTriggersListener(Obj.transform.FindChild(path + "RightBtn/Syq").gameObject, EventTriggerType.PointerExit, OnPointerExit); AddTriggersListener(Obj.transform.FindChild("TopBarBg/LeftPanel/LeftButtons/mainConBtn").gameObject, EventTriggerType.PointerEnter, OnPointerEnter_3);
AddTriggersListener(Obj.transform.FindChild("TopBarBg/LeftPanel/LeftButtons/mainConBtn").gameObject, EventTriggerType.PointerExit, OnPointerExit_3); } } //监控系统下拉菜单点击关闭
public void MouseClickUpdate(GameObject Obj,GameObject Obj_2)
{ if (m_toggleState && Input.GetMouseButton() && Obj.transform.GetComponent<Toggle>().isOn && m_state && m_state_2 )
{
Obj.transform.FindChild("Text")
.GetComponent<Text>()
.color = new Color( / 255f, / 255f, / 255f, );
Obj_2.SetActive(false);
Obj.transform.GetComponent<Toggle>().isOn = false;
} } //门户小界面按钮功能 /// <summary>
/// 为obj添加Eventrigger监听事件
/// </summary>
/// <param name="obj">添加监听的对象</param>
/// <param name="eventType">添加的监听类型</param>
/// <param name="action">触发的函数</param>
public void AddTriggersListener(GameObject obj, EventTriggerType eventType, UnityAction<BaseEventData> action)
{
m_eventTrigger = obj.GetComponent<EventTrigger>();
if (m_eventTrigger == null)
{
m_eventTrigger = obj.AddComponent<EventTrigger>();
}
if (m_eventTrigger.triggers.Count == )
{
m_eventTrigger.triggers = new List<EventTrigger.Entry>();
}
//定义所要绑定的事件类型
EventTrigger.Entry entry = new EventTrigger.Entry();
//设置事件类型
entry.eventID = eventType;
//定义回调函数
UnityAction<BaseEventData> callback = new UnityAction<BaseEventData>(action);
//设置回调函数
entry.callback.AddListener(callback);
//添加事件触发记录到GameObject的事件触发组件
m_eventTrigger.triggers.Add(entry); }
private void Enter(GameObject obj,string path, string name_1, string name_2)
{ obj.transform.FindChild(path + "LeftBtn/" + name_1 + "/Image").gameObject.SetActive(true);
obj.transform.FindChild(path + "RightBtn/" + name_1).gameObject.SetActive(true);
if (obj.name == "mainPanel(Clone)" || obj.name == "mainControllerPanel(Clone)")
{
obj.transform.FindChild(path + "LeftBtn/" + name_1 + "/Text").gameObject.GetComponent<Text>().color =
new Color(, /225f, /225f, );
obj.transform.FindChild(path + "LeftBtn/" + name_1 + "/Text").gameObject.GetComponent<Text>().text = " " +name_2 +" >".ToString();
}
else
{
if (pathDistrictBg == "LeftBar/districtBg/mainconbg/")
{ obj.transform.FindChild(pathDistrictBg + "LeftBtn/" + name_1 + "/Text").gameObject.GetComponent<Text>().color =
new Color(, /225f, /225f, );
obj.transform.FindChild(pathDistrictBg + "LeftBtn/" + name_1 + "/Text").gameObject.GetComponent<Text>().text =
" " + name_2 + " >".ToString(); }
else
{ }
} } private void Exit(GameObject obj,string path, string name_1, string name_2)
{
obj.transform.FindChild(path + "RightBtn/" + name_1).gameObject.SetActive(false);
obj.transform.FindChild(path + "LeftBtn/" + name_1 + "/Image").gameObject.SetActive(false);
if (obj.name == "mainPanel(Clone)" || obj.name == "mainControllerPanel(Clone)")
{
obj.transform.FindChild(path + "LeftBtn/" + name_1 + "/Text").gameObject.GetComponent<Text>().text =
name_2.ToString();
obj.transform.FindChild(path + "LeftBtn/" + name_1 + "/Text").gameObject.GetComponent<Text>().color =
Color.white;
}
else
{ if (pathDistrictBg == "LeftBar/districtBg/mainconbg/")
{ obj.transform.FindChild(pathDistrictBg + "LeftBtn/" + name_1 + "/Text").gameObject.GetComponent<Text>().text =
name_2.ToString();
obj.transform.FindChild(pathDistrictBg + "LeftBtn/" + name_1 + "/Text").gameObject.GetComponent<Text>().color =
Color.white; }
else
{ }
}
} private void GwhEnter(BaseEventData arg0)
{
// Debug.Log("GwhEnter");
Enter(PanelName,pathDistrictBg, "Gwh", "管委会");
Exit(PanelName,pathDistrictBg, "Gjq", "高教区");
Exit(PanelName,pathDistrictBg, "Jmq", "居民区");
Exit(PanelName,pathDistrictBg, "Gyq", "工业区");
Exit(PanelName,pathDistrictBg, "Yfq", "研发区");
Exit(PanelName,pathDistrictBg, "Syq", "商业区"); } private void GwhExit(BaseEventData arg0)
{
// Debug.Log("GwhExit"); } private void GjqEnter(BaseEventData arg0)
{
// Debug.Log("GjqEnter");
Enter(PanelName,pathDistrictBg, "Gjq", "高教区");
Exit(PanelName,pathDistrictBg, "Gwh", "管委会");
Exit(PanelName,pathDistrictBg, "Jmq", "居民区");
Exit(PanelName,pathDistrictBg, "Gyq", "工业区");
Exit(PanelName,pathDistrictBg, "Yfq", "研发区");
Exit(PanelName,pathDistrictBg, "Syq", "商业区"); }
private void JmqEnter(BaseEventData arg0)
{
// Debug.Log("JmqEnter");
Enter(PanelName,pathDistrictBg, "Jmq", "居民区");
Exit(PanelName,pathDistrictBg, "Gwh", "管委会");
Exit(PanelName,pathDistrictBg, "Gjq", "高教区");
Exit(PanelName,pathDistrictBg, "Gyq", "工业区");
Exit(PanelName,pathDistrictBg, "Yfq", "研发区");
Exit(PanelName,pathDistrictBg, "Syq", "商业区"); }
private void GyqEnter(BaseEventData arg0)
{
// Debug.Log("GyqEnter");
Enter(PanelName,pathDistrictBg, "Gyq", "工业区");
Exit(PanelName,pathDistrictBg, "Gwh", "管委会");
Exit(PanelName,pathDistrictBg, "Jmq", "居民区");
Exit(PanelName,pathDistrictBg, "Gjq", "高教区");
Exit(PanelName,pathDistrictBg, "Yfq", "研发区");
Exit(PanelName,pathDistrictBg, "Syq", "商业区"); }
private void YfqEnter(BaseEventData arg0)
{
// Debug.Log("YfqEnter");
Enter(PanelName,pathDistrictBg, "Yfq", "研发区");
Exit(PanelName,pathDistrictBg, "Gwh", "管委会");
Exit(PanelName,pathDistrictBg, "Jmq", "居民区");
Exit(PanelName,pathDistrictBg, "Gyq", "工业区");
Exit(PanelName,pathDistrictBg, "Gjq", "高教区");
Exit(PanelName,pathDistrictBg, "Syq", "商业区"); } private void SyqEnter(BaseEventData arg0)
{
// Debug.Log("SyqEnter");
Enter(PanelName,pathDistrictBg, "Syq", "商业区");
Exit(PanelName,pathDistrictBg, "Gwh", "管委会");
Exit(PanelName,pathDistrictBg, "Jmq", "居民区");
Exit(PanelName,pathDistrictBg, "Gyq", "工业区");
Exit(PanelName,pathDistrictBg, "Yfq", "研发区");
Exit(PanelName,pathDistrictBg, "Gjq", "高教区"); }
//监控系统下拉菜单
private void OnPointerEnter(BaseEventData arg0)
{
m_state = false ;
Debug.Log("m_state" + m_state);
} private void OnPointerExit(BaseEventData arg0)
{
m_state = true ;
Debug.Log("m_state" + m_state);
}
private void OnPointerEnter_2(BaseEventData arg0)
{
m_state_2 = false ;
Debug.Log("m_state_2" + m_state_2);
} private void OnPointerExit_2(BaseEventData arg0)
{
m_state_2 = true ;
Debug.Log("m_state_2" + m_state_2);
}
private void OnPointerEnter_3(BaseEventData arg0)
{
m_toggleState = false ;
Debug.Log("m_toggleState" + m_toggleState);
} private void OnPointerExit_3(BaseEventData arg0)
{
m_toggleState = true ;
Debug.Log("m_toggleState" + m_toggleState);
}
}

unity中Event Trigger组件应用代码的更多相关文章

  1. UGUI中Event Trigger的基本用法

    UGUI中Event Trigger的基本用法 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chin ...

  2. Unity 中调用Android的JAVA代码

    首先我们要创建一个android项目 因为项目需要使用Unity提供的接口,所以需要将接口classes.jar引入至当前工程但中.接口包的所在地,打开Finder->应用程序->Unit ...

  3. 关于Unity中的transform组件(一)

    一.transform组件用途 1.维护场景树 2.对3D物体的平移,缩放,旋转 二.场景树定义 在Hierarchy视图中显示的: 一个game_scene场景,下面有Main Camera节点,D ...

  4. 关于Unity中的transform组件(二)

    在Scene视图中的蓝色网格,每一格默认是1米 一.沿着Z轴每秒移动10米 Transform cube_trans; void start(){ this.cube_trans=this.trans ...

  5. 关于Unity中的transform组件(三)

    game_root节点下右一个Cube子节点,和一个Sphere节点,脚本挂载在game_root下 四元数:(1)Quaternion rot (2)this.cube.rotation 欧拉角:V ...

  6. unity中UI的屏幕自适应代码

    public void ScreenUISelfAdptation(Transform scaleUI) { float widthrate = UnityEngine.Screen.width / ...

  7. unity中编辑器直接截屏代码

    using UnityEngine; using System.Collections; using System.Windows.Forms; public class screenshots : ...

  8. Unity中使用摇杆控制

    Unity中使用摇杆控制 本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/50 ...

  9. unity3d ppsspp模拟器中的post processing shader在unity中使用

    这个位置可以看到ppsspp的特殊处理文件位置来看看这些特效 用来测试的未加特效图片 ppsspp: 传说系列一生爱---英杰传说 最后的战士 aacolor 是关于饱和度,亮度,对比度,色调的调节, ...

随机推荐

  1. cocos creator怎么隐藏组件(setVisible)

    以 label 为例: this.label.node.active = fasle 隐藏节点this.label.ndoe.active = true显示节点

  2. 55.Vue环境搭建

    Vue环境搭建 在搭建过程中出现的错误解决办法  https://www.cnblogs.com/lovebing/p/9488198.html      cross-env使用笔记   cross- ...

  3. appium环境搭建-运行

    appium是测试移动端的测试工具 首先要下载手机模拟器,或者连接真机.我用的夜神模拟器.安装打开它.安装这个有很高的兼容性要求,我也是小白,摸索了三天才弄出来 一.原理如图: 二.需要安装的软件: ...

  4. #WEB安全基础 : HTTP协议 | 0x7 学会使用wireshark分析数据包

    wireshark是开源,免费,跨平台的抓包分析工具 我们可以通过wireshark学习HTTP报文和进行抓包分析,在CTF中的流量分析需要用到抓包 1.下载和安装 这是wireshark的官网 ht ...

  5. python assert断言函数

    python assert断言是声明布尔值必须为真的判定,如果发生异常就说明表达式为假. 可以理解assert断言语句为raise-if-not,用来测试表示式,其返回值为假,就会触发异常. self ...

  6. demo1:会下蛋的机器人

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. Hdu2602 Bone Collector (01背包)

    Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...

  8. mybatis中的foreach方法

    select  t.service_id, t.prod_id, t.prod_name, t.prod_type, t.buss_type, t.pricing_fee, t.detail from ...

  9. Visual Studio 2017 最新全量离线下载方法[有惊喜]

    从官网下载的是 VS在线安装程序,也只有这个可以下载,官网并不提供离线包下载,那么如何创建离线安装包呢? 使用cmd命令:vs_enterprise__914632938.1491737491.exe ...

  10. html5+PHP,websocket无法连接的问题(Call to undefined function socket_create())

    首先是配置文件的问题,打开extension=php_gd2.dll和extension=php_sockets.dll 扩展. 主要注意的是你当前系统使用的php版本和环境变量里面的php版本是否一 ...