public static GameObject Instantiate(GameObject prefab, Transform parent = null, bool worldPositionStays = true, bool runInEditMode = true, bool active = true) { GameObject go = UnityObject.Instantiate(prefab); go.transform.SetParent(parent, worldPositionStays); go.SetActive(active); #if UNITY_EDITOR && UNITY_EDITORVR if (!Application.isPlaying && runInEditMode) { SetRunInEditModeRecursively(go, runInEditMode); go.hideFlags = EditorVR.kDefaultHideFlags; } #endif return(go); }
private static void AddOnlyGupTest(ConCommandArgs args) { _myGupSpawnCard = Addressables.LoadAssetAsync <CharacterSpawnCard>(GupCharacterSpawnCard).WaitForCompletion(); _myGupSpawnCard = UnityObject.Instantiate(_myGupSpawnCard); _myGupSpawnCard.directorCreditCost = 1; _myGupDC = new DirectorCard { spawnCard = _myGupSpawnCard, selectionWeight = 1, preventOverhead = false, minimumStageCompletions = 0, spawnDistance = DirectorCore.MonsterSpawnDistance.Standard }; DirectorAPI.MonsterActions += OnlyGup; }
public void InstantiatingAComponentInAwakeWillAwakeThemImmidiately() { int awakeCalls = 0; GameObject objPrefab = new GameObject(true); TestComponent compPrefab = new TestComponent() { onAwake = () => { awakeCalls++; } }; objPrefab.AddComponent(compPrefab); Assert.That(awakeCalls, Is.EqualTo(1)); TestComponent inst = (TestComponent)UnityObject.Instantiate(compPrefab); Assert.That(awakeCalls, Is.EqualTo(2)); }
private static void AddInteractableTest(ConCommandArgs args) { _iscCategoryChest2DamageSpawnCard = Addressables.LoadAssetAsync <InteractableSpawnCard>(iscCategoryChest2Damage).WaitForCompletion(); _iscCategoryChest2DamageSpawnCard = UnityObject.Instantiate(_iscCategoryChest2DamageSpawnCard); _iscCategoryChest2DamageSpawnCard.directorCreditCost = 10; _my_iscCategoryChest2DamageDirectorCard = new DirectorCard { spawnCard = _iscCategoryChest2DamageSpawnCard, selectionWeight = 1, preventOverhead = false, minimumStageCompletions = 0, spawnDistance = DirectorCore.MonsterSpawnDistance.Standard }; DirectorAPI.InteractableActions += CustomInteractables; DirectorAPI.StageSettingsActions += CustomStageSettings; }
void CheckPersistentCanvas() { if (m_RootUIPersistentCanvas == null) { var uiManager = UnityObject.FindObjectOfType <DebugUIHandlerPersistentCanvas>(); if (uiManager == null) { m_PersistentRoot = UnityObject.Instantiate(Resources.Load <Transform>("DebugUI Persistent Canvas")).gameObject; m_PersistentRoot.name = "[Debug Canvas - Persistent]"; m_PersistentRoot.transform.localPosition = Vector3.zero; } else { m_PersistentRoot = uiManager.gameObject; } m_RootUIPersistentCanvas = m_PersistentRoot.GetComponent <DebugUIHandlerPersistentCanvas>(); } }