I wrote my own code to detect which asteroid are heading for kerbin and when. That bit is working great and It auto-add the SOI change to KAC. The part that is not working is making custom contracts based on that information.
Because the orbits are only available during the FLIGHT and TRACKSTATION GameScenes, I have my code try to generate a custom contract and add it to the current ones. Problem is, it doesn't seems to do anything. The contracts doesn't show up, even in the debug menu. Here is the code:
private void AddContract(String vID)
{
//Add Contract if possible
Debug.Log ("Try to find Contract for " + vID);
Debug.Log ("number of Contracts to check : " + ContractSystem.Instance.Contracts.Count ());
Debug.Log ("Status of Contract system: " + (ContractSystem.Instance == null));
Debug.Log ("ContractSystem.Instance.enabled: " + ContractSystem.Instance.enabled);
Debug.Log ("Generating new Contract ");
AsteroidRedirectContract GeneratedContractType = new AsteroidRedirectContract ();
Contract GeneratedContract = null;
Debug.Log ("Generating Contract of Type:" + GeneratedContractType.GetType ());
GeneratedContract = ContractSystem.Instance.GenerateContract (0, Contract.ContractPrestige.Trivial, GeneratedContractType.GetType ());
if (GeneratedContract != null) {
GeneratedContract.AddParameter (new AsteroidRedirectAltitudeParameters (vID));
GeneratedContract.AddParameter (new AsteroidRedirectDockingParameters (vID));
}
if (!ContractSystem.Instance.Contracts.Contains(GeneratedContract))
{
//Generate new Contract
GeneratedContract.Accept ();
ContractSystem.Instance.Contracts.Add (GeneratedContract);
Debug.Log ("Generated Contract:" + GeneratedContract.ToString ());
}
}
Now, I am obvious not a C# or Unity developper, so I have no clue if I'm doing something that is obviously wrong.... I've tried to debug this for hours trying various way and none seems to work, which is why I am posting here...
ContractSystem.Instance.Contracts.Count (), keeps going up with every contract that I Add(). So that seems to be working. Except, it doesn't do anything.
Any Ideas?