/* * Called next. */ public void Start() { Deb.Log("KramaxAutoPilot: Start {0}", this.GetInstanceID()); // read in config // initialize any variables // install any callbacks // install in toolbar if (UseAppLauncher()) { Kramax.Toolbar.AppLauncherAutoPilot.Start(this.gameObject); } else { Kramax.Toolbar.ToolbarMod.Start(); } if (mainPilot != null) { Deb.Err("KramaxAutoPilot.Start: mainPilot stil exists"); } else { Deb.Log("KramaxAutoPilot.Start: creating mainPilot"); mainPilot = AddComponent(typeof(George)) as George; } }
public static void loadAPPreset(APPreset p, George instance) { APController[] c = instance.controllers; for (int i = 0; i < c.Length && i < p.PIDGains.Count; i++) { c[i].PGain = p.PIDGains[i][0]; c[i].IGain = p.PIDGains[i][1]; c[i].DGain = p.PIDGains[i][2]; c[i].OutMin = p.PIDGains[i][3]; c[i].OutMax = p.PIDGains[i][4]; c[i].ClampLower = p.PIDGains[i][5]; c[i].ClampUpper = p.PIDGains[i][6]; c[i].Scalar = p.PIDGains[i][7]; c[i].Easing = p.PIDGains[i][8]; } Instance.activeAPPreset = p; GeneralUI.postMessage("Loaded preset " + p.name); if (Instance.activeAPPreset != Instance.craftPresetDict[craftDefaultName].apPreset) { updateCraftPreset(Instance.activeAPPreset, instance.vessel); } saveToFile(); }
public void OnDestroy() { Log.detail("KramaxAutoPilot: OnDestroy {0}", this.GetInstanceID()); if (mainPilot) { Destroy(mainPilot); mainPilot = null; } }
// called on vessel load public static void loadCraftAPPreset(George instance) { if (Instance.craftPresetDict.ContainsKey(FlightGlobals.ActiveVessel.vesselName) && Instance.craftPresetDict[FlightGlobals.ActiveVessel.vesselName].apPreset != null) { loadAPPreset(Instance.craftPresetDict[FlightGlobals.ActiveVessel.vesselName].apPreset, instance); } else { loadAPPreset(Instance.craftPresetDict[craftDefaultName].apPreset, instance); } }
public void OnDestroy() { Deb.Log("KramaxAutoPilot: OnDestroy {0}", this.GetInstanceID()); if (UseAppLauncher()) { Kramax.Toolbar.AppLauncherAutoPilot.OnDestroy(); } else { Kramax.Toolbar.ToolbarMod.OnDestroy(); } if (mainPilot) { Destroy(mainPilot); mainPilot = null; } }
/* * Called next. */ public void Start() { Log.detail("KramaxAutoPilot: Start {0}", this.GetInstanceID()); // read in config // initialize any variables // install any callbacks // install in toolbar if (mainPilot != null) { Log.error("KramaxAutoPilot.Start: mainPilot stil exists"); } else { Log.detail("KramaxAutoPilot.Start: creating mainPilot"); mainPilot = AddComponent(typeof(George)) as George; } }
static void Main(string[] args) { // // OLD MACDONALD // Chicken chicken = new Chicken(); Cow cow = new Cow(); Duck duck = new Duck(); Velociraptor cicero = new Velociraptor(); Platypus occam = new Platypus(); // Show implicit casting (Chicken to Farm Animal) FarmAnimal console = duck; Console.WriteLine(console.NameOfAnimal); Console.WriteLine(console.MakeSoundOnce()); Console.WriteLine(console.MakeSoundTwice()); Console.WriteLine(); // Show explicit casting (FarmAnimal to Chicken) Duck myDuck = (Duck)console; Console.WriteLine(myDuck.NameOfAnimal); Console.WriteLine(myDuck.MakeSoundOnce()); Console.WriteLine(myDuck.MakeSoundTwice()); Console.WriteLine(); //Applying Polymorphism, we're allowed to work in terms of // generic types and not concrete classes. In this case // the list holds a collection of IFarmAnimal, meaning // any class that implements the IFarmAnimal interface is allowed // to be in the list. //Console.WriteLine("Old MacDonald had a farm ee ay ee ay oh"); //Console.WriteLine("And on his farm there was a " + chicken.NameOfAnimal + " ee ay ee ay oh"); //Console.WriteLine("With a " + chicken.MakeSoundTwice() + " here and a " + chicken.MakeSoundTwice() + " there"); //Console.WriteLine("Here a " + chicken.MakeSoundOnce() + ", there a " + chicken.MakeSoundOnce() + " everywhere a " + chicken.MakeSoundTwice()); //Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh"); //Console.WriteLine(); //Console.WriteLine("And on his farm there was a " + cow.NameOfAnimal + " ee ay ee ay oh"); //Console.WriteLine("With a " + cow.MakeSoundTwice() + " here and a " + cow.MakeSoundTwice() + " there"); //Console.WriteLine("Here a " + cow.MakeSoundOnce() + ", there a " + cow.MakeSoundOnce() + " everywhere a " + cow.MakeSoundTwice()); //Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh"); //Console.WriteLine(); //Console.WriteLine("And on his farm there was a " + duck.NameOfAnimal + " ee ay ee ay oh"); //Console.WriteLine("With a " + duck.MakeSoundTwice() + " here and a " + duck.MakeSoundTwice() + " there"); //Console.WriteLine("Here a " + duck.MakeSoundOnce() + ", there a " + duck.MakeSoundOnce() + " everywhere a " + duck.MakeSoundTwice()); //Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh"); //Console.WriteLine(); // ----- THIS IS GETTING REPETITIVE! // We can do better // How can we use what we've learned about inheritance // to help us remove code duplication // // What if we create some sort of base class that all our animals have in common? List <FarmAnimal> animals = new List <FarmAnimal>(); animals.Add(chicken); animals.Add(cow); animals.Add(duck); Console.WriteLine("Old MacDonald had a farm ee ay ee ay oh"); foreach (FarmAnimal animal in animals) { Console.WriteLine("And on his farm there was a " + animal.NameOfAnimal + " ee ay ee ay oh"); Console.WriteLine("With a " + animal.MakeSoundTwice() + " here and a " + animal.MakeSoundTwice() + " there"); Console.WriteLine("Here a " + animal.MakeSoundOnce() + ", there a " + animal.MakeSoundOnce() + " everywhere a " + animal.MakeSoundTwice()); Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh"); Console.WriteLine(); } // Interface List <IFarmAnimal> interfaceAnimals = new List <IFarmAnimal>(); interfaceAnimals.Add(cicero); interfaceAnimals.Add(occam); Console.WriteLine(); Console.WriteLine("Old MacDonald had a farm ee ay ee ay oh"); foreach (IFarmAnimal animal in interfaceAnimals) { Console.WriteLine("And on his farm there was a " + animal.NameOfAnimal + " ee ay ee ay oh"); Console.WriteLine("With a " + animal.MakeSoundTwice() + " here and a " + animal.MakeSoundTwice() + " there"); Console.WriteLine("Here a " + animal.MakeSoundOnce() + ", there a " + animal.MakeSoundOnce() + " everywhere a " + animal.MakeSoundTwice()); Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh"); Console.WriteLine(); } George friend = new George(); friend.Fly(); Console.WriteLine(friend.NameOfAnimal); Console.WriteLine(friend.MakeSoundOnce()); Console.WriteLine(friend.MakeSoundTwice()); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); int width = 25; Console.WriteLine(CreateRow("Employee", "Hours Worked", "Total Weekly Pay", width)); Console.WriteLine(); Console.WriteLine(CreateRow("Bob Mackey", "20", "200", width)); Console.WriteLine("{0, -20}{1, -20}{2, -20}", "Employee", "Hours Worked", "Total Weekly Pay"); Console.WriteLine(); Console.WriteLine("{0, -20}{1, -20}{2, -20}", "Bob Mackey", "20", "200"); Console.ReadKey(); }
public static void updateAPPreset(George instance) { Instance.activeAPPreset.Update(instance.controllers); saveToFile(); }