PIXNET Logo登入

江鳥Unity 分享

跳到主文

這是一個分享的地方

部落格全站分類:電玩動漫

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 3月 28 週一 201610:27
  • 淚的小雨 二胡獨奏


(繼續閱讀...)
文章標籤

GABY 發表在 痞客邦 留言(0) 人氣(68)

  • 個人分類:二胡
▲top
  • 3月 25 週五 201617:40
  • 兩隻手指的操控:相同方向的移動是旋轉,相反方向的移動是縮放

using UnityEngine;
using System.Collections;
using System;
/// <summary>
/// 兩隻手指的操控:相同方向的移動是旋轉,相反方向的移動是縮放
/// </summary>
public class DetectTouchMovement : MonoBehaviour 
{
    const float pinchTurnRatio = Mathf.PI / 2;
    const float minTurnAngle = 10f;
    const float pinchRatio = 1;
    const float minPinchDistance = 1f;
    
    const float panRatio = 1;
    const float minPanDistance = 0;
    Quaternion desiredRotation;
    /// <summary>
    ///   The delta of the angle between two touch points
    /// </summary>
    static public float turnAngleDelta;
    /// <summary>
    ///   The angle between two touch points
    /// </summary>
    static public float turnAngle;
    
    /// <summary>
    ///   The delta of the distance between two touch points that were distancing from each other
    /// 兩個觸摸點之間進行了相互保持距離增量
    /// </summary>
    static public float pinchDistanceDelta;
    /// <summary>
    ///   兩隻手指距離
    /// </summary>
    static public float pinchDistance;
    public static bool mFingerUP=true;
    bool mRotate=false;
    bool mCanDistance=false;
    string mScale="30";
    string mRotationvalue="0.05";
    public Action<float> mScaleEven;
    static Touch mOldTouch1=new Touch();
    /// <summary>
    ///   Calculates Pinch and Turn - This should be used inside LateUpdate
    /// </summary>
    static public void Calculate () 
    {
        pinchDistance = pinchDistanceDelta = 0;
        turnAngle = turnAngleDelta = 0;
        
        // if two fingers are touching the screen at the same time ...
        if (Input.touchCount == 2) 
        {
            Touch touch1 = Input.touches[0];
            Touch touch2 = Input.touches[1];
            mFingerUP=false;
            // ... if at least one of them moved ...
            if (touch1.phase == TouchPhase.Moved || touch2.phase == TouchPhase.Moved) 
            {
                // ... check the delta distance between them ...
                pinchDistance = Vector2.Distance(touch1.position, touch2.position);
                float prevDistance = Vector2.Distance(touch1.position - touch1.deltaPosition,
                                                      touch2.position - touch2.deltaPosition);
                pinchDistanceDelta = pinchDistance - prevDistance;
                //dot>0=旋轉,dot <=0 縮放
                float aDot = Vector2.Dot( touch1.deltaPosition.normalized, touch2.deltaPosition.normalized );
                //Debug.Log("70 aDot="+aDot);
                if(aDot>0.8f)
                {//旋轉
                    turnAngle = Angle(touch1.position, touch2.position);
                    float prevTurn = Angle(touch1.position - touch1.deltaPosition,
                                           touch2.position - touch2.deltaPosition);
                    //turnAngleDelta = Mathf.DeltaAngle(prevTurn, turnAngle);
                    turnAngleDelta=prevTurn;
                    
                    if(mOldTouch1.position.x > touch1.position.x)
                        turnAngleDelta*=-1f;
                    
                    // ... if it's greater than a minimum threshold, it's a turn!
                    if (Mathf.Abs(turnAngleDelta) > minTurnAngle) 
                    {
                        turnAngleDelta *= pinchTurnRatio;
                    } 
                    else 
                    {
                        turnAngle = turnAngleDelta = 0;
                    }
                    
                    mOldTouch1=touch1;
                    pinchDistance = pinchDistanceDelta = 0;
                }
                else
                {//縮放
                    turnAngle = turnAngleDelta = 0;
                    Debug.Log("95 pinchDistanceDelta = "+pinchDistanceDelta);
                    // ... if it's greater than a minimum threshold, it's a pinch!
                    if (Mathf.Abs(pinchDistanceDelta) > minPinchDistance) 
                    {
                        Debug.Log("pinchDistanceDelta = "+pinchDistanceDelta);
                        pinchDistanceDelta *= pinchRatio;
                    } 
                    else 
                    {
                        pinchDistance = pinchDistanceDelta = 0;
                    }
                }
            
            }
        }
        else
        {
            mFingerUP=true;
        }
    }
    
