• 获取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装饰器的wraps作用
    lambda函数和map函数
    python直接赋值、切片、浅拷贝和深拷贝
    ubuntu shell脚本出错 dash
    关于方法论和相关书籍
    如何安全的大数据量表在线进行DML操作
    mysql group by 查询非聚集列
    MongoTemplate进行增删改查
    Mockito 的用法
    一个人开始优秀的3种迹象
  • 原文地址:https://www.cnblogs.com/Cocomo/p/5711162.html
Copyright © 2020-2023  润新知