Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize dessert Xiaoxiele Game by Unity3D

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces Unity3D how to achieve dessert Xiaoxiele game, the article introduces in great detail, has a certain reference value, interested friends must read!

Preface

Explanation:

Previously used ScreenToGif screencap, because the maximum uploaded .gif is not more than 5MB, so I did a lot of frame deletion and color weakening, which led to the color does not look very comfortable, do not stare at it for too long, otherwise it will be a little uncomfortable.

As the material used is ready-made, it does not take time and effort to pick, so the details may not be done very well.

Description:

Although this dessert Xiaoxie may seem simple and ordinary, it has somewhat increased the difficulty compared to the previous tank wars, and has been classified as an algorithm-level game.

Pull to the last look at the code, you can understand what I mean, all the code of the tank war is not as good as the code of the two classes, and the tank can only look at its back for other details.

If the tank war is low-level, then the dessert Xiaoxiele is medium-level, with a lot of animation and interaction (collision detection and dessert control, etc.), and all the mechanisms and functions of the game need to be manipulated on the model layer.

This time Xiaoxiele needs certain logical thinking, algorithm foundation, Unity comprehensive ability and programming foundation.

The square and round font and the glittering effects of Brin Brin will give the game a lovely wind atmosphere.

We divide the objects into model layer and render layer, so that they do their own job and reduce the coupling of work.

As there are still two courses and an examination left before the 12.29 th holiday, the deficiencies will be added later.

Project effect display

Project profile material presentation

Game resources (audio, pictures, special effects, etc.)

Scenes and packages (animation. Render sprites, controllers, etc.)

