// Save/load public void Load(FloodlightSaveData saveData) { _base.transform.position = saveData.Pos; _base.transform.rotation = saveData.Rot; _pitch = saveData.Pitch; _health = saveData.Health; _switchLight(saveData.On); }
public override void OnSave() { FloodlightSaveData saveData = _light.GetComponent <FloodlightBehaviour>().GetSaveData(); GameObject[] boxes = GameObject.FindObjectsOfType <GameObject>().Where(e => e.GetComponent <LightbulbBoxBehaviour>() != null && !_list.Contains(e)).ToArray(); foreach (GameObject o in boxes) { saveData.BulbPos.Add(o.transform.position); saveData.BulbRot.Add(o.transform.rotation); } FloodlightSaveData.Serialize <FloodlightSaveData>(saveData, FloodlightSaveData.SavePath); }
public override void OnLoad() { try { // Load assets AssetBundle ab = LoadAssets.LoadBundle(this, "floodlight.unity3d"); GameObject origLight = ab.LoadAsset <GameObject>("floodlight.prefab"); _light = GameObject.Instantiate <GameObject>(origLight); _light.name = "floodlight(Clone)"; _light.layer = LayerMask.NameToLayer("Parts"); _light.tag = "PART"; FloodlightBehaviour comp = _light.AddComponent <FloodlightBehaviour>(); comp.UseBattery = UseBattery; comp.Flicker = EnableFlicker; comp.Unbreakable = Unbreakable; GameObject origBox = ab.LoadAsset <GameObject>("lightbulb_box.prefab"); _box = GameObject.Instantiate <GameObject>(origBox); GameObject.Destroy(origLight); GameObject.Destroy(origBox); ab.Unload(false); // Initialize objects InitShop(); // Load save FloodlightSaveData data = FloodlightSaveData.Deserialize <FloodlightSaveData>(FloodlightSaveData.SavePath); _light.GetComponent <FloodlightBehaviour>().Load(data); for (int i = 0; i < data.BulbPos.Count; ++i) { GameObject box = GameObject.Instantiate <GameObject>(_box); box.transform.position = data.BulbPos[i]; box.transform.rotation = data.BulbRot[i]; LightbulbBoxBehaviour c = box.AddComponent <LightbulbBoxBehaviour>(); c.ShopList = _list; c.Activate(); c.SetBought(); } // Set up command ConsoleCommand.Add(new FloodlightCommand(_light)); } catch (Exception ex) { ModConsole.Error(ex.ToString()); } }