Skip to content

Commit

Permalink
Merge pull request #4 from MegaPiggy/master
Browse files Browse the repository at this point in the history
Final API Changes to release for 0.2.2
  • Loading branch information
12090113 authored May 28, 2022
2 parents 704d860 + 6c3ae64 commit bd832bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions MeteorLaunching/MeteorLaunching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class ProjectileLaunchEvent : UnityEvent<int, GameObject> { }
public ProjectileSwitchEvent OnProjectileSwitched;
public ProjectileLaunchEvent OnProjectileLaunched;

private Transform launcherOverride = null;

private void Awake()
{
instance = this;
Expand Down Expand Up @@ -85,12 +87,13 @@ private IEnumerator LateInitialize()

private GameObject LaunchMeteor()
{
var currentLauncher = launcherOverride ?? launcher;
if (projectiles == null) return null;
if (projectiles.Length == 0) return null;
if (!lateInitialized) return null;
if (p >= projectiles.Length)
p = 0;
GameObject newMeteor = Instantiate(projectiles[p], launcher.position + launcher.forward * .5f + launcher.forward * launchSize * projectiles[p].GetComponentInChildren<MeshRenderer>().bounds.size.x * .5f, launcher.rotation);
GameObject newMeteor = Instantiate(projectiles[p], currentLauncher.position + currentLauncher.forward * .5f + currentLauncher.forward * launchSize * projectiles[p].GetComponentInChildren<MeshRenderer>().bounds.size.x * .5f, currentLauncher.rotation);
/*GameObject newMeteor = GameObject.CreatePrimitive(PrimitiveType.Cube);
newMeteor.transform.position = launcher.position + launcher.forward * launchSize * 2;
newMeteor.transform.rotation = launcher.rotation;
Expand All @@ -102,15 +105,16 @@ private GameObject LaunchMeteor()
var fluid = Detector.AddComponent<DynamicFluidDetector>();
owrigid._attachedForceDetector = force;
owrigid._attachedFluidDetector = fluid;*/
newMeteor.GetComponent<Rigidbody>().velocity = launcher.forward * launchSpeed;
newMeteor.GetComponent<Rigidbody>().velocity = currentLauncher.forward * launchSpeed;
newMeteor.transform.localScale = new Vector3(launchSize, launchSize, launchSize);
newMeteor.name = "Projectile";
if (p == 0)
OnMeteorLaunched(newMeteor);
else if (p == 1)
OnMarshmallowLaunched(newMeteor);
OnMarshmallowLaunched(newMeteor, currentLauncher);
OnProjectileLaunched?.Invoke(p, newMeteor);
audio.PlayOneShot(AudioType.BH_MeteorLaunch, 0.25f);
launcherOverride = null;
return newMeteor;
}

Expand All @@ -134,9 +138,9 @@ private void OnMeteorLaunched(GameObject newMeteor)
newMeteorContr._suspendRoot = playerBody.transform;
}

private void OnMarshmallowLaunched(GameObject marshmallow)
private void OnMarshmallowLaunched(GameObject marshmallow, Transform currentLauncher)
{
marshmallow.GetComponent<Rigidbody>().velocity = launcher.forward * (launchSpeed / 4);
marshmallow.GetComponent<Rigidbody>().velocity = currentLauncher.forward * (launchSpeed / 4);
Destroy(marshmallow.GetComponent<SelfDestruct>());
marshmallow.GetComponentInChildren<MeshRenderer>().material.color = new Color(1, 1, 1, 0);
}
Expand Down Expand Up @@ -211,7 +215,9 @@ public override void Configure(IModConfig config)

public class Api
{
public Transform GetLauncher() => Instance.launcher;
public Transform GetLauncher() => Instance.launcherOverride ?? Instance.launcher;

public void OverrideLauncherForNextLaunch(Transform launcher) => Instance.launcherOverride = launcher;

public float GetLaunchSpeed() => Instance.launchSpeed;

Expand Down
2 changes: 1 addition & 1 deletion MeteorLaunching/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"author": "12090113",
"name": "Meteor Launching",
"uniqueName": "12090113.MeteorLaunching",
"version": "0.2.1",
"version": "0.2.2",
"owmlVersion": "2.0.0"
}

0 comments on commit bd832bc

Please sign in to comment.