lvjincheng пре 4 година
родитељ
комит
591d98690b

+ 10 - 13
Assets/ArtAsset/Hunter/Models/Rabbit/Rabbit.cs

@@ -78,27 +78,24 @@ public class Rabbit : TargetAnimal
 
     void Hurt() {
         RunAwayFromHunter();
-        PuaseAutoStrategy();
         addHurtFlag();
+        PuaseAutoStrategy();
         AudioMgr.ins.PlayAnimalEffect("rabbit_injured", AudioMgr.GetAudioSource(this.gameObject));
     }
-    Queue<int> hurtFlagList = new Queue<int>();
+    
+    JC.CS.CountLocker hurtFlag = new JC.CS.CountLocker();
     void addHurtFlag() {
-        hurtFlagList.Enqueue(0);
+        hurtFlag.Lock();
         Invoke("clearOneHurtFlag", 5);
     }
     void clearOneHurtFlag() {
-        if (hurtFlagList.Count > 0) {
-            hurtFlagList.Dequeue();
-            if (hurtFlagList.Count == 0) {
-                OnHurtFlagTimeOut();
-            }
-        }
+        hurtFlag.Unlock();
+        if (hurtFlag.IsReleased()) {
+            onHurtFlagTimeout();
+        }  
     }
-    void OnHurtFlagTimeOut() {
-        if (!dead) {
-            ResumeAutoStrategy();
-        }
+    void onHurtFlagTimeout() {
+        if (!dead) ResumeAutoStrategy();
     }
 
     //是否已经死亡

+ 10 - 13
Assets/ArtAsset/Hunter/Models/Wolf/Wolf.cs

@@ -80,23 +80,20 @@ public class Wolf : TargetAnimal
         RunAwayFromHunter();
         AudioMgr.ins.PlayAnimalEffect("wolf_injured", AudioMgr.GetAudioSource(this.gameObject));
     }
-    Queue<int> hurtFlagList = new Queue<int>();
+
+    JC.CS.CountLocker hurtFlag = new JC.CS.CountLocker();
     void addHurtFlag() {
-        hurtFlagList.Enqueue(0);
+        hurtFlag.Lock();
         Invoke("clearOneHurtFlag", 5);
     }
     void clearOneHurtFlag() {
-        if (hurtFlagList.Count > 0) {
-            hurtFlagList.Dequeue();
-            if (hurtFlagList.Count == 0) {
-                OnHurtFlagTimeOut();
-            }
-        }
+        hurtFlag.Unlock();
+        if (hurtFlag.IsReleased()) {
+            onHurtFlagTimeout();
+        }  
     }
-    void OnHurtFlagTimeOut() {
-        if (!dead) {
-            ResumeAutoStrategy();
-        }
+    void onHurtFlagTimeout() {
+        if (!dead) ResumeAutoStrategy();
     }
 
     //是否已经死亡
@@ -252,7 +249,7 @@ public class Wolf : TargetAnimal
         return curAnimIndex == 2;
     }
     void playAniRun() {
-        if (Random.value < 0.4 || hurtFlagList.Count > 0) {
+        if (Random.value < 0.4 || hurtFlag.IsLocked()) {
             curAnimIndex = 4;
             ap.speed = 1.3f;
             this.agent.speed = 5;

+ 0 - 21
Assets/ArtAsset/Hunter/Models/Yeji/Yeji.cs

@@ -84,29 +84,8 @@ public class Yeji : TargetAnimal
     }
 
     void Hurt() {
-        // RunAwayFromHunter();
-        // PuaseAutoStrategy();
-        // addHurtFlag();
         AudioMgr.ins.PlayAnimalEffect("bird_injured", AudioMgr.GetAudioSource(this.gameObject));
     }
-    // Queue<int> hurtFlagList = new Queue<int>();
-    // void addHurtFlag() {
-    //     hurtFlagList.Enqueue(0);
-    //     Invoke("clearOneHurtFlag", 5);
-    // }
-    // void clearOneHurtFlag() {
-    //     if (hurtFlagList.Count > 0) {
-    //         hurtFlagList.Dequeue();
-    //         if (hurtFlagList.Count == 0) {
-    //             OnHurtFlagTimeOut();
-    //         }
-    //     }
-    // }
-    // void OnHurtFlagTimeOut() {
-    //     if (!dead) {
-    //         ResumeAutoStrategy();
-    //     }
-    // }
 
     //是否已经死亡
     bool dead = false;

+ 1 - 1
Assets/BowArrow/Scripts/Bluetooth/BluetoothAim.cs

@@ -139,7 +139,7 @@ public class BluetoothAim : MonoBehaviour
             };
             bluetoothHelper.OnCharacteristicChanged += (helper, value, characteristic) =>
             {
-                if (!hasData) hasDataTime = JCUtil.GetTimestamp();
+                if (!hasData) hasDataTime = JC.CS.Utility.GetTimestamp();
                 hasData = true;
                 byte[] bytes = value;
                 // Log(String.Join(",", bytes));

+ 1 - 1
Assets/BowArrow/Scripts/View/DeviceBatteryView.cs

@@ -50,7 +50,7 @@ public class DeviceBatteryView : MonoBehaviour
     void RequestBatteryForBow()
     {
         try {
-            if (BluetoothAim.ins.hasData && JCUtil.GetTimestamp() - BluetoothAim.ins.hasDataTime > 3000) {
+            if (BluetoothAim.ins.hasData && JC.CS.Utility.GetTimestamp() - BluetoothAim.ins.hasDataTime > 3000) {
                 BluetoothAim.ins.WriteData(SceneManager.GetActiveScene().name == "Game" ? "b" :"B");
             }
         } catch (Exception) {}

+ 42 - 0
Assets/DependAsset/JC/JCLib.cs

@@ -0,0 +1,42 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace JC.CS 
+{
+    public class Utility
+    {
+        public static long GetTimestamp()
+        {
+            TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1);
+            return (long)ts.TotalMilliseconds;
+        }
+    }
+    public class CountLocker
+    {
+        int count = 0;
+        HashSet<object> objects = new HashSet<object>();
+        public void Lock()
+        {
+            count++;
+        } 
+        public void Unlock()
+        {
+            count--;
+            if (count < 0) count = 0;
+        }
+        public bool IsLocked()
+        {
+            return count > 0 || objects.Count > 0;
+        }
+        public bool IsReleased()
+        {
+            return !IsLocked();
+        }
+        public void Clear()
+        {
+            count = 0;
+            objects.Clear();
+        }
+    }
+}

+ 1 - 1
Assets/DependAsset/JC/JCUtil.cs.meta → Assets/DependAsset/JC/JCLib.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 4ab93499c9f5f2c409f6272fe65faceb
+guid: e52daed5b953b7840aebd78f7bd7052b
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 0 - 14
Assets/DependAsset/JC/JCUtil.cs

@@ -1,14 +0,0 @@
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-using System;
-
-public class JCUtil : MonoBehaviour
-{
-    // Start is called before the first frame update
-    public static long GetTimestamp()
-    {
-        TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1);
-        return (long)ts.TotalMilliseconds;
-    }
-}