You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
232 lines
7.4 KiB
232 lines
7.4 KiB
|
|
using UnityEngine; |
|
using System.Collections; |
|
using AX.TrackRecord; |
|
using AX.MessageSystem; |
|
using System; |
|
/// <summary> |
|
/// 拉梯控制 |
|
/// </summary> |
|
public abstract class BaseLadder : MonoBehaviour { |
|
protected GameObject ladderPart1; |
|
protected GameObject ladderPart2; |
|
protected GameObject ladderPart3; |
|
private bool firstFull = false; |
|
private bool firstZero = true; |
|
private bool secondFull = false; |
|
private bool secondZero = true; |
|
private float ySpeed = 5; |
|
private float rotatSpeed = 40; |
|
|
|
void Awake() { |
|
InitGameObject(); |
|
//MessageDispatcher.AddListener("LaTi6UpController", LaTi6UpController); |
|
//MessageDispatcher.AddListener("LaTi6DownController", LaTi6DownController); |
|
//MessageDispatcher.AddListener("LaTi15UpController", LaTi15UpController); |
|
//MessageDispatcher.AddListener("LaTi15DownController", LaTi15DownController); |
|
//MessageDispatcher.AddListener("ObjRotateLeftControl", ObjRotateForwardControl); |
|
//MessageDispatcher.AddListener("ObjRotateRightControl", ObjRotateBackwardControl); |
|
|
|
MessageDispatcher.AddListener("LeftShift_W", LeftShift_W); |
|
MessageDispatcher.AddListener("LeftShift_S", LeftShift_S); |
|
MessageDispatcher.AddListener("W", W); |
|
MessageDispatcher.AddListener("S", S); |
|
|
|
} |
|
|
|
private void S(IMessage message) |
|
{ |
|
if ((string)message.Data == this.gameObject.name) |
|
{ |
|
ObjRotateBackwardControl(); |
|
} |
|
} |
|
|
|
private void W(IMessage message) |
|
{ |
|
if ((string)message.Data == this.gameObject.name) |
|
{ |
|
ObjRotateForwardControl(); |
|
} |
|
} |
|
|
|
private void LeftShift_S(IMessage message) |
|
{ |
|
if ((string)message.Data == this.gameObject.name) |
|
{ |
|
if (gameObject.name.Contains("lati6")) |
|
{ |
|
LaTi6DownController(); |
|
} |
|
else if (gameObject.name.Contains("lati15")) |
|
{ |
|
LaTi15DownController(); |
|
} |
|
} |
|
|
|
} |
|
|
|
private void LeftShift_W(IMessage message) |
|
{ |
|
if ((string)message.Data == this.gameObject.name) |
|
{ |
|
if (gameObject.name.Contains("lati6")) |
|
{ |
|
LaTi6UpController(); |
|
} |
|
else if (gameObject.name.Contains("lati15")) |
|
{ |
|
LaTi15UpController(); |
|
} |
|
} |
|
} |
|
private LaTi_Rise_Attribute carAttribute = new LaTi_Rise_Attribute(); |
|
public LaTi_Rise_Attribute CarAttribute |
|
{ |
|
set |
|
{ |
|
carAttribute = value; |
|
firstZero = carAttribute.FirstZero; |
|
firstFull = carAttribute.FirstFull; |
|
secondZero = carAttribute.SecondZero; |
|
secondFull = carAttribute.SecondFull; |
|
} |
|
get |
|
{ |
|
carAttribute.FirstZero = firstZero; |
|
carAttribute.FirstFull = firstFull; |
|
carAttribute.SecondZero = secondZero; |
|
carAttribute.SecondFull = secondFull; |
|
return carAttribute; |
|
} |
|
} |
|
public abstract void InitGameObject(); |
|
void LaTi6UpController() |
|
{ |
|
if (!firstFull) |
|
{ |
|
float y = ladderPart2.transform.localPosition.y; |
|
if (y > 5.85) |
|
{ |
|
firstFull = true; |
|
} |
|
else |
|
{ |
|
ladderPart2.transform.localPosition = new Vector3(ladderPart2.transform.localPosition.x, y + Time.deltaTime * ySpeed, ladderPart2.transform.localPosition.z); |
|
firstZero = false; |
|
} |
|
} |
|
} |
|
void LaTi6DownController() |
|
{ |
|
if (!firstZero) |
|
{ |
|
float y = ladderPart2.transform.localPosition.y; |
|
if (y < 0.055) |
|
{ |
|
firstZero = true; |
|
} |
|
else |
|
{ |
|
ladderPart2.transform.localPosition = new Vector3(ladderPart2.transform.localPosition.x, y - Time.deltaTime * ySpeed, ladderPart2.transform.localPosition.z); |
|
firstFull = false; |
|
} |
|
|
|
} |
|
} |
|
void LaTi15UpController() |
|
{ |
|
if (!firstFull) |
|
{ |
|
float y = ladderPart2.transform.localPosition.y; |
|
if (y > 7.59) |
|
{ |
|
firstFull = true; |
|
Vector3 newVector = ladderPart2.transform.localPosition; |
|
newVector.y = 7.59f; |
|
} |
|
else |
|
{ |
|
ladderPart2.transform.localPosition = new Vector3(ladderPart2.transform.localPosition.x, y + Time.deltaTime * ySpeed, ladderPart2.transform.localPosition.z); |
|
firstZero = false; |
|
} |
|
|
|
} |
|
else if (!secondFull) |
|
{ |
|
float y = ladderPart3.transform.localPosition.y; |
|
if (y > 8.20f) |
|
{ |
|
secondFull = true; |
|
Vector3 newVector = ladderPart3.transform.localPosition; |
|
newVector.y = 8.20f; |
|
} |
|
else |
|
{ |
|
ladderPart3.transform.localPosition = new Vector3(ladderPart3.transform.localPosition.x, y + Time.deltaTime * ySpeed, ladderPart3.transform.localPosition.z); |
|
secondZero = false; |
|
} |
|
} |
|
|
|
} |
|
void LaTi15DownController() |
|
{ |
|
if (!secondZero) |
|
{ |
|
float y = ladderPart3.transform.localPosition.y; |
|
if (y < -0.03382) |
|
{ |
|
secondZero = true; |
|
Vector3 newVector = ladderPart3.transform.localPosition; |
|
newVector.y = -0.03382f; |
|
ladderPart3.transform.localPosition = newVector; |
|
} |
|
else |
|
{ |
|
ladderPart3.transform.localPosition = new Vector3(ladderPart2.transform.localPosition.x, y - Time.deltaTime * ySpeed, ladderPart2.transform.localPosition.z); |
|
secondFull = false; |
|
} |
|
|
|
} |
|
else if (!firstZero) |
|
{ |
|
float y = ladderPart2.transform.localPosition.y; |
|
if (y < -0.54867) |
|
{ |
|
firstZero = true; |
|
Vector3 newVector = ladderPart2.transform.localPosition; |
|
newVector.y = -0.54867f; |
|
ladderPart2.transform.localPosition = newVector; |
|
} |
|
else |
|
{ |
|
ladderPart2.transform.localPosition = new Vector3(ladderPart3.transform.localPosition.x, y - Time.deltaTime * ySpeed, ladderPart3.transform.localPosition.z); |
|
firstFull = false; |
|
} |
|
|
|
} |
|
} |
|
void ObjRotateForwardControl() |
|
{ |
|
transform.Rotate(-Time.deltaTime * rotatSpeed, 0, 0); |
|
} |
|
void ObjRotateBackwardControl() |
|
{ |
|
transform.Rotate(Time.deltaTime * rotatSpeed, 0, 0); |
|
} |
|
void OnDestroy() |
|
{ |
|
//MessageDispatcher.RemoveListener("LaTi6UpController", LaTi6UpController); |
|
//MessageDispatcher.RemoveListener("LaTi6DownController", LaTi6DownController); |
|
//MessageDispatcher.RemoveListener("LaTi15DownController", LaTi15DownController); |
|
//MessageDispatcher.RemoveListener("LaTi15UpController", LaTi15UpController); |
|
//MessageDispatcher.RemoveListener("ObjRotateLeftControl", ObjRotateForwardControl); |
|
//MessageDispatcher.RemoveListener("ObjRotateRightControl", ObjRotateBackwardControl); |
|
|
|
MessageDispatcher.RemoveListener("LeftShift_W", LeftShift_W); |
|
MessageDispatcher.RemoveListener("LeftShift_S", LeftShift_S); |
|
MessageDispatcher.RemoveListener("W", W); |
|
MessageDispatcher.RemoveListener("S", S); |
|
|
|
} |
|
}
|
|
|