public void Awake() { SceneCleanerPreserve scp = gameObject.AddComponent <SceneCleanerPreserve>(); scp.enabled = true; DontDestroyOnLoad(gameObject); }
internal GameObject GetGameObjectInternal() { if (cachedPrefab) { // This will avoid GetGameObject() being called every time the object is spawned. Could break things if there is a degree // of random generation in GetGameObject(), in that case the modder will need to do their random stuff in a MonoBehaviour.Awake() // e.g. in MinecraftFish, the tropical fish have random colours which is done in a MonoBehaviour, rather than the GetGameObject() method return(cachedPrefab); } GameObject go = GetGameObject(); if (go == null) { return(null); } go.transform.position = new Vector3(-5000, -5000, -5000); go.name = ClassID; /* Make sure prefab doesn't get cleared when quiting game to menu. */ SceneCleanerPreserve scp = go.AddComponent <SceneCleanerPreserve>(); scp.enabled = true; if (TechType != TechType.None) { go.AddComponent <Fixer>().techType = TechType; if (go.GetComponent <TechTag>() != null) { go.GetComponent <TechTag>().type = TechType; } if (go.GetComponent <Constructable>() != null) { go.GetComponent <Constructable>().techType = TechType; } } if (go.GetComponent <PrefabIdentifier>() != null) { go.GetComponent <PrefabIdentifier>().ClassId = ClassID; } // Assign the cached prefab to be used in the future cachedPrefab = go; return(go); }
internal GameObject GetGameObjectInternal() { GameObject go = GetGameObject(); if (go == null) { return(null); } go.transform.position = new Vector3(-5000, -5000, -5000); go.name = this.ClassID; /* Make sure prefab doesn't get cleared when quiting game to menu. */ SceneCleanerPreserve scp = go.AddComponent <SceneCleanerPreserve>(); scp.enabled = true; if (this.TechType != TechType.None) { go.AddComponent <Fixer>().techType = this.TechType; if (go.GetComponent <TechTag>() != null) { go.GetComponent <TechTag>().type = this.TechType; } if (go.GetComponent <Constructable>() != null) { go.GetComponent <Constructable>().techType = this.TechType; } } if (go.GetComponent <PrefabIdentifier>() != null) { go.GetComponent <PrefabIdentifier>().ClassId = this.ClassID; } return(go); }