private static void PrefabStageOpen(PrefabStage prefabStage) { if (onOpenPrefabMode != null) { onOpenPrefabMode.OnNext(prefabStage); } }
void OnPrefabStageDirtinessChanged(PrefabStage prefabStage) { if (m_SceneView.customScene == prefabStage.scene) { m_SceneView.Repaint(); } }
private static void OnPrefabStageOpened(PrefabStage stage) { Preview p = stage.prefabContentsRoot.GetComponentInChildren <Preview>(); if (p) { p.GenerateIcon(); Debug.Log("Creating preview for weapon " + stage.prefabContentsRoot.name); AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings; if (settings != null) { string prefabGuid = AssetDatabase.AssetPathToGUID(stage.prefabAssetPath); AddressableAssetEntry prefabEntry = settings.FindAssetEntry(prefabGuid); if (prefabEntry == null) { Debug.LogError("Prefab entry not found for prefab " + stage.prefabAssetPath); return; } } } else { Debug.LogError("Preview component not found on weapon " + stage.prefabContentsRoot.name + ". Please make sure your prefab contains a Preview Script on a children GameObject."); } stage.ClearDirtiness(); PrefabStage.prefabStageOpened -= OnPrefabStageOpened; }
// -------------------------------------------------------------------- private bool GetRaycastedPoint(Vector3 from, Vector3 to, out Vector3 hitPos, out Vector3 hitNormal, out Transform hitObj, Transform filterTransform = null) { hitObj = null; hitNormal = Vector3.up; hitPos = to; Vector3 dir = (to - from).normalized; PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { Scene scene = prefabStage.scene; PhysicsScene physicScene = scene.GetPhysicsScene(); if (physicScene.Raycast(from, dir, out RaycastHit hit, 100, ~0, QueryTriggerInteraction.Ignore)) { hitPos = hit.point; hitObj = hit.transform; hitNormal = hit.normal; return(!filterTransform || filterTransform && hitObj == filterTransform); } else { return(false); } }
private bool CheckIfIsPrefab() { PrefabStage prefabStage = PrefabStageUtility.GetPrefabStage(gameObject); //Debug.Log("IsPrefabSource: " + gameObject + " : " + prefabStage+", "+ (prefabStage != null)); return(IsPrefab = (prefabStage != null)); }
static public GameObject CreateNewUI() { var root = new GameObject("Canvas"); root.layer = LayerMask.NameToLayer("UI"); Canvas canvas = root.AddComponent <Canvas>(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; root.AddComponent <CanvasScaler>(); root.AddComponent <GraphicRaycaster>(); StageUtility.PlaceGameObjectInCurrentStage(root); bool customScene = false; PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { root.transform.SetParent(prefabStage.prefabContentsRoot.transform, false); customScene = true; } Undo.RegisterCreatedObjectUndo(root, "Create " + root.name); if (!customScene) { CreateEventSystem(false); } return(root); }
void PrefabStageOpened(PrefabStage stage) { if (m_PreviewObject != null) { EditorUtility.MoveToActiveScene(m_PreviewObject); } }
private static bool BelongsToCurrentStage(this GameObject go, PrefabStage prefabStage, StageHandle stageHandleMain) { var stageHandleFromObject = StageUtility.GetStageHandle(go); bool result = prefabStage != null ? (stageHandleFromObject == prefabStage.stageHandle) : (stageHandleFromObject == stageHandleMain); return(result); }
public bool GetAutoSave(PrefabStage instance) { if (instance == null) return false; if (dg_get_autoSave == null || dg_get_autoSave.Target != (object)instance) dg_get_autoSave = (Func<bool>)Delegate.CreateDelegate(typeof(Func<bool>), instance, instance.GetType().GetProperty("autoSave", BindingFlags.Instance | BindingFlags.NonPublic).GetGetMethod(true)); return dg_get_autoSave(); }
void DisplayPrefab() { if (prefab == null) { return; } stage = PrefabStageUtility.GetCurrentPrefabStage(); if (stage == null || !stage.IsPartOfPrefabContents(prefab)) { if (!AssetDatabase.OpenAsset(prefab)) { throw new Exception("Cant open prefab!"); } stage = PrefabStageUtility.GetCurrentPrefabStage(); } //stage = PrefabStageUtility.GetPrefabStage(prefab); // if(stage == null || !stage.IsPartOfPrefabContents(prefab)) // { // throw new Exception("Cant enter prefab stage!"); // } tabs.ActivateTab(1); }
private static void OnPrefabStageClosed(PrefabStage prefabStage) { if (log) { Debug.LogWarning(string.Format("Prefab stage closed, checking NGUI objects | Cameras: {0} | Panels: {1} | Drawcalls: {2}/{3}", UICamera.list.size, UIPanel.list.Count, UIDrawCall.activeList.size, UIDrawCall.inactiveList.size)); } CheckNGUIObjects(); // Since no events happened from standpoint of main stage objects, we have force them to update var stageHandleMain = StageUtility.GetMainStageHandle(); for (int s = 0; s < SceneManager.sceneCount; s++) { var sceneFromList = SceneManager.GetSceneAt(s); if (!sceneFromList.isLoaded) { continue; } var stageHandleFromList = StageUtility.GetStageHandle(sceneFromList); if (stageHandleFromList != stageHandleMain) { continue; } var sceneRootObjects = sceneFromList.GetRootGameObjects(); for (int i = 0; i < sceneRootObjects.Length; i++) { FindAndRefreshPanels(sceneRootObjects[i].transform); } } }
public bool IsOpened(bool selectionMode) { if (!IsValid) { return(false); } if (_type == ItemType.Scene) { return(SceneManager.GetActiveScene().path == _assetPath); } if (_type == ItemType.Prefab) { PrefabStage stage = PrefabStageUtility.GetCurrentPrefabStage(); if (stage == null) { return(Selection.activeObject == GetObject()); } if (stage.prefabAssetPath != _assetPath) { return(false); } return(!selectionMode || Selection.activeGameObject == stage.prefabContentsRoot); } return(Selection.activeObject == GetObject()); }
public Item(Object obj) { if (obj is GameObject go) { if (!go.scene.IsValid()) { _object = obj; _assetPath = AssetDatabase.GetAssetPath(obj); _type = ItemType.Prefab; } else { PrefabStage stage = PrefabStageUtility.GetPrefabStage(go); if (stage != null && stage.prefabContentsRoot == go) { _object = stage.prefabContentsRoot; _assetPath = stage.prefabAssetPath; _type = ItemType.Prefab; } else { _object = obj; _assetPath = go.scene.path; _instanceID = go.GetInstanceID(); _type = ItemType.HierachyObject; } } } else { _object = obj; _assetPath = AssetDatabase.GetAssetPath(obj); _type = ItemType.Asset; } }
private static void PrefabStageClose(PrefabStage prefabStage) { if (onClosePrefabMode != null) { onClosePrefabMode.OnNext(prefabStage); } }
/// <summary> /// プレハブステージが閉じる時 /// </summary> /// <param name="obj"></param> static void OnPrefabStageClosing(PrefabStage pstage) { if (prefabInstanceList.Count > 0) { DelaySavePrefabAndConnect(); } }
// UnityEditor.UI.MenuOptions public static GameObject CreateNewUI() { GameObject gameObject = new GameObject("Canvas"); gameObject.layer = LayerMask.NameToLayer("UI"); Canvas canvas = gameObject.AddComponent <Canvas>(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; gameObject.AddComponent <CanvasScaler>(); gameObject.AddComponent <GraphicRaycaster>(); StageUtility.PlaceGameObjectInCurrentStage(gameObject); bool flag = false; PrefabStage currentPrefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (currentPrefabStage != null) { gameObject.transform.SetParent(currentPrefabStage.prefabContentsRoot.transform, false); flag = true; } Undo.RegisterCreatedObjectUndo(gameObject, "Create " + gameObject.name); if (!flag) { SpringGUIMenuOptions.CreateEventSystem(false); } return(gameObject); }
public static void Button(UnityEngine.Object target, MethodInfo methodInfo) { if (methodInfo.GetParameters().Length == 0) { ButtonAttribute buttonAttribute = (ButtonAttribute)methodInfo.GetCustomAttributes(typeof(ButtonAttribute), true)[0]; string buttonText = string.IsNullOrEmpty(buttonAttribute.Text) ? methodInfo.Name : buttonAttribute.Text; if (GUILayout.Button(buttonText)) { methodInfo.Invoke(target, null); // Set target object and scene dirty to serialize changes to disk EditorUtility.SetDirty(target); PrefabStage stage = PrefabStageUtility.GetCurrentPrefabStage(); if (stage != null) { // Prefab mode EditorSceneManager.MarkSceneDirty(stage.scene); } else { // Normal scene EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } } } else { string warning = typeof(ButtonAttribute).Name + " works only on methods with no parameters"; HelpBox_Layout(warning, MessageType.Warning, context: target, logToConsole: true); } }
static GameObject CreateNewUI() { // Root for the UI var root = new GameObject("Canvas"); root.layer = LayerMask.NameToLayer("UI"); Canvas canvas = root.AddComponent <Canvas>(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; root.AddComponent <CanvasScaler>(); root.AddComponent <GraphicRaycaster>(); // Works for all stages. StageUtility.PlaceGameObjectInCurrentStage(root); bool customScene = false; PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { root.transform.SetParent(prefabStage.prefabContentsRoot.transform, false); customScene = true; } Undo.RegisterCreatedObjectUndo(root, "Create " + root.name); // If there is no event system add one... // No need to place event system in custom scene as these are temporary anyway. // It can be argued for or against placing it in the user scenes, // but let's not modify scene user is not currently looking at. if (!customScene) { CreateEventSystem(false, null); } return(root); }
/// <summary> /// Get all <see cref="INotchSimulatorTarget"> and update them. /// </summary> internal static void UpdateSimulatorTargets() { var simulatedRectRelative = NotchSimulatorUtility.enableSimulation ? NotchSimulatorUtility.CalculateSimulatorSafeAreaRelative() : new Rect(0, 0, 1, 1); var simulatedCutoutsRelative = NotchSimulatorUtility.enableSimulation ? NotchSimulatorUtility.CalculateSimulatorCutoutsRelative() : new Rect[0]; //This value could be used by the component statically. NotchSolutionUtility.SimulatedSafeAreaRelative = simulatedRectRelative; #if UNITY_2019_2_OR_NEWER NotchSolutionUtility.SimulatedCutoutsRelative = simulatedCutoutsRelative; #endif var normalSceneSimTargets = GameObject.FindObjectsOfType <UIBehaviour>().OfType <INotchSimulatorTarget>(); foreach (var nst in normalSceneSimTargets) { nst.SimulatorUpdate(simulatedRectRelative, simulatedCutoutsRelative); } //Now find one in the prefab mode scene as well PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { var prefabSceneSimTargets = prefabStage.stageHandle.FindComponentsOfType <UIBehaviour>().OfType <INotchSimulatorTarget>(); foreach (var nst in prefabSceneSimTargets) { nst.SimulatorUpdate(simulatedRectRelative, simulatedCutoutsRelative); } } }
public static List <T> FindInAllScenes <T>() { List <T> interfaces = new List <T>(); PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { TryAddToList(prefabStage.prefabContentsRoot, interfaces); } else { for (int i = 0; i < SceneManager.sceneCount; i++) { Scene scene = SceneManager.GetSceneAt(i); if (!scene.isLoaded) { continue; } List <T> inScene = FindInScene <T>(scene); foreach (T obj in inScene) { interfaces.Add(obj); } } } return(interfaces); }
/// <summary> /// TODO: now only called when hierarchy changes, not when a new prefab is dragged into the scene. /// </summary> private void UpdateAvailableMenuControllers() { EnsureSettingsObject(); // TODO: support MenuControllers in prefabs? _availableMenuControllers = HierarchyHelper.GetObjectsOfType <MenuController>(); #if UNITY_2018_3_OR_NEWER // Add the open prefab to the list. PrefabStage currentPrefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (currentPrefabStage != null) { AddPrefabStageMenuControllers(currentPrefabStage); } #endif int labelSize = _availableMenuControllers.Length; _availableMenuControllersLabels = new string[labelSize]; for (int i = 0; i < _availableMenuControllers.Length; i++) { _availableMenuControllersLabels[i] = _availableMenuControllers[i].name; if (_editorMenuCreatorSettings.MenuController == _availableMenuControllers[i]) { _selectedMenuController = i; } } if (_selectedMenuController >= _availableMenuControllers.Length) { _selectedMenuController = -1; } }
protected virtual void OnValidate() { #if UNITY_EDITOR PrefabStage s = PrefabStageUtility.GetCurrentPrefabStage(); UTDevModeManagment.SetDevMode(_editMode || s != null, transform, _hiddenSiblings); #endif }
public static bool IsMissingNestPrefab(string assetPath) { if (!IsPrefab(assetPath)) { return(false); } OpenPrefabStage(assetPath); PrefabStage stage = PrefabStageUtility.GetCurrentPrefabStage(); GameObject rootGO = stage.prefabContentsRoot; Transform[] transforms = rootGO.GetComponentsInChildren <Transform>(); foreach (var t in transforms) { if (t.name.IndexOf("Missing Prefab") >= 0) { return(true); } } ClosePrefabStage(); return(false); }
static void OnPrefabStageClosing(PrefabStage stage) { // When closing, we want the bricks that are in the scene var bricks = StageUtility.GetMainStageHandle().FindComponentsOfType <Brick>(); SetShowBricks(showAllBricks, bricks); }
static public GameObject CreateNewUI() { // Root for the UI var root = ObjectFactory.CreateGameObject("Canvas", typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster)); root.layer = LayerMask.NameToLayer(kUILayerName); Canvas canvas = root.GetComponent <Canvas>(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; // Works for all stages. StageUtility.PlaceGameObjectInCurrentStage(root); bool customScene = false; PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { Undo.SetTransformParent(root.transform, prefabStage.prefabContentsRoot.transform, ""); customScene = true; } Undo.SetCurrentGroupName("Create " + root.name); // If there is no event system add one... // No need to place event system in custom scene as these are temporary anyway. // It can be argued for or against placing it in the user scenes, // but let's not modify scene user is not currently looking at. if (!customScene) { CreateEventSystem(false); } return(root); }
public static void MethodButton(UnityEngine.Object target, MethodInfo methodInfo) { ButtonAttribute buttonAttribute = (ButtonAttribute)methodInfo.GetCustomAttributes(typeof(ButtonAttribute), true)[0]; string buttonName = string.IsNullOrEmpty(buttonAttribute.buttonName) ? ObjectNames.NicifyVariableName(methodInfo.Name) : buttonAttribute.buttonName; if (GUILayout.Button(buttonName)) { object[] defaultParams = methodInfo.GetParameters().Select(p => p.DefaultValue).ToArray(); IEnumerator methodResult = methodInfo.Invoke(target, defaultParams) as IEnumerator; if (!Application.isPlaying) { // Set target object and scene dirty to serialize changes to disk EditorUtility.SetDirty(target); PrefabStage stage = PrefabStageUtility.GetCurrentPrefabStage(); // Prefab mode if (stage != null) { EditorSceneManager.MarkSceneDirty(stage.scene); } // Normal scene else { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } } else if (methodResult != null && target is MonoBehaviour behaviour) { behaviour.StartCoroutine(methodResult); } } }
void OnPrefabStageIconChanged(PrefabStage prefabStage) { if (m_PrefabHeaderContent != null) { m_PrefabHeaderContent.image = prefabStage.prefabFileIcon; } }
// TODO: finish void OnGUI() { EditorGUILayout.Space(); EditorGUILayout.LabelField($"Current profile:"); EditorGUILayout.BeginVertical(); selectedFontAsset = (TMP_FontAsset)EditorGUILayout.ObjectField("Select font:", selectedFontAsset, typeof(TMP_FontAsset), false); if (GUILayout.Button($"b1")) { Scene curScene; PrefabStage stage = PrefabStageUtility.GetCurrentPrefabStage(); if (stage != null) { curScene = stage.scene; List <GameObject> roots = new List <GameObject>(curScene.rootCount); curScene.GetRootGameObjects(roots); } else { curScene = SceneManager.GetActiveScene(); List <GameObject> roots = new List <GameObject>(curScene.rootCount); curScene.GetRootGameObjects(roots); } } if (GUILayout.Button($"b2")) { Debug.Log($"b2 pressed"); } EditorGUILayout.EndVertical(); }
/// <summary> /// Get all <see cref="INotchSimulatorTarget"/> and update them. /// </summary> internal static void UpdateSimulatorTargets() { var enableSimulation = Settings.Instance.EnableSimulation; var selectedDevice = SimulationDatabase.ByIndex(Settings.Instance.ActiveConfiguration.DeviceIndex); var simulatedRectRelative = enableSimulation && selectedDevice != null?NotchSimulatorUtility.CalculateSimulatorSafeAreaRelative(selectedDevice) : NotchSolutionUtility.defaultSafeArea; var simulatedCutoutsRelative = enableSimulation && selectedDevice != null?NotchSimulatorUtility.CalculateSimulatorCutoutsRelative(selectedDevice) : NotchSolutionUtility.defaultCutouts; var normalSceneSimTargets = GameObject.FindObjectsOfType <MonoBehaviour>().OfType <INotchSimulatorTarget>(); foreach (var nst in normalSceneSimTargets) { nst.SimulatorUpdate(simulatedRectRelative, simulatedCutoutsRelative); } //Now find one in the prefab mode scene as well PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { var prefabSceneSimTargets = prefabStage.stageHandle.FindComponentsOfType <MonoBehaviour>().OfType <INotchSimulatorTarget>(); foreach (var nst in prefabSceneSimTargets) { nst.SimulatorUpdate(simulatedRectRelative, simulatedCutoutsRelative); } } }
public override void ProcessAsset(SearchJob job) { #if UNITY_2018_3_OR_NEWER PrefabStage stage = PrefabStageUtility.GetPrefabStage(sceneObjects[0]); if (stage != null) { isInPrefabStage = true; } #endif roots = sceneObjects.ToArray(); job.OnAssetSearchBegin(); foreach (GameObject root in roots) { job.searchGameObject(root); } #if UNITY_2018_3_OR_NEWER if (assetIsDirty && isInPrefabStage) { EditorSceneManager.MarkSceneDirty(stage.scene); } #endif }