public GameObject AddBomberDoors(Transform aircraft, AIEjectPilot ejector, bool rightDoor)
    {
        GameObject ejectorDoorPrefab;

        Debug.Log("Trying to get ejector door!");
        if (rightDoor)
        {
            ejectorDoorPrefab = UnitCatalogue.GetUnitPrefab("ABomberAI").transform.Find("CockpitPart").Find("ejectPanelRight.002").gameObject;
        }
        else
        {
            ejectorDoorPrefab = UnitCatalogue.GetUnitPrefab("ABomberAI").transform.Find("CockpitPart").Find("ejectPanelLeft.002").gameObject;
        }
        Debug.Log("Got ejector door!");

        GameObject ejectorDoor = Instantiate(ejectorDoorPrefab, aircraft);

        ejectorDoor.transform.localPosition = new Vector3(0, -3.582781f, 7.093267f);
        ejectorDoor.transform.localRotation = Quaternion.Euler(-90, 0, 0);

        ejectorDoor.SetActive(false);
        ejector.canopyObject  = ejectorDoor;
        ejector.canopyBooster = ejectorDoor.GetComponentInChildren <SolidBooster>();
        ejector.OnBegin.AddListener(delegate { ejectorDoor.SetActive(true); });
        return(ejectorDoor);
    }
    public void SetupCrew(int crewAmmount, Rigidbody rb)
    {
        prebailTime  = new MinMax(3, 5);
        bailInterval = new MinMax(0.5f, 1);

        spawnPositions = new Vector3[] { new Vector3(-4.69f, -0.392f, -15.84f), new Vector3(4.69f, -0.392f, -15.84f) };

        Debug.Log("Trying to get ejector seat!");
        GameObject ejectorSeatPrefab = UnitCatalogue.GetUnitPrefab("FA-26B AI").GetComponentInChildren <AIEjectPilot>(true).gameObject;

        Debug.Log("Got ejector seat!");


        crew = new AIEjectPilot[crewAmmount];
        for (int i = 0; i < crewAmmount; i++)
        {
            GameObject ejectorSeat = Instantiate(ejectorSeatPrefab, transform);
            ejectorSeat.transform.localPosition = spawnPositions[UnityEngine.Random.Range(0, spawnPositions.Length)];
            ejectorSeat.transform.localRotation = Quaternion.identity;
            ejectorSeat.transform.parent        = transform;

            AIEjectPilot ejectPilot = ejectorSeat.GetComponent <AIEjectPilot>();
            ejectPilot.parentRb = rb;
            ejectPilot.OnBegin.RemoveAllListeners();

            ejectPilot.booster.burnTime = 0;
            ejectPilot.delay            = new MinMax(0, 0);
            ejectPilot.ejectDelay       = 0;
            ejectPilot.parachuteDelay   = 2;

            crew[i] = ejectPilot;
        }
    }
    public AIEjectPilot AddEjectorSeat(Health health, Rigidbody rb, Vector3 position)
    {
        Debug.Log("Trying to get ejector seat!");
        GameObject ejectorSeatPrefab = UnitCatalogue.GetUnitPrefab("FA-26B AI").GetComponentInChildren <AIEjectPilot>(true).gameObject;

        Debug.Log("Got ejector seat!");

        GameObject ejectorSeat = Instantiate(ejectorSeatPrefab, health.transform);

        ejectorSeat.transform.localPosition = position;
        ejectorSeat.transform.localRotation = Quaternion.identity;

        AIEjectPilot ejectPilot = ejectorSeat.GetComponent <AIEjectPilot>();

        health.OnDeath.AddListener(ejectPilot.BeginEjectSequence);
        ejectPilot.parentRb = rb;
        ejectPilot.OnBegin.RemoveAllListeners();
        return(ejectPilot);
    }
    public static void SetupEjection(UnitSpawner __instance)
    {
        if (CheesesAITweaks.settings.enemyEjectorSeats)
        {
            Traverse  unitSpawnerTraverse = Traverse.Create(__instance);
            UnitSpawn unitSpawn           = unitSpawnerTraverse.Field("_spawnedUnit").GetValue <UnitSpawn>();
            switch (__instance.unitID)
            {
            case "ASF-30":
                AIEjectPilot eject  = CheesesAITweaks.instance.AddEjectorSeat(unitSpawn.actor.health, unitSpawn.GetComponent <Rigidbody>(), new Vector3(0, 0, 8));
                GameObject   canopy = unitSpawn.actor.transform.Find("enemyFighterNS").Find("canopy").gameObject;
                eject.OnBegin.AddListener(delegate { canopy.SetActive(false); });

                GameObject cockpit = CheesesAITweaks.instance.AddFACockpit(unitSpawn.transform, new Vector3(0, 0.27729f, 6.581f), Vector3.one * 100);
                eject.OnBegin.AddListener(delegate { cockpit.SetActive(true); });
                break;

            case "ASF-33":
                AIEjectPilot eject2  = CheesesAITweaks.instance.AddEjectorSeat(unitSpawn.actor.health, unitSpawn.GetComponent <Rigidbody>(), new Vector3(0, 0.3f, 8));
                GameObject   canopy2 = unitSpawn.actor.transform.Find("lod0").Find("canopy").gameObject;
                eject2.OnBegin.AddListener(delegate { canopy2.SetActive(false); });

                GameObject cockpit2 = CheesesAITweaks.instance.AddFACockpit(unitSpawn.transform, new Vector3(0, 0.465f, 6.581f), Vector3.one * 100);
                eject2.OnBegin.AddListener(delegate { cockpit2.SetActive(true); });
                break;

            case "ASF-58":
                AIEjectPilot eject3  = CheesesAITweaks.instance.AddEjectorSeat(unitSpawn.actor.health, unitSpawn.GetComponent <Rigidbody>(), new Vector3(0, 0.025f, 14.122f));
                GameObject   canopy3 = unitSpawn.actor.transform.Find("body").Find("canopy").gameObject;
                eject3.OnBegin.AddListener(delegate { canopy3.SetActive(false); });

                AIEjectPilot eject6 = CheesesAITweaks.instance.AddEjectorSeat(unitSpawn.actor.health, unitSpawn.GetComponent <Rigidbody>(), new Vector3(0, 0.41f, 12.126f));
                eject6.OnBegin.AddListener(delegate { canopy3.SetActive(false); });

                GameObject cockpit3 = CheesesAITweaks.instance.AddFACockpit(unitSpawn.transform, new Vector3(0, 0.107f, 11.57f), Vector3.one * 125);
                eject3.OnBegin.AddListener(delegate { cockpit3.SetActive(true); });
                eject6.OnBegin.AddListener(delegate { cockpit3.SetActive(true); });
                break;

            case "GAV-25":
                CheesesAITweaks.instance.AddEjectorSeat(unitSpawn.actor.health, unitSpawn.GetComponent <Rigidbody>(), new Vector3(0, -0.7f, 4.2f));
                break;

            case "EBomberAI":
                AIEjectPilot eject4 = CheesesAITweaks.instance.AddEjectorSeat(unitSpawn.actor.health, unitSpawn.GetComponent <Rigidbody>(), new Vector3(-0.629f, 0.397f, 23.806f));
                AIEjectPilot eject5 = CheesesAITweaks.instance.AddEjectorSeat(unitSpawn.actor.health, unitSpawn.GetComponent <Rigidbody>(), new Vector3(0.629f, 0.397f, 23.806f));

                GameObject canopy4 = unitSpawn.actor.transform.Find("CockpitPart").Find("ejectPanelLeft").gameObject;
                eject4.OnBegin.AddListener(delegate { canopy4.SetActive(false); });

                GameObject canopy5 = unitSpawn.actor.transform.Find("CockpitPart").Find("ejectPanelRight").gameObject;
                eject5.OnBegin.AddListener(delegate { canopy5.SetActive(false); });

                CheesesAITweaks.instance.AddBomberDoors(unitSpawn.actor.transform, eject4, false);
                CheesesAITweaks.instance.AddBomberDoors(unitSpawn.actor.transform, eject5, true);

                unitSpawn.transform.Find("CockpitPart").GetComponent <VehiclePart>().detachDelay = new MinMax(3, 8);
                break;

            case "E-4":
            case "AEW-50":
                AICrewBailer crewBailer = unitSpawn.actor.gameObject.AddComponent <AICrewBailer>();
                crewBailer.SetupCrew(15, unitSpawn.GetComponent <Rigidbody>());
                unitSpawn.actor.health.OnDeath.AddListener(crewBailer.BeginBailout);
                break;

            case "KC-49":
                AICrewBailer crewBailer2 = unitSpawn.actor.gameObject.AddComponent <AICrewBailer>();
                crewBailer2.SetupCrew(3, unitSpawn.GetComponent <Rigidbody>());
                unitSpawn.actor.health.OnDeath.AddListener(crewBailer2.BeginBailout);
                break;

            default:
                break;
            }
        }
    }