    static private float Angle (Vector2 pos1, Vector2 pos2) {
        Vector2 from = pos2 - pos1;
        Vector2 to = new Vector2(1, 0);
        
        float result = Vector2.Angle( from, to );
        Vector3 cross = Vector3.Cross( from, to );
        
        if (cross.z > 0) {
            result = 360f - result;
        }
        
        return result;
    }
    void Update ()
    {
    
        Calculate();
        if (Mathf.Abs(pinchDistanceDelta) > 0) 
        { // zoom
            mRotate=false;
            if(mCanDistance)
            {
                float aValue=this.transform.parent.localScale.x+pinchDistanceDelta/float.Parse(mScale);
                Debug.Log("aValue="+aValue);
                this.transform.parent.localScale=new Vector3(aValue,1f,1f);
            }
            else
                mCanDistance=true;
            
        }
        else if (Mathf.Abs(turnAngleDelta) > 0) 
        { // rotate
            Vector3 rotationDeg = Vector3.zero;
            rotationDeg.y = -turnAngleDelta*float.Parse(mRotationvalue);
            desiredRotation *= Quaternion.Euler(rotationDeg);
            mCanDistance=false;
            transform.rotation=desiredRotation;
        
        }
        
        if(mFingerUP)
        {
            mCanDistance=false;
            mRotate=false;
        }
        
        if(this.transform.parent.localScale.x<0.5f)
            this.transform.parent.localScale=new Vector3(0.5f,1f,1f);
        if(mScaleEven!=null)
            mScaleEven(this.transform.parent.localScale.x);
    }
}
(繼續閱讀...)
文章標籤

GABY 發表在 痞客邦 留言(0) 人氣(316)

  • 個人分類:官方API應用
▲top
  • 3月 11 週五 201618:10
  • 用滑鼠或手指持續拖曳物體 的腳本

using UnityEngine;
using System.Collections;
using System;
public class OnefingerDrag : MonoBehaviour 
{
    public Action<Vector3> mDragEven;
    private  GameObject target;
    private  bool  isMouseDrag;
    private  Vector3 screenPosition;
    private  Vector3 offset;
    // Use this for initialization
    void  Start () {
        
    }
    
    // Update is called once per frame
    void  Update () 
    {
#if UNITY_EDITOR
        if  (Input.GetMouseButtonDown (0))
        {
            isMouseDrag =  true ;
        }
        if  (Input.GetMouseButtonUp(0))
        {
            isMouseDrag =  false ;
        }
#else
        if ( Input.touchCount > 0 ) 
        {
            isMouseDrag =  true ;
        }
        else
        {
            isMouseDrag =  false ;
        }
            
#endif
        if(isMouseDrag)
            GameObjectDragAndDrog();
        
    }
    
    //任意拖拽
    private  GameObject ReturnGameObjectDrag( out  RaycastHit hit)
    {
        target =  null ;
        #if UNITY_EDITOR
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        #else
        Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
        #endif
        if  (Physics.Raycast(ray.origin, ray.direction * 10,  out  hit))
        {
            target = hit.collider.gameObject;
        }
        return  target;
    }
    
    //拖拽Updata
    private  void  GameObjectDragAndDrog()
    {
        RaycastHit hitInfo;
        target = ReturnGameObjectDrag( out  hitInfo);
        if  (target !=  null )
        {
            screenPosition = Camera.main.WorldToScreenPoint(target.transform.position);
            #if UNITY_EDITOR
            offset = target.transform.position - Camera.main.ScreenToWorldPoint( new  Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPosition.z));
            #else
            offset = target.transform.position - Camera.main.ScreenToWorldPoint( new  Vector3(Input.touches[0].position.x, Input.touches[0].position.y, screenPosition.z));
            #endif
            if(mDragEven!=null)
                mDragEven(offset);
        }      
        
    
    
