zoukankan      html  css  js  c++  java
  • Unity 白猫操作小实例

    最近师兄找我说白猫的操作如何做,  0.0 结果白猫没有android的客户端玩不了,看了下视频介绍就简单做了下

    效果图:

    1

    核心代码:

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using System;
    
    public class Test : MonoBehaviour {
    
        private Test() { }
    
        private Vector3 startMouseDown;
        private Vector3 lastMouseDown;
        private float pressTimer;
        private bool isCounter;             //开始计数
        private bool isDrag;                //开始拖动
        private bool isLasting;             //开始持久点击
    
    
        public float pressTime;             //单击
        public float pressLastingTime;      //持久点击
        public float dragDistance;          //拖动大于多少才开始生效
    
        #region 事件
        public static Action<Vector3> StartPressEvent;
        public static Action<Vector3> EndPressEvent;
    
        public static Action<Vector3> StartDragEvent;
        public static Action<Vector3> EndDragEvent;
    
        public static Action<Vector3> StartLastingEvent;
        public static Action<Vector3> EndLastingEvent;
        #endregion
    
        #region 测试方法
        void Awake()
        {
            StartPressEvent += StartPress;
            EndPressEvent += EndPress;
    
            StartDragEvent += StartDrag;
            EndDragEvent += EndDrag;
    
            StartLastingEvent += StartLasting;
            EndLastingEvent += EndLasting;
        }
    
        private void StartPress(Vector3 v)
        {
            Debug.Log("开始单击事件");
        }
    
        private void EndPress(Vector3 v)
        {
            Debug.Log("结束单击事件");
        }
    
        private void StartDrag(Vector3 v)
        {
            Debug.Log("开始拖动事件");
        }
    
        private void EndDrag(Vector3 v)
        {
            Debug.Log("结束拖动事件");
        }
    
        private void StartLasting(Vector3 v)
        {
            Debug.Log("开始持续点击事件");
        }
    
        private void EndLasting(Vector3 v)
        {
            Debug.Log("结束持续点击事件");
        }
        #endregion
    
        // Update is called once per frame
        void Update () {
    
            if (Input.GetMouseButtonDown(0))
            {
                isCounter = true;
                startMouseDown = Input.mousePosition;
            }
    
            if (Input.GetMouseButtonUp(0))
            {
                lastMouseDown = Input.mousePosition;
                isCounter = false;
    
                if (isDrag) 
                {
                    //拖动
                    if (EndDragEvent != null) EndDragEvent(Input.mousePosition);
                    isDrag = false;
                }
                else if (isLasting) 
                {
                    //持久点击
                    if (EndLastingEvent != null) EndLastingEvent(Input.mousePosition);
                    isLasting = false;
                }
                else 
                {
                    //单击
                    if (EndPressEvent != null) EndPressEvent(Input.mousePosition);
                }
    
            }
    
            if (isCounter)
            {
                //开始计数
                pressTimer += Time.deltaTime;
            }
            else 
            {
                if (pressTimer > 0 && pressTimer < pressTime)
                {
                    Debug.Log("单击");
                    if (StartPressEvent != null) StartPressEvent(Input.mousePosition);
    
                }
    
                pressTimer = 0f;
            }
    
            if (isCounter && Mathf.Abs(Vector3.Distance(startMouseDown, Input.mousePosition)) > dragDistance && isLasting == false)
            {
                Debug.Log("正在拖动");
                isDrag = true;
    
                if (StartDragEvent != null) StartDragEvent(Input.mousePosition);
               
                //让人物跟谁手指的方向移动
                return;
            }
    
            if (isCounter && pressTimer > pressLastingTime && isDrag == false)
            {
                Debug.Log("持久点击");
                isLasting = true;
    
                if (StartLastingEvent != null) StartLastingEvent(Input.mousePosition);
                
                //出现技能图标,然后滑动到技能哪里就可以触发技能
                
                return;
            }
    
    
        }
    
    
    
    }

    Unity5 + UGUI制作

    完整的demo: http://yunpan.cn/cjHbIaXvzemax  访问密码 7607

    如果你感兴趣,你可以把你妹妹介绍给我
  • 相关阅读:
    函数式宏定义与普通函数
    linux之sort用法
    HDU 4390 Number Sequence 容斥原理
    HDU 4407 Sum 容斥原理
    HDU 4059 The Boss on Mars 容斥原理
    UVA12653 Buses
    UVA 12651 Triangles
    UVA 10892
    HDU 4292 Food
    HDU 4288 Coder
  • 原文地址:https://www.cnblogs.com/plateFace/p/4474072.html
Copyright © 2011-2022 走看看