Exemple #1
0
        private void LoadAssetBundle()
        {
            // Stack Overflow: https://stackoverflow.com/questions/52797/how-do-i-get-the-path-of-the-assembly-the-code-is-in
            string     codeBase = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri      = new UriBuilder(codeBase);
            string     path     = Path.Combine(Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path)), "lightswitch.assets");

            modAB = AssetBundle.LoadFromFile(path);

            if (modAB == null)
            {
                throw new Exception("Light Switch AssetBundle not found! Path: " + path);
            }

            // Load GameObject
            var lightSwitch = modAB.LoadAsset <GameObject>("LightSwitch");

            PrefabUtils.AddBasicComponents(ref lightSwitch, "LightSwitch");

            var constructable = lightSwitch.AddComponent <Constructable>();

            constructable.allowedOnWall    = true;
            constructable.allowedOnGround  = false;
            constructable.allowedInSub     = true;
            constructable.allowedInBase    = true;
            constructable.allowedOnCeiling = false;
            constructable.allowedOutside   = false;
            constructable.techType         = TechType;
            constructable.model            = lightSwitch.FindChild("model");

            var bounds = lightSwitch.AddComponent <ConstructableBounds>();

            var techTag = lightSwitch.AddComponent <TechTag>();

            techTag.type = TechType;

            var collider = lightSwitch.AddComponent <BoxCollider>();

            collider.size = new Vector3(0.43f, 0.25f, 0.07f);

            var rb = lightSwitch.GetComponent <Rigidbody>();

            MonoBehaviour.DestroyImmediate(rb);

            var lightToggle = lightSwitch.AddComponent <BaseLightToggle>();

            var prefabId = lightSwitch.GetComponent <PrefabIdentifier>();

            if (prefabId == null)
            {
                prefabId = lightSwitch.AddComponent <PrefabIdentifier>();
            }
            prefabId.ClassId = "LightSwitch";

            loadedPrefab = lightSwitch;
        }