Skip to content

Commit

Permalink
初步将 Space Shooter 和登录模块、房间系统整合到一个场景中
Browse files Browse the repository at this point in the history
  • Loading branch information
Caizc committed Sep 7, 2017
1 parent edf8644 commit 72986bd
Show file tree
Hide file tree
Showing 22 changed files with 180 additions and 13 deletions.
Binary file added Assets/Prefabs/Environment.prefab
Binary file not shown.
9 changes: 9 additions & 0 deletions Assets/Prefabs/Environment.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Prefabs/GameController.prefab
Binary file not shown.
9 changes: 9 additions & 0 deletions Assets/Prefabs/GameController.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Prefabs/Player.prefab
Binary file not shown.
9 changes: 9 additions & 0 deletions Assets/Prefabs/Player.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Prefabs/RegularCamera.prefab
Binary file not shown.
9 changes: 9 additions & 0 deletions Assets/Prefabs/RegularCamera.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Prefabs/UICamera.prefab
Binary file not shown.
9 changes: 9 additions & 0 deletions Assets/Prefabs/UICamera.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Assets/Resources/LoginPanel.prefab
Binary file not shown.
8 changes: 7 additions & 1 deletion Assets/Scripts/core/Root.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ public class Root : MonoBehaviour
{
void Start()
{
DontDestroyOnLoad(this);
Application.runInBackground = true;

// 打开登录面板
PanelMgr.instance.OpenPanel<LoginPanel>("");

Debug.Log("Application has been started up!");
}

void Update()
void FixedUpdate()
{
// 固定时间间隔更新,处理消息队列中的消息
NetMgr.Update();
}
}
9 changes: 6 additions & 3 deletions Assets/Scripts/core/net/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,15 @@ public bool Send(ProtocolBase protocol, MsgDistribution.Delegate cb)
return Send(protocol, cbName, cb);
}


/// <summary>
/// 每个逻辑帧处理消息分发和向服务端发送心跳消息
/// </summary>
public void Update()
{
//消息
// 消息分发
msgDist.Update();
//心跳

// 心跳
if (status == Status.Connected)
{
if (Time.time - lastTickTime > heartBeatTime)
Expand Down
9 changes: 7 additions & 2 deletions Assets/Scripts/core/net/MsgDistribution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public class MsgDistribution

private Dictionary<string, Delegate> onceDict = new Dictionary<string, Delegate>();

//Update
/// <summary>
/// 每一逻辑帧处理消息分发
/// </summary>
public void Update()
{
for (int i = 0; i < num; i++)
Expand All @@ -43,7 +45,10 @@ public void Update()
}
}

// 消息分发
/// <summary>
/// 向各监听者分发消息
/// </summary>
/// <param name="protocol"></param>
public void DispatchMsgEvent(ProtocolBase protocol)
{
string name = protocol.GetName();
Expand Down
11 changes: 7 additions & 4 deletions Assets/Scripts/gameplay/GameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class GameController : MonoBehaviour

void Start()
{
DontDestroyOnLoad(this);

_isGameOver = false;
_isRestart = false;
gameOverText.enabled = false;
Expand All @@ -41,16 +43,17 @@ void Update()
{
if (_isRestart)
{
#if UNITY_EDITOR
// TODO: 这里可不能重新加载场景,要改为还原现场,或者说重置所有对象的状态

if (Input.GetKeyDown(KeyCode.R))
{
SceneManager.LoadScene("Main");
SceneManager.LoadScene("Online");
}
#endif

#if UNITY_ANDROID || UNITY_IOS
if (Input.touchCount != 0)
{
SceneManager.LoadScene("Main");
SceneManager.LoadScene("Online");
}
#endif
}
Expand Down
15 changes: 14 additions & 1 deletion Assets/Scripts/gameplay/PlayerController.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
using UnityEngine;

/// <summary>
/// 地图边界
/// </summary>
[System.SerializableAttribute]
public class Boundary
{
public float xMin, xMax, zMin, zMax;
}

/// <summary>
/// 角色控制器
/// </summary>
public class PlayerController : MonoBehaviour
{
// 移动速度
[SerializeField] private float speed;
// 转向速度
[SerializeField] private float rotateSpeed;
[SerializeField] private Boundary boundary;
// 机身倾斜系数
[SerializeField] private float tilt;

[SerializeField] private GameObject shot;
[SerializeField] private Transform shotSpawn;
[SerializeField] private float fireDelta = 0.25f;

[SerializeField] private ParticleSystem particleSystem1;
[SerializeField] private ParticleSystem particleSystem1;
[SerializeField] private ParticleSystem particleSystem2;

private Rigidbody _rigidbody;
Expand All @@ -26,7 +35,9 @@ public class PlayerController : MonoBehaviour
private float _myTime = 0.0f;
private float _nextFire = 0.25f;

// 移动增量
[HideInInspector] public Vector2 deltaMovement;
// 转向增量
[HideInInspector] public Vector2 deltaRotation;

public enum InputForcedMode
Expand Down Expand Up @@ -69,12 +80,14 @@ void FixedUpdate()
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
_rigidbody.velocity = movement * speed;

// 限制角色移动范围
_rigidbody.position = new Vector3(
Mathf.Clamp(_rigidbody.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp(_rigidbody.position.z, boundary.zMin, boundary.zMax)
);

// 左右平移时稍微倾斜一下机身(绕 z 轴)
_rigidbody.rotation = Quaternion.Euler(0.0f, 0.0f, _rigidbody.velocity.x * -tilt);

// 旋转方向
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/panel/RoomPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ public void OnStartBack(ProtocolBase protocol)
}
}


// TODO: 这里开始战斗
public void RecvFight(ProtocolBase protocol)
{
ProtocolBytes proto = (ProtocolBytes)protocol;
MultiBattle.instance.StartBattle(proto);
// MultiBattle.instance.StartBattle(proto);
Close();
}

Expand Down
Binary file added Assets/Textures/title-space.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions Assets/Textures/title-space.jpg.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Assets/_Scenes/Online.unity
Binary file not shown.
Binary file modified Assets/_Scenes/Standalone.unity
Binary file not shown.
Binary file modified ProjectSettings/EditorBuildSettings.asset
Binary file not shown.

0 comments on commit 72986bd

Please sign in to comment.