public bool TryGetThrough(CharacterPawn pawn, IntVector3 fromRoom) { if (!Available) { return(false); } Room room = GameLoader.Instance.GetRoomByLogicPosition(fromRoom); if (room == parentRoom) { //get out if (ConnectType == CONNECTOR_TYPE.ONE_WAY_IN) { return(false); } bool result = false; //If link another connector, then get through it; if (otherConnector != null) { result = otherConnector.TryGetThrough(pawn, fromRoom); } if (!result) { FindRoomErrorCode err = FindOtherConnector(); switch (err) { case FindRoomErrorCode.NoError: result = otherConnector.TryGetThrough(pawn, fromRoom); break; case FindRoomErrorCode.RoomInvalid: //get out of "the house" break; case FindRoomErrorCode.RoomNotConnected: UIManager.Instance.Message("This door is locked from the other side."); break; case FindRoomErrorCode.CannotCreateRoom: UIManager.Instance.Message("This door is somehow broken."); break; case FindRoomErrorCode.CreateRoomNotConnected: Debug.LogError("After create a new room, there is still no connector!!"); break; default: Debug.LogError("this log is impossible!!"); break; } } if (result) { Property.Connector thisProp = connectorProp; Property.Connector otherProp = otherConnector.connectorProp; if (!thisProp.IsPortal && !otherProp.IsPortal) { //open door ConnectorMono connMono = mono as ConnectorMono; if (connMono != null) { connMono.Open(); } else { Debug.LogErrorFormat("Connector {0} doesn't have connectorMono!!", connectorProp.name); } } else { parentRoom.Show(false); } } return(result); } else { //get in if (ConnectType == CONNECTOR_TYPE.ONE_WAY_OUT) { return(false); } if (otherConnector != null) { otherConnector.OnPlayerExit(pawn.controller); } Property.Connector thisProp = connectorProp; Property.Connector otherProp = otherConnector == null ? null : otherConnector.connectorProp; if (thisProp.IsPortal || otherProp == null || otherProp.IsPortal) { //transport Transform tran = ((ConnectorMono)mono).FindPlayerStart(); //parentRoom.OnPawnEnter(pawn); mono.Show(true); parentRoom.Show(true); pawn.Transport(tran.position, tran.rotation); OnPlayerEnter(pawn.controller); Debug.LogFormat("pawn enter {0} pos:{1},{2},{3}", parentRoom.RoomProp.roomName, LogicPosition.x, LogicPosition.y, LogicPosition.z); } else { //set room transform, then hide the door Transform tran = otherConnector.actorTrans; Quaternion targetRot = flipRot * tran.rotation; Quaternion delta = targetRot * Quaternion.Inverse(Quaternion.Euler(socket.LocalEulerRotation)); Vector3 vec = delta * -socket.LocalPosition + tran.position; parentRoom.SetTransform(vec, delta); mono.Show(false); parentRoom.Show(true); } return(true); } }
public Connector(Property.Connector prop) : base(prop) { ConnectType = prop.ConnectType; }