Переглянути джерело

5/22更新

2025/5/21 完成WalkDogs场景下,2D音乐游戏的主要逻辑部分
2025/5/22 添加完整的狗转移程序,包括迁出二维码,迁出取消,迁入扫码
Jees 2 місяців тому
батько
коміт
49df7c2aa0
30 змінених файлів з 931 додано та 146 видалено
  1. 8 0
      Assets/Pictures/WalkDogs.meta
  2. 136 0
      Assets/Pictures/WalkDogs/actionTarget.mat
  3. 8 0
      Assets/Pictures/WalkDogs/actionTarget.mat.meta
  4. BIN
      Assets/Pictures/WalkDogs/actionTarget.png
  5. 166 0
      Assets/Pictures/WalkDogs/actionTarget.png.meta
  6. 10 0
      Assets/Resources/Data/languages.json
  7. 0 73
      Assets/Resources/Status/Status.prefab
  8. 111 20
      Assets/Resources/Status/StatusController.cs
  9. 1 0
      Assets/Resources/Status/StatusUI.uxml
  10. 6 6
      Assets/Resources/WalkDogs/SoundTrack/track_1.json
  11. 1 1
      Assets/Scenes/Login.unity
  12. BIN
      Assets/Scenes/Walk A Dog/Sprite/circle4.png
  13. 0 0
      Assets/Scenes/WalkDogs.meta
  14. 157 12
      Assets/Scenes/WalkDogs.unity
  15. 45 0
      Assets/Scenes/WalkDogs/Sound Game Input.inputactions
  16. 14 0
      Assets/Scenes/WalkDogs/Sound Game Input.inputactions.meta
  17. 0 0
      Assets/Scenes/WalkDogs/Sprite.meta
  18. 0 0
      Assets/Scenes/WalkDogs/Sprite/arrow.png
  19. 0 0
      Assets/Scenes/WalkDogs/Sprite/arrow.png.meta
  20. 0 0
      Assets/Scenes/WalkDogs/Sprite/circle1.png
  21. 0 0
      Assets/Scenes/WalkDogs/Sprite/circle1.png.meta
  22. BIN
      Assets/Scenes/WalkDogs/Sprite/circle4.png
  23. 5 5
      Assets/Scenes/WalkDogs/Sprite/circle4.png.meta
  24. 6 6
      Assets/Scripts/Develop Script/TestSetup.cs
  25. 1 1
      Assets/Scripts/GameControllers/DogProperty.cs
  26. 11 1
      Assets/Scripts/GameControllers/GameTool.cs
  27. 19 8
      Assets/Scripts/Login/CreateOrAdopt.cs
  28. 13 4
      Assets/Scripts/WalkDogs/NoteController.cs
  29. 1 1
      Assets/Scripts/WalkDogs/SoundGame/SoundTrackManager.cs
  30. 212 8
      Assets/Scripts/WalkDogs/SoundGameController.cs

+ 8 - 0
Assets/Pictures/WalkDogs.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 19ba9d263760cb8418ca483790bbef8c
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 136 - 0
Assets/Pictures/WalkDogs/actionTarget.mat

@@ -0,0 +1,136 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!114 &-3427986967466146216
+MonoBehaviour:
+  m_ObjectHideFlags: 11
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 0}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  version: 9
+--- !u!21 &2100000
+Material:
+  serializedVersion: 8
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_Name: actionTarget
+  m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
+  m_Parent: {fileID: 0}
+  m_ModifiedSerializedProperties: 0
+  m_ValidKeywords: []
+  m_InvalidKeywords: []
+  m_LightmapFlags: 4
+  m_EnableInstancingVariants: 0
+  m_DoubleSidedGI: 0
+  m_CustomRenderQueue: 2000
+  stringTagMap:
+    RenderType: Opaque
+  disabledShaderPasses:
+  - MOTIONVECTORS
+  m_LockedProperties: 
+  m_SavedProperties:
+    serializedVersion: 3
+    m_TexEnvs:
+    - _BaseMap:
+        m_Texture: {fileID: 2800000, guid: a0f5e0d9db53df64e975149f61b29ffe, type: 3}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _BumpMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _DetailAlbedoMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _DetailMask:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _DetailNormalMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _EmissionMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _MainTex:
+        m_Texture: {fileID: 2800000, guid: a0f5e0d9db53df64e975149f61b29ffe, type: 3}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _MetallicGlossMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _OcclusionMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _ParallaxMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _SpecGlossMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - unity_Lightmaps:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - unity_LightmapsInd:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - unity_ShadowMasks:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    m_Ints: []
+    m_Floats:
+    - _AddPrecomputedVelocity: 0
+    - _AlphaClip: 0
+    - _AlphaToMask: 0
+    - _Blend: 0
+    - _BlendModePreserveSpecular: 1
+    - _BumpScale: 1
+    - _ClearCoatMask: 0
+    - _ClearCoatSmoothness: 0
+    - _Cull: 2
+    - _Cutoff: 0.5
+    - _DetailAlbedoMapScale: 1
+    - _DetailNormalMapScale: 1
+    - _DstBlend: 0
+    - _DstBlendAlpha: 0
+    - _EnvironmentReflections: 1
+    - _GlossMapScale: 0
+    - _Glossiness: 0
+    - _GlossyReflections: 0
+    - _Metallic: 0
+    - _OcclusionStrength: 1
+    - _Parallax: 0.005
+    - _QueueOffset: 0
+    - _ReceiveShadows: 1
+    - _Smoothness: 0.5
+    - _SmoothnessTextureChannel: 0
+    - _SpecularHighlights: 1
+    - _SrcBlend: 1
+    - _SrcBlendAlpha: 1
+    - _Surface: 0
+    - _WorkflowMode: 1
+    - _ZWrite: 1
+    m_Colors:
+    - _BaseColor: {r: 1, g: 1, b: 1, a: 1}
+    - _Color: {r: 1, g: 1, b: 1, a: 1}
+    - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
+    - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
+  m_BuildTextureStacks: []
+  m_AllowLocking: 1

+ 8 - 0
Assets/Pictures/WalkDogs/actionTarget.mat.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: d97987a40e4fd56448855c5cdd0b7c96
+NativeFormatImporter:
+  externalObjects: {}
+  mainObjectFileID: 2100000
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Pictures/WalkDogs/actionTarget.png


+ 166 - 0
Assets/Pictures/WalkDogs/actionTarget.png.meta

