void UpdateState() { Vector3?tp = InputPlatform.Singleton.GetTouchPoint(); Ray? ray = null; if (tp != null) { ray = Camera.main.ScreenPointToRay(tp.Value); } //update state switch (jadeState) { case InlayItemState.Free: if (ray != null) { RaycastHit hitInfo; if (Physics.Raycast(ray.Value, out hitInfo)) { if (hitInfo.collider == GetComponent <Collider>()) { jadeState = InlayItemState.Holding; float rayDis; constraintPlane.Raycast(ray.Value, out rayDis); holdPosOffset = ray.Value.GetPoint(rayDis) - transform.position; } } } break; case InlayItemState.Holding: if (ray == null) { jadeState = InlayItemState.Free; break; } if (Vector3.Distance(targetPoint.position, transform.position) < targetJudgeRadius) { if (OnInlayHandler != null && !OnInlayHandler()) { break; } jadeState = InlayItemState.ReachTarget; transform.position = targetPoint.position; break; } break; case InlayItemState.ReachTarget: break; default: break; } //process based on state if (jadeState == InlayItemState.Holding) { float rayDis; constraintPlane.Raycast(ray.Value, out rayDis); Vector3 tPosition = ray.Value.GetPoint(rayDis) - holdPosOffset; if (Vector3.Distance(tPosition, moveCenter) > constraintRange) { Vector3 dir = tPosition - moveCenter; transform.position = moveCenter + dir.normalized * constraintRange; } else { transform.position = tPosition; } } else if (jadeState == InlayItemState.Free) { transform.position = Vector3.Lerp(transform.position, moveCenter, Time.deltaTime * 10f); } }
void UpdateState() { Vector3?tp = InputPlatform.Singleton.GetTouchPoint(); Ray? ray = null; if (tp != null) { ray = Camera.main.ScreenPointToRay(tp.Value); } //update state switch (lidState) { case InlayItemState.Free: if (ray != null) { RaycastHit hitInfo; if (Physics.Raycast(ray.Value, out hitInfo, 30f)) { if (hitInfo.collider == GetComponent <Collider>()) { lidState = InlayItemState.Holding; float rayDis; constraintPlane.Raycast(ray.Value, out rayDis); holdPosOffset = ray.Value.GetPoint(rayDis) - transform.position; } } } break; case InlayItemState.Holding: highLighted = false; if (Vector3.Distance(targetPoint.position, transform.position) < targetJudgeRadius) { lidState = InlayItemState.ReachTarget; GlobalEventManager.SendEvent(reachTargetEvent); transform.position = targetPoint.position; break; } if (ray == null) { lidState = InlayItemState.Free; } break; case InlayItemState.ReachTarget: break; default: break; } //process based on state if (lidState == InlayItemState.Holding) { float rayDis; constraintPlane.Raycast(ray.Value, out rayDis); Vector3 tPosition = ray.Value.GetPoint(rayDis) - holdPosOffset; if (Vector3.Distance(tPosition, moveCenter) > constraintRange) { Vector3 dir = tPosition - moveCenter; transform.position = moveCenter + dir.normalized * constraintRange; } else { transform.position = tPosition; } } }