lvjincheng 3 жил өмнө
parent
commit
513905aa2b

+ 53 - 5
Assets/BowArrow/Scenes/GameChallengeScene/GameChallenge.unity

@@ -7102,6 +7102,7 @@ Transform:
   - {fileID: 909015801}
   - {fileID: 1576391957}
   - {fileID: 720035913}
+  - {fileID: 842737656}
   - {fileID: 1731683003}
   - {fileID: 925075950}
   m_Father: {fileID: 0}
@@ -17588,11 +17589,11 @@ PrefabInstance:
       objectReference: {fileID: 0}
     - target: {fileID: 184764, guid: c34dd698ff306f0439f184ee015a6a5e, type: 3}
       propertyPath: m_NavMeshLayer
-      value: 1
+      value: 0
       objectReference: {fileID: 0}
     - target: {fileID: 184764, guid: c34dd698ff306f0439f184ee015a6a5e, type: 3}
       propertyPath: m_StaticEditorFlags
-      value: 8
+      value: 0
       objectReference: {fileID: 0}
     - target: {fileID: 481810, guid: c34dd698ff306f0439f184ee015a6a5e, type: 3}
       propertyPath: m_RootOrder
@@ -19405,6 +19406,53 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 79816c5ef5f3e4b45bd0b7c0280375fa, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
+--- !u!1 &842737655
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 842737656}
+  - component: {fileID: 842737657}
+  m_Layer: 0
+  m_Name: StoneObstacle
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 0
+--- !u!4 &842737656
+Transform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 842737655}
+  m_LocalRotation: {x: 0, y: -0.26193643, z: 0, w: 0.9650852}
+  m_LocalPosition: {x: -3.52, y: 0, z: 12.62}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_Children: []
+  m_Father: {fileID: 279869869}
+  m_RootOrder: 12
+  m_LocalEulerAnglesHint: {x: 0, y: -30.37, z: 0}
+--- !u!208 &842737657
+NavMeshObstacle:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 842737655}
+  m_Enabled: 1
+  serializedVersion: 3
+  m_Shape: 1
+  m_Extents: {x: 0.5, y: 0.5, z: 0.5}
+  m_MoveThreshold: 0.1
+  m_Carve: 1
+  m_CarveOnlyStationary: 1
+  m_Center: {x: 0, y: 0, z: 0}
+  m_TimeToStationary: 0.5
 --- !u!1001 &842772917
 PrefabInstance:
   m_ObjectHideFlags: 0
@@ -21686,7 +21734,7 @@ PrefabInstance:
     m_Modifications:
     - target: {fileID: 2297963711468612111, guid: 46ebe146d6695254194666b6c2cb4285, type: 3}
       propertyPath: m_RootOrder
-      value: 13
+      value: 14
       objectReference: {fileID: 0}
     - target: {fileID: 2297963711468612111, guid: 46ebe146d6695254194666b6c2cb4285, type: 3}
       propertyPath: m_LocalPosition.x
@@ -24263,7 +24311,7 @@ PrefabInstance:
       objectReference: {fileID: 0}
     - target: {fileID: 184764, guid: c34dd698ff306f0439f184ee015a6a5e, type: 3}
       propertyPath: m_StaticEditorFlags
-      value: 8
+      value: 0
       objectReference: {fileID: 0}
     - target: {fileID: 481810, guid: c34dd698ff306f0439f184ee015a6a5e, type: 3}
       propertyPath: m_RootOrder
@@ -38963,7 +39011,7 @@ RectTransform:
   - {fileID: 807439190}
   - {fileID: 1595379893}
   m_Father: {fileID: 279869869}
-  m_RootOrder: 12
+  m_RootOrder: 13
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 0}
   m_AnchorMax: {x: 0, y: 0}

BIN
Assets/BowArrow/Scenes/GameChallengeScene/GameChallenge/NavMesh.asset


+ 4 - 0
Assets/BowArrow/Scripts/GameChallenge/Animals/Rabbit.cs

@@ -60,6 +60,10 @@ public class Rabbit : TargetAnimal
         if (isMirror) {
             Destroy(agent);
         }
+        if (GameMgr.ins) {
+            GameObject stoneObstacle = GameMgr.ins.transform.Find("StoneObstacle").gameObject;
+            if (!stoneObstacle.activeSelf) stoneObstacle.SetActive(true);
+        }
     }
 
     void Start()

+ 4 - 0
Assets/BowArrow/Scripts/GameChallenge/Animals/Wolf.cs

@@ -20,6 +20,10 @@ public class Wolf : TargetAnimal
         ap = GetComponent<AnimationPlayer>();
         agent = GetComponent<NavMeshAgent>();
         this.onlineHandler.InitOnAwake(this);
+        if (GameMgr.ins) {
+            GameObject stoneObstacle = GameMgr.ins.transform.Find("StoneObstacle").gameObject;
+            if (!stoneObstacle.activeSelf) stoneObstacle.SetActive(true);
+        }
     }
 
     void Start()

