void SetColor()
{
Color aColor = new Color(mR, mG, mB, 1f);
mRenderer.materials[2].SetColor("_Color", aColor);
mText.text = "Hex: "+ColorUtility.ToHtmlStringRGB(aColor);
}
GABY 發表在 痞客邦 留言(0) 人氣(55)

測試環境:
Window 10
GABY 發表在 痞客邦 留言(0) 人氣(81)
http://simcai.com/2015/11/29/Unity%E8%B5%84%E6%BA%90%E8%B7%AF%E5%BE%84%E5%8F%8A%E5%8A%A0%E8%BD%BD%E5%A4%96%E9%83%A8%E8%B5%84%E6%BA%90%E4%BB%8B%E7%BB%8D/
GABY 發表在 痞客邦 留言(0) 人氣(66)
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)
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)
XMIND載點:
https://drive.google.com/open?id=0B6Xpdy0YQfa6TVRkVFpwSXlRVms
GABY 發表在 痞客邦 留言(0) 人氣(150)
#region 要掛在有MESH RENDER的物件上才有用
/// <summary>
GABY 發表在 痞客邦 留言(0) 人氣(209)
[MenuItem("Edit/Play-Unplay, But From Prelaunch Scene %0")]
publicstaticvoidPlayFromPrelaunchScene()
{
if(EditorApplication.isPlaying ==true)
{
EditorApplication.isPlaying =false;
return;
}
EditorApplication.SaveCurrentSceneIfUserWantsTo();
EditorApplication.OpenScene(
"Assets/stuff/Scenes/__preEverythingScene.unity");
EditorApplication.isPlaying =true;
}
}
GABY 發表在 痞客邦 留言(0) 人氣(67)
public float ex, ey, ez;
float qx, qy, qz, qw;
GABY 發表在 痞客邦 留言(0) 人氣(563)