zoukankan      html  css  js  c++  java
  • 获取Button的名字 并在按下时持续打印

    //方法一:利用泛型集合 获取Button名字 实现持续打印
    
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;
    using System.Collections.Generic;
    
    public class PrintInfo : MonoBehaviour
    {
      public List<GameObject> printAddInfo = new List<GameObject>();//增加按钮
      public List<GameObject> PrintSubInfo = new List<GameObject>();//减小按钮
      bool flag = false;
      GameObject go;
      void Start()
      {
        for (int i = 0; i < printAddInfo.Count; i++)
        {
          int j = i;
          EventTriggerListener.Get(printAddInfo[j]).onDown += MouseOnDown;
          EventTriggerListener.Get(printAddInfo[j]).onUp += MouseOnUp;
        }
        for (int i = 0; i <PrintSubInfo.Count; i++)
        {
          int j = i;
          EventTriggerListener.Get(PrintSubInfo[j]).onDown += MouseOnDown;
          EventTriggerListener.Get(PrintSubInfo[j]).onUp += MouseOnUp;
        }
      }
      void MouseOnDown(GameObject btn)
      {
        go = btn;
        flag = true;
      }
      void MouseOnUp(GameObject btn)
      {
        go = null;
        flag = false;
      }
      void Update()
      {
        if (go != null)
        {
          Debug.Log(go.name);
        }
      }
    }
    
     
    
    //方法二:读取字符串 获取名字 在属性面板绑定字符串
    
    using UnityEngine;
    using System.Collections;
    using UnityEngine.EventSystems;
    public class PrintNewInfo : MonoBehaviour,IPointerDownHandler,IPointerUpHandler
    
    {
      public string Info;
      bool flag = false;
      void Update () 
      {
        if(flag)
        {
          Debug.Log(Info);
        }
      }
      public void OnPointerDown(PointerEventData eventData)
      {
        flag = true;
      }
      public void OnPointerUp(PointerEventData eventData)
      {
        flag = false;
      }
    
    }
  • 相关阅读:
    python中不可变数据类型和可变数据类型
    悲观锁与乐观锁
    MySql的隔离级别和锁的关系
    关于content-type请求头的说明
    数据库事务的四大特性以及事务的隔离级别
    [Vue] : 路由
    [Vue] : 组件
    [Vue] : vue-resource 实现 get, post, jsonp请求
    [Vue] : 动画
    [Vue] : 自定义指令
  • 原文地址:https://www.cnblogs.com/Cocomo/p/5711162.html
Copyright © 2011-2022 走看看