        //    Vector3 currentScreenSpace =  new  Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPosition.z);
        //    Vector3 currentPosition = Camera.main.ScreenToWorldPoint(currentScreenSpace) + offset;
        //    target.transform.localPosition =  new  Vector3(currentPosition.x, currentPosition.y, currentPosition.z);
            
    }
}
(繼續閱讀...)
文章標籤

GABY 發表在 痞客邦 留言(2) 人氣(4,831)

  • 個人分類:官方API應用
▲top
  • 3月 06 週日 201613:05
  • 聖靈的江河 二胡敬拜


(繼續閱讀...)
文章標籤

GABY 發表在 痞客邦 留言(0) 人氣(9)

  • 個人分類:二胡
▲top
  • 3月 06 週日 201613:03
  • 能不能 二胡敬拜


(繼續閱讀...)
文章標籤

GABY 發表在 痞客邦 留言(0) 人氣(17)

  • 個人分類:二胡
▲top
  • 9月 15 週二 201521:07
  • 什麼樣的自由值得你擁有

什麼樣的自由值得你擁有
 
 
檔案下載
https://drive.google.com/file/d/0B6Xpdy0YQfa6SS02QmFReF9WZ0k/view?usp=sharing
(繼續閱讀...)
文章標籤

GABY 發表在 痞客邦 留言(0) 人氣(10)

  • 個人分類:禮拜紀錄
▲top
  • 9月 12 週六 201510:39
  • Unity5.1 VR 座談會 參加心得

VR +雲端   講座筆記
 
 
XMIND載點:
https://drive.google.com/open?id=0B6Xpdy0YQfa6TVRkVFpwSXlRVms
(繼續閱讀...)
文章標籤

GABY 發表在 痞客邦 留言(0) 人氣(150)

  • 個人分類:官方API應用
▲top
  • 9月 05 週六 201519:48
  • 人是不完全的

人是不完全的
 
(繼續閱讀...)
文章標籤

GABY 發表在 痞客邦 留言(0) 人氣(39)

  • 個人分類:禮拜紀錄
▲top
  • 8月 22 週六 201508:12
  • 神是愛

神
 
(繼續閱讀...)
文章標籤

GABY 發表在 痞客邦 留言(0) 人氣(43)

  • 個人分類:禮拜紀錄
▲top
  • 5月 27 週三 201522:18
  • GOOGLE MAP API應用 (UNITY內取Google靜態地圖)

【地址取经纬度】
http://maps.google.cn/maps/api/geocode/json?address=地址
(繼續閱讀...)
文章標籤

GABY 發表在 痞客邦 留言(0) 人氣(3,411)

  • 個人分類:非官方API運用
▲top
«1234...8»

文章分類

toggle 二胡 (1)
  • 二胡 (3)
toggle 作品集 (2)
  • 我的獨立創作 (3)
  • Hololens (1)
  • EASYROAD (1)
  • 禮拜紀錄 (3)
  • Vuforia (3)
  • Shader (4)
  • 工商服務 (1)
  • PlayMaker (1)
  • UNITY物理引擎應用-坦克 (2)
  • 引用 (2)
  • 電玩影片 (1)
  • 投票區 (1)
  • C#遊戲應用 (8)
  • NGUI使用 (7)
  • 非官方API運用 (6)
  • 官方API應用 (29)
  • 未分類文章 (1)

最新文章

  • GPU Resident Drawer 介紹
  • 在Unity有波紋效果的基本 水 Shader 著色器
  • 有反射天空+環境光的water URP版
  • Unity TextureImporterPlatform 設定
  • [摸型 購買]HONDA CB750F 1/12 [完成品]
  • EasyRoad 3D API 使用
  • 真實天氣 API
  • EasyRoad3D Tunnel 隧道 官方DEMO 解析
  • 2019 個人最新遊戲
  • Two Normal Maps on same Material

熱門文章

  • (310)NGUI3.6.8 Example 14 - Endless Scroll Views

參觀人氣

  • 本日人氣:
  • 累積人氣:

pixGoogleAdsense1

pixGoogleAdsense2

動態訂閱