public override void OnInspectorGUI() { // Update the object and draw the default inspector serializedObject.Update(); DrawDefaultInspector(); // Get the manager ConversationManager manager = FindObjectOfType <ConversationManager>(); // If a manager was found, setup the tracker to drive the rect transforms of the name text and dialogue text if (manager) { tracker = new DrivenRectTransformTracker(); tracker.Add(target, manager.NameText.rectTransform, DrivenTransformProperties.AnchoredPositionY); tracker.Add(target, manager.DialogueText.rectTransform, DrivenTransformProperties.AnchoredPosition | DrivenTransformProperties.SizeDelta); tracker.Add(target, manager.DialoguePanel, DrivenTransformProperties.SizeDeltaY); // Use a button to toggle the npc if (GUILayout.Button("Toggle NPC")) { manager.NpcIcon.enabled = !manager.NpcIcon.enabled; // Validate the dialogue manager when the button is pressed DialogueManager dialogue = target as DialogueManager; dialogue.OnValidate(); } } // Apply modified properties serializedObject.ApplyModifiedProperties(); }
void Awake() { _t = transform; _driven = new DrivenRectTransformTracker(); _driven.Clear(); _driven.Add(this, _t as RectTransform, DrivenTransformProperties.Scale); _image = GetComponent <Image>(); }
private void DriveHeadersParent() { if (headersParent != null && !swipyMenu.FreezeHeaders) { headersParentRectDriver.Clear(); headersParentRectDriver = new DrivenRectTransformTracker(); headersParentRectDriver.Clear(); headersParentRectDriver.Add(this, headersParent, DrivenTransformProperties.All); } }
private void SetupDrivenTransforms() { tracker = new DrivenRectTransformTracker(); tracker.Clear(); //So that we can calculate everything correctly foreach (RectTransform child in contentTransform) { tracker.Add(this, child, DrivenTransformProperties.Anchors); child.anchorMax = new Vector2(0, 1); child.anchorMin = new Vector2(0, 1); } }
void OnDestroy() { foreach (var nested in m_NestedModules.Values) { nested.OnDestroy(); } // Suppress MissingReferenceException in tests EditorApplication.delayCall -= OnSelectionChanged; #if UNITY_EDITOR DrivenRectTransformTracker.StartRecordingUndo(); #endif }
void OnDestroy() { foreach (var nested in m_NestedModules.Values) { nested.OnDestroy(); } #if UNITY_EDITOR #if UNITY_2018_2_OR_NEWER DrivenRectTransformTracker.StartRecordingUndo(); #elif UNDO_PATCH DrivenRectTransformTracker.BlockUndo = false; #endif #endif }
public static int constructor(IntPtr l) { int result; try { DrivenRectTransformTracker drivenRectTransformTracker = default(DrivenRectTransformTracker); LuaObject.pushValue(l, true); LuaObject.pushValue(l, drivenRectTransformTracker); result = 2; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
public override void ValidateEditor() { base.ValidateEditor(); if (this.label == null) { this.label = this.GetComponentInChildren <ButtonComponent>(true); } if (this.list == null) { this.list = this.GetComponentInChildren <ListComponent>(true); } if (this.list != null) { this.scrollRect = this.list.GetComponent <ScrollRect>(); if (this.scrollRect == null) { return; } this.drivenRectTransformTracker = new DrivenRectTransformTracker(); this.drivenRectTransformTracker.Add(this, this.list.rectTransform, DrivenTransformProperties.Anchors | DrivenTransformProperties.Pivot | DrivenTransformProperties.AnchoredPosition); if (this.minMaxSizeX.x >= 0f || this.minMaxSizeX.y >= 0f) { this.drivenRectTransformTracker.Add(this, this.list.rectTransform, DrivenTransformProperties.SizeDeltaX); } if (this.minMaxSizeY.x >= 0f || this.minMaxSizeY.y >= 0f) { this.drivenRectTransformTracker.Add(this, this.list.rectTransform, DrivenTransformProperties.SizeDeltaY); } this.list.hiddenByDefault = true; this.list.AddEditorParametersRegistry(new EditorParametersRegistry() { holder = this, hiddenByDefault = true, hiddenByDefaultDescription = "Value is hold by DropdownComponent" }); this.CalculateAnchorsAndPivot(); this.ApplyMinMaxSize(); } }
/// <summary> /// Drive RectTransform`s to prevent user from editing RectTransform`s that supposed to be handled only by SwipyMenuGenerator. /// </summary> private void DriveRectTransforms() { rectsDriver.Clear(); rectsDriver = new DrivenRectTransformTracker(); rectsDriver.Clear(); if (menusParent != null) { rectsDriver.Add(this, menusParent, DrivenTransformProperties.All); } if (menusContent != null) { rectsDriver.Add(this, menusContent, DrivenTransformProperties.All); } for (int i = 0; i < swipyMenu.menus.Length; i++) { rectsDriver.Add(this, headersParent.GetChild(i).GetComponent <RectTransform>(), DrivenTransformProperties.All); rectsDriver.Add(this, menusContent.GetChild(i).GetComponent <RectTransform>(), DrivenTransformProperties.All); } DriveHeadersParent(); }
internal void Initialize() { if (UpdateInputManager != null) { UpdateInputManager(); } #if UNITY_EDITOR DrivenRectTransformTracker.StopRecordingUndo(); if (!Application.isPlaying) { ClearDeveloperConsoleIfNecessary(); } #endif HandleInitialization(); UnityBrandColorScheme.sessionGradient = UnityBrandColorScheme.GetRandomCuratedLightGradient(); UnityBrandColorScheme.saturatedSessionGradient = UnityBrandColorScheme.GetRandomCuratedGradient(); var delayedInitializationModules = new List <IDelayedInitializationModule>(); foreach (var module in ModuleLoaderCore.instance.modules) { var delayedInitializationModule = module as IDelayedInitializationModule; if (delayedInitializationModule != null) { delayedInitializationModules.Add(delayedInitializationModule); } } delayedInitializationModules.Sort((a, b) => a.initializationOrder.CompareTo(b.initializationOrder)); foreach (var module in delayedInitializationModules) { module.Initialize(); } }
internal void Shutdown() { var delayedInitializationModules = new List <IDelayedInitializationModule>(); foreach (var module in ModuleLoaderCore.instance.modules) { var delayedInitializationModule = module as IDelayedInitializationModule; if (delayedInitializationModule != null) { delayedInitializationModules.Add(delayedInitializationModule); } } delayedInitializationModules.Sort((a, b) => a.shutdownOrder.CompareTo(b.shutdownOrder)); foreach (var module in delayedInitializationModules) { module.Shutdown(); } #if UNITY_EDITOR DrivenRectTransformTracker.StartRecordingUndo(); #endif }
public void OnSceneDrag(SceneView sceneView) { GameObject go = target as GameObject; if (!PrefabUtility.IsPartOfPrefabAsset(go)) { return; } var prefabAssetRoot = go.transform.root.gameObject; Event evt = Event.current; switch (evt.type) { case EventType.DragUpdated: Scene destinationScene = sceneView.customScene.IsValid() ? sceneView.customScene : SceneManager.GetActiveScene(); if (dragObject == null) { // While dragging the instantiated prefab we do not want to record undo for this object // this will cause a remerge of the instance since changes are undone while dragging. // The DrivenRectTransformTracker by default records Undo when used when driving // UI components. This breaks our hideflag setup below due to a remerge of the dragged instance. // StartRecordingUndo() is called on DragExited. Fixes case 1223793. DrivenRectTransformTracker.StopRecordingUndo(); if (!EditorApplication.isPlaying || EditorSceneManager.IsPreviewScene(destinationScene)) { dragObject = (GameObject)PrefabUtility.InstantiatePrefab(prefabAssetRoot, destinationScene); dragObject.name = go.name; } else { // Instatiate as regular GameObject in Play Mode so runtime logic // won't run into restrictions on restructuring Prefab instances. dragObject = Instantiate(prefabAssetRoot); SceneManager.MoveGameObjectToScene(dragObject, destinationScene); } dragObject.hideFlags = HideFlags.HideInHierarchy; } if (HandleUtility.ignoreRaySnapObjects == null) { HandleUtility.ignoreRaySnapObjects = dragObject.GetComponentsInChildren <Transform>(); } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; Vector3 point, normal; if (HandleUtility.PlaceObject(evt.mousePosition, out point, out normal)) { float offset = 0; if (Tools.pivotMode == PivotMode.Center) { float geomOffset = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, normal); if (geomOffset != Mathf.Infinity) { offset = Vector3.Dot(dragObject.transform.position, normal) - geomOffset; } } dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(point + (normal * offset)); } else { dragObject.transform.position = HandleUtility.GUIPointToWorldRay(evt.mousePosition).GetPoint(10); } // Use prefabs original z position when in 2D mode if (sceneView.in2DMode) { Vector3 dragPosition = dragObject.transform.position; dragPosition.z = prefabAssetRoot.transform.position.z; dragObject.transform.position = dragPosition; } evt.Use(); break; case EventType.DragPerform: if (!DragPerform(sceneView, dragObject, go)) { return; } dragObject = null; evt.Use(); break; case EventType.DragExited: // DragExited is always fired after DragPerform so we do no need to call StartRecordingUndo // in DragPerform DrivenRectTransformTracker.StartRecordingUndo(); if (dragObject) { UnityObject.DestroyImmediate(dragObject, false); HandleUtility.ignoreRaySnapObjects = null; dragObject = null; evt.Use(); } break; } }
void Initialize() { #if UNITY_EDITOR #if UNITY_2018_2_OR_NEWER DrivenRectTransformTracker.StopRecordingUndo(); #elif UNDO_PATCH DrivenRectTransformTracker.BlockUndo = true; #endif #endif Nested.evr = this; // Set this once for the convenience of all nested classes m_DefaultTools = DefaultTools; SetHideFlags(defaultHideFlags); #if UNITY_EDITOR if (!Application.isPlaying) { ClearDeveloperConsoleIfNecessary(); } #endif HandleInitialization(); m_Interfaces = (Interfaces)AddNestedModule(typeof(Interfaces)); AddModule <SerializedPreferencesModule>(); // Added here in case any nested modules have preference serialization AddNestedModule(typeof(SerializedPreferencesModuleConnector)); var nestedClassTypes = ObjectUtils.GetExtensionsOfClass(typeof(Nested)); foreach (var type in nestedClassTypes) { AddNestedModule(type); } LateBindNestedModules(nestedClassTypes); #if UNITY_EDITOR if (!Application.isPlaying) { AddModule <HierarchyModule>(); AddModule <ProjectFolderModule>(); } #endif AddModule <AdaptivePositionModule>(); var viewer = GetNestedModule <Viewer>(); viewer.preserveCameraRig = preserveLayout; viewer.InitializeCamera(); var deviceInputModule = AddModule <DeviceInputModule>(); deviceInputModule.InitializePlayerHandle(); deviceInputModule.CreateDefaultActionMapInputs(); deviceInputModule.processInput = ProcessInput; deviceInputModule.updatePlayerHandleMaps = Tools.UpdatePlayerHandleMaps; deviceInputModule.inputDeviceForRayOrigin = rayOrigin => (from deviceData in m_DeviceData where deviceData.rayOrigin == rayOrigin select deviceData.inputDevice).FirstOrDefault(); GetNestedModule <UI>().Initialize(); AddModule <KeyboardModule>(); var multipleRayInputModule = GetModule <MultipleRayInputModule>(); var dragAndDropModule = AddModule <DragAndDropModule>(); multipleRayInputModule.rayEntered += dragAndDropModule.OnRayEntered; multipleRayInputModule.rayExited += dragAndDropModule.OnRayExited; multipleRayInputModule.dragStarted += dragAndDropModule.OnDragStarted; multipleRayInputModule.dragEnded += dragAndDropModule.OnDragEnded; var tooltipModule = AddModule <TooltipModule>(); this.ConnectInterfaces(tooltipModule); multipleRayInputModule.rayEntered += tooltipModule.OnRayEntered; multipleRayInputModule.rayHovering += tooltipModule.OnRayHovering; multipleRayInputModule.rayExited += tooltipModule.OnRayExited; AddModule <ActionsModule>(); AddModule <HighlightModule>(); var lockModule = AddModule <LockModule>(); lockModule.updateAlternateMenu = (rayOrigin, o) => Menus.SetAlternateMenuVisibility(rayOrigin, o != null); AddModule <SelectionModule>(); var spatialHashModule = AddModule <SpatialHashModule>(); spatialHashModule.shouldExcludeObject = go => go.GetComponentInParent <EditorVR>(); spatialHashModule.Setup(); var intersectionModule = AddModule <IntersectionModule>(); this.ConnectInterfaces(intersectionModule); intersectionModule.Setup(spatialHashModule.spatialHash); // TODO: Support module dependencies via ConnectInterfaces GetNestedModule <Rays>().ignoreList = intersectionModule.standardIgnoreList; AddModule <SnappingModule>(); var vacuumables = GetNestedModule <Vacuumables>(); var miniWorlds = GetNestedModule <MiniWorlds>(); var workspaceModule = AddModule <WorkspaceModule>(); workspaceModule.preserveWorkspaces = preserveLayout; workspaceModule.HiddenTypes = HiddenTypes; workspaceModule.workspaceCreated += vacuumables.OnWorkspaceCreated; workspaceModule.workspaceCreated += miniWorlds.OnWorkspaceCreated; workspaceModule.workspaceCreated += workspace => { deviceInputModule.UpdatePlayerHandleMaps(); }; workspaceModule.workspaceDestroyed += vacuumables.OnWorkspaceDestroyed; workspaceModule.workspaceDestroyed += miniWorlds.OnWorkspaceDestroyed; UnityBrandColorScheme.sessionGradient = UnityBrandColorScheme.GetRandomCuratedLightGradient(); UnityBrandColorScheme.saturatedSessionGradient = UnityBrandColorScheme.GetRandomCuratedGradient(); var sceneObjectModule = AddModule <SceneObjectModule>(); sceneObjectModule.tryPlaceObject = (obj, targetScale) => { foreach (var miniWorld in miniWorlds.worlds) { if (!miniWorld.Contains(obj.position)) { continue; } var referenceTransform = miniWorld.referenceTransform; obj.transform.parent = null; obj.position = referenceTransform.position + Vector3.Scale(miniWorld.miniWorldTransform.InverseTransformPoint(obj.position), miniWorld.referenceTransform.localScale); obj.rotation = referenceTransform.rotation * Quaternion.Inverse(miniWorld.miniWorldTransform.rotation) * obj.rotation; obj.localScale = Vector3.Scale(Vector3.Scale(obj.localScale, referenceTransform.localScale), miniWorld.miniWorldTransform.lossyScale.Inverse()); spatialHashModule.AddObject(obj.gameObject); return(true); } return(false); }; AddModule <HapticsModule>(); AddModule <GazeDivergenceModule>(); AddModule <SpatialHintModule>(); AddModule <SpatialScrollModule>(); AddModule <FeedbackModule>(); AddModule <WebModule>(); //TODO: External module support (removes need for CCU in this instance) #if INCLUDE_POLY_TOOLKIT AddModule <PolyModule>(); #endif viewer.AddPlayerModel(); viewer.AddPlayerFloor(); GetNestedModule <Rays>().CreateAllProxies(); // In case we have anything selected at start, set up manipulators, inspector, etc. EditorApplication.delayCall += OnSelectionChanged; }
protected override void OnPrefabInit() { base.OnPrefabInit(); rectTracker = default(DrivenRectTransformTracker); UpdateStretching(); }
internal void OnSceneDragInternal(SceneView sceneView, int index, EventType type, Vector2 mousePosition, bool alt) { GameObject go = target as GameObject; if (!PrefabUtility.IsPartOfPrefabAsset(go)) { return; } var prefabAssetRoot = go.transform.root.gameObject; switch (type) { case EventType.DragUpdated: Scene destinationScene = sceneView.customScene.IsValid() ? sceneView.customScene : SceneManager.GetActiveScene(); if (m_DragObject == null) { // While dragging the instantiated prefab we do not want to record undo for this object // this will cause a remerge of the instance since changes are undone while dragging. // The DrivenRectTransformTracker by default records Undo when used when driving // UI components. This breaks our hideflag setup below due to a remerge of the dragged instance. // StartRecordingUndo() is called on DragExited. Fixes case 1223793. DrivenRectTransformTracker.StopRecordingUndo(); if (!EditorApplication.isPlaying || EditorSceneManager.IsPreviewScene(destinationScene)) { m_DragObject = (GameObject)PrefabUtility.InstantiatePrefab(prefabAssetRoot, destinationScene); m_DragObject.name = go.name; } else { // Instatiate as regular GameObject in Play Mode so runtime logic // won't run into restrictions on restructuring Prefab instances. m_DragObject = Instantiate(prefabAssetRoot); SceneManager.MoveGameObjectToScene(m_DragObject, destinationScene); } m_DragObject.hideFlags = HideFlags.HideInHierarchy; if (HandleUtility.ignoreRaySnapObjects == null) { HandleUtility.ignoreRaySnapObjects = m_DragObject.GetComponentsInChildren <Transform>(); } else { HandleUtility.ignoreRaySnapObjects = HandleUtility.ignoreRaySnapObjects.Union(m_DragObject.GetComponentsInChildren <Transform>()).ToArray(); } PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { GameObject prefab = AssetDatabase.LoadMainAssetAtPath(prefabStage.assetPath) as GameObject; if (prefab != null) { if (PrefabUtility.CheckIfAddingPrefabWouldResultInCyclicNesting(prefab, target)) { s_CyclicNestingDetected = true; } } } } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; Vector3 point, normal; float offset = 0; if (index == 0) { s_PlaceObject = HandleUtility.PlaceObject(mousePosition, out s_PlaceObjectPoint, out s_PlaceObjectNormal); } point = s_PlaceObjectPoint; normal = s_PlaceObjectNormal; if (s_PlaceObject) { if (Tools.pivotMode == PivotMode.Center) { float geomOffset = HandleUtility.CalcRayPlaceOffset(m_DragObject.GetComponentsInChildren <Transform>(), normal); if (geomOffset != Mathf.Infinity) { offset = Vector3.Dot(m_DragObject.transform.position, normal) - geomOffset; } } m_DragObject.transform.position = Matrix4x4.identity.MultiplyPoint(point + (normal * offset)); } else { m_DragObject.transform.position = HandleUtility.GUIPointToWorldRay(mousePosition).GetPoint(10); } if (alt) { if (offset != 0) { m_DragObject.transform.position = point; } m_DragObject.transform.position += prefabAssetRoot.transform.localPosition; } // Use prefabs original z position when in 2D mode if (sceneView.in2DMode) { Vector3 dragPosition = m_DragObject.transform.position; dragPosition.z = prefabAssetRoot.transform.position.z; m_DragObject.transform.position = dragPosition; } // Schedule selection clearing for when we start performing the actual drag action s_ShouldClearSelection = true; break; case EventType.DragPerform: DragPerform(sceneView, m_DragObject, go); m_DragObject = null; break; case EventType.DragExited: // DragExited is always fired after DragPerform so we do no need to call StartRecordingUndo // in DragPerform DrivenRectTransformTracker.StartRecordingUndo(); if (m_DragObject) { DestroyImmediate(m_DragObject, false); HandleUtility.ignoreRaySnapObjects = null; m_DragObject = null; } s_ShouldClearSelection = false; s_CyclicNestingDetected = false; break; } }