|
|
@@ -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;
|
|
|
+ }
|
|
|
}
|