public static bool UnityEngineVector3MCall(object objSelf, string functionName, List <CQ_Value> param, out CQ_Value returnValue, bool mustEqual) { UnityEngine.Vector3 obj = (UnityEngine.Vector3)objSelf; if (param.Count == 3 && functionName == "Set" && MatchType(param, new Type[] { typeof(float), typeof(float), typeof(float) }, mustEqual)) { returnValue = null; obj.Set((float)param[0].ConvertTo(typeof(float)), (float)param[1].ConvertTo(typeof(float)), (float)param[2].ConvertTo(typeof(float))); return(true); } if (param.Count == 1 && functionName == "Scale" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3) }, mustEqual)) { returnValue = null; obj.Scale((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3))); return(true); } if (param.Count == 0 && functionName == "GetHashCode") { returnValue = new CQ_Value(); returnValue.type = typeof(int); returnValue.value = obj.GetHashCode(); return(true); } if (param.Count == 1 && functionName == "Equals" && MatchType(param, new Type[] { typeof(object) }, mustEqual)) { returnValue = new CQ_Value(); returnValue.type = typeof(bool); returnValue.value = obj.Equals((object)param[0].ConvertTo(typeof(object))); return(true); } if (param.Count == 0 && functionName == "Normalize") { returnValue = null; obj.Normalize(); return(true); } if (param.Count == 0 && functionName == "ToString") { returnValue = new CQ_Value(); returnValue.type = typeof(string); returnValue.value = obj.ToString(); return(true); } if (param.Count == 1 && functionName == "ToString" && MatchType(param, new Type[] { typeof(string) }, mustEqual)) { returnValue = new CQ_Value(); returnValue.type = typeof(string); returnValue.value = obj.ToString((string)param[0].ConvertTo(typeof(string))); return(true); } if (param.Count == 0 && functionName == "GetType") { returnValue = new CQ_Value(); returnValue.type = typeof(System.Type); returnValue.value = obj.GetType(); return(true); } returnValue = null; return(false); }
protected virtual void Update() { // Store var oldScale = transform.localPosition; if (_localScale.Equals(Vector3.zero)) { _localScale = transform.localScale; // } // Get the fingers we want to use var fingers = Use.GetFingers(); // Calculate pinch scale, and make sure it's valid var pinchScale = LeanGesture.GetPinchScale(fingers); var newScale = transform.localScale * pinchScale; if (newScale.x > _localScale.x * MAX_SCALE || newScale.x < _localScale.x * MIN_SCALE) { pinchScale = 1f; } if (pinchScale != 1.0f) { pinchScale = Mathf.Pow(pinchScale, Sensitivity); // Perform the translation if this is a relative scale if (Relative == true) { var pinchScreenCenter = LeanGesture.GetScreenCenter(fingers); if (transform is RectTransform) { TranslateUI(pinchScale, pinchScreenCenter); } else { Translate(pinchScale, pinchScreenCenter); } } transform.localScale *= pinchScale; remainingScale += transform.localPosition - oldScale; } // Get t value var factor = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime); // Dampen remainingDelta var newRemainingScale = Vector3.Lerp(remainingScale, Vector3.zero, factor); // Shift this transform by the change in delta transform.localPosition = oldScale + remainingScale - newRemainingScale; // Update remainingDelta with the dampened value remainingScale = newRemainingScale; }
private Vector3 GenerateRandomFruitPosition() { Vector3 currentHeadPos = this.transform.position; Vector3 fruitPos; do { fruitPos = new Vector3(UnityEngine.Random.Range(minX, maxX), 0f, UnityEngine.Random.Range(minZ, maxX)); } while (fruitPos.Equals(currentHeadPos)); return(fruitPos); }
void Update() { if (_isHead) //La cabeza de la serpiente es la que maneja el input del player { _timeToNextTick -= Time.deltaTime; //Time.deltaTime devuelve el tiempo en segundos que paso desde el último frame, nos permite contar tiempo de manera independiente del framerate del juego if (_timeToNextTick < 0) { //Hay que consultar que tecla esta presionando el player: // - Si no esta presionando ninguna mantenemos la direccion previa de la viborita // - La viborita no puede moverse en la direccion opuesta a la que actualmente se encuentra mirando ya que se chocaria consigo misma. if (Input.GetKey(KeyCode.W) && !_lookingDirection.Equals(Vector3.back)) { _lookingDirection = Vector3.forward; } else if (Input.GetKey(KeyCode.S) && !_lookingDirection.Equals(Vector3.forward)) { _lookingDirection = Vector3.back; } else if (Input.GetKey(KeyCode.D) && !_lookingDirection.Equals(Vector3.left)) { _lookingDirection = Vector3.right; } else if (Input.GetKey(KeyCode.A) && !_lookingDirection.Equals(Vector3.right)) { _lookingDirection = Vector3.left; } Move(this.transform.position + _lookingDirection * movingDistance); _timeToNextTick = tickRate; //Reiniciamos el contador para la siguiente vez } } }
static int Equals(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); UnityEngine.Vector3 obj = (UnityEngine.Vector3)ToLua.ToObject(L, 1); object arg0 = ToLua.ToVarObject(L, 2); bool o = obj.Equals(arg0); LuaDLL.lua_pushboolean(L, o); ToLua.SetBack(L, 1, obj); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public bool Equals(PlacedObject other) { return(PrefabIndex == other.PrefabIndex && Scale.Equals(other.Scale) && Position.Equals(other.Position) && BoundingBox.Equals(other.BoundingBox) && Rotation.Equals(other.Rotation) && ProjectedArea.Equals(other.ProjectedArea)); }
// methods static bool Vector3_Equals__Object(JSVCall vc, int argc) { int len = argc; if (len == 1) { System.Object arg0 = (System.Object)JSMgr.datax.getWhatever((int)JSApi.GetType.Arg); UnityEngine.Vector3 argThis = (UnityEngine.Vector3)vc.csObj; JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(argThis.Equals(arg0))); JSMgr.changeJSObj(vc.jsObjID, argThis); } return(true); }
/// <summary> /// Move camera with keyboard or with screen edge, emphasis on OR. /// </summary> private void Move() { if (useKeyboardInput && KeyboardInput != Vector2.zero) { Vector3 desiredMove = new Vector3(KeyboardInput.x, 0, KeyboardInput.y); desiredMove *= keyboardMovementSpeed; desiredMove *= Time.deltaTime; desiredMove = Quaternion.Euler(new Vector3(0f, transform.eulerAngles.y, 0f)) * desiredMove; desiredMove = m_Transform.InverseTransformDirection(desiredMove); m_Transform.Translate(desiredMove, Space.Self); //Debug if (!desiredMove.Equals(Vector3.zero)) { keyboardMove = true; } else { keyboardMove = false; } } else if (usePanning && Input.GetKey(panningKey) /*&& MouseAxis != Vector2.zero*/) { Vector3 desiredMove = new Vector3(-MouseAxis.x, 0, -MouseAxis.y); desiredMove *= panningSpeed; desiredMove *= Time.deltaTime; desiredMove = Quaternion.Euler(new Vector3(0f, transform.eulerAngles.y, 0f)) * desiredMove; desiredMove = m_Transform.InverseTransformDirection(desiredMove); m_Transform.Translate(desiredMove, Space.Self); //Debug panningMove = true; } else if (useScreenEdgeInput) { Vector3 desiredMove = new Vector3(); Rect leftRect = new Rect(0, 0, screenEdgeBorder, Screen.height); Rect rightRect = new Rect(Screen.width - screenEdgeBorder, 0, screenEdgeBorder, Screen.height); Rect upRect = new Rect(0, Screen.height - screenEdgeBorder, Screen.width, screenEdgeBorder); Rect downRect = new Rect(0, 0, Screen.width, screenEdgeBorder); desiredMove.x = leftRect.Contains(MouseInput) ? -1 : rightRect.Contains(MouseInput) ? 1 : 0; desiredMove.z = upRect.Contains(MouseInput) ? 1 : downRect.Contains(MouseInput) ? -1 : 0; desiredMove *= screenEdgeMovementSpeed; desiredMove *= Time.deltaTime; desiredMove = Quaternion.Euler(new Vector3(0f, transform.eulerAngles.y, 0f)) * desiredMove; desiredMove = m_Transform.InverseTransformDirection(desiredMove); m_Transform.Translate(desiredMove, Space.Self); //Debug if (desiredMove != Vector3.zero) { mouseMove = true; } } }
protected bool needUpdate() { m_lastMousePos = m_curMousePos; m_curMousePos = Input.mousePosition; if(m_lastMousePos.Equals(m_curMousePos)) { return false; } return true; }
// Update is called once per frame void Update() { if (!GameController.GetInstance().GamePaused) { lifeImage.fillAmount = (float)life / (float)maxLife; if (hasBuff && startBuffTimer) { if (buffTimer >= buffDisapear) { StopBuffs(); } buffTimer += Time.deltaTime; Debug.Log(buffTimer); } if (Input.GetKeyDown(cameraChange) && !cameraChanged) { ChangeCamera(); } if (!cameraChanged) { timer += Time.deltaTime; if (Input.GetMouseButton(0)) { if (timer >= fireRate) { // lineRenderer.enabled = true; GameController.GetInstance().InstantiateParticles("Shot", LocFire.transform.position); if (shotgun) { ShotgunECS(LocFire.transform.position, LocFire.transform.forward); } else { ShootECS(LocFire.transform.position, LocFire.transform.rotation); } SoundManager.GetInstance().PlayOneShotSound(shotSoundPath, LocFire.transform.position); anim.SetBool("Shoting", true); timer = 0f; } } else if (Input.GetMouseButtonUp(0) && !Input.GetMouseButton(1)) { lineRenderer.enabled = false; anim.SetBool("Shoting", false); } if (Input.GetMouseButtonDown(1)) { CancelInvoke("Deaim"); InvokeRepeating("Aim", 0, Time.deltaTime); // lineRenderer.enabled = true; anim.SetBool("Shoting", true); } else if (Input.GetMouseButtonUp(1)) { CancelInvoke("Aim"); InvokeRepeating("Deaim", 0, Time.deltaTime); deaim = true; if (!Input.GetMouseButton(0)) { lineRenderer.enabled = false; anim.SetBool("Shoting", false); } } else if (!deaim && !Input.GetMouseButton(1)) { CancelInvoke("Aim"); InvokeRepeating("Deaim", 0, Time.deltaTime); deaim = true; } if (Input.GetMouseButton(2)) { if (Input.GetMouseButtonDown(2)) { CreatePreviewTrap(); } UpdatePreviewTrap(); } else if (Input.GetMouseButtonUp(2)) { CreateTrap(); } if (Input.GetKeyDown(KeyCode.Escape)) { lineRenderer.enabled = false; anim.SetBool("Shoting", false); } hor = Input.GetAxis("Horizontal"); ver = Input.GetAxis("Vertical"); movPlayer = new Vector3(hor, 0, ver).normalized; float targetAngle = Mathf.Atan2(movPlayer.x, movPlayer.z) * Mathf.Rad2Deg + cam.eulerAngles.y; float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime); transform.rotation = Quaternion.Euler(0f, angle, 0f); if (movPlayer.magnitude >= 0.1f) { moveDir = Quaternion.Euler(0, targetAngle, 0f) * Vector3.forward; } if (movPlayer.magnitude >= 0.1f) { moveDir = Quaternion.Euler(0, targetAngle, 0f) * Vector3.forward; } //speedper = WalkSpeed; if (Input.GetKey(RunKey)) { speedper = RunSpeed; } else { speedper = WalkSpeed; } /*if (Input.GetKeyUp(RunKey)) * { * speedper = WalkSpeed; * }*/ //movPlayer.magnitude >= 0.1f ? speedper : 0f anim.SetFloat("Speed", movPlayer.magnitude > 0.5F ? speedper : 0f); anim.SetBool("onGround", characterController.isGrounded); if (movPlayer.Equals(Vector3.zero)) { if (!SoundManager.GetInstance().IsPlaying(idleSoundEvent)) { idleSoundEvent = SoundManager.GetInstance().PlayEvent(idleSoundPath, transform.position, 0.7f); } } else { idleSoundEvent.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT); } setGravity(); Jump(); } } else { idleSoundEvent.stop(FMOD.Studio.STOP_MODE.IMMEDIATE); } }
/// <summary> /// Function to render the intersection of a plane and a square /// </summary> /// <param name="height"></param> /// <param name="vertices"></param> /// <param name="crossSectionRenderer"></param> public void crossSectSquare(Unity.Mathematics.float3 point, Unity.Mathematics.float3 normalDirection, float3[] vertices, UnityEngine.LineRenderer crossSectionRenderer) { //Vertices are organized in clockwise manner starting from top left //top left Unity.Mathematics.float3 a = vertices[0]; //top right Unity.Mathematics.float3 b = vertices[1]; //bottom right Unity.Mathematics.float3 c = vertices[2]; //bottom left Unity.Mathematics.float3 d = vertices[3]; //intermediate calculations Unity.Mathematics.float3 ab_hat = (b - a) / UnityEngine.Vector3.Magnitude(b - a); Unity.Mathematics.float3 bc_hat = (c - b) / UnityEngine.Vector3.Magnitude(c - b); Unity.Mathematics.float3 cd_hat = (d - c) / UnityEngine.Vector3.Magnitude(d - c); Unity.Mathematics.float3 da_hat = (a - d) / UnityEngine.Vector3.Magnitude(a - d); //calculations for point of intersection on different segments Unity.Mathematics.float3 ab_star = IMRE.Math.Operations.SegmentPlaneIntersection(a, b, point, normalDirection); Unity.Mathematics.float3 bc_star = IMRE.Math.Operations.SegmentPlaneIntersection(b, c, point, normalDirection); Unity.Mathematics.float3 cd_star = IMRE.Math.Operations.SegmentPlaneIntersection(c, d, point, normalDirection); Unity.Mathematics.float3 da_star = IMRE.Math.Operations.SegmentPlaneIntersection(d, a, point, normalDirection); //booleans for if the intersection hits a vertex bool ab_star_isEndpoint = ab_star.Equals(a) || ab_star.Equals(b); bool bc_star_isEndpoint = bc_star.Equals(b) || bc_star.Equals(c); bool cd_star_isEndpoint = cd_star.Equals(c) || cd_star.Equals(d); bool da_star_isEndpoint = da_star.Equals(d) || da_star.Equals(a); //booleans for if the intersection hits somewhere on the segments besides the vertices bool ab_star_onSegment = !ab_star.Equals(new float3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity)); bool bc_star_onSegment = !bc_star.Equals(new float3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity)); bool cd_star_onSegment = !cd_star.Equals(new float3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity)); bool da_star_onSegment = !da_star.Equals(new float3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity)); Debug.Log(ab_star); Debug.Log(bc_star); Debug.Log(cd_star); Debug.Log(da_star); //track how many vertices are hit in the intersection int endpointCount = 0; if (ab_star_isEndpoint) { endpointCount++; } if (bc_star_isEndpoint) { endpointCount++; } if (cd_star_isEndpoint) { endpointCount++; } if (da_star_isEndpoint) { endpointCount++; } //intersection does not hit triangle if (!(ab_star_onSegment || bc_star_onSegment || cd_star_onSegment || da_star_onSegment)) { crossSectionRenderer.enabled = false; UnityEngine.Debug.Log("Line does not intersect with any of triangle sides."); } //intersection is an edge of the square else if (endpointCount >= 2 && (!ab_star.Equals(bc_star) || !ab_star.Equals(da_star) || !bc_star.Equals(cd_star) || !cd_star.Equals(da_star))) { crossSectionRenderer.enabled = true; //Case where edge is the intersection //drop the two trivial cases, keep the two non-trivial cases. UnityEngine.Vector3 result0 = ab_star; UnityEngine.Vector3 result1 = cd_star; if (result0.Equals(point) || result1.Equals(point)) { //I know that the trivial cases are on opposite sides, because this is the case where the edge is the intersection. //there are only two pairs of opposite sides. if it's not one, it's the other. result0 = bc_star; result1 = da_star; crossSectionRenderer.SetPosition(0, result0); crossSectionRenderer.SetPosition(1, result1); } else { Debug.LogWarning("Error in calculation of line plane intersection"); crossSectionRenderer.enabled = false; } } //intersection hits one vertice and somewhere on a segment else if (endpointCount == 2 && (ab_star.Equals(bc_star) || bc_star.Equals(cd_star) || cd_star.Equals(da_star))) { //find which vertex is in the intersection, and from there find which of the two possible segments are the other point of intersection //the same logic carries through all of these subcases if (ab_star.Equals(bc_star)) { if (cd_star_onSegment) { crossSectionRenderer.SetPosition(0, b); crossSectionRenderer.SetPosition(1, cd_star); } else { crossSectionRenderer.SetPosition(0, b); crossSectionRenderer.SetPosition(1, da_star); } } else if (bc_star.Equals(cd_star)) { if (ab_star_onSegment) { crossSectionRenderer.SetPosition(0, c); crossSectionRenderer.SetPosition(1, ab_star); } else { crossSectionRenderer.SetPosition(0, c); crossSectionRenderer.SetPosition(1, da_star); } } else if (cd_star.Equals(da_star)) { if (ab_star_onSegment) { crossSectionRenderer.SetPosition(0, d); crossSectionRenderer.SetPosition(1, ab_star); } else { crossSectionRenderer.SetPosition(0, c); crossSectionRenderer.SetPosition(1, bc_star); } } else if (da_star.Equals(ab_star)) { if (cd_star_onSegment) { crossSectionRenderer.SetPosition(0, a); crossSectionRenderer.SetPosition(1, cd_star); } if (bc_star_onSegment) { crossSectionRenderer.SetPosition(0, a); crossSectionRenderer.SetPosition(1, bc_star); } } else { Debug.LogWarning("Error in calculation of line plane intersection"); crossSectionRenderer.enabled = false; } } //intersection hits two segments of the square else { crossSectionRenderer.enabled = true; //use booleans to determine which two segments are in the intersection if (ab_star_onSegment && bc_star_onSegment) { crossSectionRenderer.SetPosition(0, ab_star); crossSectionRenderer.SetPosition(1, bc_star); } else if (ab_star_onSegment && cd_star_onSegment) { crossSectionRenderer.SetPosition(0, ab_star); crossSectionRenderer.SetPosition(1, cd_star); } else if (ab_star_onSegment && da_star_onSegment) { crossSectionRenderer.SetPosition(0, ab_star); crossSectionRenderer.SetPosition(1, da_star); } else if (bc_star_onSegment && da_star_onSegment) { crossSectionRenderer.SetPosition(0, bc_star); crossSectionRenderer.SetPosition(1, da_star); } else if (bc_star_onSegment && cd_star_onSegment) { crossSectionRenderer.SetPosition(0, bc_star); crossSectionRenderer.SetPosition(1, cd_star); } else if (cd_star_onSegment && da_star_onSegment) { crossSectionRenderer.SetPosition(0, cd_star); crossSectionRenderer.SetPosition(1, da_star); } else { Debug.LogWarning("Error in calculation of line plane intersection"); crossSectionRenderer.enabled = false; } } }
public bool Equals(Bounds other) { return(minPosition.Equals(other.minPosition) && maxPosition.Equals(other.maxPosition)); }