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()); } }
public void InitShop() { if (_list != null) { foreach (var o in _list) { GameObject.Destroy(o); } } _list = new List <GameObject>(3); for (int i = 0; i < 3; ++i) { GameObject box = GameObject.Instantiate <GameObject>(_box); box.tag = "Untagged"; box.transform.position = ShelfPos[i]; box.transform.rotation = new Quaternion(); box.GetComponent <Rigidbody>().isKinematic = true; LightbulbBoxBehaviour comp = box.AddComponent <LightbulbBoxBehaviour>(); comp.ShopList = _list; _list.Add(box); } GameObject.Destroy(_box); }