예제 #1
0
        public static bool Launch()
        {
            Log.Info("Launch");
            if (!GTAvailable || !ConfigInfo.Instance.VesselOptions[ModuleNASACountdown.CraftName(FlightGlobals.ActiveVessel)].useGravityTurn)
            {
                return(false);
            }
            if (!ConfigInfo.Instance.VesselOptions[ModuleNASACountdown.CraftName(FlightGlobals.ActiveVessel)].LaunchSequenceControl)
            {
                return(false);
            }
            Log.Info("GravityTurn detected");
            try
            {
                Type calledType = Type.GetType("GravityTurn.GravityTurner,GravityTurn");
                if (calledType != null)
                {
                    MonoBehaviour GTRef = (MonoBehaviour)UnityEngine.Object.FindObjectOfType(calledType); //assumes only one instance of class GravityTurn exists as this command returns first instance found, also must inherit MonoBehavior for this command to work. Getting a reference to your Historian object another way would work also.
                    if (GTRef != null)
                    {
                        MethodInfo myMethod = calledType.GetMethod("Launch", BindingFlags.Instance | BindingFlags.Public);

                        if (myMethod != null)
                        {
                            Log.Info("Invoking Launch");
                            myMethod.Invoke(GTRef, null);
                            GravityTurnActive = true;
                            return(true);
                        }
                        else
                        {
                            Log.Info("Launch not available in GravityTurn");
                            GTAvailable = false;
                            return(false);
                        }
                    }
                    else
                    {
                        Log.Info("GTRef  failed");
                        GTAvailable = false;
                        return(false);
                    }
                }
                Log.Info("calledtype failed");
                GTAvailable = false;
                return(false);
            }
            catch (Exception e)
            {
                Log.Info("Error calling type: " + e);
                GTAvailable = false;
                return(false);
            }
        }
        public static string CraftName(Vessel v)
        {
            foreach (var p in v.Parts)
            {
                if (p.Modules.Contains <ModuleCommand>())
                {
                    ModuleNASACountdown m = p.Modules.GetModule <ModuleNASACountdown>();
                    return(m.craftName);
                }
            }

            return(v.vesselName);
        }