/// <summary> /// Applies current settings to provided <see cref="SnapZone"/>. /// </summary> public void ApplySettingsToSnapZone(SnapZone snapZone) { snapZone.interactionLayerMask = InteractionLayerMask; snapZone.ShownHighlightObjectColor = HighlightColor; snapZone.ValidationMaterial = ValidationMaterial; snapZone.InvalidMaterial = InvalidMaterial; }
public void StartMatching(SnapZone snapZone) { if (blockHandler.isDropped) { if (snapZone != null && snapZone.block != null) { MatchingManager.AddMatchedBlocks(snapZone.block); } if (snapZone.upSnapZone != null && snapZone.upSnapZone.block != null) { MatchingManager.AddMatchedBlocks(snapZone.upSnapZone.block); } if (snapZone.downSnapZone != null && snapZone.downSnapZone.block != null) { MatchingManager.AddMatchedBlocks(snapZone.downSnapZone.block); } if (snapZone.rightSnapZone != null && snapZone.rightSnapZone.block != null) { MatchingManager.AddMatchedBlocks(snapZone.rightSnapZone.block); } if (snapZone.leftSnapZone != null && snapZone.leftSnapZone.block != null) { MatchingManager.AddMatchedBlocks(snapZone.leftSnapZone.block); } } }
/// <summary> /// Constructor for event arguments. /// </summary> /// <remarks> /// Used internally to support NetRix infrastructure. There is no need to call this constructor directly. /// </remarks> /// <param name="editor"></param> /// <param name="el"></param> /// <param name="pVar"></param> /// <param name="rect"></param> public AfterSnapRectEventArgs(IHtmlEditor editor, Interop.IHTMLElement el, Interop.RECT rect, Interop.ELEMENT_CORNER pVar) { element = editor.GenericElementFactory.CreateElement(el); rectangle = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); zone = (SnapZone)(int)pVar; }
public override bool CheckRequirements() { if (leftSnapZone.HeldItem && rightSnapZone.HeldItem) { if (leftSnapZone.HeldItem.GetComponentInChildren <HandleCleaverCut>(true)) { _mainSnapZone = leftSnapZone; return(false); } if (!rightSnapZone.HeldItem.GetComponentInChildren <HandleCleaverCut>(true)) { return(true); } _mainSnapZone = rightSnapZone; return(false); } _mainSnapZone = leftSnapZone.HeldItem ? leftSnapZone : rightSnapZone; if (!_mainSnapZone.HeldItem) { return(true); } return(!_mainSnapZone.HeldItem.GetComponentInChildren <HandleCleaverCut>(true)); }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.ObjectField(EditorGUIUtility.TrTempContent("Script"), MonoScript.FromMonoBehaviour((SnapZone)target), typeof(SnapZone), false); EditorGUI.EndDisabledGroup(); EditorGUILayout.PropertyField(interactionManager, Tooltips.InteractionManager); EditorGUILayout.PropertyField(interactionLayerMask, Tooltips.InteractionLayerMask); EditorGUILayout.PropertyField(attachTransform, Tooltips.AttachTransform); EditorGUILayout.PropertyField(startingSelectedInteractable, Tooltips.StartingSelectedInteractable); EditorGUILayout.Space(); EditorGUILayout.LabelField(EditorGUIUtility.TrTempContent("Snap Zone"), EditorStyles.boldLabel); EditorGUILayout.PropertyField(showHighlightInEditor, Tooltips.ShowHighlightInEditor); EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(shownHighlightObject, Tooltips.ShownHighlightObject); EditorGUILayout.PropertyField(shownHighlightObjectColor, Tooltips.ShownHighlightObjectColor); bool isPreviewMeshChanged = EditorGUI.EndChangeCheck(); EditorGUILayout.PropertyField(interactableHoverMeshValidMaterial, Tooltips.InteractableHoverMeshMaterial); EditorGUILayout.PropertyField(interactableHoverMeshInvalidMaterial, Tooltips.InteractableHoverMeshInvalidMaterial); EditorGUI.indentLevel--; EditorGUILayout.PropertyField(socketActive, Tooltips.SocketActive); EditorGUILayout.Space(); onHoverEntered.isExpanded = EditorGUILayout.Foldout(onHoverEntered.isExpanded, EditorGUIUtility.TrTempContent("Interactor Events"), true); if (onHoverEntered.isExpanded) { // UnityEvents have not yet supported Tooltips EditorGUILayout.PropertyField(onHoverEntered); EditorGUILayout.PropertyField(onHoverExited); EditorGUILayout.PropertyField(onSelectEntered); EditorGUILayout.PropertyField(onSelectExited); } serializedObject.ApplyModifiedProperties(); if (isPreviewMeshChanged) { SnapZone snapZone = (SnapZone)target; snapZone.PreviewMesh = null; SnapZonePreviewDrawer preview = snapZone.attachTransform.gameObject.GetComponent <SnapZonePreviewDrawer>(); if (preview != null) { preview.UpdateMesh(); } } }
private void OnMouseDown() { if (!isMatched) { snapZone = blockHandler.snapZone; MatchingManager.currentMatchingColor = blockHandler.currentBlockColor; StartMatching(snapZone); } }
void Awake() { mySnapZone = GetComponent <SnapZone> (); if (mySnapZone == null) { Debug.LogError("we don't have a snapzone with a snap macro on " + name); } myPlayer = transform.parent.GetComponent <TTPlayer> (); }
private void GetNeighbours() { up = Physics2D.RaycastAll(this.transform.position, transform.up, 0.9f); down = Physics2D.RaycastAll(this.transform.position, -transform.up, 0.9f); right = Physics2D.RaycastAll(this.transform.position, transform.right, 0.9f); left = Physics2D.RaycastAll(this.transform.position, -transform.right, 0.9f); upSnapZone = CheckRaycastHitArray(up); downSnapZone = CheckRaycastHitArray(down); rightSnapZone = CheckRaycastHitArray(right); leftSnapZone = CheckRaycastHitArray(left); }
private SnapZone CheckRaycastHitArray(RaycastHit2D[] arr) { SnapZone snapZone = null; for (int i = 0; i < arr.Length; i++) { if (arr[i].collider.gameObject != this.gameObject) { if (snapZone == null) { snapZone = arr[i].collider.GetComponent <SnapZone>(); return(snapZone); } } } return(null); }
public IEnumerator HighlightObjectNotShown() { // Given a snappable property with a snapzone highlight deactivated parameter active. DynamicRuntimeConfiguration testRuntimeConfiguration = new DynamicRuntimeConfiguration(); testRuntimeConfiguration.SetAvailableModes(new List <IMode> { new Mode("Test", new WhitelistTypeRule <IOptional>(), new Dictionary <string, object> { { "ShowSnapzoneHighlightObject", false } }), }); RuntimeConfigurator.Configuration = testRuntimeConfiguration; SnappablePropertyMock mockedProperty = CreateSnappablePropertyMock(); SnapZoneProperty snapZoneProperty = CreateSnapZoneProperty(); SnapZone zone = snapZoneProperty.SnapZone; mockedProperty.SetSnapZone(snapZoneProperty); yield return(null); SnappedCondition condition = new SnappedCondition(mockedProperty, snapZoneProperty); condition.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); yield return(null); condition.Update(); // When activated condition.LifeCycle.Activate(); while (condition.LifeCycle.Stage != Stage.Active) { yield return(null); condition.Update(); } // Then the highlight is still inactive. Assert.IsFalse(snapZoneProperty.SnapZone.ShowHighlightObject); }
public IEnumerator HighlightColorCanBeChanged() { // Given a snappable property with a highlight color changed DynamicRuntimeConfiguration testRuntimeConfiguration = new DynamicRuntimeConfiguration(); testRuntimeConfiguration.SetAvailableModes(new List <IMode> { new Mode("Test", new WhitelistTypeRule <IOptional>(), new Dictionary <string, object> { { "HighlightColor", Color.yellow } }), }); RuntimeConfigurator.Configuration = testRuntimeConfiguration; SnappablePropertyMock mockedProperty = CreateSnappablePropertyMock(); SnapZoneProperty snapZoneProperty = CreateSnapZoneProperty(); SnapZone zone = snapZoneProperty.SnapZone; mockedProperty.SetSnapZone(snapZoneProperty); yield return(null); SnappedCondition condition = new SnappedCondition(mockedProperty, snapZoneProperty); condition.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); yield return(null); condition.Update(); // When activated condition.LifeCycle.Activate(); while (condition.LifeCycle.Stage != Stage.Active) { yield return(null); condition.Update(); } // Then the highlight color changed properly Assert.AreEqual(Color.yellow, snapZoneProperty.SnapZone.ShownHighlightObjectColor); }
public void CheckWithRaycast() { hit = Physics2D.Raycast(raycastPosition.position, raycastPosition.forward, 1f, tileLayerMask); if (hit.collider != null) { snapZone = hit.collider.GetComponent <SnapZone>(); isTheTileEmpty = snapZone.isEmpty; } else { foreach (BlockElementDragHandler block in blockManager.blocks) { if (block.snapZone != null) { block.snapZone.ResetOrginalColor(); block.snapZone = null; } } isTheTileEmpty = false; } }
public IEnumerator HoverMeshShown() { // Given a snappable property with an AlwaysShowSnapzoneHighlight parameter set to false. DynamicRuntimeConfiguration testRuntimeConfiguration = new DynamicRuntimeConfiguration(); testRuntimeConfiguration.SetAvailableModes(new List <IMode> { new Mode("Test", new WhitelistTypeRule <IOptional>(), new Dictionary <string, object> { { "ShowSnapzoneHoverMeshes", true } }), }); RuntimeConfigurator.Configuration = testRuntimeConfiguration; SnappablePropertyMock mockedProperty = CreateSnappablePropertyMock(); SnapZoneProperty snapZoneProperty = CreateSnapZoneProperty(); SnapZone zone = snapZoneProperty.SnapZone; mockedProperty.SetSnapZone(snapZoneProperty); yield return(null); SnappedCondition condition = new SnappedCondition(mockedProperty, snapZoneProperty); condition.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); // When activated condition.LifeCycle.Activate(); while (condition.LifeCycle.Stage != Stage.Active) { yield return(null); condition.Update(); } // Then the highlightAlwaysActive variable should be false Assert.IsTrue(snapZoneProperty.SnapZone.showInteractableHoverMeshes); }
public void SetSnapZoneWithSnapZoneSettings() { // Given a snap zone SnapZoneSettings settings = SnapZoneSettings.Settings; SnapZoneProperty snapZoneProperty = CreateSnapZoneProperty(); SnapZone snapZone = snapZoneProperty.SnapZone; // When the snap zone settings are modified and the changes applied to the snap zone LayerMask testLayerMask = 0; Color testHighlightColor = Color.magenta; Color testValidationColor = Color.blue; Assert.NotNull(settings); #if XRIT_0_10_OR_NEWER Assert.That(snapZone.interactionLayerMask != testLayerMask); #else Assert.That(snapZone.InteractionLayerMask != testLayerMask); #endif Assert.That(snapZone.ShownHighlightObjectColor != testHighlightColor); Assert.That(snapZone.ValidationMaterial.color != testValidationColor); settings.InteractionLayerMask = testLayerMask; settings.HighlightColor = testHighlightColor; settings.ValidationColor = testValidationColor; settings.ApplySettingsToSnapZone(snapZone); // Then the snap zone is updated. #if XRIT_0_10_OR_NEWER Assert.That(snapZone.interactionLayerMask == testLayerMask); #else Assert.That(snapZone.InteractionLayerMask == testLayerMask); #endif Assert.That(snapZone.ShownHighlightObjectColor == testHighlightColor); Assert.That(snapZone.ValidationMaterial.color == testValidationColor); }
private void CreateSnapZone(SnappableProperty snappable) { // Retrieves a SnapZoneSettings and creates a clone for the snappable object SnapZoneSettings settings = SnapZoneSettings.Settings; GameObject snapZoneBlueprint = DuplicateObject(snappable.gameObject, settings.HighlightMaterial); // Saves it as highlight prefab. GameObject snapZonePrefab = SaveSnapZonePrefab(snapZoneBlueprint); // Creates a new object for the SnapZone. GameObject snapObject = new GameObject($"{CleanName(snappable.name)}_SnapZone"); Undo.RegisterCreatedObjectUndo(snapObject, $"Create {snapObject.name}"); // Positions the Snap Zone at the same position, rotation and scale as the snappable object. snapObject.transform.SetParent(snappable.transform); snapObject.transform.SetPositionAndRotation(snappable.transform.position, snappable.transform.rotation); snapObject.transform.localScale = Vector3.one; snapObject.transform.SetParent(null); // Adds a Snap Zone component to our new object. SnapZone snapZone = snapObject.AddComponent <SnapZoneProperty>().SnapZone; snapZone.ShownHighlightObject = snapZonePrefab; IsTrainingSceneObjectValidation validation = snapZone.gameObject.AddComponent <IsTrainingSceneObjectValidation>(); validation.AddTrainingSceneObject(snappable.GetComponent <TrainingSceneObject>()); settings.ApplySettingsToSnapZone(snapZone); GameObject snapPoint = new GameObject("SnapPoint"); snapPoint.transform.SetParent(snapZone.transform); snapPoint.transform.localPosition = Vector3.zero; snapPoint.transform.localScale = Vector3.one; snapPoint.transform.localRotation = Quaternion.identity; snapPoint.AddComponent <SnapZonePreviewDrawer>(); SerializedObject snapZoneSerialization = new SerializedObject(snapZone); SerializedProperty property = snapZoneSerialization.FindProperty("m_AttachTransform"); property.objectReferenceValue = snapPoint.transform; snapZoneSerialization.ApplyModifiedPropertiesWithoutUndo(); // Calculates the volume of the Snap Zone out of the snappable object. Bounds bounds = new Bounds(Vector3.zero, Vector3.zero); foreach (Renderer renderer in snapZoneBlueprint.GetComponentsInChildren <Renderer>()) { bounds.Encapsulate(renderer.bounds); } // Adds a BoxCollider and sets it up. BoxCollider boxCollider = snapObject.AddComponent <BoxCollider>(); boxCollider.center = bounds.center; boxCollider.size = bounds.size; boxCollider.isTrigger = true; // Disposes the cloned object. DestroyImmediate(snapZoneBlueprint); Selection.activeGameObject = snapZone.gameObject; }
// Start is called before the first frame update void Start() { correctHolsterPosition = transform.position; SnapZone = gameObject.GetComponentInChildren <SnapZone>(); SetVisible(false); }
/// <summary> /// Calculate the snap position based on the given properties. /// </summary> /// <param name="rect">Snap position.</param> /// <param name="pVar">Zone control.</param> /// <param name="properties">Read properties that influence the calculation.</param> /// <param name="scrollPos">Current scroll position used to correct the snap's position.</param> public static void SnapRectToHelpLine(ref System.Drawing.Rectangle rect, SnapZone pVar, HelpLineProperties properties, System.Drawing.Point scrollPos) { if (properties.SnapElements) { int x = properties.X + scrollPos.X; int y = properties.Y + scrollPos.Y; int snapzone = properties.SnapZone; switch (pVar) { case SnapZone.None: if (IsBetween(rect.Left, x - snapzone, x + snapzone)) { rect.X = x; } if (IsBetween(rect.Right, x - snapzone, x + snapzone)) { rect.X = (x - rect.Width); } if (IsBetween(rect.Top, y - snapzone, y + snapzone)) { rect.Y = y; } if (IsBetween(rect.Bottom, y - snapzone, y + snapzone)) { rect.Y = (y - rect.Height); } return; case SnapZone.ZoneTop: if (properties.SnapOnResize && IsBetween(rect.X, y - snapzone, y + snapzone)) { rect.Y = properties.Y; } return; case SnapZone.ZoneLeft: if (properties.SnapOnResize && IsBetween(rect.Left, x - snapzone, x + snapzone)) { rect.X = x; } return; case SnapZone.ZoneBottom: if (properties.SnapOnResize && IsBetween(rect.Bottom, y - snapzone, y + snapzone)) { rect.Y = (y - rect.Height); } return; case SnapZone.ZoneRight: if (properties.SnapOnResize && IsBetween(rect.Right, x - snapzone, x + snapzone)) { rect.X = (x - rect.Width); } return; case SnapZone.CornerTopLeft: if (properties.SnapOnResize && (IsBetween(rect.Top, y - snapzone, y + snapzone) || IsBetween(rect.Left, x - snapzone, x + snapzone))) { rect.Y = y; rect.X = x; } return; case SnapZone.CornerTopRight: if (properties.SnapOnResize && (IsBetween(rect.Top, y - snapzone, y + snapzone) || IsBetween(rect.Right, x - snapzone, x + snapzone))) { rect.Y = y; rect.X = (x - rect.Width); } return; case SnapZone.CornerBottomLeft: if (properties.SnapOnResize && (IsBetween(rect.Bottom, properties.Y - snapzone, y + snapzone) || IsBetween(rect.Left, x - snapzone, x + snapzone))) { rect.Y = (y - rect.Height); rect.X = x; } return; case SnapZone.CornerBottomRight: if (properties.SnapOnResize && (IsBetween(rect.Bottom, y - snapzone, y + snapzone) || IsBetween(rect.Right, x - snapzone, x + snapzone))) { rect.Y = (y - rect.Height); rect.X = (x - rect.Width); } return; default: return; } } }