mirror of
https://github.com/ApfelTeeSaft/Slender.git
synced 2026-08-27 19:22:22 +00:00
Complete Upgrade
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class Boundary
|
||||
{
|
||||
public Vector2 min;
|
||||
|
||||
public Vector2 max;
|
||||
|
||||
public Boundary()
|
||||
{
|
||||
min = Vector2.zero;
|
||||
max = Vector2.zero;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5b4e53334c5b7846a897477a856a6ea
|
||||
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
[RequireComponent(typeof(CharacterController))]
|
||||
public class CameraRelativeControl : MonoBehaviour
|
||||
{
|
||||
public Joystick moveJoystick;
|
||||
|
||||
public Joystick rotateJoystick;
|
||||
|
||||
public Transform cameraPivot;
|
||||
|
||||
public Transform cameraTransform;
|
||||
|
||||
public float speed;
|
||||
|
||||
public float jumpSpeed;
|
||||
|
||||
public float inAirMultiplier;
|
||||
|
||||
public Vector2 rotationSpeed;
|
||||
|
||||
private Transform thisTransform;
|
||||
|
||||
private CharacterController character;
|
||||
|
||||
private Vector3 velocity;
|
||||
|
||||
private bool canJump;
|
||||
|
||||
public CameraRelativeControl()
|
||||
{
|
||||
speed = 5f;
|
||||
jumpSpeed = 8f;
|
||||
inAirMultiplier = 0.25f;
|
||||
rotationSpeed = new Vector2(50f, 25f);
|
||||
canJump = true;
|
||||
}
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
thisTransform = (Transform)GetComponent(typeof(Transform));
|
||||
character = (CharacterController)GetComponent(typeof(CharacterController));
|
||||
GameObject gameObject = GameObject.Find("PlayerSpawn");
|
||||
if ((bool)gameObject)
|
||||
{
|
||||
thisTransform.position = gameObject.transform.position;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void FaceMovementDirection()
|
||||
{
|
||||
Vector3 vector = character.velocity;
|
||||
vector.y = 0f;
|
||||
if (!(vector.magnitude <= 0.1f))
|
||||
{
|
||||
thisTransform.forward = vector.normalized;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnEndGame()
|
||||
{
|
||||
moveJoystick.Disable();
|
||||
rotateJoystick.Disable();
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
Vector3 motion = cameraTransform.TransformDirection(new Vector3(moveJoystick.position.x, 0f, moveJoystick.position.y));
|
||||
motion.y = 0f;
|
||||
motion.Normalize();
|
||||
Vector2 vector = new Vector2(Mathf.Abs(moveJoystick.position.x), Mathf.Abs(moveJoystick.position.y));
|
||||
motion *= speed * ((vector.x <= vector.y) ? vector.y : vector.x);
|
||||
if (character.isGrounded)
|
||||
{
|
||||
if (!rotateJoystick.IsFingerDown())
|
||||
{
|
||||
canJump = true;
|
||||
}
|
||||
if (canJump && rotateJoystick.tapCount == 2)
|
||||
{
|
||||
velocity = character.velocity;
|
||||
velocity.y = jumpSpeed;
|
||||
canJump = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity.y += Physics.gravity.y * Time.deltaTime;
|
||||
motion.x *= inAirMultiplier;
|
||||
motion.z *= inAirMultiplier;
|
||||
}
|
||||
motion += velocity;
|
||||
motion += Physics.gravity;
|
||||
motion *= Time.deltaTime;
|
||||
character.Move(motion);
|
||||
if (character.isGrounded)
|
||||
{
|
||||
velocity = Vector3.zero;
|
||||
}
|
||||
FaceMovementDirection();
|
||||
Vector2 position = rotateJoystick.position;
|
||||
position.x *= rotationSpeed.x;
|
||||
position.y *= rotationSpeed.y;
|
||||
position *= Time.deltaTime;
|
||||
cameraPivot.Rotate(0f, position.x, 0f, Space.World);
|
||||
cameraPivot.Rotate(position.y, 0f, 0f);
|
||||
}
|
||||
|
||||
public virtual void Main()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9b9985dba1ff2784c3e4a9142310ea4
|
||||
timeCreated: 1779529516
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
name:
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 0}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public enum ConstraintAxis
|
||||
{
|
||||
X = 0,
|
||||
Y = 1,
|
||||
Z = 2
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c730a05a81bf18e4abea0c473d6c540e
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public enum ControlState
|
||||
{
|
||||
WaitingForFirstTouch = 0,
|
||||
WaitingForSecondTouch = 1,
|
||||
MovingCharacter = 2,
|
||||
WaitingForMovement = 3,
|
||||
ZoomingCamera = 4,
|
||||
RotatingCamera = 5,
|
||||
WaitingForNoFingers = 6
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7674891d4bd3d3545ba6f4bf377794c8
|
||||
@@ -0,0 +1,171 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
[RequireComponent(typeof(CharacterController))]
|
||||
public class FirstPersonControl : MonoBehaviour
|
||||
{
|
||||
public Joystick moveTouchPad;
|
||||
|
||||
public Joystick rotateTouchPad;
|
||||
|
||||
public Transform cameraPivot;
|
||||
|
||||
public float forwardSpeed;
|
||||
|
||||
public float backwardSpeed;
|
||||
|
||||
public float sidestepSpeed;
|
||||
|
||||
public float jumpSpeed;
|
||||
|
||||
public float inAirMultiplier;
|
||||
|
||||
public Vector2 rotationSpeed;
|
||||
|
||||
public float tiltPositiveYAxis;
|
||||
|
||||
public float tiltNegativeYAxis;
|
||||
|
||||
public float tiltXAxisMinimum;
|
||||
|
||||
private Transform thisTransform;
|
||||
|
||||
private CharacterController character;
|
||||
|
||||
private Vector3 cameraVelocity;
|
||||
|
||||
private Vector3 velocity;
|
||||
|
||||
private bool canJump;
|
||||
|
||||
public FirstPersonControl()
|
||||
{
|
||||
forwardSpeed = 4f;
|
||||
backwardSpeed = 1f;
|
||||
sidestepSpeed = 1f;
|
||||
jumpSpeed = 8f;
|
||||
inAirMultiplier = 0.25f;
|
||||
rotationSpeed = new Vector2(50f, 25f);
|
||||
tiltPositiveYAxis = 0.6f;
|
||||
tiltNegativeYAxis = 0.4f;
|
||||
tiltXAxisMinimum = 0.1f;
|
||||
canJump = true;
|
||||
}
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
thisTransform = (Transform)GetComponent(typeof(Transform));
|
||||
character = (CharacterController)GetComponent(typeof(CharacterController));
|
||||
GameObject gameObject = GameObject.Find("PlayerSpawn");
|
||||
if ((bool)gameObject)
|
||||
{
|
||||
thisTransform.position = gameObject.transform.position;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnEndGame()
|
||||
{
|
||||
moveTouchPad.Disable();
|
||||
if ((bool)rotateTouchPad)
|
||||
{
|
||||
rotateTouchPad.Disable();
|
||||
}
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
Vector3 motion = thisTransform.TransformDirection(new Vector3(moveTouchPad.position.x, 0f, moveTouchPad.position.y));
|
||||
motion.y = 0f;
|
||||
motion.Normalize();
|
||||
Vector2 vector = new Vector2(Mathf.Abs(moveTouchPad.position.x), Mathf.Abs(moveTouchPad.position.y));
|
||||
if (!(vector.y <= vector.x))
|
||||
{
|
||||
if (!(moveTouchPad.position.y <= 0f))
|
||||
{
|
||||
motion *= forwardSpeed * vector.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
motion *= backwardSpeed * vector.y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
motion *= sidestepSpeed * vector.x;
|
||||
}
|
||||
if (character.isGrounded)
|
||||
{
|
||||
bool flag = false;
|
||||
Joystick joystick = null;
|
||||
joystick = ((!rotateTouchPad) ? moveTouchPad : rotateTouchPad);
|
||||
if (!joystick.IsFingerDown())
|
||||
{
|
||||
canJump = true;
|
||||
}
|
||||
if (canJump && joystick.tapCount >= 2)
|
||||
{
|
||||
flag = true;
|
||||
canJump = false;
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
velocity = character.velocity;
|
||||
velocity.y = jumpSpeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity.y += Physics.gravity.y * Time.deltaTime;
|
||||
motion.x *= inAirMultiplier;
|
||||
motion.z *= inAirMultiplier;
|
||||
}
|
||||
motion += velocity;
|
||||
motion += Physics.gravity;
|
||||
motion *= Time.deltaTime;
|
||||
character.Move(motion);
|
||||
if (character.isGrounded)
|
||||
{
|
||||
velocity = Vector3.zero;
|
||||
}
|
||||
if (!character.isGrounded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Vector2 vector2 = Vector2.zero;
|
||||
if ((bool)rotateTouchPad)
|
||||
{
|
||||
vector2 = rotateTouchPad.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 acceleration = Input.acceleration;
|
||||
float num = Mathf.Abs(acceleration.x);
|
||||
if (!(acceleration.z >= 0f) && !(acceleration.x >= 0f))
|
||||
{
|
||||
if (!(num < tiltPositiveYAxis))
|
||||
{
|
||||
vector2.y = (num - tiltPositiveYAxis) / (1f - tiltPositiveYAxis);
|
||||
}
|
||||
else if (!(num > tiltNegativeYAxis))
|
||||
{
|
||||
vector2.y = (0f - (tiltNegativeYAxis - num)) / tiltNegativeYAxis;
|
||||
}
|
||||
}
|
||||
if (!(Mathf.Abs(acceleration.y) < tiltXAxisMinimum))
|
||||
{
|
||||
vector2.x = (0f - (acceleration.y - tiltXAxisMinimum)) / (1f - tiltXAxisMinimum);
|
||||
}
|
||||
}
|
||||
vector2.x *= rotationSpeed.x;
|
||||
vector2.y *= rotationSpeed.y;
|
||||
vector2 *= Time.deltaTime;
|
||||
thisTransform.Rotate(0f, vector2.x, 0f, Space.World);
|
||||
cameraPivot.Rotate(0f - vector2.y, 0f, 0f);
|
||||
}
|
||||
|
||||
public virtual void Main()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09ecb758ccbbfd3f3c476ca0e58cd8e5
|
||||
timeCreated: 1779529516
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
name:
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 0}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class FollowTransform : MonoBehaviour
|
||||
{
|
||||
public Transform targetTransform;
|
||||
|
||||
public bool faceForward;
|
||||
|
||||
private Transform thisTransform;
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
thisTransform = transform;
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
thisTransform.position = targetTransform.position;
|
||||
if (faceForward)
|
||||
{
|
||||
thisTransform.forward = targetTransform.forward;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Main()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69e591ca1b33d5fa7d6f0ca7053e1756
|
||||
timeCreated: 1779529516
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
name:
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 0}
|
||||
@@ -0,0 +1,276 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class Joystick : MonoBehaviour
|
||||
{
|
||||
[NonSerialized]
|
||||
private static Joystick[] joysticks;
|
||||
|
||||
[NonSerialized]
|
||||
private static bool enumeratedJoysticks;
|
||||
|
||||
[NonSerialized]
|
||||
private static float tapTimeDelta = 0.3f;
|
||||
|
||||
public bool touchPad;
|
||||
|
||||
public Rect touchZone;
|
||||
|
||||
public Vector2 deadZone = Vector2.zero;
|
||||
|
||||
public bool normalize;
|
||||
|
||||
public Vector2 position;
|
||||
|
||||
public int tapCount;
|
||||
|
||||
private int lastFingerId = -1;
|
||||
|
||||
private float tapTimeWindow;
|
||||
|
||||
private Vector2 fingerDownPos;
|
||||
|
||||
private float fingerDownTime;
|
||||
|
||||
private float firstDeltaTime = 0.5f;
|
||||
|
||||
private Rect defaultRect;
|
||||
|
||||
private Boundary guiBoundary = new Boundary();
|
||||
|
||||
private Vector2 guiTouchOffset;
|
||||
|
||||
private Vector2 guiCenter;
|
||||
|
||||
void Start()
|
||||
{
|
||||
defaultRect = new Rect(
|
||||
Screen.width * 0.1f,
|
||||
Screen.height * 0.1f,
|
||||
128,
|
||||
128
|
||||
);
|
||||
|
||||
if (touchPad)
|
||||
{
|
||||
touchZone = defaultRect;
|
||||
return;
|
||||
}
|
||||
|
||||
guiTouchOffset.x = defaultRect.width * 0.5f;
|
||||
guiTouchOffset.y = defaultRect.height * 0.5f;
|
||||
|
||||
guiCenter.x = defaultRect.x + guiTouchOffset.x;
|
||||
guiCenter.y = defaultRect.y + guiTouchOffset.y;
|
||||
|
||||
guiBoundary.min.x = defaultRect.x - guiTouchOffset.x;
|
||||
guiBoundary.max.x = defaultRect.x + guiTouchOffset.x;
|
||||
|
||||
guiBoundary.min.y = defaultRect.y - guiTouchOffset.y;
|
||||
guiBoundary.max.y = defaultRect.y + guiTouchOffset.y;
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
enumeratedJoysticks = false;
|
||||
}
|
||||
|
||||
public void ResetJoystick()
|
||||
{
|
||||
lastFingerId = -1;
|
||||
position = Vector2.zero;
|
||||
|
||||
defaultRect.x = guiCenter.x - guiTouchOffset.x;
|
||||
defaultRect.y = guiCenter.y - guiTouchOffset.y;
|
||||
}
|
||||
|
||||
public bool IsFingerDown()
|
||||
{
|
||||
return lastFingerId != -1;
|
||||
}
|
||||
|
||||
public void LatchedFinger(int fingerId)
|
||||
{
|
||||
if (lastFingerId == fingerId)
|
||||
{
|
||||
ResetJoystick();
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!enumeratedJoysticks)
|
||||
{
|
||||
joysticks = FindObjectsOfType<Joystick>();
|
||||
enumeratedJoysticks = true;
|
||||
}
|
||||
|
||||
int count = Input.touchCount;
|
||||
|
||||
if (tapTimeWindow > 0)
|
||||
{
|
||||
tapTimeWindow -= Time.deltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
tapCount = 0;
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
ResetJoystick();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
Touch touch = Input.GetTouch(i);
|
||||
|
||||
Vector2 guiTouchPos = touch.position - guiTouchOffset;
|
||||
|
||||
bool shouldLatchFinger = false;
|
||||
|
||||
if (touchPad)
|
||||
{
|
||||
if (touchZone.Contains(touch.position))
|
||||
{
|
||||
shouldLatchFinger = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Rect touchRect = new Rect(
|
||||
guiCenter.x - guiTouchOffset.x,
|
||||
guiCenter.y - guiTouchOffset.y,
|
||||
guiTouchOffset.x * 2,
|
||||
guiTouchOffset.y * 2
|
||||
);
|
||||
|
||||
if (touchRect.Contains(touch.position))
|
||||
{
|
||||
shouldLatchFinger = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
shouldLatchFinger &&
|
||||
(lastFingerId == -1 || lastFingerId != touch.fingerId)
|
||||
)
|
||||
{
|
||||
if (touchPad)
|
||||
{
|
||||
fingerDownPos = touch.position;
|
||||
fingerDownTime = Time.time;
|
||||
}
|
||||
|
||||
lastFingerId = touch.fingerId;
|
||||
|
||||
if (tapTimeWindow > 0)
|
||||
{
|
||||
tapCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
tapCount = 1;
|
||||
tapTimeWindow = tapTimeDelta;
|
||||
}
|
||||
|
||||
foreach (Joystick j in joysticks)
|
||||
{
|
||||
if (j != this)
|
||||
{
|
||||
j.LatchedFinger(touch.fingerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lastFingerId == touch.fingerId)
|
||||
{
|
||||
if (touch.tapCount > tapCount)
|
||||
{
|
||||
tapCount = touch.tapCount;
|
||||
}
|
||||
|
||||
if (touchPad)
|
||||
{
|
||||
position.x = Mathf.Clamp(
|
||||
(touch.position.x - fingerDownPos.x) /
|
||||
(touchZone.width / 2),
|
||||
-1,
|
||||
1
|
||||
);
|
||||
|
||||
position.y = Mathf.Clamp(
|
||||
(touch.position.y - fingerDownPos.y) /
|
||||
(touchZone.height / 2),
|
||||
-1,
|
||||
1
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultRect.x = Mathf.Clamp(
|
||||
guiTouchPos.x,
|
||||
guiBoundary.min.x,
|
||||
guiBoundary.max.x
|
||||
);
|
||||
|
||||
defaultRect.y = Mathf.Clamp(
|
||||
guiTouchPos.y,
|
||||
guiBoundary.min.y,
|
||||
guiBoundary.max.y
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
touch.phase == TouchPhase.Ended ||
|
||||
touch.phase == TouchPhase.Canceled
|
||||
)
|
||||
{
|
||||
ResetJoystick();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!touchPad)
|
||||
{
|
||||
position.x =
|
||||
(defaultRect.x + guiTouchOffset.x - guiCenter.x) /
|
||||
guiTouchOffset.x;
|
||||
|
||||
position.y =
|
||||
(defaultRect.y + guiTouchOffset.y - guiCenter.y) /
|
||||
guiTouchOffset.y;
|
||||
}
|
||||
|
||||
float absoluteX = Mathf.Abs(position.x);
|
||||
float absoluteY = Mathf.Abs(position.y);
|
||||
|
||||
if (absoluteX < deadZone.x)
|
||||
{
|
||||
position.x = 0;
|
||||
}
|
||||
else if (normalize)
|
||||
{
|
||||
position.x =
|
||||
Mathf.Sign(position.x) *
|
||||
(absoluteX - deadZone.x) /
|
||||
(1 - deadZone.x);
|
||||
}
|
||||
|
||||
if (absoluteY < deadZone.y)
|
||||
{
|
||||
position.y = 0;
|
||||
}
|
||||
else if (normalize)
|
||||
{
|
||||
position.y =
|
||||
Mathf.Sign(position.y) *
|
||||
(absoluteY - deadZone.y) /
|
||||
(1 - deadZone.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65187bed3c56715767fa128544625bd6
|
||||
timeCreated: 1779529516
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
name:
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 0}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class ObliqueNear : MonoBehaviour
|
||||
{
|
||||
public Transform plane;
|
||||
|
||||
public virtual Matrix4x4 CalculateObliqueMatrix(Matrix4x4 projection, Vector4 clipPlane)
|
||||
{
|
||||
Vector4 b = projection.inverse * new Vector4(Mathf.Sign(clipPlane.x), Mathf.Sign(clipPlane.y), 1f, 1f);
|
||||
Vector4 vector = clipPlane * (2f / Vector4.Dot(clipPlane, b));
|
||||
projection[2] = vector.x - projection[3];
|
||||
projection[6] = vector.y - projection[7];
|
||||
projection[10] = vector.z - projection[11];
|
||||
projection[14] = vector.w - projection[15];
|
||||
return projection;
|
||||
}
|
||||
|
||||
public virtual void OnPreCull()
|
||||
{
|
||||
Matrix4x4 projectionMatrix = GetComponent<Camera>().projectionMatrix;
|
||||
Matrix4x4 worldToCameraMatrix = GetComponent<Camera>().worldToCameraMatrix;
|
||||
Vector3 rhs = worldToCameraMatrix.MultiplyPoint(plane.position);
|
||||
Vector3 vector = worldToCameraMatrix.MultiplyVector(-Vector3.up);
|
||||
vector.Normalize();
|
||||
Vector4 clipPlane = vector;
|
||||
clipPlane.w = 0f - Vector3.Dot(vector, rhs);
|
||||
GetComponent<Camera>().projectionMatrix = CalculateObliqueMatrix(projectionMatrix, clipPlane);
|
||||
}
|
||||
|
||||
public virtual void Main()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e3ae02f57c245a8092054f7431802ed
|
||||
timeCreated: 1779529516
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
name:
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 0}
|
||||
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
[RequireComponent(typeof(CharacterController))]
|
||||
public class PlayerRelativeControl : MonoBehaviour
|
||||
{
|
||||
public Joystick moveJoystick;
|
||||
|
||||
public Joystick rotateJoystick;
|
||||
|
||||
public Transform cameraPivot;
|
||||
|
||||
public float forwardSpeed;
|
||||
|
||||
public float backwardSpeed;
|
||||
|
||||
public float sidestepSpeed;
|
||||
|
||||
public float jumpSpeed;
|
||||
|
||||
public float inAirMultiplier;
|
||||
|
||||
public Vector2 rotationSpeed;
|
||||
|
||||
private Transform thisTransform;
|
||||
|
||||
private CharacterController character;
|
||||
|
||||
private Vector3 cameraVelocity;
|
||||
|
||||
private Vector3 velocity;
|
||||
|
||||
public PlayerRelativeControl()
|
||||
{
|
||||
forwardSpeed = 4f;
|
||||
backwardSpeed = 1f;
|
||||
sidestepSpeed = 1f;
|
||||
jumpSpeed = 8f;
|
||||
inAirMultiplier = 0.25f;
|
||||
rotationSpeed = new Vector2(50f, 25f);
|
||||
}
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
thisTransform = (Transform)GetComponent(typeof(Transform));
|
||||
character = (CharacterController)GetComponent(typeof(CharacterController));
|
||||
GameObject gameObject = GameObject.Find("PlayerSpawn");
|
||||
if ((bool)gameObject)
|
||||
{
|
||||
thisTransform.position = gameObject.transform.position;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnEndGame()
|
||||
{
|
||||
moveJoystick.Disable();
|
||||
rotateJoystick.Disable();
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
Vector3 motion = thisTransform.TransformDirection(new Vector3(moveJoystick.position.x, 0f, moveJoystick.position.y));
|
||||
motion.y = 0f;
|
||||
motion.Normalize();
|
||||
Vector3 zero = Vector3.zero;
|
||||
Vector2 vector = new Vector2(Mathf.Abs(moveJoystick.position.x), Mathf.Abs(moveJoystick.position.y));
|
||||
if (!(vector.y <= vector.x))
|
||||
{
|
||||
if (!(moveJoystick.position.y <= 0f))
|
||||
{
|
||||
motion *= forwardSpeed * vector.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
motion *= backwardSpeed * vector.y;
|
||||
zero.z = moveJoystick.position.y * 0.75f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
motion *= sidestepSpeed * vector.x;
|
||||
zero.x = (0f - moveJoystick.position.x) * 0.5f;
|
||||
}
|
||||
if (character.isGrounded)
|
||||
{
|
||||
if (rotateJoystick.tapCount == 2)
|
||||
{
|
||||
velocity = character.velocity;
|
||||
velocity.y = jumpSpeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity.y += Physics.gravity.y * Time.deltaTime;
|
||||
zero.z = (0f - jumpSpeed) * 0.25f;
|
||||
motion.x *= inAirMultiplier;
|
||||
motion.z *= inAirMultiplier;
|
||||
}
|
||||
motion += velocity;
|
||||
motion += Physics.gravity;
|
||||
motion *= Time.deltaTime;
|
||||
character.Move(motion);
|
||||
if (character.isGrounded)
|
||||
{
|
||||
velocity = Vector3.zero;
|
||||
}
|
||||
Vector3 localPosition = cameraPivot.localPosition;
|
||||
localPosition.x = Mathf.SmoothDamp(localPosition.x, zero.x, ref cameraVelocity.x, 0.3f);
|
||||
localPosition.z = Mathf.SmoothDamp(localPosition.z, zero.z, ref cameraVelocity.z, 0.5f);
|
||||
cameraPivot.localPosition = localPosition;
|
||||
if (character.isGrounded)
|
||||
{
|
||||
Vector2 position = rotateJoystick.position;
|
||||
position.x *= rotationSpeed.x;
|
||||
position.y *= rotationSpeed.y;
|
||||
position *= Time.deltaTime;
|
||||
thisTransform.Rotate(0f, position.x, 0f, Space.World);
|
||||
cameraPivot.Rotate(position.y, 0f, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Main()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db56b1e730afc4a381e4f4838827ca1f
|
||||
timeCreated: 1779529516
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
name:
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 0}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc3f1d46a91f0504a9a0df727b5c848e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// [assembly: AssemblyVersion("0.0.0.0")]
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55e2b601d2ec3694c94eff62c477f45b
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class RollABall : MonoBehaviour
|
||||
{
|
||||
public Vector3 tilt;
|
||||
|
||||
public float speed;
|
||||
|
||||
private float circ;
|
||||
|
||||
private Vector3 previousPosition;
|
||||
|
||||
public RollABall()
|
||||
{
|
||||
tilt = Vector3.zero;
|
||||
}
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
circ = (float)Math.PI * 2f * GetComponent<Collider>().bounds.extents.x;
|
||||
previousPosition = transform.position;
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
tilt.x = 0f - Input.acceleration.y;
|
||||
tilt.z = Input.acceleration.x;
|
||||
GetComponent<Rigidbody>().AddForce(tilt * speed * Time.deltaTime);
|
||||
}
|
||||
|
||||
public virtual void LateUpdate()
|
||||
{
|
||||
Vector3 vector = transform.position - previousPosition;
|
||||
vector = new Vector3(vector.z, 0f, 0f - vector.x);
|
||||
transform.Rotate(vector / circ * 360f, Space.World);
|
||||
previousPosition = transform.position;
|
||||
}
|
||||
|
||||
public virtual void Main()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4549b9ef3489c4d055c2eed36fac5717
|
||||
timeCreated: 1779529516
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
name:
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 0}
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class RotationConstraint : MonoBehaviour
|
||||
{
|
||||
public ConstraintAxis axis;
|
||||
|
||||
public float min;
|
||||
|
||||
public float max;
|
||||
|
||||
private Transform thisTransform;
|
||||
|
||||
private Vector3 rotateAround;
|
||||
|
||||
private Quaternion minQuaternion;
|
||||
|
||||
private Quaternion maxQuaternion;
|
||||
|
||||
private float range;
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
thisTransform = transform;
|
||||
switch (axis)
|
||||
{
|
||||
case ConstraintAxis.X:
|
||||
rotateAround = Vector3.right;
|
||||
break;
|
||||
case ConstraintAxis.Y:
|
||||
rotateAround = Vector3.up;
|
||||
break;
|
||||
case ConstraintAxis.Z:
|
||||
rotateAround = Vector3.forward;
|
||||
break;
|
||||
}
|
||||
minQuaternion = thisTransform.localRotation * Quaternion.AngleAxis(min, rotateAround);
|
||||
maxQuaternion = thisTransform.localRotation * Quaternion.AngleAxis(max, rotateAround);
|
||||
range = max - min;
|
||||
}
|
||||
|
||||
public virtual void LateUpdate()
|
||||
{
|
||||
Quaternion localRotation = thisTransform.localRotation;
|
||||
Quaternion a = Quaternion.AngleAxis(localRotation.eulerAngles[(int)axis], rotateAround);
|
||||
float num = Quaternion.Angle(a, minQuaternion);
|
||||
float num2 = Quaternion.Angle(a, maxQuaternion);
|
||||
if (num > range || num2 > range)
|
||||
{
|
||||
Vector3 eulerAngles = localRotation.eulerAngles;
|
||||
if (!(num <= num2))
|
||||
{
|
||||
eulerAngles[(int)axis] = maxQuaternion.eulerAngles[(int)axis];
|
||||
}
|
||||
else
|
||||
{
|
||||
eulerAngles[(int)axis] = minQuaternion.eulerAngles[(int)axis];
|
||||
}
|
||||
thisTransform.localEulerAngles = eulerAngles;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Main()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d51114f55bfb4dc352a069ada321c99
|
||||
timeCreated: 1779529516
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
name:
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 0}
|
||||
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
[RequireComponent(typeof(CharacterController))]
|
||||
public class SidescrollControl : MonoBehaviour
|
||||
{
|
||||
public Joystick moveTouchPad;
|
||||
|
||||
public Joystick jumpTouchPad;
|
||||
|
||||
public float forwardSpeed;
|
||||
|
||||
public float backwardSpeed;
|
||||
|
||||
public float jumpSpeed;
|
||||
|
||||
public float inAirMultiplier;
|
||||
|
||||
private Transform thisTransform;
|
||||
|
||||
private CharacterController character;
|
||||
|
||||
private Vector3 velocity;
|
||||
|
||||
private bool canJump;
|
||||
|
||||
public SidescrollControl()
|
||||
{
|
||||
forwardSpeed = 4f;
|
||||
backwardSpeed = 4f;
|
||||
jumpSpeed = 16f;
|
||||
inAirMultiplier = 0.25f;
|
||||
canJump = true;
|
||||
}
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
thisTransform = (Transform)GetComponent(typeof(Transform));
|
||||
character = (CharacterController)GetComponent(typeof(CharacterController));
|
||||
GameObject gameObject = GameObject.Find("PlayerSpawn");
|
||||
if ((bool)gameObject)
|
||||
{
|
||||
thisTransform.position = gameObject.transform.position;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnEndGame()
|
||||
{
|
||||
moveTouchPad.Disable();
|
||||
jumpTouchPad.Disable();
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
Vector3 zero = Vector3.zero;
|
||||
zero = ((moveTouchPad.position.x <= 0f) ? (Vector3.right * backwardSpeed * moveTouchPad.position.x) : (Vector3.right * forwardSpeed * moveTouchPad.position.x));
|
||||
if (character.isGrounded)
|
||||
{
|
||||
bool flag = false;
|
||||
Joystick joystick = jumpTouchPad;
|
||||
if (!joystick.IsFingerDown())
|
||||
{
|
||||
canJump = true;
|
||||
}
|
||||
if (canJump && joystick.IsFingerDown())
|
||||
{
|
||||
flag = true;
|
||||
canJump = false;
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
velocity = character.velocity;
|
||||
velocity.y = jumpSpeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity.y += Physics.gravity.y * Time.deltaTime;
|
||||
zero.x *= inAirMultiplier;
|
||||
}
|
||||
zero += velocity;
|
||||
zero += Physics.gravity;
|
||||
zero *= Time.deltaTime;
|
||||
character.Move(zero);
|
||||
if (character.isGrounded)
|
||||
{
|
||||
velocity = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Main()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 642cc87fb840754badd09af229c4e42b
|
||||
timeCreated: 1779529516
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
name:
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 0}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class SmoothFollow2D : MonoBehaviour
|
||||
{
|
||||
public Transform target;
|
||||
|
||||
public float smoothTime;
|
||||
|
||||
private Transform thisTransform;
|
||||
|
||||
private Vector2 velocity;
|
||||
|
||||
public SmoothFollow2D()
|
||||
{
|
||||
smoothTime = 0.3f;
|
||||
}
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
thisTransform = transform;
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
float x = Mathf.SmoothDamp(thisTransform.position.x, target.position.x, ref velocity.x, smoothTime);
|
||||
Vector3 position = thisTransform.position;
|
||||
float num = (position.x = x);
|
||||
Vector3 vector = (thisTransform.position = position);
|
||||
float y = Mathf.SmoothDamp(thisTransform.position.y, target.position.y, ref velocity.y, smoothTime);
|
||||
Vector3 position2 = thisTransform.position;
|
||||
float num2 = (position2.y = y);
|
||||
Vector3 vector3 = (thisTransform.position = position2);
|
||||
}
|
||||
|
||||
public virtual void Main()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5131f4e06be4a18e1afbf7c7a284258c
|
||||
timeCreated: 1779529516
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
name:
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 0}
|
||||
@@ -0,0 +1,373 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class TapControl : MonoBehaviour
|
||||
{
|
||||
public GameObject cameraObject;
|
||||
|
||||
public Transform cameraPivot;
|
||||
|
||||
public Rect jumpButton = new Rect(20, 20, 128, 128);
|
||||
|
||||
public float speed;
|
||||
|
||||
public float jumpSpeed;
|
||||
|
||||
public float inAirMultiplier;
|
||||
|
||||
public float minimumDistanceToMove;
|
||||
|
||||
public float minimumTimeUntilMove;
|
||||
|
||||
public bool zoomEnabled;
|
||||
|
||||
public float zoomEpsilon;
|
||||
|
||||
public float zoomRate;
|
||||
|
||||
public bool rotateEnabled;
|
||||
|
||||
public float rotateEpsilon;
|
||||
|
||||
private ZoomCamera zoomCamera;
|
||||
|
||||
private Camera cam;
|
||||
|
||||
private Transform thisTransform;
|
||||
|
||||
private CharacterController character;
|
||||
|
||||
private Vector3 targetLocation;
|
||||
|
||||
private bool moving;
|
||||
|
||||
private float rotationTarget;
|
||||
|
||||
private float rotationVelocity;
|
||||
|
||||
private Vector3 velocity;
|
||||
|
||||
private ControlState state;
|
||||
|
||||
private int[] fingerDown;
|
||||
|
||||
private Vector2[] fingerDownPosition;
|
||||
|
||||
private int[] fingerDownFrame;
|
||||
|
||||
private float firstTouchTime;
|
||||
|
||||
public TapControl()
|
||||
{
|
||||
inAirMultiplier = 0.25f;
|
||||
minimumDistanceToMove = 1f;
|
||||
minimumTimeUntilMove = 0.25f;
|
||||
rotateEpsilon = 1f;
|
||||
state = ControlState.WaitingForFirstTouch;
|
||||
fingerDown = new int[2];
|
||||
fingerDownPosition = new Vector2[2];
|
||||
fingerDownFrame = new int[2];
|
||||
}
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
thisTransform = transform;
|
||||
zoomCamera = (ZoomCamera)cameraObject.GetComponent(typeof(ZoomCamera));
|
||||
cam = cameraObject.GetComponent<Camera>();
|
||||
character = (CharacterController)GetComponent(typeof(CharacterController));
|
||||
ResetControlState();
|
||||
GameObject gameObject = GameObject.Find("PlayerSpawn");
|
||||
if ((bool)gameObject)
|
||||
{
|
||||
thisTransform.position = gameObject.transform.position;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnEndGame()
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
public virtual void FaceMovementDirection()
|
||||
{
|
||||
Vector3 vector = character.velocity;
|
||||
vector.y = 0f;
|
||||
if (!(vector.magnitude <= 0.1f))
|
||||
{
|
||||
thisTransform.forward = vector.normalized;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void CameraControl(Touch touch0, Touch touch1)
|
||||
{
|
||||
if (rotateEnabled && state == ControlState.RotatingCamera)
|
||||
{
|
||||
Vector2 vector = touch1.position - touch0.position;
|
||||
Vector2 lhs = vector / vector.magnitude;
|
||||
Vector2 vector2 = touch1.position - touch1.deltaPosition - (touch0.position - touch0.deltaPosition);
|
||||
Vector2 rhs = vector2 / vector2.magnitude;
|
||||
float num = Vector2.Dot(lhs, rhs);
|
||||
if (!(num >= 1f))
|
||||
{
|
||||
Vector3 lhs2 = new Vector3(vector.x, vector.y);
|
||||
Vector3 rhs2 = new Vector3(vector2.x, vector2.y);
|
||||
float z = Vector3.Cross(lhs2, rhs2).normalized.z;
|
||||
float num2 = Mathf.Acos(num);
|
||||
rotationTarget += num2 * 57.29578f * z;
|
||||
if (!(rotationTarget >= 0f))
|
||||
{
|
||||
rotationTarget += 360f;
|
||||
}
|
||||
else if (!(rotationTarget < 360f))
|
||||
{
|
||||
rotationTarget -= 360f;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (zoomEnabled && state == ControlState.ZoomingCamera)
|
||||
{
|
||||
float magnitude = (touch1.position - touch0.position).magnitude;
|
||||
float magnitude2 = (touch1.position - touch1.deltaPosition - (touch0.position - touch0.deltaPosition)).magnitude;
|
||||
float num3 = magnitude - magnitude2;
|
||||
zoomCamera.zoom += num3 * zoomRate * Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void CharacterControl()
|
||||
{
|
||||
int touchCount = Input.touchCount;
|
||||
if (touchCount == 1 && state == ControlState.MovingCharacter)
|
||||
{
|
||||
Touch touch = Input.GetTouch(0);
|
||||
if (character.isGrounded && jumpButton.Contains(touch.position))
|
||||
{
|
||||
velocity = character.velocity;
|
||||
velocity.y = jumpSpeed;
|
||||
}
|
||||
else if (!jumpButton.Contains(touch.position) && touch.phase != TouchPhase.Began)
|
||||
{
|
||||
Ray ray = cam.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y));
|
||||
RaycastHit hitInfo = default(RaycastHit);
|
||||
if (Physics.Raycast(ray, out hitInfo))
|
||||
{
|
||||
float magnitude = (transform.position - hitInfo.point).magnitude;
|
||||
if (!(magnitude <= minimumDistanceToMove))
|
||||
{
|
||||
targetLocation = hitInfo.point;
|
||||
}
|
||||
moving = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Vector3 motion = Vector3.zero;
|
||||
if (moving)
|
||||
{
|
||||
motion = targetLocation - thisTransform.position;
|
||||
motion.y = 0f;
|
||||
float magnitude2 = motion.magnitude;
|
||||
if (!(magnitude2 >= 1f))
|
||||
{
|
||||
moving = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
motion = motion.normalized * speed;
|
||||
}
|
||||
}
|
||||
if (!character.isGrounded)
|
||||
{
|
||||
velocity.y += Physics.gravity.y * Time.deltaTime;
|
||||
motion.x *= inAirMultiplier;
|
||||
motion.z *= inAirMultiplier;
|
||||
}
|
||||
motion += velocity;
|
||||
motion += Physics.gravity;
|
||||
motion *= Time.deltaTime;
|
||||
character.Move(motion);
|
||||
if (character.isGrounded)
|
||||
{
|
||||
velocity = Vector3.zero;
|
||||
}
|
||||
FaceMovementDirection();
|
||||
}
|
||||
|
||||
public virtual void ResetControlState()
|
||||
{
|
||||
state = ControlState.WaitingForFirstTouch;
|
||||
fingerDown[0] = -1;
|
||||
fingerDown[1] = -1;
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
int touchCount = Input.touchCount;
|
||||
if (touchCount == 0)
|
||||
{
|
||||
ResetControlState();
|
||||
}
|
||||
else
|
||||
{
|
||||
int num = default(int);
|
||||
Touch touch = default(Touch);
|
||||
Touch[] touches = Input.touches;
|
||||
Touch touch2 = default(Touch);
|
||||
Touch touch3 = default(Touch);
|
||||
bool flag = false;
|
||||
bool flag2 = false;
|
||||
if (state == ControlState.WaitingForFirstTouch)
|
||||
{
|
||||
for (num = 0; num < touchCount; num++)
|
||||
{
|
||||
touch = touches[num];
|
||||
if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
|
||||
{
|
||||
state = ControlState.WaitingForSecondTouch;
|
||||
firstTouchTime = Time.time;
|
||||
fingerDown[0] = touch.fingerId;
|
||||
fingerDownPosition[0] = touch.position;
|
||||
fingerDownFrame[0] = Time.frameCount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (state == ControlState.WaitingForSecondTouch)
|
||||
{
|
||||
for (num = 0; num < touchCount; num++)
|
||||
{
|
||||
touch = touches[num];
|
||||
if (touch.phase == TouchPhase.Canceled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (touchCount >= 2 && touch.fingerId != fingerDown[0])
|
||||
{
|
||||
state = ControlState.WaitingForMovement;
|
||||
fingerDown[1] = touch.fingerId;
|
||||
fingerDownPosition[1] = touch.position;
|
||||
fingerDownFrame[1] = Time.frameCount;
|
||||
break;
|
||||
}
|
||||
if (touchCount == 1)
|
||||
{
|
||||
Vector2 vector = touch.position - fingerDownPosition[0];
|
||||
if (touch.fingerId == fingerDown[0] && (Time.time > firstTouchTime + minimumTimeUntilMove || touch.phase == TouchPhase.Ended))
|
||||
{
|
||||
state = ControlState.MovingCharacter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (state == ControlState.WaitingForMovement)
|
||||
{
|
||||
for (num = 0; num < touchCount; num++)
|
||||
{
|
||||
touch = touches[num];
|
||||
if (touch.phase == TouchPhase.Began)
|
||||
{
|
||||
if (touch.fingerId == fingerDown[0] && fingerDownFrame[0] == Time.frameCount)
|
||||
{
|
||||
touch2 = touch;
|
||||
flag = true;
|
||||
}
|
||||
else if (touch.fingerId != fingerDown[0] && touch.fingerId != fingerDown[1])
|
||||
{
|
||||
fingerDown[1] = touch.fingerId;
|
||||
touch3 = touch;
|
||||
flag2 = true;
|
||||
}
|
||||
}
|
||||
if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Ended)
|
||||
{
|
||||
if (touch.fingerId == fingerDown[0])
|
||||
{
|
||||
touch2 = touch;
|
||||
flag = true;
|
||||
}
|
||||
else if (touch.fingerId == fingerDown[1])
|
||||
{
|
||||
touch3 = touch;
|
||||
flag2 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
if (flag2)
|
||||
{
|
||||
Vector2 vector2 = fingerDownPosition[1] - fingerDownPosition[0];
|
||||
Vector2 vector3 = touch3.position - touch2.position;
|
||||
Vector2 lhs = vector2 / vector2.magnitude;
|
||||
Vector2 rhs = vector3 / vector3.magnitude;
|
||||
float num2 = Vector2.Dot(lhs, rhs);
|
||||
if (!(num2 >= 1f))
|
||||
{
|
||||
float num3 = Mathf.Acos(num2);
|
||||
if (!(num3 <= rotateEpsilon * ((float)Math.PI / 180f)))
|
||||
{
|
||||
state = ControlState.RotatingCamera;
|
||||
}
|
||||
}
|
||||
if (state == ControlState.WaitingForMovement)
|
||||
{
|
||||
float f = vector2.magnitude - vector3.magnitude;
|
||||
if (!(Mathf.Abs(f) <= zoomEpsilon))
|
||||
{
|
||||
state = ControlState.ZoomingCamera;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
state = ControlState.WaitingForNoFingers;
|
||||
}
|
||||
}
|
||||
if (state == ControlState.RotatingCamera || state == ControlState.ZoomingCamera)
|
||||
{
|
||||
for (num = 0; num < touchCount; num++)
|
||||
{
|
||||
touch = touches[num];
|
||||
if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Ended)
|
||||
{
|
||||
if (touch.fingerId == fingerDown[0])
|
||||
{
|
||||
touch2 = touch;
|
||||
flag = true;
|
||||
}
|
||||
else if (touch.fingerId == fingerDown[1])
|
||||
{
|
||||
touch3 = touch;
|
||||
flag2 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
if (flag2)
|
||||
{
|
||||
CameraControl(touch2, touch3);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
state = ControlState.WaitingForNoFingers;
|
||||
}
|
||||
}
|
||||
}
|
||||
CharacterControl();
|
||||
}
|
||||
|
||||
public virtual void LateUpdate()
|
||||
{
|
||||
float y = Mathf.SmoothDampAngle(cameraPivot.eulerAngles.y, rotationTarget, ref rotationVelocity, 0.3f);
|
||||
Vector3 eulerAngles = cameraPivot.eulerAngles;
|
||||
float num = (eulerAngles.y = y);
|
||||
Vector3 vector = (cameraPivot.eulerAngles = eulerAngles);
|
||||
}
|
||||
|
||||
public virtual void Main()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a041c96f5a2a12f21ac654918fb30c4
|
||||
timeCreated: 1779529516
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
name:
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 0}
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class ZoomCamera : MonoBehaviour
|
||||
{
|
||||
public Transform origin;
|
||||
|
||||
public float zoom;
|
||||
|
||||
public float zoomMin;
|
||||
|
||||
public float zoomMax;
|
||||
|
||||
public float seekTime;
|
||||
|
||||
public bool smoothZoomIn;
|
||||
|
||||
private Vector3 defaultLocalPosition;
|
||||
|
||||
private Transform thisTransform;
|
||||
|
||||
private float currentZoom;
|
||||
|
||||
private float targetZoom;
|
||||
|
||||
private float zoomVelocity;
|
||||
|
||||
public ZoomCamera()
|
||||
{
|
||||
zoomMin = -5f;
|
||||
zoomMax = 5f;
|
||||
seekTime = 1f;
|
||||
}
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
thisTransform = transform;
|
||||
defaultLocalPosition = thisTransform.localPosition;
|
||||
currentZoom = zoom;
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
zoom = Mathf.Clamp(zoom, zoomMin, zoomMax);
|
||||
int layerMask = -261;
|
||||
RaycastHit hitInfo = default(RaycastHit);
|
||||
Vector3 position = origin.position;
|
||||
Vector3 position2 = defaultLocalPosition + thisTransform.parent.InverseTransformDirection(thisTransform.forward * zoom);
|
||||
Vector3 end = thisTransform.parent.TransformPoint(position2);
|
||||
if (Physics.Linecast(position, end, out hitInfo, layerMask))
|
||||
{
|
||||
Vector3 vector = hitInfo.point + thisTransform.TransformDirection(Vector3.forward);
|
||||
targetZoom = (vector - thisTransform.parent.TransformPoint(defaultLocalPosition)).magnitude;
|
||||
}
|
||||
else
|
||||
{
|
||||
targetZoom = zoom;
|
||||
}
|
||||
targetZoom = Mathf.Clamp(targetZoom, zoomMin, zoomMax);
|
||||
if (!smoothZoomIn && !(targetZoom - currentZoom <= 0f))
|
||||
{
|
||||
currentZoom = targetZoom;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentZoom = Mathf.SmoothDamp(currentZoom, targetZoom, ref zoomVelocity, seekTime);
|
||||
}
|
||||
position2 = defaultLocalPosition + thisTransform.parent.InverseTransformDirection(thisTransform.forward * currentZoom);
|
||||
thisTransform.localPosition = position2;
|
||||
}
|
||||
|
||||
public virtual void Main()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4077bef0bea230cfdab154d63734cfe8
|
||||
timeCreated: 1779529516
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
name:
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 0}
|
||||
Reference in New Issue
Block a user