internal static void ModifyKitPrefab(string kit, Settings.InitializationType initializationType) { string gameObjectName = kit + "Init"; string gameObjectScriptName = kit + "Init"; GameObject gameObject = null; foreach (GameObject obj in UnityEngine.Object.FindObjectsOfType (typeof (GameObject))) { if (obj.name.StartsWith (gameObjectName)) { gameObject = obj; break; } } if (gameObject == null) { Fabric.Internal.Editor.Utils.Warn ("Couldn't find {0}'s GameObject", kit); return; } Component script = gameObject.GetComponent (gameObjectScriptName); switch (initializationType) { case Settings.InitializationType.Manual: if (script != null) { Fabric.Internal.Editor.Utils.Log ("Removing component {0} from {1} prefab.", gameObjectScriptName, gameObject); Component.DestroyImmediate (script); } break; case Settings.InitializationType.Automatic: if (script == null) { Fabric.Internal.Editor.Utils.Log ("Adding component {0} to {1} prefab.", gameObjectScriptName, gameObject); gameObject.AddComponent (Type.GetType (string.Format ("Fabric.Internal.{0}", gameObjectScriptName))); } break; } }
internal static void ModifyKitPrefabs(Settings.InitializationType initializationType) { // Use imported kits instead of installed kits. If the user has dragged the prefab // into a scene but has not finished onboarding completely, we need to remove the // attached script. foreach (ImportedKit kit in Controller.KitUtils.ListImportedKits (null)()) { ModifyKitPrefab (kit.Name, initializationType); } }
private static void UpdateDependenciesRecord(Settings.InstalledKit installed) { installed.Meta.RemoveAll (tuple => tuple.Key.Equals (DependenciesKey, StringComparison.OrdinalIgnoreCase)); installed.Meta.Add (new Settings.InstalledKit.MetaTuple { Key = DependenciesKey, Value = SerializeDependenciesRecord (PeriodicUpdateManager.TransitiveDependencyChainFor (installed.Name)) }); }
private static Settings.InstalledKit.MetaTuple FindDependenciesRecordFor(Settings.InstalledKit kit) { return kit.Meta.Find (tuple => tuple.Key.Equals (DependenciesKey, StringComparison.OrdinalIgnoreCase)); }
private static HashSet<VersionedDependency> DeserializeDependenciesRecord(Settings.InstalledKit kit) { return DeserializeDependenciesRecord (FindDependenciesRecordFor (kit)); }
internal static HashSet<VersionedDependency> DeserializeDependenciesRecord(Settings.InstalledKit.MetaTuple record) { if (record == null || record.Value == null) { return new HashSet<VersionedDependency> (); } return new HashSet<VersionedDependency> ((Internal.ThirdParty.MiniJSON.Json.Deserialize (record.Value) as List<object>).ConvertAll ( obj => { Dictionary<string, object> typed = obj as Dictionary<string, object>; return new VersionedDependency { Name = typed ["name"] as string, Version = typed ["version"] as string }; } )); }