Esempio n. 1
0
    void MissionChanged(object source, FileSystemEventArgs e)
    {
        Debug.Log(e.ChangeType.ToString());
        if (e.ChangeType == WatcherChangeTypes.Created || e.ChangeType == WatcherChangeTypes.Changed)
        {
            LoadMissionFile(e.FullPath.FixPath());
        }
        else if (e.ChangeType == WatcherChangeTypes.Deleted)
        {
            foreach (string key in Missions.Keys.ToArray())
            {
                MissionName mission = Missions[key];
                if (mission.Mission.Path.FixPath() == e.FullPath.FixPath())
                {
                    Missions.Remove(key);
                    var type       = FindType("Assets.Scripts.Missions.MissionManager");
                    var instance   = type.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public).GetValue(null, null);
                    var modmission = instance.GetType().GetMethod("GetMission", @public).Invoke(instance, new object[] { mission.Mission.ID });
                    ModMissions.Remove(modmission);

                    if (SelectedMission == mission)
                    {
                        StartButton.GetComponent <Button>().interactable = false;
                    }

                    Destroy(mission.gameObject);
                }
            }
        }
        else
        {
            Log("[MissionMaker] Unhandled change type encountered: " + e.ChangeType.ToString());
        }
    }
Esempio n. 2
0
    void LoadMissionFile(string path)
    {
        string json = File.ReadAllText(path);
        List <CustomMission> custommissions = new List <CustomMission>();

        try
        {
            custommissions = JsonConvert.DeserializeObject <List <CustomMission> >(json);
        }
        catch (Exception)
        {
            try
            {
                custommissions.Add(JsonConvert.DeserializeObject <CustomMission>(json));
            }
            catch (Exception error)
            {
                Log("Unable to parse JSON for mission at {0}! Error: {1}", path, error.Message);
                return;
            }
        }

        foreach (CustomMission customMission in custommissions)
        {
            customMission.Path = path;

            if (customMission.ID == null)
            {
                Log("A mission called \"{0}\" doesn't have an ID! Skipping mission.", customMission.Name);
                continue;
            }

            MissionName missionName;
            if (Missions.ContainsKey(customMission.ID))
            {
                missionName = Missions[customMission.ID];
            }
            else
            {
                missionName = Instantiate(MissionNamePrefab);
                missionName.gameObject.SetActive(true);
                missionName.transform.SetParent(MissionNamePrefab.transform.parent, false);
            }

            missionName.Name      = customMission.Name;
            missionName.Mission   = customMission;
            missionName.KMMission = CreateMission(customMission);

            Missions[customMission.ID] = missionName;

            var type       = FindType("Assets.Scripts.Missions.MissionManager");
            var instance   = type.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public).GetValue(null, null);
            var modmission = instance.GetType().GetMethod("GetMission", @public).Invoke(instance, new object[] { customMission.ID });
            if (modmission == null)
            {
                ModMissions.Add(missionName.KMMission);
            }
            else
            {
                ModMissions[ModMissions.IndexOf(modmission)] = missionName.KMMission;
            }
        }
    }