@@ -0,0 +1,166 @@
+fileFormatVersion: 2
+guid: a0f5e0d9db53df64e975149f61b29ffe
+TextureImporter:
+  internalIDToNameTable: []
+  externalObjects: {}
+  serializedVersion: 13
+  mipmaps:
+    mipMapMode: 0
+    enableMipMap: 0
+    sRGBTexture: 1
+    linearTexture: 0
+    fadeOut: 0
+    borderMipMap: 0
+    mipMapsPreserveCoverage: 0
+    alphaTestReferenceValue: 0.5
+    mipMapFadeDistanceStart: 1
+    mipMapFadeDistanceEnd: 3
+  bumpmap:
+    convertToNormalMap: 0
+    externalNormalMap: 0
+    heightScale: 0.25
+    normalMapFilter: 0
+    flipGreenChannel: 0
+  isReadable: 0
+  streamingMipmaps: 0
+  streamingMipmapsPriority: 0
+  vTOnly: 0
+  ignoreMipmapLimit: 0
+  grayScaleToAlpha: 0
+  generateCubemap: 6
+  cubemapConvolution: 0
+  seamlessCubemap: 0
+  textureFormat: 1
+  maxTextureSize: 2048
+  textureSettings:
+    serializedVersion: 2
+    filterMode: 1
+    aniso: 1
+    mipBias: 0
+    wrapU: 1
+    wrapV: 1
+    wrapW: 0
+  nPOTScale: 0
+  lightmap: 0
+  compressionQuality: 50
+  spriteMode: 2
+  spriteExtrude: 1
+  spriteMeshType: 1
+  alignment: 0
+  spritePivot: {x: 0.5, y: 0.5}
+  spritePixelsToUnits: 100
+  spriteBorder: {x: 0, y: 0, z: 0, w: 0}
+  spriteGenerateFallbackPhysicsShape: 1
+  alphaUsage: 1
+  alphaIsTransparency: 1
+  spriteTessellationDetail: -1
+  textureType: 8
+  textureShape: 1
+  singleChannelComponent: 0
+  flipbookRows: 1
+  flipbookColumns: 1
+  maxTextureSizeSet: 0
+  compressionQualitySet: 0
+  textureFormatSet: 0
+  ignorePngGamma: 0
+  applyGammaDecoding: 0
+  swizzle: 50462976
+  cookieLightType: 0
+  platformSettings:
+  - serializedVersion: 4
+    buildTarget: DefaultTexturePlatform
+    maxTextureSize: 2048
+    resizeAlgorithm: 0
+    textureFormat: -1
+    textureCompression: 1
+    compressionQuality: 50
+    crunchedCompression: 0
+    allowsAlphaSplitting: 0
+    overridden: 0
+    ignorePlatformSupport: 0
+    androidETC2FallbackOverride: 0
+    forceMaximumCompressionQuality_BC6H_BC7: 0
+  - serializedVersion: 4
+    buildTarget: Standalone
+    maxTextureSize: 2048
+    resizeAlgorithm: 0
+    textureFormat: -1
+    textureCompression: 1
+    compressionQuality: 50
+    crunchedCompression: 0
+    allowsAlphaSplitting: 0
+    overridden: 0
+    ignorePlatformSupport: 0
+    androidETC2FallbackOverride: 0
+    forceMaximumCompressionQuality_BC6H_BC7: 0
+  - serializedVersion: 4
+    buildTarget: Android
+    maxTextureSize: 2048
+    resizeAlgorithm: 0
+    textureFormat: -1
+    textureCompression: 1
+    compressionQuality: 50
+    crunchedCompression: 0
+    allowsAlphaSplitting: 0
+    overridden: 0
+    ignorePlatformSupport: 0
+    androidETC2FallbackOverride: 0
+    forceMaximumCompressionQuality_BC6H_BC7: 0
+  - serializedVersion: 4
+    buildTarget: iOS
+    maxTextureSize: 2048
+    resizeAlgorithm: 0
+    textureFormat: -1
+    textureCompression: 1
+    compressionQuality: 50
+    crunchedCompression: 0
+    allowsAlphaSplitting: 0
+    overridden: 0
+    ignorePlatformSupport: 0
+    androidETC2FallbackOverride: 0
+    forceMaximumCompressionQuality_BC6H_BC7: 0
+  spriteSheet:
+    serializedVersion: 2
+    sprites:
+    - serializedVersion: 2
+      name: actionTarget_0
+      rect:
+        serializedVersion: 2
+        x: 3
+        y: 3
+        width: 185
+        height: 186
+      alignment: 0
+      pivot: {x: 0.5, y: 0.5}
+      border: {x: 0, y: 0, z: 0, w: 0}
+      customData: 
+      outline: []
+      physicsShape: []
+      tessellationDetail: 0
+      bones: []
+      spriteID: c5b09893e43327545a51fdd0839ce048
+      internalID: -922857493
+      vertices: []
+      indices: 
+      edges: []
+      weights: []
+    outline: []
+    customData: 
+    physicsShape: []
+    bones: []
+    spriteID: d396c5df2c5b538418372770800792a2
+    internalID: 0
+    vertices: []
+    indices: 
+    edges: []
+    weights: []
+    secondaryTextures: []
+    spriteCustomMetadata:
+      entries: []
+    nameFileIdTable:
+      actionTarget_0: -922857493
+  mipmapLimitGroupName: 
+  pSDRemoveMatte: 0
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 10 - 0
Assets/Resources/Data/languages.json

@@ -950,6 +950,16 @@
                 "en": "Price:",
                 "zh-cn": "价格:"
             }
+        },
+        "message": {
+            "receive_success": {
+                "en": "Adopt successfully.",
+                "zh-cn": "领养成功。"
+            },
+            "receive_fail": {
+                "en": "Adopt failed.",
+                "zh-cn": "领养失败。"
+            }
         }
     },
     "FeedbackUI": {

+ 0 - 73
Assets/Resources/Status/Status.prefab

@@ -1,77 +1,5 @@
 %YAML 1.1
 %TAG !u! tag:unity3d.com,2011:
---- !u!1 &2330952801800188458
-GameObject:
-  m_ObjectHideFlags: 0
-  m_CorrespondingSourceObject: {fileID: 0}
-  m_PrefabInstance: {fileID: 0}
-  m_PrefabAsset: {fileID: 0}
-  serializedVersion: 6
-  m_Component:
-  - component: {fileID: 2036284543114359424}
-  - component: {fileID: 4389362542847398255}
-  - component: {fileID: 1922957480217080132}
-  m_Layer: 5
-  m_Name: QRCode
-  m_TagString: Untagged
-  m_Icon: {fileID: 0}
-  m_NavMeshLayer: 0
-  m_StaticEditorFlags: 0
-  m_IsActive: 1
---- !u!224 &2036284543114359424
-RectTransform:
-  m_ObjectHideFlags: 0
-  m_CorrespondingSourceObject: {fileID: 0}
-  m_PrefabInstance: {fileID: 0}
-  m_PrefabAsset: {fileID: 0}
-  m_GameObject: {fileID: 2330952801800188458}
-  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
-  m_LocalPosition: {x: 0, y: 0, z: 0}
-  m_LocalScale: {x: 1, y: 1, z: 1}
-  m_ConstrainProportionsScale: 0
-  m_Children: []
-  m_Father: {fileID: 8435704930564478781}
-  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
-  m_AnchorMin: {x: 0.5, y: 0.5}
-  m_AnchorMax: {x: 0.5, y: 0.5}
-  m_AnchoredPosition: {x: 0, y: 60}
-  m_SizeDelta: {x: 256, y: 256}
-  m_Pivot: {x: 0.5, y: 0.5}
---- !u!222 &4389362542847398255
-CanvasRenderer:
-  m_ObjectHideFlags: 0
-  m_CorrespondingSourceObject: {fileID: 0}
-  m_PrefabInstance: {fileID: 0}
-  m_PrefabAsset: {fileID: 0}
-  m_GameObject: {fileID: 2330952801800188458}
-  m_CullTransparentMesh: 1
---- !u!114 &1922957480217080132
-MonoBehaviour:
-  m_ObjectHideFlags: 0
-  m_CorrespondingSourceObject: {fileID: 0}
-  m_PrefabInstance: {fileID: 0}
-  m_PrefabAsset: {fileID: 0}
-  m_GameObject: {fileID: 2330952801800188458}
-  m_Enabled: 1
-  m_EditorHideFlags: 0
-  m_Script: {fileID: 11500000, guid: 1344c3c82d62a2a41a3576d8abb8e3ea, type: 3}
-  m_Name: 
-  m_EditorClassIdentifier: 
-  m_Material: {fileID: 0}
-  m_Color: {r: 1, g: 1, b: 1, a: 1}
-  m_RaycastTarget: 1
-  m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
-  m_Maskable: 1
-  m_OnCullStateChanged:
-    m_PersistentCalls:
-      m_Calls: []
-  m_Texture: {fileID: 0}
-  m_UVRect:
-    serializedVersion: 2
-    x: 0
-    y: 0
-    width: 1
-    height: 1
 --- !u!1 &2559338786808445806
 GameObject:
   m_ObjectHideFlags: 0
@@ -172,7 +100,6 @@ RectTransform:
   m_ConstrainProportionsScale: 0
   m_Children:
   - {fileID: 6977922947396265147}
-  - {fileID: 2036284543114359424}
   m_Father: {fileID: 0}
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 0}

