//Use this for initialization void Start() { //Default Gravity Physics.gravity = gravityZeroG; try { CircularGravity circularGravity = circularGravityGameObject.GetComponent <CircularGravity>(); //Default GUI values hSliderSize = circularGravity.size; hSceneTimeScale = Time.timeScale; hSliderForcePower = circularGravity.forcePower; hSliderCapsuleRadius = circularGravity.capsuleRadius; togglePulse = circularGravity.pulseProperties.pulse; toggleDrawForce = circularGravity.drawGravityProperties.drawGravityForce; hSliderPulseSpeed = circularGravity.pulseProperties.speed; hSliderPulseMinSize = circularGravity.pulseProperties.minSize; hSliderPulseMaxSize = circularGravity.pulseProperties.maxSize; noGravity = toggleNoGravity; } catch (System.Exception) { Debug.LogWarning("Error reading CircularGravity GameObject"); } }
private static void CreateHoverTrigger(GameObject cgf = null, CircularGravity circularGravity = null) { GameObject triggerEnableObj = new GameObject(); triggerEnableObj.name = "Trigger Hover"; if (circularGravity != null) { triggerEnableObj.AddComponent <CGF_HoverTrigger>().Cgf = circularGravity; } else { triggerEnableObj.AddComponent <CGF_HoverTrigger>(); } if (cgf != null) { triggerEnableObj.transform.SetParent(cgf.transform, false); } triggerEnableObj.transform.position = triggerEnableObj.transform.position + Vector3.left * 6f; triggerEnableObj.transform.rotation = Quaternion.Euler(-180, 0, 0); if (cgf == null) { FocusGameObject(triggerEnableObj); } }
void OnDrawGizmos() { if (enable) { circularGravity = this.GetComponent <CircularGravity>(); DrawGravityForceGizmos(); } }
void Update() { if (buttonCreate) { //Creates empty gameobject. GameObject cgf = new GameObject(); //Creates Circular Gravity Force component CircularGravity circularGravity = cgf.AddComponent <CircularGravity>(); //Sets up properties circularGravity.shape = cgfShape; circularGravity.forcePower = cgfForcePower; circularGravity.size = cgfSize; circularGravity.capsuleRadius = cgfCapsuleRadius; circularGravity.constraintProperties.alignToForce = cgfAngleToForce; circularGravity.drawGravityProperties.drawGravityForce = cgfDrawGravityForce; circularGravity.drawGravityProperties.thickness = cgfDrawGravityForceThickness; if (cgfVisualizer) { CircularGravityVisualizer circularGravityVisualizer = cgf.AddComponent <CircularGravityVisualizer>(); circularGravityVisualizer.circularGravityGameObject = cgf; circularGravityVisualizer.guiLocation.x = cgfVisualizerGUIx; circularGravityVisualizer.guiLocation.y = cgfVisualizerGUIy; } //Sets gameojbect Name cgf.name = "CGF"; //Creates Circular Gravity Force Gizmos componet if (cgfGizmos) { cgf.AddComponent <CircularGravityGizmos>(); } //Sets the create location for the Circular Gravity Force gameobject if (SceneView.lastActiveSceneView != null) { cgf.transform.position = SceneView.lastActiveSceneView.pivot; //Sets the Circular Gravity Force gameobject selected in the hierarchy Selection.activeGameObject = cgf; //focus the editor camera on the Circular Gravity Force gameobject SceneView.lastActiveSceneView.FrameSelected(); } else { cgf.transform.position = Vector3.zero; } //Disables the buttonCreateNewCGF buttonCreate = false; } }
void Start() { cgf = this.GetComponent <CircularGravity>(); //Sets up pulse if (_pulseProperties.Pulse) { cgf.Size = _pulseProperties.MinSize; pulse_Positive = true; } }
void Awake() { cgf = this.GetComponent <CircularGravity>(); SetIdleValues(); }
// Use this for initialization void Start() { cgf = this.GetComponent <CircularGravity>(); cgf.Size = maxCgfSize; }
private void UpdateCGFGUI() { if (buttonCreate3D) { //Creates empty gameobject. GameObject cgf = new GameObject(); //Creates Circular Gravity Force component CircularGravity circularGravity = cgf.AddComponent <CircularGravity>(); //Adds Controls if (modAxisControls) { cgf.AddComponent <CGF_AxisControls>(); } if (modKeyControls) { cgf.AddComponent <CGF_KeyControls>(); } //Adds Mods if (modPulse) { cgf.AddComponent <CGF_Pulse>(); } if (modSize) { cgf.AddComponent <CGF_SizeByRaycast>(); } //Sets up properties circularGravity._shape = cgfShape; circularGravity._forceType = cgfForceType; circularGravity.ForcePower = cgfForcePower; circularGravity._forceMode = cgfForceMode; circularGravity._forceTypeProperties.ExplosionForceUpwardsModifier = cfgExplosionForceUpwardsModifier; circularGravity._forceTypeProperties.TorqueMaxAngularVelocity = cfgTorqueMaxAngularVelocity; circularGravity.Size = cgfSize; circularGravity.CapsuleRadius = cgfCapsuleRadius; circularGravity._constraintProperties.AlignToForce = cgfAlignToForce; circularGravity._constraintProperties.SlerpSpeed = cgfslerpSpeed; circularGravity._drawGravityProperties.DrawGravityForce = cgfDrawGravityForce; circularGravity._drawGravityProperties.GravityLineMaterial = new Material(Shader.Find("UI/Default")); circularGravity._drawGravityProperties.Thickness = cgfDrawGravityForceThickness; //Sets gameojbect Name cgf.name = "CGF"; FocusGameObject(cgf); if (triggerEnable) { CreateEnableTrigger(cgf, circularGravity); } if (triggerHover) { CreateHoverTrigger(cgf, circularGravity); } //Disables the buttonCreateNewCGF buttonCreate3D = false; } }
//Draws the GUI void OnGUI() { GUIStyle labelGUIStyle = new GUIStyle(); labelGUIStyle.normal.textColor = Color.white; labelGUIStyle.alignment = TextAnchor.MiddleRight; GUI.Label(new Rect(guiLocation.x + 5, guiLocation.y + 5, 100, 20), "Shape:", labelGUIStyle); if (GUI.Button(new Rect(guiLocation.x + 110, guiLocation.y + 5, 63, 20), "Sphere")) { circularGravityGameObject.GetComponent <CircularGravity>().shape = CircularGravity.Shape.Sphere; } else if (GUI.Button(new Rect(guiLocation.x + 178, guiLocation.y + 5, 63, 20), "Capsule")) { circularGravityGameObject.GetComponent <CircularGravity>().shape = CircularGravity.Shape.Capsule; } else if (GUI.Button(new Rect(guiLocation.x + 248, guiLocation.y + 5, 63, 20), "Raycast")) { circularGravityGameObject.GetComponent <CircularGravity>().shape = CircularGravity.Shape.RayCast; } GUI.Label(new Rect(guiLocation.x + 5, guiLocation.y + 25, 100, 20), "Force Power:", labelGUIStyle); hSliderForcePower = GUI.HorizontalSlider(new Rect(guiLocation.x + 110, guiLocation.y + 30, 200, 20), hSliderForcePower, forcePower.min, forcePower.max); if (circularGravityGameObject.GetComponent <CircularGravity>().shape == CircularGravity.Shape.Capsule) { GUI.Label(new Rect(guiLocation.x + 5, guiLocation.y + 50, 100, 20), "Capsule Radius:", labelGUIStyle); hSliderCapsuleRadius = GUI.HorizontalSlider(new Rect(guiLocation.x + 110, guiLocation.y + 55, 200, 20), hSliderCapsuleRadius, capsuleRadius.min, capsuleRadius.max); } toggleGravityEffect = GUI.Toggle(new Rect(guiLocation.x + 315, guiLocation.y + 25, 150, 20), toggleGravityEffect, "Gravity Effect"); toggleAngleToForce = GUI.Toggle(new Rect(guiLocation.x + 315, guiLocation.y + 50, 150, 20), toggleAngleToForce, "Angle to Force"); togglePulse = GUI.Toggle(new Rect(guiLocation.x + 315, guiLocation.y + 75, 50, 20), togglePulse, "Pulse"); toggleDrawForce = GUI.Toggle(new Rect(guiLocation.x + 315, guiLocation.y + 100, 80, 20), toggleDrawForce, "Draw Force"); toggleNoGravity = GUI.Toggle(new Rect(guiLocation.x + 315, guiLocation.y + 125, 80, 20), toggleNoGravity, "No Gravity"); float topLocButton; if (!togglePulse) { GUI.Label(new Rect(guiLocation.x + 5, guiLocation.y + 75, 100, 20), "Custom Size:", labelGUIStyle); hSliderSize = GUI.HorizontalSlider(new Rect(guiLocation.x + 110, guiLocation.y + 80, 200, 20), hSliderSize, sizeProperties.min, sizeProperties.max); GUI.Label(new Rect(guiLocation.x + 5, guiLocation.y + 100, 100, 20), "Time Scale:", labelGUIStyle); hSceneTimeScale = GUI.HorizontalSlider(new Rect(guiLocation.x + 110, guiLocation.y + 105, 200, 20), hSceneTimeScale, sceneTimeScale.min, sceneTimeScale.max); topLocButton = 125; } else { GUI.Label(new Rect(guiLocation.x + 5, guiLocation.y + 75, 100, 20), "pulse Max Size:", labelGUIStyle); hSliderPulseMaxSize = GUI.HorizontalSlider(new Rect(guiLocation.x + 110, guiLocation.y + 80, 200, 20), hSliderPulseMaxSize, pulseMaxSize.min, pulseMaxSize.max); GUI.Label(new Rect(guiLocation.x + 5, guiLocation.y + 100, 100, 20), "Pulse Min Size:", labelGUIStyle); hSliderPulseMinSize = GUI.HorizontalSlider(new Rect(guiLocation.x + 110, guiLocation.y + 105, 200, 20), hSliderPulseMinSize, pulseMinSize.min, pulseMinSize.max); GUI.Label(new Rect(guiLocation.x + 5, guiLocation.y + 125, 100, 20), "Pulse Speed:", labelGUIStyle); hSliderPulseSpeed = GUI.HorizontalSlider(new Rect(guiLocation.x + 110, guiLocation.y + 130, 200, 20), hSliderPulseSpeed, pulseSpeed.min, pulseSpeed.max); GUI.Label(new Rect(guiLocation.x + 5, guiLocation.y + 150, 100, 20), "Time Scale:", labelGUIStyle); hSceneTimeScale = GUI.HorizontalSlider(new Rect(guiLocation.x + 110, guiLocation.y + 155, 200, 20), hSceneTimeScale, sceneTimeScale.min, sceneTimeScale.max); topLocButton = 175; } if (GUI.Button(new Rect(guiLocation.x + 260, guiLocation.y + topLocButton, 50, 20), "Reset")) { Application.LoadLevel(Application.loadedLevelName); hSceneTimeScale = 1f; } try { CircularGravity circularGravity = circularGravityGameObject.GetComponent <CircularGravity>(); //Defaults the effect if (circularGravity.specialEffect.attachedGameObject == null && defaultAttachedGameObject != null) { circularGravity.specialEffect.attachedGameObject = defaultAttachedGameObject; } if (!togglePulse) { circularGravity.size = hSliderSize; } circularGravity.constraintProperties.alignToForce = toggleAngleToForce; if (toggleGravityEffect) { circularGravity.specialEffect.timeEffected = 3.0f; circularGravity.specialEffect.physicsEffect = CircularGravity.PhysicsEffect.NoGravity; } else { circularGravity.specialEffect.timeEffected = 0.0f; circularGravity.specialEffect.physicsEffect = CircularGravity.PhysicsEffect.None; } circularGravity.forcePower = hSliderForcePower; circularGravity.capsuleRadius = hSliderCapsuleRadius; circularGravity.pulseProperties.pulse = togglePulse; circularGravity.drawGravityProperties.drawGravityForce = toggleDrawForce; circularGravity.pulseProperties.speed = hSliderPulseSpeed; circularGravity.pulseProperties.minSize = hSliderPulseMinSize; circularGravity.pulseProperties.maxSize = hSliderPulseMaxSize; Time.timeScale = hSceneTimeScale; } catch (System.Exception) { Debug.LogWarning("Error reading CircularGravity GameObject"); } }
//Enables/Disable the circular gravity private void EnableCircularGravity(bool enable) { CircularGravity circularGravity = this.GetComponent <CircularGravity>(); circularGravity.enable = enable; }
void SyncGunSelection() { CircularGravity cgf = cgfGameObject.GetComponent <CircularGravity> (); switch (_gunType) { case GunType.GravityGunForce: cgf._forceType = CircularGravity.ForceType.Force; cgf._forceMode = ForceMode.Force; cgf._shape = CircularGravity.Shape.RayCast; sizeByRaycast.enabled = true; if (Input.GetButton("Fire1")) { cgf.ForcePower = cgfForcePower; } else if (Input.GetButton("Fire2")) { cgf.ForcePower = -cgfForcePower; } else { cgf.ForcePower = 0f; } animator.SetBool("isShooting", cgf.ForcePower != 0f); break; case GunType.LauncherForce: cgf._forceType = CircularGravity.ForceType.Force; cgf._forceMode = ForceMode.Impulse; cgf._shape = CircularGravity.Shape.RayCast; sizeByRaycast.enabled = false; sizeByRaycast.HitPoint = Vector3.zero; cgf.Size = 1f; cgf.ForcePower = 25f; if (Input.GetButtonDown("Fire1")) { spawnPosBullet.Spawning(); spawnPosBullet.LastSpawned.GetComponent <CircularGravity>().ForcePower = cgfForcePower; if (SceneSettings.Instance != null) { spawnPosBullet.LastSpawned.GetComponent <CircularGravity>()._drawGravityProperties.DrawGravityForce = SceneSettings.Instance.ToggleCGF; } animator.SetBool("isShooting", true); } else if (Input.GetButtonDown("Fire2")) { spawnNegBullet.Spawning(); spawnNegBullet.LastSpawned.GetComponent <CircularGravity>().ForcePower = -cgfForcePower; if (SceneSettings.Instance != null) { spawnNegBullet.LastSpawned.GetComponent <CircularGravity>()._drawGravityProperties.DrawGravityForce = SceneSettings.Instance.ToggleCGF; } animator.SetBool("isShooting", true); } else { animator.SetBool("isShooting", false); } break; case GunType.GravityGunTorque: cgf._forceType = CircularGravity.ForceType.Torque; cgf._forceMode = ForceMode.Force; cgf._shape = CircularGravity.Shape.RayCast; sizeByRaycast.enabled = true; if (Input.GetButton("Fire1")) { cgf.ForcePower = cgfForcePower; } else if (Input.GetButton("Fire2")) { cgf.ForcePower = -cgfForcePower; } else { cgf.ForcePower = 0f; } animator.SetBool("isShooting", cgf.ForcePower != 0f); break; case GunType.LauncherTorque: cgf._forceType = CircularGravity.ForceType.Force; cgf._forceMode = ForceMode.Impulse; sizeByRaycast.enabled = false; sizeByRaycast.HitPoint = Vector3.zero; cgf.Size = 1f; cgf.ForcePower = 30f; if (Input.GetButtonDown("Fire1")) { spawnPosBulletTor.Spawning(); spawnPosBulletTor.LastSpawned.GetComponent <CircularGravity>().ForcePower = cgfForcePower; if (SceneSettings.Instance != null) { spawnPosBulletTor.LastSpawned.GetComponent <CircularGravity>()._drawGravityProperties.DrawGravityForce = SceneSettings.Instance.ToggleCGF; } animator.SetBool("isShooting", true); } else if (Input.GetButtonDown("Fire2")) { spawnNegBulletTor.Spawning(); spawnNegBulletTor.LastSpawned.GetComponent <CircularGravity>().ForcePower = -cgfForcePower; if (SceneSettings.Instance != null) { spawnNegBulletTor.LastSpawned.GetComponent <CircularGravity>()._drawGravityProperties.DrawGravityForce = SceneSettings.Instance.ToggleCGF; } animator.SetBool("isShooting", true); } else { animator.SetBool("isShooting", false); } break; } }