+ 68 - 5
Assets/BowArrow/Scripts/GameChallenge/Animals/Yeji.cs

@@ -15,12 +15,25 @@ public class Yeji : TargetAnimal
     [System.NonSerialized] public float flyPlaneHeight = 5;
     float currentHeight = 0;
     float toFlyHeight = float.NaN;
+    bool _firstSetFlyHeight = true;
     public void SetFlyHeight(float value) {
         if (toFlyHeight.Equals(float.NaN)) toFlyHeight = value;
         currentHeight = value;
         float agentBaseOffset = value - flyPlaneHeight;
-        this.agent.baseOffset = agentBaseOffset / transform.localScale.y;//因为agent的baseoffset会受节点的scale影响
-        state.flying = currentHeight > 0;
+        this.agent.baseOffset = agentBaseOffset / GetScaleY();//因为agent的baseoffset会受节点的scale影响
+        if (_firstSetFlyHeight) {
+            _firstSetFlyHeight = false;
+            state.flying = currentHeight > GetLandHeight();
+        }
+    }
+    private float GetLandHeight() {
+        if (stoneRecorder.IsStoneLocker(this)) return stoneRecorder.GetStoneYOffLand();
+        return 0f;
+    }
+    float _scaleY = -1;
+    private float GetScaleY() {
+        if (_scaleY < 0) _scaleY = transform.localScale.y;
+        return _scaleY;
     }
 
     void Awake()
@@ -49,6 +62,7 @@ public class Yeji : TargetAnimal
         yejiSet.Remove(this);
         tryReleaseOccupyTree();
         ReleasePreHeight(this);
+        stoneRecorder.TryRelease(this);
     }
 
     void Update()
@@ -203,8 +217,9 @@ public class Yeji : TargetAnimal
             }
             if (state.down && state.flying) { //下降阶段
                 float nextH = currentHeight - Time.deltaTime * downSpeed;
-                if (nextH <= 0) { //下降完成
-                    nextH = 0;
+                float minH = GetLandHeight();
+                if (nextH <= minH) { //下降完成
+                    nextH = minH;
                     state.landing = true;
                     state.flying = false;
                     StopNavigation();
@@ -260,7 +275,10 @@ public class Yeji : TargetAnimal
                     float distance = Vector3.Distance(myP, desP);
                     if (distance < keyDistance) {
                         needCheckFlyDown = false;
-                        if (Random.value < 0.5 && tryOccupyTree()) {
+                        if (stoneRecorder.IsStoneLocker(this)) {
+                            state.down = true;
+                        } else if (Random.value < 0.5 && tryOccupyTree()) {
+                        // } else if (tryOccupyTree()) {
                             state.down = true;
                         } else {
                             willStayOnTree = true;
@@ -284,6 +302,15 @@ public class Yeji : TargetAnimal
                 return;
             }
 
+            //可以飞向石头
+            if (!stoneRecorder.IsOnStone(this) && Random.value < 0.7f && stoneRecorder.TryLock(this)) {
+            // if (!stoneRecorder.IsOnStone(this) && stoneRecorder.TryLock(this)) {
+                var newPos1 = stoneRecorder.GetLockPosition(animalsBaseT, flyPlaneHeight);
+                SetDestination(newPos1);
+                needCheckFlyDown = true;
+                return;
+            }
+
             //飞向别的树
             #region 
                 Vector3 myPos = this.transform.position; 
@@ -315,6 +342,7 @@ public class Yeji : TargetAnimal
             state.up = true;
             animator.CrossFade("FlyFromGround", 0.1f);
             tryReleaseOccupyTree();
+            stoneRecorder.TryRelease(this);
         }
 
         void CancelFlyStay() {
@@ -509,4 +537,39 @@ public class Yeji : TargetAnimal
     public override int GetOnlineID() {
         return onlineHandler.uid;
     }
+
+    static StoneRecorder stoneRecorder = new StoneRecorder();
+}
+public class StoneRecorder {
+    private object locker;
+    public bool TryLock(object locker) {
+        if (this.locker == null) {
+            this.locker = locker;
+            return true;
+        }
+        return false;
+    }
+    public bool TryRelease(object locker) {
+        if (this.locker == locker) {
+            this.locker = null;
+            return true;
+        }
+        return false;
+    }
+    public bool IsStoneLocker(object locker) {
+        return this.locker == locker;
+    }
+    float stoneX = 158.981f;
+    float stoneZ = 140.848f;
+    public float GetStoneYOffLand() {
+        return 0.35f;
+    }
+    public Vector3 GetLockPosition(Transform animalsBaseT, float flyPlaneHeight) {
+        return new Vector3(stoneX, animalsBaseT.position.y + flyPlaneHeight, stoneZ);
+    }
+    public bool IsOnStone(MonoBehaviour animal) {
+        Vector3 pos = animal.transform.position;
+        float distance = Mathf.Sqrt(Mathf.Pow(stoneX - pos.x, 2) + Mathf.Pow(stoneZ - pos.z, 2));
+        return distance < 0.6f;
+    }
 }