public void CheckTrackpad() { touchPositions.Clear(); for (int i = 0; i < Input.touchCount; i++) { var touch = Input.GetTouch(i); touchPositions.Add(touch.position); } if (touchPositions.Count == 0) { if (Input.GetMouseButton(0)) { touchPositions.Add(Input.mousePosition); } } bool trackpadTouched = false; List <RaycastResult> results = new List <RaycastResult>(); for (int i = 0; i < touchPositions.Count; i++) { results.Clear(); var touchPosition = touchPositions[i]; pointerEventData.position = touchPosition; eventSystem.RaycastAll(pointerEventData, results); foreach (RaycastResult result in results) { if (result.gameObject == trackpadImage.gameObject) { var trackpadRectTransform = trackpadImage.rectTransform; Vector2 localCursor; RectTransformUtility.ScreenPointToLocalPointInRectangle(trackpadRectTransform, pointerEventData.position, pointerEventData.enterEventCamera, out localCursor); localCursor.x = localCursor.x / (trackpadRectTransform.rect.width / 2.0f); localCursor.y = localCursor.y / (trackpadRectTransform.rect.height / 2.0f); var magnitude = localCursor.magnitude; localCursor.Normalize(); if (magnitude <= 1) { controllerStatus.trackpadTouched = true; controllerStatus.trackpad = Vector2Serializable.FromVector2(localCursor); trackpadImage.color = Color.green; return; } } } } trackpadImage.color = Color.red; controllerStatus.trackpad = Vector2Serializable.FromVector2(Vector2.zero); controllerStatus.trackpadTouched = false; }
public Player(string name, Gender gender, string spriteName, Vector2 startPosition) { this.name = name; this.gender = gender; this.spriteName = spriteName; currentPosition = new Vector2Serializable(startPosition); tools = new List<Tool>(); }
public Npc(string name, string spriteName, Vector2 currentStartPosition, float boxSize, bool canMove) { this.name = name; this.spriteName = spriteName; this.currentStartPosition = new Vector2Serializable(currentStartPosition); this.movementBoxSize = boxSize; this.canMove = canMove; }
public static void AddVector2(this SerializationInfo info, string name, Vector2Serializable v) { if (info is null) { throw new ArgumentNullException(nameof(info)); } info.AddValue(name, v); }
public override bool Equals(object obj) { if (obj is Vector2Serializable || obj is Vector2) { Vector2Serializable vector = ( Vector2Serializable )obj; return(this.x == vector.x && this.y == vector.y); } return(false); }
public static Vector3 ToVector3xz(this Vector2Serializable vs, float y = 0) { return(new Vector3(vs.x, y, vs.y)); }
public static Vector3 ToVector3(this Vector2Serializable vs, float z = 0) { return(new Vector3(vs.x, vs.y, z)); }
public CameraData(Camera camera) { Location = camera.transform.position; Zoom = camera.orthographicSize; }