/// <summary> /// Add a new mountable module to this module mount. /// </summary> /// <param name="createdModule">The module to be added (must be already created in the scene).</param> /// <param name="prefabReference">The prefab the module was made from.</param> /// <param name="mountImmediately">Whether the module should be mounted immediately. </param> /// <returns>The MountableModule class instance for the newly stored module.</returns> public MountableModule AddMountableModule(Module createdModule, Module prefabReference = null, bool mountImmediately = false) { if (specifyMountableTypes && !mountableTypes.Contains(createdModule.ModuleType)) { return(null); } // Update the module createdModule.SetRootTransform(rootTransform); createdModule.transform.SetParent(transform); createdModule.transform.localPosition = Vector3.zero; createdModule.transform.localRotation = Quaternion.identity; createdModule.gameObject.SetActive(false); // Add to mountable modules list MountableModule newMountableModule = new MountableModule(prefabReference, createdModule); mountableModules.Add(newMountableModule); // Mount if (mountImmediately) { MountModule(mountableModules.Count - 1); } else { newMountableModule.createdModule.Unmount(); } return(newMountableModule); }
/// <summary> /// Mount a module at the module mount. /// </summary> /// <param name="mountableModule">The Mountable Module reference.</param> public void MountModule(MountableModule mountableModule) { int index = mountableModules.IndexOf(mountableModule); if (index != -1) { MountModule(index); } }
// Save the module loadout of the vehicle public static void SaveModuleLoadout(Vehicle modifiedVehicle, int vehicleIndex, PlayerItemManager itemManager) { if (vehicleIndex < 0 || vehicleIndex >= itemManager.vehicles.Count) { Debug.LogError("Vehicle index out of range for the PlayerItemManager's vehicle list. Unable to save loadout to PlayerPrefs"); return; } string stringVal = ""; for (int i = 0; i < modifiedVehicle.ModuleMounts.Count; ++i) { if (modifiedVehicle.ModuleMounts[i].MountedModuleIndex == -1) { stringVal += modifiedVehicle.ModuleMounts[i].MountedModuleIndex.ToString(); if (i != modifiedVehicle.ModuleMounts.Count - 1) { stringVal += " "; } continue; } MountableModule mountedModule = modifiedVehicle.ModuleMounts[i].MountableModules[modifiedVehicle.ModuleMounts[i].MountedModuleIndex]; int index = itemManager.modulePrefabs.IndexOf(mountedModule.modulePrefab); if (index == -1) { Debug.LogWarning("Module found on ModuleMount has a prefab that does not exist in the PlayerItemManager allModulePrefabs list."); } stringVal += index.ToString(); if (i != modifiedVehicle.ModuleMounts.Count - 1) { stringVal += " "; } } PlayerPrefs.SetString("VehicleModuleLoadout" + vehicleIndex.ToString(), stringVal); }