< t.childCount; i++) SetLayerRecursively(t.GetChild(i).gameObject, layer); } // Graphic elements [MenuItem("GameObject/UI/Text", false, 2000)] static public void AddText(MenuCommand menuCommand) { GameObject go; using (new FactorySwapToEditor()) go = DefaultControls.CreateText(GetStandardResources()); PlaceUIElementRoot(go, menuCommand); } [MenuItem("GameObject/UI/Image", false, 2001)] static public void AddImage(MenuCommand menuCommand) { GameObject go; using (new FactorySwapToEditor()) go = DefaultControls.CreateImage(GetStandardResources()); PlaceUIElementRoot(go, menuCommand); } [MenuItem("GameObject/UI/Raw Image", false, 2002)] static public void AddRawImage(MenuCommand menuCommand) { GameObject go; using (new FactorySwapToEditor()) go = DefaultControls.CreateRawImage(GetStandardResources()); PlaceUIElementRoot(go, menuCommand); } // Controls // Button and toggle are controls you just click on. [MenuItem("GameObject/UI/Button", false, 2030)] static public void AddButton(MenuCommand menuCommand) { GameObject go; using (new FactorySwapToEditor()) go = DefaultControls.CreateButton(GetStandardResources()); PlaceUIElementRoot(go, menuCommand); } [MenuItem("GameObject/UI/Toggle", false, 2031)] static public void AddToggle(MenuCommand menuCommand) { GameObject go; using (new FactorySwapToEditor()) go = DefaultControls.CreateToggle(GetStandardResources()); PlaceUIElementRoot(go, menuCommand); } // Slider and Scrollbar modify a number [MenuItem("GameObject/UI/Slider", false, 2033)] static public void AddSlider(MenuCommand menuCommand) { GameObject go; using (new FactorySwapToEditor()) go = DefaultControls.CreateSlider(GetStandardResources()); PlaceUIElementRoot(go, menuCommand); } [MenuItem("GameObject/UI/Scrollbar", false, 2034)] static public void AddScrollbar(MenuCommand menuCommand) { GameObject go; using (new FactorySwapToEditor()) go = DefaultControls.CreateScrollbar(GetStandardResources()); PlaceUIElementRoot(go, menuCommand); } // More advanced controls below [MenuItem("GameObject/UI/Dropdown", false, 2035)] static public void AddDropdown(MenuCommand menuCommand) { GameObject go; using (new FactorySwapToEditor()) go = DefaultControls.CreateDropdown(GetStandardResources()); PlaceUIElementRoot(go, menuCommand); } [MenuItem("GameObject/UI/Input Field", false, 2036)] public static void AddInputField(MenuCommand menuCommand) { GameObject go; using (new FactorySwapToEditor()) go = DefaultControls.CreateInputField(GetStandardResources()); PlaceUIElementRoot(go, menuCommand); } // Containers [MenuItem("GameObject/UI/Canvas", false, 2060)] static public void AddCanvas(MenuCommand menuCommand) { var go = CreateNewUI(); SetParentAndAlign(go, menuCommand.context as GameObject); if (go.transform.parent as RectTransform) { RectTransform rect = go.transform as RectTransform; rect.anchorMin = Vector2.zero; rect.anchorMax = Vector2.one; rect.anchoredPosition = Vector2.zero; rect.sizeDelta = Vector2.zero; } Selection.activeGameObject = go; } [MenuItem("GameObject/UI/Panel", false, 2061)] static public void AddPanel(MenuCommand menuCommand) { GameObject go; using (new FactorySwapToEditor()) go = DefaultControls.CreatePanel(GetStandardResources()); PlaceUIElementRoot(go, menuCommand); // Panel is special, we need to ensure there's no padding after repositioning. RectTransform rect = go.GetComponent(); rect.anchoredPosition = Vector2.zero; rect.sizeDelta = Vector2.zero; } [MenuItem("GameObject/UI/Scroll View", false, 2062)] static public void AddScrollView(MenuCommand menuCommand) { GameObject go; using (new FactorySwapToEditor()) go = DefaultControls.CreateScrollView(GetStandardResources()); PlaceUIElementRoot(go, menuCommand); } // Helper methods 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.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; } [MenuItem("GameObject/UI/Event System", false, 2100)] public static void CreateEventSystem(MenuCommand menuCommand) { GameObject parent = menuCommand.context as GameObject; CreateEventSystem(true, parent); } private static void CreateEventSystem(bool select) { CreateEventSystem(select, null); } private static void CreateEventSystem(bool select, GameObject parent) { StageHandle stage = parent == null ? StageUtility.GetCurrentStageHandle() : StageUtility.GetStageHandle(parent); var esys = stage.FindComponentOfType(); if (esys == null) { var eventSystem = ObjectFactory.CreateGameObject("EventSystem"); if (parent == null) StageUtility.PlaceGameObjectInCurrentStage(eventSystem); else SetParentAndAlign(eventSystem, parent); esys = ObjectFactory.AddComponent(eventSystem); ObjectFactory.AddComponent(eventSystem); Undo.RegisterCreatedObjectUndo(eventSystem, "Create " + eventSystem.name); } if (select && esys != null) { Selection.activeGameObject = esys.gameObject; } } // Helper function that returns a Canvas GameObject; preferably a parent of the selection, or other existing Canvas. static public GameObject GetOrCreateCanvasGameObject() { GameObject selectedGo = Selection.activeGameObject; // Try to find a gameobject that is the selected GO or one if its parents. Canvas canvas = (selectedGo != null) ? selectedGo.GetComponentInParent() : null; if (IsValidCanvas(canvas)) return canvas.gameObject; // No canvas in selection or its parents? Then use any valid canvas. // We have to find all loaded Canvases, not just the ones in main scenes. Canvas[] canvasArray = StageUtility.GetCurrentStageHandle().FindComponentsOfType(); for (int i = 0; i < canvasArray.Length; i++) if (IsValidCanvas(canvasArray[i])) return canvasArray[i].gameObject; // No canvas in the scene at all? Then create a new one. return MenuOptions.CreateNewUI(); } static bool IsValidCanvas(Canvas canvas) { if (canvas == null || !canvas.gameObject.activeInHierarchy) return false; // It's important that the non-editable canvas from a prefab scene won't be rejected, // but canvases not visible in the Hierarchy at all do. Don't check for HideAndDontSave. if (EditorUtility.IsPersistent(canvas) || (canvas.hideFlags & HideFlags.HideInHierarchy) != 0) return false; return StageUtility.GetStageHandle(canvas.gameObject) == StageUtility.GetCurrentStageHandle(); } }} Editor-EventSystem-EventTriggerEditors.cs using System;using UnityEngine;using UnityEngine.EventSystems; namespace UnityEditor.EventSystems{ [CustomEditor(typeof(EventTrigger), true)] public class EventTriggerEditor : Editor { SerializedProperty m_DelegatesProperty; GUIContent m_IconToolbarMinus; GUIContent m_EventIDName; GUIContent[] m_EventTypes; GUIContent m_AddButonContent; protected virtual void OnEnable() { m_DelegatesProperty = serializedObject.FindProperty("m_Delegates"); m_AddButonContent = EditorGUIUtility.TrTextContent("Add New Event Type"); m_EventIDName = new GUIContent(""); // Have to create a copy since otherwise the tooltip will be overwritten. m_IconToolbarMinus = new GUIContent(EditorGUIUtility.IconContent("Toolbar Minus")); m_IconToolbarMinus.tooltip = "Remove all events in this list."; string[] eventNames = Enum.GetNames(typeof(EventTriggerType)); m_EventTypes = new GUIContent[eventNames.Length]; for (int i = 0; i < eventNames.Length; ++i) { m_EventTypes[i] = new GUIContent(eventNames[i]); } } public override void OnInspectorGUI() { serializedObject.Update(); int toBeRemovedEntry = -1; EditorGUILayout.Space(); Vector2 removeButtonSize = GUIStyle.none.CalcSize(m_IconToolbarMinus); for (int i = 0; i < m_DelegatesProperty.arraySize; ++i) { SerializedProperty delegateProperty = m_DelegatesProperty.GetArrayElementAtIndex(i); SerializedProperty eventProperty = delegateProperty.FindPropertyRelative("eventID"); SerializedProperty callbacksProperty = delegateProperty.FindPropertyRelative("callback"); m_EventIDName.text = eventProperty.enumDisplayNames[eventProperty.enumValueIndex]; EditorGUILayout.PropertyField(callbacksProperty, m_EventIDName); Rect callbackRect = GUILayoutUtility.GetLastRect(); Rect removeButtonPos = new Rect(callbackRect.xMax - removeButtonSize.x - 8, callbackRect.y + 1, removeButtonSize.x, removeButtonSize.y); if (GUI.Button(removeButtonPos, m_IconToolbarMinus, GUIStyle.none)) { toBeRemovedEntry = i; } EditorGUILayout.Space(); } if (toBeRemovedEntry >

