public override bool GetGroundPosition(Vector3 screenPosition, ref Vector3 groundPosition) { if (this.unityCamera.enabled) { Vector3 position = this.unityCamera.transform.position; return(CameraUtils.GetGroundPositionHelper(this.unityCamera, screenPosition, position, this.distanceFromEyeToScreen, base.GroundOffset, ref groundPosition)); } return(false); }
private bool CameraReachedTheEncounter(bool atStartup = false) { // in order to init CameraUtils.GetRightEdgeWorldPosition(); float offset = atStartup ? CameraUtils.CamWorldSize.x / 2f : 0f; return(CameraUtils.GetRightEdgeWorldPosition() - offset > transform.position.x); }
private void Start() { Energy = MaxEnergy; ShootTimer = FireRate / 2; MoveForward = true; SinOffset = CameraUtils.OrthographicBounds().extents.x; InGame = false; Invoke("SetInGame", 0.5f); }
private void InitInputBlocker() { GameObject obj2 = CameraUtils.CreateInputBlocker(CameraUtils.FindFirstByLayer(base.gameObject.layer), "AddFriendInputBlocker"); obj2.transform.parent = base.transform.parent; this.m_inputBlocker = obj2.AddComponent <PegUIElement>(); this.m_inputBlocker.AddEventListener(UIEventType.RELEASE, new UIEvent.Handler(this.OnInputBlockerReleased)); TransformUtil.SetPosZ(this.m_inputBlocker, base.transform.position.z + 1f); }
public void ConnectInterface(object target, object userData = null) { var usesCameraRig = target as IUsesCameraRig; if (usesCameraRig != null) { usesCameraRig.cameraRig = CameraUtils.GetCameraRig(); } }
void Start() { collBehaviour = GetComponent <CollisionBehaviour>(); collider = GetComponent <Collider2D>(); camBounds = Camera.main.GetComponent <CameraUtils>(); float angleTorotate = Vector3.Angle(-transform.right, movementVector); transform.rotation *= Quaternion.Euler(0, 0, angleTorotate); }
void SetViewerScale(float scale) { var camera = CameraUtils.GetMainCamera(); CameraUtils.GetCameraRig().localScale = Vector3.one * scale; camera.nearClipPlane = m_OriginalNearClipPlane * scale; camera.farClipPlane = m_OriginalFarClipPlane * scale; Shader.SetGlobalFloat(k_WorldScaleProperty, 1f / scale); }
protected virtual void OnVerticalDragging(Transform rayOrigin) { if (m_DragClone) { var fieldGrabOrigin = this.GetFieldGrabOriginForRayOrigin(rayOrigin); var rotation = MathUtilsExt.ConstrainYawRotation(CameraUtils.GetMainCamera().transform.rotation); MathUtilsExt.LerpTransform(m_DragClone, fieldGrabOrigin.position, rotation, m_DragLerp); } }
private IEnumerator AllowCameraFollowCoroutine() { while (IsEnemyAlive()) { yield return(new WaitForSeconds(1f)); } CameraUtils.EnableFollow(true); }
private bool ensureCrosshairCamera() { if (_crosshairCamera != null) { return(true); } _crosshairCamera = CameraUtils.getWorldspaceUiCamera(); return(_crosshairCamera != null); }
private void Setup() { petInstance = (GameObject)Instantiate(petPrefab, Vector3.zero, Quaternion.identity); petInstance.transform.SetParent(transform, true); petInstance.transform.position = inhaler.transform.position = CameraUtils.RandomWorldPointOnScreen(Camera.main, .4f, .33f, 0); inhaler.transform.position = petInstance.GetComponent <MicroMixAnatomy>().mouth.transform.position + new Vector3(.4f, -.2f); petInstance.GetComponentInChildren <Animator>().Play("Breathe Out", 0, 1); petInstance.GetComponentInChildren <Animator>().speed = 0; }
public void Calculate() { if (Cam != null) { Height = CameraUtils.FrustumHeightAtDistance(Cam.farClipPlane - 1.0f, Cam.fieldOfView); Width = Height * Cam.aspect; transform.localScale = new Vector3(Width * 0.1f, 1.0f, Height * 0.1f); } }
private bool ensureHammerCam() { if (_hammerCam != null) { return(true); } _hammerCam = CameraUtils.getWorldspaceUiCamera(); return(_hammerCam != null); }
public static void SaveImage(Texture2D image) { byte[] bytes = image.EncodeToPNG(); string filename = CameraUtils.ScreenShotName(image.width, image.height); Debug.Log(string.Format("Took screenshot to: {0}", filename)); System.IO.File.WriteAllBytes(filename, bytes); }
private bool ensureHudCamera() { if (_hudCamera != null) { return(true); } _hudCamera = CameraUtils.getWorldspaceUiCamera(); return(_hudCamera != null); }
private void Update() { var worldPosition = CameraUtils.GetWorldPosition3D( CameraUtils.ScreenCenter() ); if (debugAimObject != null) { debugAimObject.position = worldPosition; } aimCamera.gameObject.SetActive(input.aim); if (input.aim) { thirdPersonController.Sensitivity = aimSensitivity; thirdPersonController.RotateOnMove = false; var worldAimTarget = worldPosition; worldAimTarget.y = transform.position.y; var aimDirection = (worldAimTarget - transform.position).normalized; transform.forward = Vector3.Lerp( transform.forward, aimDirection, Time.deltaTime * rotateCharacterSpeed ); animator.SetLayerWeight( 1, Mathf.Lerp(animator.GetLayerWeight(1), 1f, Time.deltaTime * aimSpeed) ); } else { thirdPersonController.Sensitivity = normalSensitivity; thirdPersonController.RotateOnMove = true; animator.SetLayerWeight( 1, Mathf.Lerp(animator.GetLayerWeight(1), 0f, Time.deltaTime * aimSpeed) ); } if (input.shoot) { var projectileDirection = (worldPosition - projectileSpawner.position).normalized; Instantiate( projectilePrefab, projectileSpawner.position, Quaternion.LookRotation(projectileDirection, Vector3.up) ); input.shoot = false; } }
private void OnCollisionEnter2D(Collision2D coll) { #region Hit Monster if (coll.gameObject.layer == LayerMaskDefines.MONSTER.id) { MonsterEntity2D entity = coll.gameObject.GetComponent <MonsterEntity2D>(); if (entity.machine.currentState.GetName() != StateTypes.Dead.ToString()) { if (OnHit != null) { OnHit(); } if (data.WOE == 0) { entity.OnSkillHit(owner, data, coll.contacts[0].point); } ProcessCollision(coll); ProcessPhsysicsType(coll.gameObject, data.physicsType); if (data.vibrateType == SkillVibrateType.Hit) { CameraUtils.Shake(); } } else { body2D.velocity = velocity; Collider2D[] colliders = coll.gameObject.GetComponents <Collider2D>(); for (int index = 0; index < colliders.Length; index++) { Physics2D.IgnoreCollision(GetComponent <Collider2D>(), colliders[index]); } } } #endregion #region Hit Missile if (coll.gameObject.layer == LayerMaskDefines.MONSTER_MISSILE.id) { ProcessCollision(coll); ProcessPhsysicsType(coll.gameObject, data.physicsType); if (data.vibrateType == SkillVibrateType.Hit) { CameraUtils.Shake(); } } #endregion }
public void OnBehaviorUpdate() { if (m_ModuleParent == null) { return; } if (snappingEnabled) { var camera = CameraUtils.GetMainCamera(); var shouldActivateGroundPlane = false; foreach (var statesForRay in m_SnappingStates) { foreach (var kvp in statesForRay.Value) { var state = kvp.Value; if (state.groundSnapping) { shouldActivateGroundPlane = true; } var widget = state.widget; if (state.surfaceSnapping && widgetEnabled) { if (widget == null) { widget = EditorXRUtils.Instantiate(m_Widget, m_ModuleParent).transform; state.widget = widget; } widget.gameObject.SetActive(true); var distanceToCamera = Vector3.Distance(camera.transform.position, state.snappingPosition); widget.position = state.snappingPosition; widget.rotation = state.snappingRotation; widget.localScale = k_WidgetScale * distanceToCamera * Vector3.one; } else if (state.widget != null) { widget.gameObject.SetActive(false); } } } m_GroundPlane.SetActive(shouldActivateGroundPlane); if (shouldActivateGroundPlane) { m_GroundPlane.transform.localScale = k_GroundPlaneScale * this.GetViewerScale() * Vector3.one; } } else { m_GroundPlane.SetActive(false); } }
public void CreateWorkspace(Type t, Action <IWorkspace> createdCallback = null) { if (!typeof(IWorkspace).IsAssignableFrom(t)) { return; } // HACK: MiniWorldWorkspace is not working in single pass yet #if UNITY_EDITOR if (t == typeof(MiniWorldWorkspace) && PlayerSettings.stereoRenderingPath != StereoRenderingPath.MultiPass) { Debug.LogWarning("The MiniWorld workspace is not working on single pass, currently."); return; } #endif var cameraTransform = CameraUtils.GetMainCamera().transform; var workspaceComponent = EditorXRUtils.CreateGameObjectWithComponent(t, CameraUtils.GetCameraRig(), false); var workspace = (IWorkspace)workspaceComponent; m_Workspaces.Add(workspace); workspace.destroyed += OnWorkspaceDestroyed; this.ConnectInterfaces(workspace); this.InjectFunctionalitySingle(workspace); var evrWorkspace = workspace as Workspace; if (evrWorkspace != null) { evrWorkspace.leftRayOrigin = leftRayOrigin; evrWorkspace.rightRayOrigin = rightRayOrigin; } //Explicit setup call (instead of setting up in Awake) because we need interfaces to be hooked up first workspace.Setup(); var offset = DefaultWorkspaceOffset; offset.z += workspace.vacuumBounds.extents.z; var workspaceTransform = workspace.transform; workspaceTransform.position = cameraTransform.TransformPoint(offset); ResetRotation(workspace, cameraTransform.forward); if (createdCallback != null) { createdCallback(workspace); } if (workspaceCreated != null) { workspaceCreated(workspace); } #if UNITY_EDITOR EditorXRAnalyticsEvents.WorkspaceState.Send(new UiComponentArgs(t.Name, true)); #endif }
public bool IsOverShape(Touch touch) { if (this.SwallowTouch && touch == this.Touch) { return(true); } bool overShape = this.TouchShape.PositionOverShape(CameraUtils.TouchToWorldPoint(touch, this.Camera.transform, this.Camera)); return(overShape); }
public void ResetWorkspaceRotations() { var cameraTransform = CameraUtils.GetMainCamera().transform; foreach (var ws in workspaces) { var forward = (ws.transform.position - cameraTransform.position).normalized; ResetRotation(ws, forward); } }
/// <summary> /// Finds the cameras. /// </summary> private static void FindCameras(bool sceneViewCameras) { CameraUtils.GetAllCameras(ref s_Cameras, sceneViewCameras); Array.Resize(ref s_CameraNames, s_Cameras.Length); for (int index = 0; index < s_Cameras.Length; index++) { s_CameraNames[index] = new GUIContent(s_Cameras[index].name); } }
protected virtual Camera FindDrawingCamera() { Camera v_camera = CameraUtils.FindDrawingCamera(this.gameObject); if (v_camera == null) { v_camera = CameraUtils.CachedMainCamera; } return(v_camera); }
void Update() { if (hit || MicroMixManager.Instance.IsPaused || MicroMixManager.Instance.IsTutorial) { return; } Vector3 currentPos = CameraUtils.ScreenToWorldPointZ(Camera.main, Input.mousePosition, 0); transform.position = Vector3.MoveTowards(transform.position, currentPos, speed); }
private void Awake() { s_instance = this; this.CreateHitTestPriorityMap(); this.m_FullscreenEffectsCamera = CameraUtils.FindFullScreenEffectsCamera(true); if (this.m_FullscreenEffectsCamera != null) { this.m_FullscreenEffectsCameraActive = true; } }
public static void SetBufferDistance(Transform[] transforms) { if (transforms != null) { var bounds = ObjectUtils.GetBounds(transforms); s_BufferDistance = bounds.size != Vector3.zero ? (bounds.center - CameraUtils.GetMainCamera().transform.position).magnitude : 1f; s_BufferDistance /= IUsesViewerScaleMethods.getViewerScale(); // Normalize this value in case viewer scale changes before paste happens } }
public bool ForcedInputIsOver(Camera camera, GameObject gameObj, out RaycastHit hitInfo) { LayerMask layerMask = ((GameLayer)gameObj.layer).LayerBit(); if (!CameraUtils.Raycast(camera, this.GetMousePosition(), layerMask, out hitInfo)) { return(false); } return(hitInfo.collider.gameObject == gameObj); }
void Update() { Mesh mesh = GetComponent <MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; //Vector3[] normals = mesh.normals; Vector3 mousePosition = Input.mousePosition; Vector3 realPos = CameraUtils.ScreenToWorldPointZ(Camera.main, mousePosition, 50f); float distance = Mathf.Infinity; //Vector3 closest = Vector3.zero; int vertIndex = -1; //We have found the index of the vertex we want to remove if (true) //Input.GetKeyDown(KeyCode.Space)){ { for (int i = 0; i < mesh.vertices.Length; i++) { if (Vector3.SqrMagnitude(realPos - mesh.vertices[i]) < distance) { distance = Vector3.SqrMagnitude(realPos - mesh.vertices[i]); //closest = mesh.vertices[i]; vertIndex = i; } } /*int triIndex = -1; //Now we must find the index of that index (as a value) in triangles * for(int i = 0; i < mesh.triangles.Length; i++){ * if(mesh.triangles[i] == vertIndex){ * triIndex = i; * } * } * string s = triIndex + ": "; * for(int i = 0; i < 3; i++){ * s += GetIndeces(triIndex)[i] + ","; * } * Debug.Log(s); * //Vector3[] newVerts = new Vector3[mesh.vertices.Length-3]; //So go through and see if their value is one of the values at triangles[GetIndeces] * //Vector3[] newNorms = new Vector3[newVerts.Length]; * int[] newTris = new int[mesh.triangles.Length - 3]; * int index = 0; * * for(int i = 0; i < mesh.triangles.Length; i++){ * if(!Contains(newTris, i)){ * newTris[index] = mesh.triangles[i]; * Debug.Log(i + ":" + index); * index++; * } * } * * mesh.triangles = newTris;*/ vertices[vertIndex] = new Vector3(0, 0, 0); mesh.vertices = vertices; Debug.Log(vertIndex); } }
private void Setup() { petInstance = (GameObject)Instantiate(petPrefab, Vector3.zero, Quaternion.identity); petInstance.transform.SetParent(transform); petInstance.GetComponentInChildren <Animator>().Play("Breathe Out", 0, 1); do { inhalerItem.transform.position = CameraUtils.RandomWorldPointOnScreen(Camera.main, .2f, .2f, 0); petInstance.transform.position = CameraUtils.RandomWorldPointOnScreen(Camera.main, .33f, .33f, 0); } while (Vector3.Distance(inhalerItem.transform.position, petInstance.transform.position) < 1f); }
void SaveCameraState() { var camera = CameraUtils.GetMainCamera(); var cameraRig = CameraUtils.GetCameraRig(); var cameraTransform = camera.transform; var cameraRigScale = cameraRig.localScale.x; m_Preferences.cameraRigScale = cameraRigScale; m_Preferences.cameraPosition = cameraTransform.position; m_Preferences.cameraRotation = MathUtilsExt.ConstrainYawRotation(cameraTransform.rotation); }