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. Go 初体验 - 令人惊叹的语法 - defer.1 - 基本概念和用法

    在我们编程时,难免遇见 流.远程连接.文件等 io 操作,为了高性能,我们不得不打开和关系这些 io 对象. 在 java.C# 语言里这些打开和关闭的操作都需要程序员自己选择操作时机,一般是在 io ...

  2. flask 在视图函数里操作数据库

    在视图函数里操作数据库 在视图函数里操作数据的方式和在python shell中的联系基本相同,只不过需要一些额外的工作.比如把查询结果作为参数 传入模板渲染出来,或是获取表单的字段值作为提交到数据库 ...

  3. consul 集群

    主机运行 : consul agent -server -bootstrap-expect 2  -data-dir D:\consul  -node=winyh -bind=192.168.10.1 ...

  4. 零基础快速入门web学习路线(含视频教程)

    下面小编专门为广大web学习爱好者汇总了一条完整的自学线路:零基础快速入门web学习路线(含视频教程)(绝对纯干货)适合初学者的最新WEB前端学习路线汇总! 在当下来说web前端开发工程师可谓是高福利 ...

  5. double保留两位小数

    public static String format(double dValue, int lScale) { // ////负数,则装化为正数后进行四舍五入 boolean bFlag = fal ...

  6. hisi 生产固件生成

    生产需求,需要16M bin 文件 给 spi flash烧写 一般有三种方式 1.把文件都导入flash,拆了flash 用烧录器读取,比较可靠! 2.编译时候合并,需要在空余地方填充0xFF拼成1 ...

  7. 01:golang开发环境

    1.1 go环境安装 1.go下载安装 官方:https://golang.org/dl 国内: https://golang.google.cn/dl/ https://www.golangtc.c ...

  8. kubeflow 创建tensorflow过程

    online deployable ,install k8s 代码 Kubeflow有三个核心组件 TFJob Operator 和 Controller: 作为Kubernetes的扩展,来简化分布 ...

  9. 数据库分区分表(sql、mysql)

    http://blog.csdn.net/lgb934/article/details/8662956 http://www.2cto.com/database/201503/380348.html ...

  10. POJ 1390 Blocks(DP + 思维)题解

    题意:有一排颜色的球,每次选择一个球消去,那么这个球所在的同颜色的整段都消去(和消消乐同理),若消去k个,那么得分k*k,问你消完所有球最大得分 思路:显然这里我们直接用二位数组设区间DP行不通,我们 ...