-1) {RemoveEntry (toBeRemovedEntry);} Rect btPosition = GUILayoutUtility.GetRect (m_AddButonContent, GUI.skin.button); const float addButonWidth = 200f; btPosition.x = btPosition.x + (btPosition.width-addButonWidth) / 2; btPosition.width = addButonWidth If (GUI.Button (btPosition, m_AddButonContent)) {ShowAddTriggermenu ();} serializedObject.ApplyModifiedProperties ();} private void RemoveEntry (int toBeRemovedEntry) {m_DelegatesProperty.DeleteArrayElementAtIndex (toBeRemovedEntry) } void ShowAddTriggermenu () {/ / Now create the menu, add items and show it GenericMenu menu = new GenericMenu (); for (int I = 0; I

< m_EventTypes.Length; ++i) { bool active = true; // Check if we already have a Entry for the current eventType, if so, disable it for (int p = 0; p < m_DelegatesProperty.arraySize; ++p) { SerializedProperty delegateEntry = m_DelegatesProperty.GetArrayElementAtIndex(p); SerializedProperty eventProperty = delegateEntry.FindPropertyRelative("eventID"); if (eventProperty.enumValueIndex == i) { active = false; } } if (active) menu.AddItem(m_EventTypes[i], false, OnAddNewSelected, i); else menu.AddDisabledItem(m_EventTypes[i]); } menu.ShowAsContext(); Event.current.Use(); } private void OnAddNewSelected(object index) { int selected = (int)index; m_DelegatesProperty.arraySize += 1; SerializedProperty delegateEntry = m_DelegatesProperty.GetArrayElementAtIndex(m_DelegatesProperty.arraySize - 1); SerializedProperty eventProperty = delegateEntry.FindPropertyRelative("eventID"); eventProperty.enumValueIndex = selected; serializedObject.ApplyModifiedProperties(); } }} Runtime-UIElements-ExecuteEvents.cs using System;using System.Collections.Generic;using UnityEngine.Pool; namespace UnityEngine.EventSystems{ public static class ExecuteEvents { public delegate void EventFunction(T1 handler, BaseEventData eventData); public static T ValidateEventData(BaseEventData data) where T : class { if ((data as T) == null) throw new ArgumentException(String.Format("Invalid type: {0} passed to event expecting {1}", data.GetType(), typeof(T))); return data as T; } private static readonly EventFunction s_PointerMoveHandler = Execute; private static void Execute(IPointerMoveHandler handler, BaseEventData eventData) { handler.OnPointerMove(ValidateEventData(eventData)); } private static readonly EventFunction s_PointerEnterHandler = Execute; private static void Execute(IPointerEnterHandler handler, BaseEventData eventData) { handler.OnPointerEnter(ValidateEventData(eventData)); } private static readonly EventFunction s_PointerExitHandler = Execute; private static void Execute(IPointerExitHandler handler, BaseEventData eventData) { handler.OnPointerExit(ValidateEventData(eventData)); } private static readonly EventFunction s_PointerDownHandler = Execute; private static void Execute(IPointerDownHandler handler, BaseEventData eventData) { handler.OnPointerDown(ValidateEventData(eventData)); } private static readonly EventFunction s_PointerUpHandler = Execute; private static void Execute(IPointerUpHandler handler, BaseEventData eventData) { handler.OnPointerUp(ValidateEventData(eventData)); } private static readonly EventFunction s_PointerClickHandler = Execute; private static void Execute(IPointerClickHandler handler, BaseEventData eventData) { handler.OnPointerClick(ValidateEventData(eventData)); } private static readonly EventFunction s_InitializePotentialDragHandler = Execute; private static void Execute(IInitializePotentialDragHandler handler, BaseEventData eventData) { handler.OnInitializePotentialDrag(ValidateEventData(eventData)); } private static readonly EventFunction s_BeginDragHandler = Execute; private static void Execute(IBeginDragHandler handler, BaseEventData eventData) { handler.OnBeginDrag(ValidateEventData(eventData)); } private static readonly EventFunction s_DragHandler = Execute; private static void Execute(IDragHandler handler, BaseEventData eventData) { handler.OnDrag(ValidateEventData(eventData)); } private static readonly EventFunction s_EndDragHandler = Execute; private static void Execute(IEndDragHandler handler, BaseEventData eventData) { handler.OnEndDrag(ValidateEventData(eventData)); } private static readonly EventFunction s_DropHandler = Execute; private static void Execute(IDropHandler handler, BaseEventData eventData) { handler.OnDrop(ValidateEventData(eventData)); } private static readonly EventFunction s_ScrollHandler = Execute; private static void Execute(IScrollHandler handler, BaseEventData eventData) { handler.OnScroll(ValidateEventData(eventData)); } private static readonly EventFunction s_UpdateSelectedHandler = Execute; private static void Execute(IUpdateSelectedHandler handler, BaseEventData eventData) { handler.OnUpdateSelected(eventData); } private static readonly EventFunction s_SelectHandler = Execute; private static void Execute(ISelectHandler handler, BaseEventData eventData) { handler.OnSelect(eventData); } private static readonly EventFunction s_DeselectHandler = Execute; private static void Execute(IDeselectHandler handler, BaseEventData eventData) { handler.OnDeselect(eventData); } private static readonly EventFunction s_MoveHandler = Execute; private static void Execute(IMoveHandler handler, BaseEventData eventData) { handler.OnMove(ValidateEventData(eventData)); } private static readonly EventFunction s_SubmitHandler = Execute; private static void Execute(ISubmitHandler handler, BaseEventData eventData) { handler.OnSubmit(eventData); } private static readonly EventFunction s_CancelHandler = Execute; private static void Execute(ICancelHandler handler, BaseEventData eventData) { handler.OnCancel(eventData); } public static EventFunction pointerMoveHandler { get { return s_PointerMoveHandler; } } public static EventFunction pointerEnterHandler { get { return s_PointerEnterHandler; } } public static EventFunction pointerExitHandler { get { return s_PointerExitHandler; } } public static EventFunction pointerDownHandler { get { return s_PointerDownHandler; } } public static EventFunction pointerUpHandler { get { return s_PointerUpHandler; } } public static EventFunction pointerClickHandler { get { return s_PointerClickHandler; } } public static EventFunction initializePotentialDrag { get { return s_InitializePotentialDragHandler; } } public static EventFunction beginDragHandler { get { return s_BeginDragHandler; } } public static EventFunction dragHandler { get { return s_DragHandler; } } public static EventFunction endDragHandler { get { return s_EndDragHandler; } } public static EventFunction dropHandler { get { return s_DropHandler; } } public static EventFunction scrollHandler { get { return s_ScrollHandler; } } public static EventFunction updateSelectedHandler { get { return s_UpdateSelectedHandler; } } public static EventFunction selectHandler { get { return s_SelectHandler; } } public static EventFunction deselectHandler { get { return s_DeselectHandler; } } public static EventFunction moveHandler { get { return s_MoveHandler; } } public static EventFunction submitHandler { get { return s_SubmitHandler; } } public static EventFunction cancelHandler { get { return s_CancelHandler; } } private static void GetEventChain(GameObject root, IList eventChain) { eventChain.Clear(); if (root == null) return; var t = root.transform; while (t != null) { eventChain.Add(t); t = t.parent; } } public static bool Execute(GameObject target, BaseEventData eventData, EventFunction functor) where T : IEventSystemHandler { var internalHandlers = ListPool.Get(); GetEventList(target, internalHandlers); // if (s_InternalHandlers.Count >

0) / / Debug.Log ("Executinng" + typeof (T) + "on" + target); var internalHandlersCount = internalHandlers.Count; for (var I = 0; I

< internalHandlersCount; i++) { T arg; try { arg = (T)internalHandlers[i]; } catch (Exception e) { var temp = internalHandlers[i]; Debug.LogException(new Exception(string.Format("Type {0} expected {1} received.", typeof(T).Name, temp.GetType().Name), e)); continue; } try { functor(arg, eventData); } catch (Exception e) { Debug.LogException(e); } } var handlerCount = internalHandlers.Count; ListPool.Release(internalHandlers); return handlerCount >

0;} / Execute the specified event on the first game object underneath the current touch. / private static readonly List s_InternalTransformList = new List (30); public static GameObject ExecuteHierarchy (GameObject root, BaseEventData eventData, EventFunction callbackFunction) where T: IEventSystemHandler {GetEventChain (root, s_InternalTransformList); var internalTransformListCount = swarm InternalTransformList.Count; for (var I = 0; I < internalTransformListCount; I +) {var transform = s _ InternalTransformList [I] If (Execute (transform.gameObject, eventData, callbackFunction) return transform.gameObject;} return null;} private static bool ShouldSendToComponent (Component component) where T: IEventSystemHandler {var valid = component is T; if (! valid) return false; var behaviour = component as Behaviour If (behaviour! = null) return behaviour.isActiveAndEnabled; return true;} / Get the specified object's event event. / / private static void GetEventList (GameObject go, IList results) where T: IEventSystemHandler {/ / Debug.LogWarning ("GetEventList"); if (results = = null) throw new ArgumentException ("Results array is null", "results"); if (go = = null | |! go.activeInHierarchy) return; var components = ListPool.Get () Go.GetComponents (components); var componentsCount = components.Count; for (var I = 0; I < componentsCount; iTunes +) {if (! ShouldSendToComponent (principals [I])) continue; / / Debug.Log (string.Format ("{2} found! On {0}. {1} ", go, sGetComponentsScratch [I] .GetType (), typeof (T)); results.Add [I] as IEventSystemHandler);} ListPool.Release (components); / / Debug.LogWarning (" end GetEventList ");} / Whether the specified game object will be able to handle the specified event. / / public static bool CanHandleEvent (GameObject go) where T: IEventSystemHandler {var internalHandlers = ListPool.Get (); GetEventList (go, internalHandlers); var handlerCount = internalHandlers.Count; ListPool.Release (internalHandlers); return handlerCount! = 0;} / Bubble the specified event on the game object, figuring out which object will actually receive the event. / / public static GameObject GetEventHandler (GameObject root) where T: IEventSystemHandler {if (root = = null) return null; Transform t = root.transform; while (t! = null) {if (CanHandleEvent (t.gameObject)) return t.gameObject; t = t.parent } return null;}} above is all the content of this article "how to realize dessert elimination game by Unity3D". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report