public void SetDragType(UnityEngine.UI.Dropdown dropdownMenu) { switch (dropdownMenu.options[dropdownMenu.value].text) { case "Free Drag": dragType = DragTypes.FREE; break; case "Square Drag": dragType = DragTypes.SQUARE; break; default: dragType = DragTypes.FREE; break; } }
public void DragEnd() { if (!Active) { return; } if (DragType == DragTypes.SelectionBox) { //Debug.Log("Drag End"); UpdateSelectionBox(false); AddSelectionBoxObjects(); } else if (DragType == DragTypes.MoveX || DragType == DragTypes.MoveZ || DragType == DragTypes.MoveXZ || DragType == DragTypes.RotateY) { ControlerFinish(); } else { } DragStarted = false; DragType = DragTypes.None; }
public void DragInit() { BeginMousePos = Input.mousePosition; if (Input.GetMouseButtonDown(0)) { Ray ray = CameraControler.Current.Cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000, ControlerLayers)) { CreateControlerPlane(false); Controler_StorePositions(); ControlerClickPoint = PosOnControler(ray); ControlerBegin = Controls.localPosition; ControlerBeginRot = Controls.localRotation; switch (hit.collider.gameObject.name) { case "X": DragType = DragTypes.MoveX; break; case "Z": DragType = DragTypes.MoveZ; break; case "XZ": DragType = DragTypes.MoveXZ; break; case "RY": DragType = DragTypes.RotateY; break; case "RX": DragType = DragTypes.RotateX; break; case "SX": DragType = DragTypes.ScaleX; break; case "SZ": DragType = DragTypes.ScaleZ; break; case "SXZ": DragType = DragTypes.ScaleXYZ; break; default: DragType = DragTypes.None; break; } if (DragType == DragTypes.RotateY || DragType == DragTypes.RotateX) { Controler_StoreRotations(); } else if (DragType == DragTypes.ScaleX || DragType == DragTypes.ScaleZ || DragType == DragTypes.ScaleXYZ) { Controler_StoreScales(); } } else { DragType = DragTypes.SelectionBox; } } else { DragType = DragTypes.None; } }
/// <summary> /// Initiate the message box with a param set. /// </summary> /// <param name="param">The param set used to initiate.</param> public void Initiate(MessageBoxParams param) { this.currentParam = param; currentOutAnimation = param.OutAnimation; //reset transform messageBox.anchoredPosition = Vector2.zero; messageBox.localRotation = Quaternion.identity; messageBox.localScale = Vector3.one; transform.localScale = initialScaleSelf; Background.transform.localScale = initialScaleBackground; //layout if (param.MessageLayout == MessageLayout.Horizontal) { horizontalGroup.gameObject.SetActive(true); verticalGroup.gameObject.SetActive(false); } else if (param.MessageLayout == MessageLayout.Vertical) { horizontalGroup.gameObject.SetActive(false); verticalGroup.gameObject.SetActive(true); } //background Background.color = Color.clear; lerpState = true; lerpValue = 0f; //message if (string.IsNullOrEmpty(param.Message)) { messageTextHorizontal.gameObject.SetActive(false); messageTextVertical.gameObject.SetActive(false); } else { messageTextHorizontal.gameObject.SetActive(true); messageTextVertical.gameObject.SetActive(true); messageTextHorizontal.text = param.Message; messageTextVertical.text = param.Message; } //message title if (string.IsNullOrEmpty(param.MessageTitle)) { messageTitleHorizontal.gameObject.SetActive(false); messageTitleVertical.gameObject.SetActive(false); } else { messageTitleHorizontal.gameObject.SetActive(true); messageTitleVertical.gameObject.SetActive(true); messageTitleHorizontal.text = param.MessageTitle; messageTitleVertical.text = param.MessageTitle; } //message box title if (string.IsNullOrEmpty(param.MessageBoxTitle)) { titleBar.gameObject.SetActive(false); } else { titleBar.gameObject.SetActive(true); messageBoxTitle.text = param.MessageBoxTitle; } //title bar close button titleBarCloseButton.gameObject.SetActive(param.ShowTitleBarCloseButton); if (param.ShowTitleBarCloseButton) { titleBarCloseButton.onClick.RemoveAllListeners(); titleBarCloseButton.onClick.AddListener(OnTitleBarCloseButtonClicked); } //message icon if (param.MessageIcon == null) { messageIconHorizontal.transform.parent.gameObject.SetActive(false); messageIconVertical.transform.parent.gameObject.SetActive(false); } else { messageIconHorizontal.transform.parent.gameObject.SetActive(true); messageIconVertical.transform.parent.gameObject.SetActive(true); messageIconHorizontal.sprite = param.MessageIcon; messageIconVertical.sprite = param.MessageIcon; } //button 1 if (string.IsNullOrEmpty(param.Button1Text) && param.Button1Icon == null) { button1.gameObject.SetActive(false); } else { button1.gameObject.SetActive(true); button1.onClick.RemoveAllListeners(); if (param.Button1Action != null) { button1.onClick.AddListener(param.Button1Action); } button1.onClick.AddListener(Close); if (string.IsNullOrEmpty(param.Button1Text)) { button1Text.gameObject.SetActive(false); } else { button1Text.gameObject.SetActive(true); button1Text.text = param.Button1Text; } if (param.Button1Icon == null) { button1Image.gameObject.SetActive(false); } else { button1Image.gameObject.SetActive(true); button1Image.sprite = param.Button1Icon; } if (param.InputFieldActionsFireOnButton == Buttons.Button1 || param.InputFieldActionsFireOnButton == Buttons.All) { button1.onClick.AddListener(FireInputFieldActions); } } //button 2 if (string.IsNullOrEmpty(param.Button2Text) && param.Button2Icon == null) { button2.gameObject.SetActive(false); } else { button2.gameObject.SetActive(true); button2.onClick.RemoveAllListeners(); if (param.Button2Action != null) { button2.onClick.AddListener(param.Button2Action); } button2.onClick.AddListener(Close); if (string.IsNullOrEmpty(param.Button2Text)) { button2Text.gameObject.SetActive(false); } else { button2Text.gameObject.SetActive(true); button2Text.text = param.Button2Text; } if (param.Button2Icon == null) { button2Image.gameObject.SetActive(false); } else { button2Image.gameObject.SetActive(true); button2Image.sprite = param.Button2Icon; } if (param.InputFieldActionsFireOnButton == Buttons.Button2 || param.InputFieldActionsFireOnButton == Buttons.All) { button2.onClick.AddListener(FireInputFieldActions); } } //button 3 if (string.IsNullOrEmpty(param.Button3Text) && param.Button3Icon == null) { button3.gameObject.SetActive(false); } else { button3.gameObject.SetActive(true); button3.onClick.RemoveAllListeners(); if (param.Button3Action != null) { button3.onClick.AddListener(param.Button3Action); } button3.onClick.AddListener(Close); if (string.IsNullOrEmpty(param.Button3Text)) { button3Text.gameObject.SetActive(false); } else { button3Text.gameObject.SetActive(true); button3Text.text = param.Button3Text; } if (param.Button3Icon == null) { button3Image.gameObject.SetActive(false); } else { button3Image.gameObject.SetActive(true); button3Image.sprite = param.Button3Icon; } if (param.InputFieldActionsFireOnButton == Buttons.Button3 || param.InputFieldActionsFireOnButton == Buttons.All) { button3.onClick.AddListener(FireInputFieldActions); } } //toggle bool toggleEnabled = !string.IsNullOrEmpty(param.ToggleText); toggle.transform.parent.gameObject.SetActive(toggleEnabled); if (toggleEnabled) { toggleText.text = param.ToggleText; toggle.onValueChanged.RemoveAllListeners(); toggle.isOn = param.DefaultToggleState; if (param.ToggleValueChangedAction != null) { toggle.onValueChanged.AddListener(param.ToggleValueChangedAction); } } //Input fields if (InputField1 != null) { if (!string.IsNullOrEmpty(param.InputField1Label)) { InputField1.text = string.IsNullOrEmpty(param.InputField1Text) ? "" : param.InputField1Text; InputField1.transform.parent.gameObject.SetActive(true); inputField1Label.text = param.InputField1Label; } else { InputField1.transform.parent.gameObject.SetActive(false); } } if (InputField2 != null) { if (!string.IsNullOrEmpty(param.InputField2Label)) { InputField2.text = string.IsNullOrEmpty(param.InputField2Text) ? "" : param.InputField2Text; InputField2.transform.parent.gameObject.SetActive(true); inputField2Label.text = param.InputField2Label; } else { InputField2.transform.parent.gameObject.SetActive(false); } } //animations switch (param.InAnimation) { case InAnimationTypes.None: animator.SetBool("In_None", true); animator.SetBool("In_Popup", false); animator.SetBool("In_Fade", false); animator.SetBool("In_Stamp", false); animator.SetBool("In_Spin", false); animator.SetBool("In_HorizontalExpand", false); animator.SetBool("In_VerticalExpand", false); animator.SetBool("Out_None", false); animator.SetBool("Out_Fade", false); animator.SetBool("Out_Shrink", false); animator.SetBool("Out_Spin", false); break; case InAnimationTypes.Popup: animator.SetBool("In_None", false); animator.SetBool("In_Popup", true); animator.SetBool("In_Fade", false); animator.SetBool("In_Stamp", false); animator.SetBool("In_Spin", false); animator.SetBool("In_HorizontalExpand", false); animator.SetBool("In_VerticalExpand", false); animator.SetBool("Out_None", false); animator.SetBool("Out_Fade", false); animator.SetBool("Out_Shrink", false); animator.SetBool("Out_Spin", false); break; case InAnimationTypes.Stamp: animator.SetBool("In_None", false); animator.SetBool("In_Popup", false); animator.SetBool("In_Fade", false); animator.SetBool("In_Stamp", true); animator.SetBool("In_Spin", false); animator.SetBool("In_HorizontalExpand", false); animator.SetBool("In_VerticalExpand", false); animator.SetBool("Out_None", false); animator.SetBool("Out_Fade", false); animator.SetBool("Out_Shrink", false); animator.SetBool("Out_Spin", false); break; case InAnimationTypes.Spin: animator.SetBool("In_None", false); animator.SetBool("In_Popup", false); animator.SetBool("In_Fade", false); animator.SetBool("In_Stamp", false); animator.SetBool("In_Spin", true); animator.SetBool("In_HorizontalExpand", false); animator.SetBool("In_VerticalExpand", false); animator.SetBool("Out_None", false); animator.SetBool("Out_Fade", false); animator.SetBool("Out_Shrink", false); animator.SetBool("Out_Spin", false); break; case InAnimationTypes.HorizontalExpand: animator.SetBool("In_None", false); animator.SetBool("In_Popup", false); animator.SetBool("In_Fade", false); animator.SetBool("In_Stamp", false); animator.SetBool("In_Spin", false); animator.SetBool("In_HorizontalExpand", true); animator.SetBool("In_VerticalExpand", false); animator.SetBool("Out_None", false); animator.SetBool("Out_Fade", false); animator.SetBool("Out_Shrink", false); animator.SetBool("Out_Spin", false); break; case InAnimationTypes.VerticalExpand: animator.SetBool("In_None", false); animator.SetBool("In_Popup", false); animator.SetBool("In_Fade", false); animator.SetBool("In_Stamp", false); animator.SetBool("In_Spin", false); animator.SetBool("In_HorizontalExpand", false); animator.SetBool("In_VerticalExpand", true); animator.SetBool("Out_None", false); animator.SetBool("Out_Fade", false); animator.SetBool("Out_Shrink", false); animator.SetBool("Out_Spin", false); break; default: animator.SetBool("In_None", true); animator.SetBool("In_Popup", false); animator.SetBool("In_Fade", false); animator.SetBool("In_Stamp", false); animator.SetBool("In_Spin", false); animator.SetBool("In_HorizontalExpand", false); animator.SetBool("In_VerticalExpand", false); animator.SetBool("Out_None", false); animator.SetBool("Out_Fade", false); animator.SetBool("Out_Shrink", false); animator.SetBool("Out_Spin", false); break; } //drag CurrentDragType = param.DragType; //sound effects if (!disableSoundEffects) { if (param.InAnimationStartSound != null) { aSource.PlayOneShot(param.InAnimationStartSound); } else if (defaultSound_InAnimationStart != null) { aSource.PlayOneShot(defaultSound_InAnimationStart); } } //close flag closeInvokedFlag = false; }
/// <summary> /// Show the message box. The appearance and behaviour of the message box is defined by setting /// a series of parameters. All parameters are optional except the 'message' string. The optional parameters /// can also be set in any order using named arguments. For example: EasyMessageBox.Show("Level complete!", layout: ContentLayouts.Vertical, messageBoxTitle:"Congratulations!"); /// </summary> /// <param name="message">The message text to show in the message box. The UI element itself will hide if set to null or an empty string.</param> /// <param name="messageIcon">The icon for the message. The UI element itself will hide if set to null. It will be to the left of the message in horizontal layout and above the message in vertical layout.</param> /// <param name="messageTitle">An additiontial title for the main message itself (not the title of the message box). It will be above the message text in horizontal layout and above the message icon in vertical layout. The UI element itself will hide if set to null or an empty string.</param> /// <param name="messageBoxTitle">The title for the message box. The title bar will hide if set to null or an empty string.</param> /// <param name="showCloseButtonInTitleBar">Indicates whether the title bar will show a close button if the title bar is displayed.</param> /// <param name="button1Icon">The icon for button 1. To hide this button, set both its icon and text to null(or an empty string).</param> /// <param name="button1Text">The text for button 1. To hide this button, set both its icon and text to null(or an empty string).</param> /// <param name="button1Action">The action to take when button 1 is pressed.</param> /// <param name="button2Icon">The icon for button 2. To hide this button, set both its icon and text to null(or an empty string).</param> /// <param name="button2Text">The text for button 2. To hide this button, set both its icon and text to null(or an empty string).</param> /// <param name="button2Action">The action to take when button 2 is pressed.</param> /// <param name="button3Icon">The icon for button 3. To hide this button, set both its icon and text to null(or an empty string).</param> /// <param name="button3Text">The text for button 3. To hide this button, set both its icon and text to null(or an empty string).</param> /// <param name="button3Action">The action to take when button 3 is pressed.</param> /// <param name="toggleText">The text for the toggle. Will hide the toggle if set to null or an empty string.</param> /// <param name="toggleAction">The action to take when the toggle's state is changed. Setting this to null will hide the toggle.</param> /// <param name="defaultToggleState">Decides whether the toggle is on when first displayed.</param> /// <param name="inputField1Label">The label text for the optional input field 1. Will hide the input field if set to null or an empty string.</param> /// <param name="inputField1Text">Optional text to show in input field 1 when it's first displayed</param> /// <param name="inputField2Label">The label text for the optional input field 2. Will hide the input field if set to null or an empty string.</param> /// <param name="inputField2Text">Optional text to show in input field 2 when it's first displayed</param> /// <param name="inputFieldAction">The action to take if any of the input field is displayed. The action requires two strings for each input field.</param> /// <param name="inputFieldActionsFireOnButton">Controls which button will fire the input field action. The default is button 1.</param> /// <param name="inAnimation">The animation type to use for animating in.</param> /// <param name="inAnimationStartSound">The audio clip to play when the message box begins to animate in.</param> /// <param name="inAnimationEndSound">The audio clip to play when the message box finishes its in-animation. This is useful when you want to emphasize when the message box is fully present, e.g. when telling the player that an achievement has be achieved.</param> /// <param name="outAnimation">The animation type to use for animating out.</param> /// <param name="outAnimationStartSound">The audio clip to play when the message box begins to animate out.</param> /// <param name="layout">Controls which layout to use for the message box.</param> /// <param name="multipleCallBehaviour">Controls the behaviour when a new call is made to show a message box while there is already a message box displaying on the screen. When set to Queue, the new calls is automatically queued and will show based on a first-in, first-out rule when an existing message box is closed. When set to ShowNewInstance, a new message box instance will show immediately.</param> /// <param name="dragType">Controls how the message box can be dragged.</param> /// <param name="templateId">Controls which template to use when displaying a message box. This is the index of the Templates list and can be found in the inspector of EasyMessageBox component.</param> public static void Show(string message, Sprite messageIcon = null, string messageTitle = null, string messageBoxTitle = null, bool showCloseButtonInTitleBar = false, Sprite button1Icon = null, string button1Text = "OK", UnityAction button1Action = null, Sprite button2Icon = null, string button2Text = null, UnityAction button2Action = null, Sprite button3Icon = null, string button3Text = null, string toggleText = null, UnityAction button3Action = null, UnityAction <bool> toggleAction = null, bool defaultToggleState = false, string inputField1Label = null, string inputField1Text = null, string inputField2Label = null, string inputField2Text = null, UnityAction <string, string> inputFieldAction = null, Buttons inputFieldActionsFireOnButton = Buttons.Button1, InAnimationTypes inAnimation = InAnimationTypes.Popup, AudioClip inAnimationStartSound = null, AudioClip inAnimationEndSound = null, OutAnimationTypes outAnimation = OutAnimationTypes.None, AudioClip outAnimationStartSound = null, MessageLayout layout = MessageLayout.Horizontal, MultipleCallBehaviours multipleCallBehaviour = MultipleCallBehaviours.ShowNewInstance, DragTypes dragType = DragTypes.TitleOnly, int templateId = 0 ) { var param = new MessageBoxParams() { Message = message, MessageIcon = messageIcon, MessageTitle = messageTitle, MessageBoxTitle = messageBoxTitle, ShowTitleBarCloseButton = showCloseButtonInTitleBar, Button1Icon = button1Icon, Button1Text = button1Text, Button1Action = button1Action, Button2Icon = button2Icon, Button2Text = button2Text, Button2Action = button2Action, Button3Icon = button3Icon, Button3Text = button3Text, Button3Action = button3Action, ToggleText = toggleText, ToggleValueChangedAction = toggleAction, InputField1Label = inputField1Label, InputField1Text = inputField1Text, InputField2Label = inputField2Label, InputField2Text = inputField2Text, InputFieldAction = inputFieldAction, InputFieldActionsFireOnButton = inputFieldActionsFireOnButton, DefaultToggleState = defaultToggleState, InAnimation = inAnimation, InAnimationStartSound = inAnimationStartSound, InAnimationEndSound = inAnimationEndSound, OutAnimation = outAnimation, OutAnimationStartSound = outAnimationStartSound, MessageLayout = layout, MultipleCallBehaviour = multipleCallBehaviour, DragType = dragType, TemplateId = templateId, }; Show(param); }