Hi!folks
Please help me.who can chang the following iPhone script to the pc script.And it can achieve the same functionality.It can record Previous action.And it can be replay.
#pragma strict
private var maxTouches : int = 5;
private var touchPos : Vector2[ ];
private var touchPhase : iPhoneTouchPhase[ ];
private var tapCount : int[ ];
private var displayOptions : boolean = false;
private var warnedAboutMaxTouches : boolean = false;
function Start()
{
// Keep cached copies of touch data for GUI.
touchPos = new Vector2[ maxTouches ];
touchPhase = new iPhoneTouchPhase[ maxTouches ];
tapCount = new int[ maxTouches ];
if ( Application.isEditor )
// This is a small hack to improve the precision of input events coming
// from Unity Remote to the editor.
Time.fixedDeltaTime = 0.01;
}
// We are using OnGUI() for simple display of the iPhone touch input, however,
// in a real iPhone application you will want to use GUITexture where you need
// performance.
function OnGUI()
{
if ( displayOptions )
{
// These are options for toggling multitouch / orientation and resetting
// the cached touch data.
GUILayout.BeginArea( Rect( 10, 10, 300, 40 ) );
GUILayout.BeginHorizontal();
// There seems to be a bug with multiTouchEnabled not being applied.
// This should be fixed in a future version of Unity iPhone.
// Regardless of this setting, multiple touches are registered.
if ( GUILayout.Button( "Multitouch: " + iPhoneInput.multiTouchEnabled, GUILayout.MinHeight( 40 ) ) )
{
iPhoneInput.multiTouchEnabled = !iPhoneInput.multiTouchEnabled;
displayOptions = false;
}
if ( GUILayout.Button( "Vertical: " + iPhoneSettings.verticalOrientation, GUILayout.MinHeight( 40 ) ) )
{
iPhoneSettings.verticalOrientation = !iPhoneSettings.verticalOrientation;
displayOptions = false;
}
if ( GUILayout.Button( “Reset”, GUILayout.MinHeight( 40 ) ) )
{
touchPos = new Vector2[ maxTouches ];
displayOptions = false;
}
GUILayout.EndHorizontal();
GUILayout.EndArea();
}
else
{
if ( GUI.Button( Rect( 0, 0, 30, 30 ), “i” ) )
displayOptions = true;
}
// Display touch data and touch positions.
for ( var i : int = 0; i < maxTouches; i++ )
{
var labelText : String = "ID: " + i + “\n” + touchPhase[ i ];
if ( tapCount[ i ] > 1 )
labelText += "\nTaps: " + tapCount[ i ];
// Y coordinates seemed to be flipped, so we flip them back for correct positioning.
GUI.Label( Rect( touchPos[ i ].x - 75, Screen.height - touchPos[ i ].y - 75, 75, 50 ), labelText );
GUI.Box( Rect( touchPos[ i ].x, Screen.height - touchPos[ i ].y, 25, 25 ), “” );
}
}
// We use FixedUpdate() instead of Update(), so that we are not framerate dependent.
function FixedUpdate()
{
var count = iPhoneInput.touchCount;
for(var i : int = 0;i < count; i++)
{
var touch : iPhoneTouch = iPhoneInput.GetTouch( i );
var fingerId : int = touch.fingerId;
if ( fingerId >= maxTouches )
{
// I’m not sure if this is a bug or how the iPhone SDK reports finger IDs,
// however, IMO there should only be five finger IDs max.
if ( !warnedAboutMaxTouches )
{
Debug.Log( "Oops! We got a finderId greater than maxTouches: " + touch.fingerId );
warnedAboutMaxTouches = true;
}
fingerId = fingerId % maxTouches;
}
// Cache the touch data.
touchPos[ fingerId ] = touch.position;
touchPhase[ fingerId ] = touch.phase;
tapCount[ fingerId ] = touch.tapCount;
}
}
194716–6932–$touchphases_184.zip (469 KB)