活动介绍

```csharp using UnityEngine; using TMPro; using UnityEngine.UI; public class ButtonClick : MonoBehaviour { public GameObject prefab; public TMP_Text prefabText; public InputField inputField; public GameObject parentObject; public GameObject[] prefabObject; public void GeneratePrefab() { GameObject newPrefab = Instantiate(prefab); newPrefab.transform.parent = parentObject.transform; TMP_Text newPrefabText = newPrefab.GetComponentInChildren<TMP_Text>(); newPrefabText.text = inputField.text; inputField.onValueChanged.AddListener(delegate { UpdatePrefabText(newPrefabText); }); } public void UpdatePrefabText(TMP_Text newPrefabText) { newPrefabText.text = inputField.text; } }修改这段代码,使得可以追踪到物体不同名字后分别进行生成不同预制体,其他功能不改变。

时间: 2024-03-16 17:45:50 浏览: 169
可以通过修改 GeneratePrefab() 方法来实现追踪不同名字生成不同预制体的功能。可以将输入框中的文本作为预制体的名称,然后在生成预制体时根据名称来选择对应的预制体。 下面是修改后的代码: ```csharp using UnityEngine; using TMPro; using UnityEngine.UI; public class ButtonClick : MonoBehaviour { public TMP_Text prefabText; public InputField inputField; public GameObject parentObject; // 添加一个预制体数组,用于存储不同预制体 public GameObject[] prefabs; public void GeneratePrefab() { string prefabName = inputField.text; // 根据名称查找对应的预制体 GameObject prefabToGenerate = null; foreach (GameObject prefab in prefabs) { if (prefab.name == prefabName) { prefabToGenerate = prefab; break; } } if (prefabToGenerate != null) { GameObject newPrefab = Instantiate(prefabToGenerate); newPrefab.transform.parent = parentObject.transform; TMP_Text newPrefabText = newPrefab.GetComponentInChildren<TMP_Text>(); newPrefabText.text = prefabName; inputField.onValueChanged.AddListener(delegate { UpdatePrefabText(newPrefabText); }); } else { Debug.LogError("Prefab not found with name: " + prefabName); } } public void UpdatePrefabText(TMP_Text newPrefabText) { newPrefabText.text = inputField.text; } } ``` 这里的 prefabs 数组是在 Inspector 窗口中手动指定的,需要将不同预制体拖拽到数组中。在 GeneratePrefab() 方法中,先获取输入框中的文本作为预制体的名称,然后遍历数组查找对应的预制体,最后生成该预制体。如果没有找到对应的预制体,会输出错误信息。
阅读全文

相关推荐

using UnityEngine; using UnityEngine.UI; using System.Collections; using System.Collections.Generic; public class DialogueManager : MonoBehaviour { public Image backgroundPanel; public Image avatarImage; public Text nameText; public Text messageText; public Transform optionsPanel; public Button continueButton; public GameObject optionButtonPrefab; private Dictionary<int, DialogueNode> nodeDict = new Dictionary<int, DialogueNode>(); private DialogueNode currentNode; private bool isTyping = false; private string fullMessage; private string currentDialoguePath; public delegate void DialogueEvent(int nodeId); public event DialogueEvent OnNodeStart; public event DialogueEvent OnDialogueEnd; void Start() { continueButton.onClick.RemoveAllListeners(); continueButton.onClick.AddListener(OnContinueClicked); if (continueButton == null) { Debug.LogError("继续按钮未绑定!"); } } public void OpenDialogue(string dialoguePath, int startId = 1) { currentDialoguePath = dialoguePath; LoadDialogue(dialoguePath); gameObject.SetActive(true); StartCoroutine(StartDialogueRoutine(startId)); } IEnumerator StartDialogueRoutine(int startId) { yield return new WaitForEndOfFrame(); // 确保UI已激活 StartDialogueNode(startId); } void LoadDialogue(string path) { nodeDict.Clear(); TextAsset jsonFile = Resources.Load<TextAsset>(path); if (jsonFile == null) { Debug.LogError("对话文件未找到: " + path); return; } DialogueTree tree = JsonUtility.FromJson<DialogueTree>( "{ \"nodes\": " + jsonFile.text + "}" ); foreach (var node in tree.nodes) { nodeDict.Add(node.id, node); } } void StartDialogueNode(int nodeId) { if (!nodeDict.ContainsKey(nodeId)) { EndDialogue(); return; } currentNode = nodeDict[nodeId]; OnNodeStart?.Invoke(nodeId); UpdateUI(); } void UpdateUI() { // 清空选项区域 if (optionsPanel != null) { for (int i = optionsPanel.childCount - 1; i >= 0; i--) { Destroy(optionsPanel.GetChild(i).gameObject); } } foreach (Transform child in optionsPanel) { Destroy(child.gameObject); } nameText.text = string.IsNullOrEmpty(currentNode.name) ? "" : currentNode.name; fullMessage = currentNode.msg; if (!string.IsNullOrEmpty(currentNode.avatar)) { Sprite avatarSprite = Resources.Load<Sprite>(currentNode.avatar); if (avatarSprite != null) { avatarImage.sprite = avatarSprite; avatarImage.gameObject.SetActive(true); } else { Debug.LogWarning("头像未找到: " + currentNode.avatar); avatarImage.gameObject.SetActive(false); } } else { avatarImage.gameObject.SetActive(false); } StartCoroutine(TypewriterEffect()); if (currentNode.opts != null && currentNode.opts.Length > 0) { continueButton.gameObject.SetActive(false); for (int i = 0; i < currentNode.opts.Length; i++) { if (currentNode.opts[i] != null) // 空检查 { CreateOptionButton(currentNode.opts[i]); } } } else if (currentNode.nextid > 0) { continueButton.gameObject.SetActive(true); continueButton.GetComponentInChildren<Text>().text = "继续"; } else { continueButton.gameObject.SetActive(true); continueButton.GetComponentInChildren<Text>().text = "结束"; } } IEnumerator TypewriterEffect() { isTyping = true; messageText.text = ""; foreach (char c in fullMessage.ToCharArray()) { messageText.text += c; yield return new WaitForSeconds(0.03f); // 调整显示速度 } isTyping = false; } void CreateOptionButton(DialogueOption option) { if (optionButtonPrefab == null) { Debug.LogError("选项按钮预制体未分配!"); return; } GameObject buttonObj = Instantiate(optionButtonPrefab, optionsPanel); buttonObj.SetActive(true); Button primaryButton = buttonObj.GetComponentInChildren<Button>(true); Text primaryText = buttonObj.GetComponentInChildren<Text>(true); primaryText.text = option.msg; primaryButton.onClick.RemoveAllListeners(); primaryButton.onClick.AddListener(() => HandleOptionSelection(option)); } void HandleOptionSelection(DialogueOption option) { int targetId = option.toId != 0 ? option.toId : option.nextid; if (nodeDict.ContainsKey(targetId)) { StartDialogueNode(targetId); } else if (targetId > 0) { Debug.LogWarning($"目标节点不存在: {targetId}"); EndDialogue(); } else { EndDialogue(); // 结束对话 } } void OnContinueClicked() { if (currentNode == null) // 添加空值检查 { CloseDialogue(); return; } if (isTyping) { messageText.text = fullMessage; isTyping = false; return; } if (currentNode.nextid > 0 && nodeDict.ContainsKey(currentNode.nextid)) { StartDialogueNode(currentNode.nextid); } else { EndDialogue(); } } public void CloseDialogue() { continueButton.onClick.RemoveAllListeners(); foreach (Transform child in optionsPanel) { Button btn = child.GetComponent<Button>(); if (btn != null) btn.onClick.RemoveAllListeners(); } gameObject.SetActive(false); OnDialogueEnd?.Invoke(currentNode != null ? currentNode.id : -1); } void EndDialogue() { CloseDialogue(); OnDialogueEnd?.Invoke(currentNode.id); Debug.Log("对话结束"); } public void ChangeBackground(string bgPath) { Sprite bgSprite = Resources.Load<Sprite>(bgPath); if (bgSprite != null) { backgroundPanel.sprite = bgSprite; } else { Debug.LogWarning("背景未找到: " + bgPath); } } public void ChangeAvatar(string avatarPath) { Sprite avatarSprite = Resources.Load<Sprite>(avatarPath); if (avatarSprite != null) { avatarImage.sprite = avatarSprite; } else { Debug.LogWarning("立绘未找到: " + avatarPath); } } } using System; using UnityEngine; using UnityEngine.Serialization; namespace UnityEngine.EventSystems { [AddComponentMenu("Event/Standalone Input Module")] /// /// A BaseInputModule designed for mouse / keyboard / controller input. /// /// <remarks> /// Input module for working with, mouse, keyboard, or controller. /// </remarks> public class StandaloneInputModule : PointerInputModule { private float m_PrevActionTime; private Vector2 m_LastMoveVector; private int m_ConsecutiveMoveCount = 0; private Vector2 m_LastMousePosition; private Vector2 m_MousePosition; private GameObject m_CurrentFocusedGameObject; private PointerEventData m_InputPointerEvent; private const float doubleClickTime = 0.3f; protected StandaloneInputModule() { } [Obsolete("Mode is no longer needed on input module as it handles both mouse and keyboard simultaneously.", false)] public enum InputMode { Mouse, Buttons } [Obsolete("Mode is no longer needed on input module as it handles both mouse and keyboard simultaneously.", false)] public InputMode inputMode { get { return InputMode.Mouse; } } [SerializeField] private string m_HorizontalAxis = "Horizontal"; /// /// Name of the vertical axis for movement (if axis events are used). /// [SerializeField] private string m_VerticalAxis = "Vertical"; /// /// Name of the submit button. /// [SerializeField] private string m_SubmitButton = "Submit"; /// /// Name of the submit button. /// [SerializeField] private string m_CancelButton = "Cancel"; [SerializeField] private float m_InputActionsPerSecond = 10; [SerializeField] private float m_RepeatDelay = 0.5f; [SerializeField] [FormerlySerializedAs("m_AllowActivationOnMobileDevice")] [HideInInspector] private bool m_ForceModuleActive; [Obsolete("allowActivationOnMobileDevice has been deprecated. Use forceModuleActive instead (UnityUpgradable) -> forceModuleActive")] public bool allowActivationOnMobileDevice { get { return m_ForceModuleActive; } set { m_ForceModuleActive = value; } } /// /// Force this module to be active. /// /// <remarks> /// If there is no module active with higher priority (ordered in the inspector) this module will be forced active even if valid enabling conditions are not met. /// </remarks> [Obsolete("forceModuleActive has been deprecated. There is no need to force the module awake as StandaloneInputModule works for all platforms")] public bool forceModuleActive { get { return m_ForceModuleActive; } set { m_ForceModuleActive = value; } } /// /// Number of keyboard / controller inputs allowed per second. /// public float inputActionsPerSecond { get { return m_InputActionsPerSecond; } set { m_InputActionsPerSecond = value; } } /// /// Delay in seconds before the input actions per second repeat rate takes effect. /// /// <remarks> /// If the same direction is sustained, the inputActionsPerSecond property can be used to control the rate at which events are fired. However, it can be desirable that the first repetition is delayed, so the user doesn't get repeated actions by accident. /// </remarks> public float repeatDelay { get { return m_RepeatDelay; } set { m_RepeatDelay = value; } } /// /// Name of the horizontal axis for movement (if axis events are used). /// public string horizontalAxis { get { return m_HorizontalAxis; } set { m_HorizontalAxis = value; } } /// /// Name of the vertical axis for movement (if axis events are used). /// public string verticalAxis { get { return m_VerticalAxis; } set { m_VerticalAxis = value; } } /// /// Maximum number of input events handled per second. /// public string submitButton { get { return m_SubmitButton; } set { m_SubmitButton = value; } } /// /// Input manager name for the 'cancel' button. /// public string cancelButton { get { return m_CancelButton; } set { m_CancelButton = value; } } private bool ShouldIgnoreEventsOnNoFocus() { #if UNITY_EDITOR return !UnityEditor.EditorApplication.isRemoteConnected; #else return true; #endif } public override void UpdateModule() { if (!eventSystem.isFocused && ShouldIgnoreEventsOnNoFocus()) { if (m_InputPointerEvent != null && m_InputPointerEvent.pointerDrag != null && m_InputPointerEvent.dragging) { ReleaseMouse(m_InputPointerEvent, m_InputPointerEvent.pointerCurrentRaycast.gameObject); } m_InputPointerEvent = null; return; } m_LastMousePosition = m_MousePosition; m_MousePosition = input.mousePosition; } private void ReleaseMouse(PointerEventData pointerEvent, GameObject currentOverGo) { ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); var pointerClickHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(currentOverGo); // PointerClick and Drop events if (pointerEvent.pointerClick == pointerClickHandler && pointerEvent.eligibleForClick) { ExecuteEvents.Execute(pointerEvent.pointerClick, pointerEvent, ExecuteEvents.pointerClickHandler); } if (pointerEvent.pointerDrag != null && pointerEvent.dragging) { ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler); } pointerEvent.eligibleForClick = false; pointerEvent.pointerPress = null; pointerEvent.rawPointerPress = null; pointerEvent.pointerClick = null; if (pointerEvent.pointerDrag != null && pointerEvent.dragging) ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler); pointerEvent.dragging = false; pointerEvent.pointerDrag = null; // redo pointer enter / exit to refresh state // so that if we moused over something that ignored it before // due to having pressed on something else // it now gets it. if (currentOverGo != pointerEvent.pointerEnter) { HandlePointerExitAndEnter(pointerEvent, null); HandlePointerExitAndEnter(pointerEvent, currentOverGo); } m_InputPointerEvent = pointerEvent; } public override bool ShouldActivateModule() { if (!base.ShouldActivateModule()) return false; var shouldActivate = m_ForceModuleActive; shouldActivate |= input.GetButtonDown(m_SubmitButton); shouldActivate |= input.GetButtonDown(m_CancelButton); shouldActivate |= !Mathf.Approximately(input.GetAxisRaw(m_HorizontalAxis), 0.0f); shouldActivate |= !Mathf.Approximately(input.GetAxisRaw(m_VerticalAxis), 0.0f); shouldActivate |= (m_MousePosition - m_LastMousePosition).sqrMagnitude > 0.0f; shouldActivate |= input.GetMouseButtonDown(0); if (input.touchCount > 0) shouldActivate = true; return shouldActivate; } /// /// See BaseInputModule. /// public override void ActivateModule() { if (!eventSystem.isFocused && ShouldIgnoreEventsOnNoFocus()) return; base.ActivateModule(); m_MousePosition = input.mousePosition; m_LastMousePosition = input.mousePosition; var toSelect = eventSystem.currentSelectedGameObject; if (toSelect == null) toSelect = eventSystem.firstSelectedGameObject; eventSystem.SetSelectedGameObject(toSelect, GetBaseEventData()); } /// /// See BaseInputModule. /// public override void DeactivateModule() { base.DeactivateModule(); ClearSelection(); } public override void Process() { if (!eventSystem.isFocused && ShouldIgnoreEventsOnNoFocus()) return; bool usedEvent = SendUpdateEventToSelectedObject(); // case 1004066 - touch / mouse events should be processed before navigation events in case // they change the current selected gameobject and the submit button is a touch / mouse button. // touch needs to take precedence because of the mouse emulation layer if (!ProcessTouchEvents() && input.mousePresent) ProcessMouseEvent(); if (eventSystem.sendNavigationEvents) { if (!usedEvent) usedEvent |= SendMoveEventToSelectedObject(); if (!usedEvent) SendSubmitEventToSelectedObject(); } } private bool ProcessTouchEvents() { for (int i = 0; i < input.touchCount; ++i) { Touch touch = input.GetTouch(i); if (touch.type == TouchType.Indirect) continue; bool released; bool pressed; var pointer = GetTouchPointerEventData(touch, out pressed, out released); ProcessTouchPress(pointer, pressed, released); if (!released) { ProcessMove(pointer); ProcessDrag(pointer); } else RemovePointerData(pointer); } return input.touchCount > 0; } /// /// This method is called by Unity whenever a touch event is processed. Override this method with a custom implementation to process touch events yourself. /// /// Event data relating to the touch event, such as position and ID to be passed to the touch event destination object. /// This is true for the first frame of a touch event, and false thereafter. This can therefore be used to determine the instant a touch event occurred. /// This is true only for the last frame of a touch event. /// <remarks> /// This method can be overridden in derived classes to change how touch press events are handled. /// </remarks> protected void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released) { var currentOverGo = pointerEvent.pointerCurrentRaycast.gameObject; // PointerDown notification if (pressed) { pointerEvent.eligibleForClick = true; pointerEvent.delta = Vector2.zero; pointerEvent.dragging = false; pointerEvent.useDragThreshold = true; pointerEvent.pressPosition = pointerEvent.position; pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast; DeselectIfSelectionChanged(currentOverGo, pointerEvent); if (pointerEvent.pointerEnter != currentOverGo) { // send a pointer enter to the touched element if it isn't the one to select... HandlePointerExitAndEnter(pointerEvent, currentOverGo); pointerEvent.pointerEnter = currentOverGo; } var resetDiffTime = Time.unscaledTime - pointerEvent.clickTime; if (resetDiffTime >= doubleClickTime) { pointerEvent.clickCount = 0; } // search for the control that will receive the press // if we can't find a press handler set the press // handler to be what would receive a click. var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler); var newClick = ExecuteEvents.GetEventHandler<IPointerClickHandler>(currentOverGo); // didnt find a press handler... search for a click handler if (newPressed == null) newPressed = newClick; // Debug.Log("Pressed: " + newPressed); float time = Time.unscaledTime; if (newPressed == pointerEvent.lastPress) { var diffTime = time - pointerEvent.clickTime; if (diffTime < doubleClickTime) ++pointerEvent.clickCount; else pointerEvent.clickCount = 1; pointerEvent.clickTime = time; } else { pointerEvent.clickCount = 1; } pointerEvent.pointerPress = newPressed; pointerEvent.rawPointerPress = currentOverGo; pointerEvent.pointerClick = newClick; pointerEvent.clickTime = time; // Save the drag handler as well pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler<IDragHandler>(currentOverGo); if (pointerEvent.pointerDrag != null) ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag); } // PointerUp notification if (released) { // Debug.Log("Executing pressup on: " + pointer.pointerPress); ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); // Debug.Log("KeyCode: " + pointer.eventData.keyCode); // see if we mouse up on the same element that we clicked on... var pointerClickHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(currentOverGo); // PointerClick and Drop events if (pointerEvent.pointerClick == pointerClickHandler && pointerEvent.eligibleForClick) { ExecuteEvents.Execute(pointerEvent.pointerClick, pointerEvent, ExecuteEvents.pointerClickHandler); } if (pointerEvent.pointerDrag != null && pointerEvent.dragging) { ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler); } pointerEvent.eligibleForClick = false; pointerEvent.pointerPress = null; pointerEvent.rawPointerPress = null; pointerEvent.pointerClick = null; if (pointerEvent.pointerDrag != null && pointerEvent.dragging) ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler); pointerEvent.dragging = false; pointerEvent.pointerDrag = null; // send exit events as we need to simulate this on touch up on touch device ExecuteEvents.ExecuteHierarchy(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler); pointerEvent.pointerEnter = null; } m_InputPointerEvent = pointerEvent; } /// /// Calculate and send a submit event to the current selected object. /// /// <returns>If the submit event was used by the selected object.</returns> protected bool SendSubmitEventToSelectedObject() { if (eventSystem.currentSelectedGameObject == null) return false; var data = GetBaseEventData(); if (input.GetButtonDown(m_SubmitButton)) ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.submitHandler); if (input.GetButtonDown(m_CancelButton)) ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.cancelHandler); return data.used; } private Vector2 GetRawMoveVector() { Vector2 move = Vector2.zero; move.x = input.GetAxisRaw(m_HorizontalAxis); move.y = input.GetAxisRaw(m_VerticalAxis); if (input.GetButtonDown(m_HorizontalAxis)) { if (move.x < 0) move.x = -1f; if (move.x > 0) move.x = 1f; } if (input.GetButtonDown(m_VerticalAxis)) { if (move.y < 0) move.y = -1f; if (move.y > 0) move.y = 1f; } return move; } /// /// Calculate and send a move event to the current selected object. /// /// <returns>If the move event was used by the selected object.</returns> protected bool SendMoveEventToSelectedObject() { float time = Time.unscaledTime; Vector2 movement = GetRawMoveVector(); if (Mathf.Approximately(movement.x, 0f) && Mathf.Approximately(movement.y, 0f)) { m_ConsecutiveMoveCount = 0; return false; } bool similarDir = (Vector2.Dot(movement, m_LastMoveVector) > 0); // If direction didn't change at least 90 degrees, wait for delay before allowing consequtive event. if (similarDir && m_ConsecutiveMoveCount == 1) { if (time <= m_PrevActionTime + m_RepeatDelay) return false; } // If direction changed at least 90 degree, or we already had the delay, repeat at repeat rate. else { if (time <= m_PrevActionTime + 1f / m_InputActionsPerSecond) return false; } var axisEventData = GetAxisEventData(movement.x, movement.y, 0.6f); if (axisEventData.moveDir != MoveDirection.None) { ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisEventData, ExecuteEvents.moveHandler); if (!similarDir) m_ConsecutiveMoveCount = 0; m_ConsecutiveMoveCount++; m_PrevActionTime = time; m_LastMoveVector = movement; } else { m_ConsecutiveMoveCount = 0; } return axisEventData.used; } protected void ProcessMouseEvent() { ProcessMouseEvent(0); } [Obsolete("This method is no longer checked, overriding it with return true does nothing!")] protected virtual bool ForceAutoSelect() { return false; } /// /// Process all mouse events. /// protected void ProcessMouseEvent(int id) { var mouseData = GetMousePointerEventData(id); var leftButtonData = mouseData.GetButtonState(PointerEventData.InputButton.Left).eventData; m_CurrentFocusedGameObject = leftButtonData.buttonData.pointerCurrentRaycast.gameObject; // Process the first mouse button fully ProcessMousePress(leftButtonData); ProcessMove(leftButtonData.buttonData); ProcessDrag(leftButtonData.buttonData); // Now process right / middle clicks ProcessMousePress(mouseData.GetButtonState(PointerEventData.InputButton.Right).eventData); ProcessDrag(mouseData.GetButtonState(PointerEventData.InputButton.Right).eventData.buttonData); ProcessMousePress(mouseData.GetButtonState(PointerEventData.InputButton.Middle).eventData); ProcessDrag(mouseData.GetButtonState(PointerEventData.InputButton.Middle).eventData.buttonData); if (!Mathf.Approximately(leftButtonData.buttonData.scrollDelta.sqrMagnitude, 0.0f)) { var scrollHandler = ExecuteEvents.GetEventHandler<IScrollHandler>(leftButtonData.buttonData.pointerCurrentRaycast.gameObject); ExecuteEvents.ExecuteHierarchy(scrollHandler, leftButtonData.buttonData, ExecuteEvents.scrollHandler); } } protected bool SendUpdateEventToSelectedObject() { if (eventSystem.currentSelectedGameObject == null) return false; var data = GetBaseEventData(); ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.updateSelectedHandler); return data.used; } /// /// Calculate and process any mouse button state changes. /// protected void ProcessMousePress(MouseButtonEventData data) { var pointerEvent = data.buttonData; var currentOverGo = pointerEvent.pointerCurrentRaycast.gameObject; // PointerDown notification if (data.PressedThisFrame()) { pointerEvent.eligibleForClick = true; pointerEvent.delta = Vector2.zero; pointerEvent.dragging = false; pointerEvent.useDragThreshold = true; pointerEvent.pressPosition = pointerEvent.position; pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast; DeselectIfSelectionChanged(currentOverGo, pointerEvent); var resetDiffTime = Time.unscaledTime - pointerEvent.clickTime; if (resetDiffTime >= doubleClickTime) { pointerEvent.clickCount = 0; } // search for the control that will receive the press // if we can't find a press handler set the press // handler to be what would receive a click. var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.pointerDownHandler); var newClick = ExecuteEvents.GetEventHandler<IPointerClickHandler>(currentOverGo); // didnt find a press handler... search for a click handler if (newPressed == null) newPressed = newClick; // Debug.Log("Pressed: " + newPressed); float time = Time.unscaledTime; if (newPressed == pointerEvent.lastPress) { var diffTime = time - pointerEvent.clickTime; if (diffTime < doubleClickTime) ++pointerEvent.clickCount; else pointerEvent.clickCount = 1; pointerEvent.clickTime = time; } else { pointerEvent.clickCount = 1; } pointerEvent.pointerPress = newPressed; pointerEvent.rawPointerPress = currentOverGo; pointerEvent.pointerClick = newClick; pointerEvent.clickTime = time; // Save the drag handler as well pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler<IDragHandler>(currentOverGo); if (pointerEvent.pointerDrag != null) ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag); m_InputPointerEvent = pointerEvent; } // PointerUp notification if (data.ReleasedThisFrame()) { ReleaseMouse(pointerEvent, currentOverGo); } } protected GameObject GetCurrentFocusedGameObject() { return m_CurrentFocusedGameObject; } } } [ { "id":1, "msg":"帝帝帝大王正指挥瓦多迪建造'苹果能量塔',突然发现核心能源——星光苹果被偷。", "nextid":2 }, { "id": 2, "name": "DDD", "avatar": "Avatars/DDD", "msg": "(暴跳如雷)我的超级苹果!没有它能量塔就是废铁!等等…这粉色绒毛!(捡起沙滩上的绒毛)卡比——!!", "nextid":3 }, { "id":3, "msg": "(星之卡比从礁石后探头,抱着发光的苹果啃得正欢)", "nextid":4 }, { "id": 4, "name": "Kriby", "avatar": "Avatars/Kirby", "msg": " Poyo?(无辜眨眼,苹果汁滴在沙子上泛起星光)", "opts": [ { "msg": "主动归还苹果,但要求交换条件", "toId": 8 }, { "msg": "转身逃跑引发追逐战", "toId": 5 } ] }, { "id": 5, "name": "DDD", "avatar": "Avatars/DDD", "msg": " 可恶的粉球,给我站住不许跑!!!", "nextid":6 }, { "id": 6, "name": "Kriby", "avatar": "Avatars/Kirby", "msg": "Poyo!Poyo!", "nextid":7 }, { "id": 7, "msg": "就这样两人一直追逐下去........但是最终还是选择和解", "nextid":8 }, { "id": 8, "name": "Kriby", "avatar": "Avatars/Kirby", "msg": " Poyo-poyo!(指向远方迷雾海域)", "nextid":9 }, { "id": 9, "name": "DDD", "avatar": "Avatars/DDD", "msg": " 什么?你说海妖偷走了其他苹果?(狐疑)哼!本大王才不会被骗…(突然巨浪袭来)", "nextid":10 }, { "id": 10, "msg": " 巨型海妖现身,触手卷走苹果能量塔的核心部件,两人被困在腐朽的船舱,海水不断渗入。", "nextid":11 }, { "id": 11, "name": "DDD", "avatar": "Avatars/DDD", "msg": " 锤子卡在木梁里)可恶!粉球球,现在我们是一根绳上的蚂蚱了!", "nextid":12 }, { "id": 12, "name": "Kriby", "avatar": "Avatars/Kirby", "msg": "(变身潜水卡比,照亮黑暗)Poyo! ", "nextid":13 }, { "id": 13, "msg": " 逃生途中发现古代石板,记载着苹果能量的秘密。", "nextid":14 }, { "id": 14, "name": "MetaKnight‌", "avatar": "Avatars/MetaKnight‌", "msg": "(突然从天而降)停下!那石板会唤醒古代灾厄!(剑指帝帝帝)你又在谋划什么? ", "nextid":15 }, { "id": 15, "name": "DDD", "avatar": "Avatars/DDD", "msg": "( 本大王需要苹果救妹妹蒂芙!她的石化病…(罕见露出脆弱) ", "nextid":16 }, { "id":16, "name":"Kriby", "msg":"Poyo?(那我现在应该怎么做呢?)", "opts": [ { "msg":"卡比调和冲突,提议三方合作", "nextid":17 }, { "msg":"卡比独自吞下石板引发能量暴走", "nextid":22 } ] }, { "id":17, "msg":"三人抵达星云神殿,发现苹果能量可治愈石化病,但会毁灭梦幻岛生态。", "nextid":18 }, { "id":18, "name":"DDD", "avatar":"Avatars/DDD", "msg":"(颤抖握锤)蒂芙还是岛屿…靠你了(为卡比提供能量)", "nextid":19 }, { "id":19, "name":"MetaKnight‌", "avatar":"Avatars/MetaKnight‌", "msg":"(收剑入鞘)或许是时候该发力了(为卡比提供能量)", "nextid":20 }, { "id":20, "name":"Kriby", "avatar":"Avatars/Kirby", "msg":"(跳到祭坛中央,全身发光)POYO——!", "nextid":21 }, { "id":21, "msg":"能量不断被吸入卡比体内,在短暂光芒之后,卡比稳定下来后让帝帝帝将苹果带回,蒂芙苏醒,帝帝帝含泪道谢" }, { "id":22, "msg":"卡比吸收过量能量裂变成暗黑卡比,引发新危机" } ]仔细检查代码是否有问题为什么会是NULL

大家在看

recommend-type

电子教学套件

电子教学套件教学工具集应用开发,现代电子教学应用开发
recommend-type

gridctrl控件的使用示例程序,程序中有关于gridctrl控件的属性设置、各种方法的使用

gridctrl控件的使用示例程序,程序中有关于gridctrl控件的属性设置、各种方法的使用
recommend-type

现代密码学的答案习题

偏向于电子科大方面的教学,较为基础的信息概述和练习
recommend-type

CCF-CSP必学知识

有关CCF的CSP认证 一、CSP认证考点的知识要求 在数据结构中,线性表是基础,树是常考点,集合和映射要夕纪学。 背包问题(动态规划) 考试要求 二、考试题型 第一题:一般为水题,把C学扎实便可以过 第二题:难度比第一题大,比较多陷阱 第三题:题目很长但是思维难度不会比第二题大 第四题、第五题:难度大,变态题 三、知识点分布 1、字符串 对于字符串的以上处理要做到熟练,并且能够快速讲码打出。 例题分析(2013年12月第二题) C(有越界风险,可用c++的动态数组来写): 问题:输入后只是跳过了‘-’,但是无法判断到底这个符号是在哪里,如果输入“067-0-821162-4”同样会输出“Right”。但是考试系统不管这个,只检查输出即可。(漏洞) 2、数论 重要算法思想: 素数筛选的两种方法,排列组合(可暴力穷举),快速幂 3、STL数据结构 尤其熟悉map,wector,string 对于map的介绍(会用就可以了): map容器中常用的函数: ps:不可以对map使用sort函数,输入是无序的,会自动排序,输出是有序的 4、排序 论稳定性,越低
recommend-type

实体消歧系列文章.rar

实体消歧系列文章.rar

最新推荐

recommend-type

kernel-4.19.90-52.29.v2207.ky10.x86-64.rpm

kernel-4.19.90-52.29.v2207.ky10.x86-64.rpm
recommend-type

2025年检验检测机构评审准则宣贯试题(附答案).pdf

2025年检验检测机构评审准则宣贯试题(附答案).pdf
recommend-type

STM32F4 SDIO应用示例代码

STM32F4 SDIO应用示例代码
recommend-type

【Python毕设】5p125基于协同过滤算法的招聘信息推荐系统_django+spider.zip

项目资源包含:可运行源码+sql文件+LW; python3.8+Django+mysql5.7+vue+spider 适用人群:学习不同技术领域的小白或进阶学习者;可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 当人们打开系统的网址后,首先看到的就是首页界面。在这里,人们能够看到系统的导航条,通过导航条导航进入各功能展示页面进行操作。在个人中心页面输入个人信息可以进行更新操作; 管理员进入主页面,主要功能包括对个人中心、用户管理、招聘信息管理、留言板管理、系统管理等功能进行操作。
recommend-type

2025年高处作业吊篮安装拆卸工应知应会考试题库(含答案) .pdf

2025年高处作业吊篮安装拆卸工应知应会考试题库(含答案) .pdf
recommend-type

多数据源管理与分表实践:MybatisPlus与ShardingJdbc整合

根据给定的文件信息,我们可以详细地解读其中涉及到的关键知识点,这些知识点包括Mybatis Plus的使用、ShardingJdbc的数据分片策略、Swagger的API文档生成能力,以及如何通过注解方式切换数据源。以下是详细的知识点分析: ### Mybatis Plus Mybatis Plus是一个Mybatis的增强工具,在Mybatis的基础上只做增强不做改变,为简化开发、提高效率而生。Mybatis Plus提供了如CRUD、分页、多数据源等一些列增强功能,并且可以与Spring、Spring Boot无缝集成。 #### 使用Mybatis Plus的优势: 1. **简化CRUD操作**:Mybatis Plus自带通用的Mapper和Service,减少代码量,提高开发效率。 2. **支持多种数据库**:支持主流的数据库如MySQL、Oracle、SQL Server等。 3. **逻辑删除**:可以在数据库层面实现记录的软删除功能,无需手动在业务中进行判断。 4. **分页插件**:提供默认的分页功能,支持自定义SQL、Lambda表达式等。 5. **性能分析插件**:方便分析SQL性能问题。 6. **代码生成器**:可以一键生成实体类、Mapper、Service和Controller代码,进一步提高开发效率。 #### 关键点: - **代码生成器**:位于`com.example.demo.common.codegenerator`包下的`GeneratorConfig`类中,用户需要根据实际的数据库配置更改数据库账号密码。 ### ShardingJdbc ShardingJDBC是当当网开源的轻量级Java框架,它在JDBC的层次提供了数据分片的能力。通过ShardingJDBC,可以在应用层面进行分库分表、读写分离、分布式主键等操作。 #### 分库分表: - 通过ShardingJDBC可以配置分库分表的策略,例如按照某个字段的值来决定记录应该保存在哪个分库或分表中。 - **Sharding策略**:可以定义多种分片策略,如模运算、查找表、时间范围等。 #### 关键点: - **注解切换数据源**:文件中提到通过注解的方式切换数据源,这允许开发者在编写代码时通过简单注解即可控制数据访问的路由规则。 ### Swagger Swagger是一个规范且完整的框架,用于生成、描述、调用和可视化RESTful风格的Web服务。总体目标是使客户端和文件系统作为服务器以同样的速度来更新。Swagger文件可让机器读取以了解远程服务的功能,并且可以作为浏览器插件,以便用户与远程服务互动。 #### 使用Swagger的优势: 1. **API文档自动生成**:Swagger可以根据代码中的注释直接生成文档。 2. **动态接口测试**:可以动态地对API接口进行测试。 3. **交互式文档**:提供交互式的API文档,可以实时地在线测试API。 #### 关键点: - **动态文档**:项目中集成Swagger后,可以在开发过程中动态更新API文档,便于团队协作和文档维护。 ### 如何使用 1. **准备工作**:在解压之前,需要更改数据源的IP、账号和密码,并执行resources下的SQL脚本。 2. **数据源配置**:在实际使用中,需要根据实际情况更改GeneratorConfig类中的dataSourceConfig()的数据库账号密码。 3. **代码生成**:启动代码生成器,根据设定的模板和策略生成相应的代码,包含实体类、Mapper、Service和Controller等。 4. **分库分表配置**:配置ShardingJDBC的分库分表策略,包括分片键和分片算法等。 5. **API文档**:集成Swagger,自动生成API文档并提供动态测试功能。 ### 结语 通过本文件所描述的内容,我们可以了解到如何利用Mybatis Plus、ShardingJdbc、Swagger这三大工具配合实现复杂的数据库操作和维护,以及如何通过注解在不同数据源之间灵活切换。用户在使用时应严格按照文件中的指示进行操作,确保数据库连接信息的正确配置,并结合代码生成器快速搭建项目基础结构。同时,应充分理解ShardingJdbc的分库分表策略,以及Swagger的API文档管理功能,以优化开发流程和提高工作效率。如果以上内容使用得当,这将是一个能够有效提升项目开发和维护质量的强大工具集。
recommend-type

BLE广播机制深度解析:XN297_TO_BLE.zip中的创新实践与应用指南

# 摘要 本文全面分析了蓝牙低功耗(BLE)广播机制的理论与实践应用,特别关注了XN297_TO_BLE.zip的开发与优化。通过详细探讨BLE广播的工作原理、数据包结构、以及XN297_TO_BLE.zip的设计理念与架构,本文为开发者提供了深入了解和实践BLE技术的框架。文中不仅介绍了如何搭建开发环境和编程实践,还深入讨论了
recommend-type

我用的就是idea的内置maven呀

<think>好的,用户现在提到他们使用的是IDEA的内置Maven,但之前遇到了“mvn不是内部或外部命令”的问题。我需要仔细分析可能的场景和用户的需求。 首先,用户可能是在IDEA内部使用Maven时没有问题,但在外部命令行中使用mvn命令时遇到了问题。这说明用户可能混淆了IDEA内置Maven和系统环境变量配置的关系。内置的Maven只在IDEA内部有效,并不会自动配置系统的环境变量,因此当用户在命令行中直接运行mvn时,系统找不到该命令,导致报错。 接下来,我需要确定用户的具体使用场景。用户可能是在尝试通过命令行执行Maven命令,或者是在其他需要系统环境变量支持的地方使用mvn。
recommend-type

环保主题植树节PPT模板设计赏析

标题“清新淡雅绿色环保植树节ppt模板”和描述“茂密的一棵卡通树,散落的绿叶,藤蔓线条,清新淡雅,绿色环保,312植树节ppt模板”共同体现了该PPT模板的设计风格和主题。该模板旨在宣传和庆祝植树节,同时强调了环保的理念。以下是对标题和描述中所蕴含知识点的详细说明: 1. 植树节的概念 植树节,是为了提高人们对森林资源的认识、倡导植树造林而设定的节日。不同国家的植树节日期可能不同,而在中国,“312”植树节(每年的3月12日)被广泛认知和庆祝。这个节日起源于20世纪初,是纪念孙中山先生的逝世纪念日,并逐渐演变为全民植树造林的活动日。 2. 绿色环保理念 绿色环保是指在人类活动中,采取相应的措施减少对环境的破坏,保护地球的自然资源和生态系统。这包括节能减排、资源循环利用、减少废弃物产生、提高能源效率等方面。该PPT模板采用“清新淡雅”的视觉元素,通过卡通形象和自然元素来传递环保的理念,使人们对环保有更深的认同感。 3. 卡通风格设计 模板使用了卡通风格来呈现内容,卡通风格设计通常更加生动、活泼,易于吸引观众的注意力,尤其适合儿童及青少年教育和宣传场合。卡通化的树木和藤蔓线条,可以更好地将植树节这一主题与观众尤其是年轻一代进行连接。 4. 清新淡雅的设计风格 “清新淡雅”是一种设计理念,强调色彩的温和、简洁的布局和舒适的视觉体验。在设计中,它通常表现为使用柔和的色调、简单的图形和没有过多装饰的版面,以创造出一种宁静、舒适的感觉。这种风格的模板适合用于教育、公益宣传等场合,易于传达温暖、积极的信息。 5. PPT模板的应用 PPT(PowerPoint演示文稿)是微软公司开发的一款演示软件,广泛用于商业汇报、教育授课、会议演讲和各类展示活动。一个精心设计的PPT模板可以提高演示的专业性和观赏性,同时通过统一的风格和格式,帮助使用者节省准备演示的时间和精力。模板中预设的版式、字体和配色可以被用户根据自己的需求进行调整和补充内容。 结合以上知识点,可以得出这个植树节PPT模板的设计意图和使用价值。它不仅具有美化演示文稿的作用,而且通过其环保主题和设计风格,传达了植树造林、保护环境的重要性。模板的视觉元素如卡通树木和藤蔓线条等,使得环保理念的表达更为直观和亲民,适合在植树节等环保主题活动上使用。
recommend-type

BLE调试必备:XN297_TO_BLE.zip故障排除与性能监控手册

# 摘要 本文详细介绍了BLE技术的基础知识,并针对XN297_TO_BLE.zip这一软件包进行了深入分析。通过对安装、配置、故障排查、性能优化、高级功能实现及案例研究等方面的探讨,提供了全面的实施指导和最佳实践。文章首先概括了BLE技术的核心要点,随后重点阐述了XN297_TO_BLE.zip的安装、初始配置以及功能验证,特别是在连接故障诊断、数据同步问题解决、性能