+ 111 - 20
Assets/Resources/Status/StatusController.cs

@@ -4,8 +4,16 @@ using System.Collections.Generic;
 using Newtonsoft.Json;
 using UnityEngine;
 using UnityEngine.SceneManagement;
+using UnityEngine.UI;
 using UnityEngine.UIElements;
 
+
+using ZXing;
+using ZXing.QrCode;
+//using UnityEngine.UI;
+using Button = UnityEngine.UIElements.Button;
+//using Image = UnityEngine.UIElements.Image;
+
 /* 这个controller 是用于控制 Status UI菜单的
  * 包含显示狗的最新状态
  * 添加狗,把狗送给朋友,删除狗
@@ -13,23 +21,27 @@ using UnityEngine.UIElements;
 public class StatusController : MonoBehaviour
 {
     private Button backButton, cancelButton;
-    private Label nameLabel, genderLabel, breedLabel, hostLabel, hostnameLabel, ageLabel, ageValueLabel,commandLabel, commandValueLabel, statusLabel, statusValueLabel, resetVoice;
+    private Label nameLabel, genderLabel, breedLabel, hostLabel, hostnameLabel, ageLabel, ageValueLabel, commandLabel, commandValueLabel, statusLabel, statusValueLabel, resetVoice;
     private Label leftArrow, rightArrow;
     private Label addLabel, transfer, remove, callback;
-    private Label transferMsgLabel;
-    private string transferMsgBasic;
-    private DateTime transferCountStartTime = new DateTime();
+    
+    
+    private float transferCountStartTime;
     DogProperty puppy;
-    private VisualElement selectElement, statusElement, transferElement;
+    private VisualElement selectElement, statusElement, transferElement, QRcode;
     private StausUIPage currentPage = StausUIPage.Status;
+
+    // 转移狗使用的变量
+    private Label transferMsgLabel;
+    private string transferMsgOrigin;
+    private string transferCode;
     // Start is called before the first frame update
     void OnEnable()
     {
         var root = GetComponent<UIDocument>().rootVisualElement;
-        statusElement = root.Q("statusElement");
-        transferElement = root.Q("transferElement");
+        // 状态相关的控件
+        statusElement = root.Q<VisualElement>("statusUI");
         backButton = root.Q<Button>("back");
-        cancelButton = root.Q<Button>("cancel");
         nameLabel = root.Q<Label>("name");
         genderLabel = root.Q<Label>("gender");
         breedLabel = root.Q<Label>("breed");
@@ -49,11 +61,16 @@ public class StatusController : MonoBehaviour
         transfer = root.Q<Label>("transfer");
         remove = root.Q<Label>("remove");
         callback = root.Q<Label>("callback");
+
+        // 转移狗的相关控件
         transferMsgLabel = root.Q<Label>("transferMsg");
+        QRcode = root.Q<VisualElement>("QRcode");
+        cancelButton = root.Q<Button>("cancel");
+        transferElement = root.Q<VisualElement>("transferElement");
 
         // 绑定事件
         backButton.clicked += BackBtnClick;
-        cancelButton.clicked += CancelBtnClick;
+        cancelButton.clicked += CancelTransferBtnClick;
         leftArrow.RegisterCallback<ClickEvent>(e => LeftArrowClicked(e));
         rightArrow.RegisterCallback<ClickEvent>(e => RightArrowClicked(e));
         addLabel.RegisterCallback<ClickEvent>(e => AddClick(e));
@@ -109,14 +126,24 @@ public class StatusController : MonoBehaviour
         // StatusSummary();
         if (currentPage == StausUIPage.Transfer)
         {
-            TimeSpan ts = DateTime.Now - transferCountStartTime;
-            if (ts.TotalSeconds > 120)
+            float ts = Time.time - transferCountStartTime;
+            if (ts > 120f)
             {
                 // todo 超过120秒,关闭二维码
                 transferElement.style.display = DisplayStyle.None;
                 statusElement.style.display = DisplayStyle.Flex;
                 currentPage = StausUIPage.Status;
             }
+            else
+            {
+                // todo 未超过120秒,保持二维码显示
+                transferElement.style.display = DisplayStyle.Flex;
+                statusElement.style.display = DisplayStyle.None;
+                currentPage = StausUIPage.Transfer;
+                string remainingTime = Mathf.RoundToInt(120 - ts).ToString();
+                string transferMsg = transferMsgOrigin.Replace("<<second>>", remainingTime);
+                transferMsgLabel.text = transferMsg;
+            }
         }
 
         if (currentPage == StausUIPage.Status)
@@ -163,7 +190,7 @@ public class StatusController : MonoBehaviour
         hostnameLabel.text = UserProperty.name;
 
         // 计算狗生日和现在时间差
-        TimeSpan ts = System.DateTime.Now - puppy.brithday;
+        TimeSpan ts = System.DateTime.Now - puppy.birthday;
         ageValueLabel.text = ts.Days.ToString();
 
     }
@@ -185,7 +212,7 @@ public class StatusController : MonoBehaviour
         textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "label", "resetVoice", EnviromentSetting.languageCode });
         resetVoice.text = textValue;
         textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "statusUI", "message", "scan_QRcode", EnviromentSetting.languageCode });
-        transferMsgBasic = textValue;
+        transferMsgOrigin = textValue;
     }
 
     void CommandSummary()
@@ -396,10 +423,13 @@ public class StatusController : MonoBehaviour
     {
         // todo 重置狗的声音提交成功
         var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
-        if (data != null && data["status"].ToString() == "success"){
+        if (data != null && data["status"].ToString() == "success")
+        {
             // 跳转login场景,重新登录
             MaskTransitions.TransitionManager.Instance.LoadLevel("Login");
-        }else{
+        }
+        else
+        {
             Debug.Log(data["message"]);
         }
     }
@@ -416,8 +446,9 @@ public class StatusController : MonoBehaviour
         }
     }
 
-    void CancelBtnClick()
+    void CancelTransferBtnClick()
     {
+        CancelTransferDogRequest();
         statusElement.style.display = DisplayStyle.Flex;
         transferElement.style.display = DisplayStyle.None;
         currentPage = StausUIPage.Status;
@@ -484,7 +515,7 @@ public class StatusController : MonoBehaviour
 
     void TransferDogRequest()
     {
-        string url = "/api/transfer_dog/receive/";
+        string url = "/api/transfer_dog/send/";
         Dictionary<string, string> formData = new();
         WWWForm form = new();
         form.AddField("user_id", UserProperty.userId);
@@ -494,10 +525,70 @@ public class StatusController : MonoBehaviour
 
     void TransferDogCallback(string json)
     {
-        // TODO 生成二维码,和120秒倒计时
-        transferCountStartTime = DateTime.Now;
-        currentPage = StausUIPage.Transfer;
+        var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
+        if (data != null && data["status"].ToString() == "success")
+        {
+            transferCountStartTime = Time.time;
+            currentPage = StausUIPage.Transfer;
+            transferCode = data["transfer_code"].ToString();
+            transferCode = "ARdog://transfer/" + transferCode;
+            Texture2D qrCodeTexture = GenerateQRCode(transferCode);
+            QRcode.style.backgroundImage = new StyleBackground(qrCodeTexture);
+        }
+        else
+        {
+            Debug.Log(data["message"]);
+        }
+    }
+
+    void CancelTransferDogRequest()
+    {
+        string url = "/api/transfer_dog/cancel/";
+        Dictionary<string, string> formData = new();
+        WWWForm form = new();
+        form.AddField("user_id", UserProperty.userId);
+        form.AddField("transfer_code", transferCode);
+        StartCoroutine(WebController.PostRequest(url, form, callback: CancelTransferDogCallback));
+    }
+
+    void CancelTransferDogCallback(string json)
+    {
+        var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
+        if (data != null && data["status"].ToString() == "success")
+        {
+            Debug.Log("取消转移成功");
+        }
+        else
+        {
+            Debug.Log(data["message"]);
+        }
+    }
+
+    Texture2D GenerateQRCode(string text)
+    {
+        // 创建二维码编码器
+        BarcodeWriter barcodeWriter = new BarcodeWriter
+        {
+            Format = BarcodeFormat.QR_CODE,
+            Options = new QrCodeEncodingOptions
+            {
+                Width = 256,
+                Height = 256
+            }
+        };
+
+        // 生成二维码
+        Color32[] color32 = barcodeWriter.Write(text);
+
+        // 创建纹理并设置像素
+        Texture2D qrCodeTexture = new Texture2D(256, 256);
+        qrCodeTexture.SetPixels32(color32);
+        qrCodeTexture.Apply();
+        return qrCodeTexture;
 
+        // 将纹理转换为Sprite
+        // Sprite qrCodeSprite = Sprite.Create(qrCodeTexture, new Rect(0, 0, qrCodeTexture.width, qrCodeTexture.height), new Vector2(0.5f, 0.5f));
+        // return qrCodeSprite;
     }
 }
 

+ 1 - 0
Assets/Resources/Status/StatusUI.uxml

@@ -31,5 +31,6 @@
     <ui:VisualElement name="transferElement" style="flex-grow: 1; flex-direction: column-reverse; bottom: 70px; display: none;">
         <ui:Button text="&lt;cancel&gt;" name="cancel" enable-rich-text="false" emoji-fallback-support="false" class="button" style="align-self: center; background-color: rgb(255, 255, 255);" />
         <ui:Label text="trasnfer message here." name="transferMsg" class="message" style="border-top-width: 2px; border-right-width: 2px; border-bottom-width: 2px; border-left-width: 2px; border-top-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-bottom-left-radius: 2px; background-color: rgba(255, 198, 109, 0.86); margin-bottom: 4px; border-left-color: rgba(0, 0, 0, 0.24); border-right-color: rgba(0, 0, 0, 0.24); border-top-color: rgba(0, 0, 0, 0.24); border-bottom-color: rgba(0, 0, 0, 0.24);" />
+        <ui:VisualElement name="QRcode" style="flex-grow: initial; width: 256px; height: 256px; align-self: center; flex-shrink: initial; background-image: url(&quot;project://database/Assets/Packages/Loading%20Games/Toon%20City%20Pack/Textures/atm-B-texture.png?fileID=2800000&amp;guid=f32756579eae143f1a7a528feae659da&amp;type=3#atm-B-texture&quot;);" />
     </ui:VisualElement>
 </ui:UXML>

+ 6 - 6
Assets/Resources/WalkDogs/SoundTrack/track_1.json

@@ -7,7 +7,7 @@
     "action points": [
         {
             "time": 5,
-            "action": "left"
+            "action": "tap"
         },
         {
             "time": 5.5,
@@ -15,16 +15,16 @@
         },
         {
             "time": 6,
-            "action": "left"
+            "action": "up"
         },
         {
             "time": 7,
-            "action": "right"
+            "action": "down"
         },
         {
-            "time": 7.25,
-            "action": "tap"
-        },
+            "time": 7.5,
+            "action": "left"
+        }, 
         {
             "time": 8,
             "action": "tap"

+ 1 - 1
Assets/Scenes/Login.unity

@@ -2701,7 +2701,7 @@ Terrain:
   m_BakeLightProbesForTrees: 1
   m_PreserveTreePrototypeLayers: 0
   m_DeringLightProbesForTrees: 1
-  m_ReceiveGI: 1
+  m_ReceiveGI: 2
   m_ScaleInLightmap: 0.0256
   m_LightmapParameters: {fileID: 15203, guid: 0000000000000000f000000000000000, type: 0}
   m_GroupingID: 0

BIN
Assets/Scenes/Walk A Dog/Sprite/circle4.png


+ 0 - 0
Assets/Scenes/Walk A Dog.meta → Assets/Scenes/WalkDogs.meta


+ 157 - 12
Assets/Scenes/WalkDogs.unity

@@ -131,12 +131,12 @@ GameObject:
   - component: {fileID: 586495881}
   - component: {fileID: 586495883}
   m_Layer: 7
-  m_Name: ClickAction
+  m_Name: ClickAction(not use)
   m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
-  m_IsActive: 1
+  m_IsActive: 0
 --- !u!212 &586495881
 SpriteRenderer:
   m_ObjectHideFlags: 0
@@ -186,7 +186,7 @@ SpriteRenderer:
   m_FlipX: 0
   m_FlipY: 0
   m_DrawMode: 0
-  m_Size: {x: 1, y: 1}
+  m_Size: {x: 1.4, y: 1.4}
   m_AdaptiveModeThreshold: 0.5
   m_SpriteTileMode: 0
   m_WasSpriteAssigned: 1
@@ -220,7 +220,7 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   speed: 2
-  hitTime: 0
+  hitTime: 4
   action: 
 --- !u!1 &621789137
 GameObject:
@@ -234,12 +234,12 @@ GameObject:
   - component: {fileID: 621789138}
   - component: {fileID: 621789140}
   m_Layer: 7
-  m_Name: SwipeAction
+  m_Name: SwipeAction(not use)
   m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
-  m_IsActive: 1
+  m_IsActive: 0
 --- !u!212 &621789138
 SpriteRenderer:
   m_ObjectHideFlags: 0
@@ -323,8 +323,8 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   speed: 2
-  hitTime: 0
-  action: 
+  hitTime: 4
+  action: right
 --- !u!1 &844310270
 GameObject:
   m_ObjectHideFlags: 0
@@ -386,7 +386,7 @@ SpriteRenderer:
   m_SortingLayerID: 0
   m_SortingLayer: 0
   m_SortingOrder: 0
-  m_Sprite: {fileID: -2413806693520163455, guid: a86470a33a6bf42c4b3595704624658b, type: 3}
+  m_Sprite: {fileID: -922857493, guid: a0f5e0d9db53df64e975149f61b29ffe, type: 3}
   m_Color: {r: 1, g: 1, b: 1, a: 1}
   m_FlipX: 0
   m_FlipY: 0
@@ -407,7 +407,7 @@ Transform:
   serializedVersion: 2
   m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
   m_LocalPosition: {x: 0, y: -2, z: 5.1}
-  m_LocalScale: {x: 0.8, y: 0.8, z: 0.8}
+  m_LocalScale: {x: 1, y: 1, z: 1}
   m_ConstrainProportionsScale: 1
   m_Children: []
   m_Father: {fileID: 0}
@@ -543,7 +543,7 @@ Transform:
   m_GameObject: {fileID: 992489242}
   serializedVersion: 2
   m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
-  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalPosition: {x: 0, y: 0, z: -3.5}
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_ConstrainProportionsScale: 0
   m_Children: []
@@ -559,6 +559,8 @@ GameObject:
   m_Component:
   - component: {fileID: 1374855187}
   - component: {fileID: 1374855186}
+  - component: {fileID: 1374855188}
+  - component: {fileID: 1374855189}
   m_Layer: 0
   m_Name: 2D Game Controller
   m_TagString: Untagged
@@ -589,10 +591,153 @@ Transform:
   m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
   m_LocalPosition: {x: -3.0912347, y: -1.2701702, z: 3.2612984}
   m_LocalScale: {x: 1, y: 1, z: 1}
-  m_ConstrainProportionsScale: 0
+  m_ConstrainProportionsScale: 1
   m_Children: []
   m_Father: {fileID: 0}
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!82 &1374855188
+AudioSource:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1374855185}
+  m_Enabled: 1
+  serializedVersion: 4
+  OutputAudioMixerGroup: {fileID: 0}
+  m_audioClip: {fileID: 8300000, guid: b6bf186a001b92f4595bfcd3bf0b6702, type: 3}
+  m_Resource: {fileID: 8300000, guid: b6bf186a001b92f4595bfcd3bf0b6702, type: 3}
+  m_PlayOnAwake: 1
+  m_Volume: 1
+  m_Pitch: 1
+  Loop: 0
+  Mute: 0
+  Spatialize: 0
+  SpatializePostEffects: 0
+  Priority: 128
+  DopplerLevel: 1
+  MinDistance: 1
+  MaxDistance: 500
+  Pan2D: 0
+  rolloffMode: 0
+  BypassEffects: 0
+  BypassListenerEffects: 0
+  BypassReverbZones: 0
+  rolloffCustomCurve:
+    serializedVersion: 2
+    m_Curve:
+    - serializedVersion: 3
+      time: 0
+      value: 1
+      inSlope: 0
+      outSlope: 0
+      tangentMode: 0
+      weightedMode: 0
+      inWeight: 0.33333334
+      outWeight: 0.33333334
+    - serializedVersion: 3
+      time: 1
+      value: 0
+      inSlope: 0
+      outSlope: 0
+      tangentMode: 0
+      weightedMode: 0
+      inWeight: 0.33333334
+      outWeight: 0.33333334
+    m_PreInfinity: 2
+    m_PostInfinity: 2
+    m_RotationOrder: 4
+  panLevelCustomCurve:
+    serializedVersion: 2
+    m_Curve:
+    - serializedVersion: 3
+      time: 0
+      value: 0
+      inSlope: 0
+      outSlope: 0
+      tangentMode: 0
+      weightedMode: 0
+      inWeight: 0.33333334
+      outWeight: 0.33333334
+    m_PreInfinity: 2
+    m_PostInfinity: 2
+    m_RotationOrder: 4
+  spreadCustomCurve:
+    serializedVersion: 2
+    m_Curve:
+    - serializedVersion: 3
+      time: 0
+      value: 0
+      inSlope: 0
+      outSlope: 0
+      tangentMode: 0
+      weightedMode: 0
+      inWeight: 0.33333334
+      outWeight: 0.33333334
+    m_PreInfinity: 2
+    m_PostInfinity: 2
+    m_RotationOrder: 4
+  reverbZoneMixCustomCurve:
+    serializedVersion: 2
+    m_Curve:
+    - serializedVersion: 3
+      time: 0
+      value: 1
+      inSlope: 0
+      outSlope: 0
+      tangentMode: 0
+      weightedMode: 0
+      inWeight: 0.33333334
+      outWeight: 0.33333334
+    m_PreInfinity: 2
+    m_PostInfinity: 2
+    m_RotationOrder: 4
+--- !u!114 &1374855189
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1374855185}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_Actions: {fileID: -944628639613478452, guid: c160a599b3c914c44823153bcd1ec0fc, type: 3}
+  m_NotificationBehavior: 2
+  m_UIInputModule: {fileID: 0}
+  m_DeviceLostEvent:
+    m_PersistentCalls:
+      m_Calls: []
+  m_DeviceRegainedEvent:
+    m_PersistentCalls:
+      m_Calls: []
+  m_ControlsChangedEvent:
+    m_PersistentCalls:
+      m_Calls: []
+  m_ActionEvents:
+  - m_PersistentCalls:
+      m_Calls:
+      - m_Target: {fileID: 1374855186}
+        m_TargetAssemblyTypeName: SoundGameController, Assembly-CSharp
+        m_MethodName: TapOrSwipe
+        m_Mode: 0
+        m_Arguments:
+          m_ObjectArgument: {fileID: 0}
+          m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
+          m_IntArgument: 0
+          m_FloatArgument: 0
+          m_StringArgument: 
+          m_BoolArgument: 0
+        m_CallState: 2
+    m_ActionId: e27673ca-0fad-4949-806d-ebf34b43276c
+    m_ActionName: 'Player/TapandSwipe[/Mouse/leftButton,/Device Simulator Touchscreen/press]'
+  m_NeverAutoSwitchControlSchemes: 0
+  m_DefaultControlScheme: 
+  m_DefaultActionMap: Player
+  m_SplitScreenIndex: -1
+  m_Camera: {fileID: 0}
 --- !u!1 &1449772400
 GameObject:
   m_ObjectHideFlags: 0

+ 45 - 0
Assets/Scenes/WalkDogs/Sound Game Input.inputactions

@@ -0,0 +1,45 @@
+{
+    "name": "Sound Game Input",
+    "maps": [
+        {
+            "name": "Player",
+            "id": "981fc5ab-615d-4f99-8f0e-55848f01fc4f",
+            "actions": [
+                {
+                    "name": "TapandSwipe",
+                    "type": "Button",
+                    "id": "e27673ca-0fad-4949-806d-ebf34b43276c",
+                    "expectedControlType": "",
+                    "processors": "",
+                    "interactions": "",
+                    "initialStateCheck": false
+                }
+            ],
+            "bindings": [
+                {
+                    "name": "",
+                    "id": "a8034271-5f1a-4cf8-a93c-09b889fb0852",
+                    "path": "<Mouse>/leftButton",
+                    "interactions": "",
+                    "processors": "",
+                    "groups": "",
+                    "action": "TapandSwipe",
+                    "isComposite": false,
+                    "isPartOfComposite": false
+                },
+                {
+                    "name": "",
+                    "id": "b80dd2f7-0c72-48dc-8930-74b9e12903e1",
+                    "path": "<Touchscreen>/Press",
+                    "interactions": "",
+                    "processors": "",
+                    "groups": "",
+                    "action": "TapandSwipe",
+                    "isComposite": false,
+                    "isPartOfComposite": false
+                }
+            ]
+        }
+    ],
+    "controlSchemes": []
+}

+ 14 - 0
Assets/Scenes/WalkDogs/Sound Game Input.inputactions.meta

@@ -0,0 +1,14 @@
+fileFormatVersion: 2
+guid: c160a599b3c914c44823153bcd1ec0fc
+ScriptedImporter:
+  internalIDToNameTable: []
+  externalObjects: {}
+  serializedVersion: 2
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
+  script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
+  generateWrapperCode: 0
+  wrapperCodePath: 
+  wrapperClassName: 
+  wrapperCodeNamespace: 

+ 0 - 0
Assets/Scenes/Walk A Dog/Sprite.meta → Assets/Scenes/WalkDogs/Sprite.meta


+ 0 - 0
Assets/Scenes/Walk A Dog/Sprite/arrow.png → Assets/Scenes/WalkDogs/Sprite/arrow.png


+ 0 - 0
Assets/Scenes/Walk A Dog/Sprite/arrow.png.meta → Assets/Scenes/WalkDogs/Sprite/arrow.png.meta


+ 0 - 0
Assets/Scenes/Walk A Dog/Sprite/circle1.png → Assets/Scenes/WalkDogs/Sprite/circle1.png


+ 0 - 0
Assets/Scenes/Walk A Dog/Sprite/circle1.png.meta → Assets/Scenes/WalkDogs/Sprite/circle1.png.meta


BIN
Assets/Scenes/WalkDogs/Sprite/circle4.png


+ 5 - 5
Assets/Scenes/Walk A Dog/Sprite/circle4.png.meta → Assets/Scenes/WalkDogs/Sprite/circle4.png.meta

@@ -126,12 +126,12 @@ TextureImporter:
       name: circle4_0
       rect:
         serializedVersion: 2
-        x: 30
-        y: 30
-        width: 200
-        height: 200
+        x: 28
+        y: 28
+        width: 140
+        height: 140
       alignment: 0
-      pivot: {x: 0, y: 0}
+      pivot: {x: 0.5, y: 0.5}
       border: {x: 0, y: 0, z: 0, w: 0}
       customData: 
       outline: []

+ 6 - 6
Assets/Scripts/Develop Script/TestSetup.cs

@@ -58,13 +58,13 @@ public class TestSetup : MonoBehaviour
     {
         if (SceneManager.GetActiveScene().name == "Login")
         {
-            PlayerPrefs.SetString("LoginToken", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiSlRZTlpQOU8iLCJleHAiOjE3NTY1NDUxNzd9.oQgjY_6ZHJVYaYxh2b_LMIkUaCJ9FX8UpxpHOt_yLg8");
-            DateTime now = DateTime.Now;
-            DateTime oneHourAgo = now.AddHours(-1);
-            PlayerPrefs.SetString("LoginTokenTime", oneHourAgo.ToString());
-            EnviromentSetting.UUID = "abc";
+            // PlayerPrefs.SetString("LoginToken", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiSlRZTlpQOU8iLCJleHAiOjE3NTY1NDUxNzd9.oQgjY_6ZHJVYaYxh2b_LMIkUaCJ9FX8UpxpHOt_yLg8");
+            // DateTime now = DateTime.Now;
+            // DateTime oneHourAgo = now.AddHours(-1);
+            // PlayerPrefs.SetString("LoginTokenTime", oneHourAgo.ToString());
+            // EnviromentSetting.UUID = "abc";
 
-            //PlayerPrefs.DeleteAll();
+            // PlayerPrefs.DeleteAll();
             // EnviromentSetting.languageCode = "en";
         }
 

+ 1 - 1
Assets/Scripts/GameControllers/DogProperty.cs

@@ -20,7 +20,7 @@ public class DogProperty
     public string breed = "shibaInu";       // 狗的默认模型
     public string skin = "black";     // 狗的默认贴图
     public string adoption = "home";
-    public DateTime brithday = new(2023, 1, 1, 12, 0, 0);
+    public DateTime birthday = new(2023, 1, 1, 12, 0, 0);
     public int satiety = 15;
     public int happiness = 50;
     public int stamina = 29;

+ 11 - 1
Assets/Scripts/GameControllers/GameTool.cs

@@ -5,6 +5,7 @@ using System.Net.Mail;
 using System.Text.RegularExpressions;
 using Unity.Mathematics;
 using UnityEngine;
+using UnityEngine.SceneManagement;
 
 public static class GameTool
 {
@@ -108,7 +109,7 @@ public static class GameTool
             return false;
         }
     }
-    
+
     public static bool IsValidEmail(string email)
     {
         try
@@ -121,4 +122,13 @@ public static class GameTool
             return false;
         }
     }
+    
+    public static void ReloadCurrentScene()
+    {
+        // 获取当前场景的名称
+        string currentSceneName = SceneManager.GetActiveScene().name;
+
+        // 使用LoadScene方法重新加载当前场景
+        SceneManager.LoadScene(currentSceneName);
+    }
 }

+ 19 - 8
Assets/Scripts/Login/CreateOrAdopt.cs

@@ -62,7 +62,7 @@ public class CreateOrAdopt : MonoBehaviour
             interval -= Time.deltaTime;
             if (interval <= 0)
             {
-                interval = 0.5f;
+                interval = 0.25f; // 重置间隔
                 ScanQRCode();
             }
         }
@@ -144,9 +144,16 @@ public class CreateOrAdopt : MonoBehaviour
             if (result != null)
             {
                 Debug.Log("扫描结果:" + result.Text); // 将扫描结果输出到控制台
-                SubmitQRCodeRequest(result.Text); // 提交二维码请求
-                isScanning = false;
-                webCamTexture.Stop();
+                string qrCode = result.Text;
+                if (qrCode.Length > 18 && qrCode.Substring(0, 17) == "ARdog://transfer/")
+                {
+                    // 处理二维码内容
+                    string transferCode = qrCode.Substring(17);
+                    Debug.Log("转移代码:" + transferCode);
+                    SubmitQRCodeRequest(result.Text); // 提交二维码请求 
+                    isScanning = false;
+                    webCamTexture.Stop();
+                }
             }
         }
     }
@@ -159,13 +166,13 @@ public class CreateOrAdopt : MonoBehaviour
         }
     }
 
-    private void SubmitQRCodeRequest(string qrCode)
+    private void SubmitQRCodeRequest(string transferCode)
     {
         string url = "/api/transfer_dog/receive/";
         Dictionary<string, string> formData = new();
         WWWForm form = new();
         form.AddField("user_id", UserProperty.userId);
-        form.AddField("transfer_code", qrCode);
+        form.AddField("transfer_code", transferCode);
         StartCoroutine(WebController.PostRequest(url, form, callback: SubmitQRCodeCallback));
     }
 
@@ -176,12 +183,16 @@ public class CreateOrAdopt : MonoBehaviour
         if (response.Contains("success"))
         {
             // 成功处理逻辑
-            Debug.Log("狗狗领养成功!");
+            string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "InitDogUI", "message", "receive_success", EnviromentSetting.languageCode });
+            MessageBoxController.ShowMessage(msg, () => GameTool.ReloadCurrentScene());
         }
         else
         {
             // 失败处理逻辑
-            Debug.Log("狗狗领养失败!");
+            string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "InitDogUI", "message", "receive_fail", EnviromentSetting.languageCode });
+            MessageBoxController.ShowMessage(msg, () => GameTool.ReloadCurrentScene());
+            ClickEvent e = new ClickEvent();
+            CancelClick(e);
         }
     }
 }

+ 13 - 4
Assets/Scripts/WalkDogs/NoteController.cs

@@ -11,14 +11,14 @@ using UnityEngine;
 public class NoteController : MonoBehaviour
 {
     public float speed = 2; // 音符移动速度
-    public float hitTime = 0f; // 音符点击的时间
-    private float endTime = 0f; // 音符消失时间
+    public float hitTime = 4f; // 音符点击的时间
+    private float endTime; // 音符消失时间
     public string action = ""; // 音符对应的动作
     private float hitLeadTime = 4f; // 音符提前创建的时间
 
     // Start is called once before the first execution of Update after the MonoBehaviour is created
     void Start()
-    {   
+    {
         hitLeadTime = GameData.noteStartLeadTime; // 获取音符提前创建的时间
         transform.position = new Vector3(-1 * hitLeadTime * speed, -2, 5); // 初始化音符位置
         transform.localScale = NoteSize(); // 设置音符大小
@@ -27,7 +27,7 @@ public class NoteController : MonoBehaviour
         {
             transform.rotation = Quaternion.Euler(0, 0, -90); // 设置音符旋转角度
         }
-        else if(action == "right")
+        else if (action == "right")
         {
             transform.rotation = Quaternion.Euler(0, 0, 90); // 设置音符旋转角度
         }
@@ -35,6 +35,10 @@ public class NoteController : MonoBehaviour
         {
             transform.rotation = Quaternion.Euler(0, 0, 180); // 设置音符旋转角度
         }
+        else if (action == "down")
+        {
+            // transform.rotation = Quaternion.Euler(0, 0, 0); // 设置音符旋转角度
+        }
     }
 
     // Update is called once per frame
@@ -61,4 +65,9 @@ public class NoteController : MonoBehaviour
         float size = 0.4f + 0.6f * deltaSize; // 根据时间差计算音符大小
         return new Vector3(size, size, 1); // 调整音符大小
     }
+
+    void OnDestroy()
+    {
+
+    }
 }

+ 1 - 1
Assets/Scripts/WalkDogs/SoundGame/SoundTrackManager.cs

@@ -34,6 +34,6 @@ public class SoundAction
 {
     public float time { set; get; } = 0f;
     public string action { set; get; } = "";
-    public bool isPlayed = false;      // 表示当前这个音乐动作是否被播放过
+    public bool isTapped = false;      // 表示当前这个音乐动作是否被播放过
     public bool isActive = false;     // 表示当前这个音乐动作是否正在场景中激活
 }

+ 212 - 8
Assets/Scripts/WalkDogs/SoundGameController.cs

@@ -1,10 +1,28 @@
 using System.Collections;
 using UnityEngine;
+using UnityEngine.InputSystem;
 
 public class SoundGameController : MonoBehaviour
 {
     SoundTrackManager soundTrackManager = new();
     GameObject notePrefabSwipe, notePrefabTap;
+
+    float gameStartTime;
+    float GameEndTime;
+    // 游戏得分统计
+    int score = 0;
+    int combo = 0;
+    int PerfectCount = 0;
+    int GoodCount = 0;
+    int PoorCount = 0;
+    int MissCount = 0;
+    int totalCount = 0;
+
+    // TapOrSwipe 触控检测
+    Vector2 pressDownPosition = new Vector2(0, 0);
+    Vector2 pressUpPosition = new Vector2(0, 0);
+    float pressDownTime = 0f;
+    float pressUpTime = 0f;
     // Start is called once before the first execution of Update after the MonoBehaviour is created
     void Start()
     {
@@ -28,26 +46,61 @@ public class SoundGameController : MonoBehaviour
 
     IEnumerator PlaySoundGame()
     {
-        float startTime = Time.time;
-        float endTime = startTime + soundTrackManager.length;
+        // 加载音乐
+        AudioClip audioClip = Resources.Load<AudioClip>(soundTrackManager.resource);
+        AudioSource audioSource = gameObject.AddComponent<AudioSource>();
+        audioSource.clip = audioClip;
+        audioSource.Play();
 
-        while (Time.time < endTime)
+        gameStartTime = Time.time;
+        GameEndTime = gameStartTime + soundTrackManager.length;
+
+        while (Time.time < GameEndTime)
         {
+            // 用于提前n秒创建音符
             foreach (var note in soundTrackManager.soundAction)
             {
-                if (!note.isActive && Time.time >= startTime - GameData.noteStartLeadTime)
+                if (!note.isActive && Time.time >= (note.time - GameData.noteStartLeadTime))
                 {
                     note.isActive = true;
-                    CreateNote(note.time, note.action);
+                    CreateNote(note.time, note.action, soundTrackManager.soundAction.IndexOf(note).ToString());
                     continue;
                 }
             }
-        }
 
-        return null;
+            // 检测音符是否超时未被点击
+            foreach (var note in soundTrackManager.soundAction)
+            {
+                float TapTimeDeadline = note.time + gameStartTime + 0.35f; // 计算点击事件超时
+                if (note.isActive && !note.isTapped && Time.time > TapTimeDeadline)
+                {
+                    note.isTapped = true;
+                    MissCount++;
+                    Debug.Log("Miss!" + Time.time + " Tap time deadline: " + TapTimeDeadline + " total miss:" + MissCount);
+                    Debug.Log("index of note:" + soundTrackManager.soundAction.IndexOf(note));
+                    break;
+                }
+            }
+
+            // 检测游戏是否结束并统计分数
+            totalCount = PerfectCount + GoodCount + PoorCount + MissCount;
+            if (totalCount == soundTrackManager.soundAction.Count)
+            {
+                GameEndTime = Time.time;
+                Debug.Log("Game Over!");
+                Debug.Log($"Perfect: {PerfectCount}, Good: {GoodCount}, Poor: {PoorCount}, Miss: {MissCount}");
+                Debug.Log($"Total Count: {totalCount}");
+                Debug.Log($"Score: {score}");
+                Debug.Log($"Combo: {combo}");
+                // 结束游戏
+                break;      // 跳出 while 循环
+            }
+            yield return new WaitForSeconds(0.01f);
+        }
+        yield return null;
     }
 
-    private void CreateNote(float hitTime, string action)
+    private void CreateNote(float hitTime, string action, string noteName)
     {
         GameObject note;
         if (action == "tap")
@@ -58,9 +111,160 @@ public class SoundGameController : MonoBehaviour
         {
             note = Instantiate(notePrefabSwipe);
         }
+        note.gameObject.name = noteName;
         NoteController noteController = note.GetComponent<NoteController>();
         noteController.speed = soundTrackManager.speed;
         noteController.hitTime = hitTime;
         noteController.action = action;
     }
+
+    // 触控检测,检测通过按下和和抬起的触控点位置计算点击或者上下左右滑动
+    public void TapOrSwipe(InputAction.CallbackContext context)
+    {
+
+        if (context.phase == InputActionPhase.Started)
+        {
+            pressDownPosition = Pointer.current.position.ReadValue();
+            pressDownTime = Time.time;
+            return;
+        }
+        if (context.phase == InputActionPhase.Canceled)
+        {
+            pressUpPosition = Pointer.current.position.ReadValue();
+            pressUpTime = Time.time;
+            float deltaX = pressUpPosition.x - pressDownPosition.x;
+            float deltaY = pressUpPosition.y - pressDownPosition.y;
+            float distance = Mathf.Sqrt(deltaX * deltaX + deltaY * deltaY);
+            // Debug.Log($"deltaX: {deltaX}, deltaY: {deltaY}, distance: {distance}");
+            float timeDelta = pressUpTime - pressDownTime;
+            string action;
+            if (timeDelta > 0.2f)
+            {
+                return;
+            }
+            else
+            {
+                if (distance < 20f)
+                {
+                    action = "tap";
+                }
+                else
+                {
+                    if (Mathf.Abs(deltaX) > Mathf.Abs(deltaY))
+                    {
+                        if (deltaX > 0)
+                        {
+                            action = "right";
+                        }
+                        else
+                        {
+                            action = "left";
+                        }
+                    }
+                    else
+                    {
+                        if (deltaY > 0)
+                        {
+                            action = "up";
+                        }
+                        else
+                        {
+                            action = "down";
+                        }
+                    }
+                }
+            }
+            TouchResponse touchResponse = new TouchResponse(action, pressUpTime);
+            // Debug.Log($"TouchResponse: {touchResponse.action}, {touchResponse.time}");
+            // 检测点击的音符
+            ScoreCheck(touchResponse);
+        }
+        return;
+    }
+
+    private void ScoreCheck(TouchResponse touchResponse)
+    {
+        if (touchResponse != null)
+        {
+            foreach (var note in soundTrackManager.soundAction)
+            {
+                // float TapTimeDeadline = note.time + gameStartTime + 0.35f; // 计算点击事件超时
+                // if (note.isActive && !note.isTapped && Time.time > TapTimeDeadline)
+                // {
+                //     note.isTapped = true;
+                //     MissCount++;
+                //     Debug.Log("Miss!" + Time.time + " Tap time deadline: " + TapTimeDeadline + " total miss:" + MissCount);
+                //     Debug.Log("index of note:" + soundTrackManager.soundAction.IndexOf(note));
+                //     break;
+                // }
+
+                float TapTimeDelta = Mathf.Abs(touchResponse.time - (note.time + gameStartTime));       // 计算点击时间和音符时间的差值
+                if (note.isActive && !note.isTapped && TapTimeDelta < 0.3f)
+                {
+                    note.isTapped = true;
+                    if (touchResponse.action == note.action)
+                    {
+                        if (TapTimeDelta < 0.1f)
+                        {
+                            score += 100;
+                            combo++;
+                            PerfectCount++;
+                            Debug.Log("Perfect!" + Time.time + " total perfect:" + PerfectCount);
+                            string noteName = soundTrackManager.soundAction.IndexOf(note).ToString();
+                            DestroyNote(noteName);
+                        }
+                        else if (TapTimeDelta < 0.2f)
+                        {
+                            score += 30;
+                            combo = 0;
+                            GoodCount++;
+                            Debug.Log("Good!" + Time.time + " total good:" + GoodCount);
+                            string noteName = soundTrackManager.soundAction.IndexOf(note).ToString();
+                            DestroyNote(noteName);
+                        }
+                        else
+                        {
+                            score += 10;
+                            combo = 0;
+                            PoorCount++;
+                            Debug.Log("Poor!" + Time.time + " total poor:" + PoorCount);
+                        }
+                    }
+                    else
+                    {
+                        combo = 0;
+                        MissCount++;
+                        Debug.Log("Wrong!" + Time.time + " total miss:" + MissCount);
+                    }
+                    Debug.Log("index of note:" + soundTrackManager.soundAction.IndexOf(note));
+                    break;
+                }
+            }
+        }
+    }
+
+    private void DestroyNote(string noteName)
+    {
+        GameObject note = GameObject.Find(noteName);
+        if (note != null)
+        {
+            Destroy(note);
+        }
+        else
+        {
+            Debug.Log("Note not found: " + noteName);
+        }
+    }
+}
+
+public class TouchResponse
+{
+    public string action = "";  // 触控动作 up, down, left, right, tap, none(表示无效)
+    public float time;
+
+    public TouchResponse(string action, float time)
+    {
+        this.action = action;
+        this.time = time;
+    }
 }