// updating // // at each update: // private void Update() { // track the last time that the player was within nonzeroly affecting gravity zonage // if (GravityZone.playerWithinNonzerolyAffectingZonage()) { lastTimeWithinNonzerolyAffectingGravityZonage = Time.time; } }
public void refreshGuideLines(Vector2 focalPoint) { //Get the gravity center gz = GravityZone.getGravityZone(focalPoint); if (gz) { center = gz.transform.position; difference = focalPoint - center; direction = difference.normalized; magnitude = difference.magnitude; endPos = focalPoint + (direction * 10); } }
public static Vector2 getUpDirection(Vector2 pos) { GravityZone gz = getGravityZone(pos); if (!gz) { return(Vector2.zero); } //Check to see if the camera rotation needs updated return((gz.radialGravity) ? (pos - (Vector2)gz.transform.position) : (Vector2)gz.transform.up); }
// Update is called once per frame void Update() { if (MenuManager.Open) { //do nothing } else { if (Managers.Rewind.Rewinding) { Managers.Rewind.processRewind(); Managers.Physics2DSurrogate.processFrame(); } else { //Check all the scene loaders //to see if their scene needs loaded or unloaded //(done this way because standard trigger methods in Unity //don't always play nice with teleporting characters) Managers.Scene.checkScenes(); //Camera screen dimensions Managers.Camera.checkScreenDimensions(); //NPC Dialogue if (Managers.NPC.enabled) { Managers.NPC.processDialogue(); } //Music Fade Managers.Music.processFade(); } //Check to see if the camera rotation needs updated Vector2 camPos = Managers.Camera.transform.position; GravityZone gz = GravityZone.getGravityZone(camPos); if (gz && Vector2.Distance(gz.transform.position, camPos) >= CAM_ROTATE_MIN) { Managers.Camera.Up = (gz.radialGravity) ? (camPos - (Vector2)gz.transform.position) : (Vector2)gz.transform.up; } } Managers.Gesture.processGestures(); Managers.Camera.updateCameraPosition(); //If in demo mode, if (Managers.DemoMode.GameDemoLength > 0) { Managers.DemoMode.processDemoMode(); } }
/// <summary> /// Registers a GravityZone with the ability. /// </summary> /// <param name="gravityZone">The GravityZone that should be registered.</param> public void RegisterGravityZone(GravityZone gravityZone) { if (m_GravityZones == null) { m_GravityZones = new GravityZone[1]; } else if (m_GravityZones.Length == m_GravityZoneCount) { System.Array.Resize(ref m_GravityZones, m_GravityZoneCount + 1); } m_GravityZones[m_GravityZoneCount] = gravityZone; m_GravityZoneCount++; if (!IsActive) { StartAbility(); } }
// method: determine whether the player is within box gravity zonage that is actually enabled to gravitize the player // public static bool playerWithinAffectingZonageBox() { if (!playerWithinZonage || (GravityMultiplier.currentGravityModifier() == 0f)) { return(false); } else { foreach (Collider playerCollidingGravityZoneCollider in playerCollidingGravityZoneColliders) { GravityZone playerCollidingGravityZone = playerCollidingGravityZoneCollider.GetComponent <GravityZone>(); if (playerCollidingGravityZone.gravitizingEnabled && playerCollidingGravityZone.gravitizeRigidbodies && playerCollidingGravityZoneCollider.GetComponent <GravityZoneBox>()) { return(true); } } return(false); } }
// method: determine whether the player is within spherical gravity zonage that is actually enabled to gravitize the player with a nonzero force // public static bool playerWithinNonzerolyAffectingZonageSphere() { if (!playerWithinZonage || (GravityMultiplier.currentGravityModifier() == 0f)) { return(false); } else { foreach (Collider playerCollidingGravityZoneCollider in playerCollidingGravityZoneColliders) { GravityZone playerCollidingGravityZone = playerCollidingGravityZoneCollider.GetComponent <GravityZone>(); if (playerCollidingGravityZone.gravitizingEnabled && playerCollidingGravityZone.gravitizeRigidbodies && (playerCollidingGravityZone.gravitationForce != FloatsVector.zeroes) && playerCollidingGravityZoneCollider.GetComponent <GravityZoneSphere>()) { return(true); } } return(false); } }
public void levelPoints() { checkEndIndex(); if (!ssc) { Debug.LogError("SpriteShapeTool needs a SpriteShapeController to level"); return; } GravityZone gz = GravityZone.getGravityZone(ssc.transform.position); if (!gz) { Debug.LogError("SpriteShapeTool: This SpriteShapeController needs to be in a GravityZone in order to be leveled"); return; } //Radial Gravity if (gz.radialGravity) { int pointCount = ssc.spline.GetPointCount(); float rValue = Vector2.Distance( ssc.transform.TransformPoint( ssc.spline.GetPosition(correctHeightIndex % pointCount) ), gz.transform.position ); for (int i = startIndex; i <= endIndex; i++) { Vector2 newPoint = (ssc.transform.TransformPoint(ssc.spline.GetPosition(i % pointCount)) - gz.transform.position) .normalized * rValue + gz.transform.position; ssc.spline.SetPosition(i % pointCount, ssc.transform.InverseTransformPoint(newPoint)); } } //Straight Gravity else { //TODO: Make leveler for Straight Gravity 2020-04-08a } }
public void flip() { // invert the tracking for whether the player is flipped currently // flipped = !flipped; // track the last time that a flip occurred as the current time // timeOfLastFlip = Time.time; // rotate the player by 180° on the z axis, then set the player body's x and z positions to what they were before rotation // Vector3 bodyPositionBeforeRotation = bodyTransform.position; // track the the player's body position before rotation Player.instance.transform.Rotate(Vector3.forward * 180f); // rotate the player by 180° on the z axis Vector3 bodyPositionAfterRotation = bodyTransform.position; // track the the player's body position after rotation playerTransform.position -= ((new Vector3(bodyPositionAfterRotation.x, 0f, bodyPositionAfterRotation.z)) - (new Vector3(bodyPositionBeforeRotation.x, 0f, bodyPositionBeforeRotation.z))); // unoffset the player's x and z positions such that the player body's x and z positions are back to what they were before rotation of the player // if gravity zones' forces are set to be flipped when flipping the player: // if (flipGravityZoneForces) { // flip the gravitation force for all gravity zones // GravityZone.flipForceForAll(); } }
void Start() { _gc = GameController.Instance; _ship = FindObjectOfType <Ship> (); _rigidbody = GetComponent <Rigidbody> (); _animator = GetComponentInChildren <Animator> (); _cmd = GetComponent <CommandCenter> (); _camera = GetComponentInChildren <Camera>(); transform.parent = _ship.transform; _gZone = _ship.GetComponent <GravityZone>(); if (!isLocalPlayer) { DisableCharacter(); GetComponentInChildren <AudioListener> ().enabled = false; } else { _animator.gameObject.GetComponentInChildren <SkinnedMeshRenderer> ().gameObject.layer = 12; GetComponentInChildren <Camera> ().cullingMask = ~(1 << 12); GameController.Instance.RegisterLocalPlayer(this); } }
void rotateCamera(SceneView sceneview) { if (ecro.autoRotate) { GravityZone gz = GravityZone.getGravityZone(sceneview.camera.transform.position); Vector2 up = sceneview.camera.transform.up; if (gz) { if (gz.radialGravity) { up = sceneview.camera.transform.position - gz.transform.position; } else { up = gz.transform.up; } } if ((Vector2)sceneview.camera.transform.up != up) { sceneview.isRotationLocked = false; sceneview.camera.transform.up = up; sceneview.camera.Render(); //sceneview.cameraSettings. ecro.rotZ = sceneview.camera.transform.eulerAngles.z; } } else { Quaternion angle = Quaternion.AngleAxis(ecro.rotZ, Vector3.forward); if (sceneview.camera.transform.localRotation != angle) { sceneview.isRotationLocked = false; sceneview.camera.transform.localRotation = angle; sceneview.camera.Render(); } } }
/// <summary> /// Unregisters a GravityZone with the ability. /// </summary> /// <param name="gravityZone">The GravityZone that should be unregistered.</param> public void UnregisterGravityZone(GravityZone gravityZone) { for (int i = 0; i < m_GravityZoneCount; ++i) { if (m_GravityZones[i] != gravityZone) { continue; } // Shift all of the array elements down one. for (int j = i; j < m_GravityZoneCount - 1; ++j) { m_GravityZones[j] = m_GravityZones[j + 1]; } m_GravityZoneCount--; m_GravityZones[m_GravityZoneCount] = null; break; } if (m_GravityZoneCount == 0) { StopAbility(); } }
// method: remove the given disabled Gravity Zone's collider from the tracking, then if the player is no longer in a Gravity Zone: toggle off the player zonage tracking // public static void updateForDisabledZone(GravityZone gravityZone) { Collider gravityZoneCollider = gravityZone.collider; // connect to the gravity zone's collider if (GravityZone.playerCollidingGravityZoneColliders.Contains(gravityZoneCollider)) { GravityZone.playerCollidingGravityZoneColliders.Remove(gravityZoneCollider); } bool playerStillInAGravityZone = false; foreach (Collider collidingGravityZoneCollider in GravityZone.playerCollidingGravityZoneColliders) { if (collidingGravityZoneCollider && collidingGravityZoneCollider.gameObject) { playerStillInAGravityZone = true; break; } } if (!playerStillInAGravityZone) { toggleZonageForPlayerExitFromTheAll(); } }
// method: toggle gravitizing for the given gravity zone // public static void toggleGravitizing(GravityZone gravityZone) { gravityZone.toggleGravitizing(); }
public void RefreshZone() { _gZone = GameController.Instance.GetComponentInParents <GravityZone>(gameObject); }
// Use this for initialization void Start() { _rigidbody = GetComponent <Rigidbody>(); _gZone = GameController.Instance.GetComponentInParents <GravityZone>(gameObject); }
// method: flip the gravitation force for the given gravity zone // public static void flipForce(GravityZone gravityZone) { gravityZone.flipForce(); }
// method: change the gravitation force to the given force for the given gravity zone // public static void changeForce(GravityZone gravityZone, Vector3 force) { gravityZone.changeForce(force); }
// This is called for each window that your tool is active in. Put the functionality of your tool here. public override void OnToolGUI(EditorWindow window) { if (clickPos == Vector2.zero) { updateVars(); } bool mouseDown = Event.current.type == EventType.MouseDown; bool mouseUp = Event.current.type == EventType.MouseUp; if (mouseDown) { positions.Clear(); foreach (Transform t in Selection.transforms) { positions.Add(t, t.position); } center = Vector2.zero; GravityZone gz = GravityZone.getGravityZone(Tools.handlePosition); if (gz) { center = gz.transform.position; } updateVars(); } if (mouseUp) { positions.Clear(); updateVars(); } EditorGUI.BeginChangeCheck(); using (new Handles.DrawingScope(Handles.xAxisColor)) { xPos = Handles.Slider(xPos, xPointDir); } using (new Handles.DrawingScope(Handles.yAxisColor)) { yPos = Handles.Slider(yPos, yPointDir); } if (EditorGUI.EndChangeCheck()) { Vector2 xDir = xPos - clickPos; Vector2 yDir = yPos - clickPos; float xMag = xDir.magnitude; float yMag = yDir.magnitude; Vector2 delta = new Vector2( xMag * Mathf.Sign(Vector2.Dot(xDir, xPointDir)), yMag * Mathf.Sign(Vector2.Dot(yDir, yPointDir)) ); Undo.RecordObjects( Selection.transforms, "Move w/ Radial Gravity" ); foreach (Transform transform in Selection.transforms) { Vector2 direction = (positions[transform] - center).normalized; float distance = Vector2.Distance(positions[transform], center); //delta x transform.position = positions[transform].travelAlongCircle( center, delta.x ); direction = ((Vector2)transform.position - center).normalized; //delta y distance += delta.y; //composite transform.up = direction; transform.position = direction * distance + center; } } }
// method: toggle player zonage according to the toggling setting for player exiting from the all of the Gravity Zones (and first, track whether the player was affected right before last exiting the all; and after, play audio for player exiting from the all of the Gravity Zones if applicable) // private static void toggleZonageForPlayerExitFromTheAll() { GravityZone.toggleZonage(zonageToggling); applicablyPlayAudioForExitFromTheAll(); }
// methods // // method: determine the (boolean) state of this Dependency Requisite // public override bool state() { return(GravityZone.playerWithinNonzerolyAffectingZonageBox()); }
// methods // // method: determine the (boolean) state of this Dependency Requisite // public override bool state() { return(GravityZone.playerWithinAffectingZonage()); }