hand
_1_7_116
4
返回栏目
1k
0.2k
0.5k
0.1k
0k
0.2k
0k
0.7k
0k
0k
0.4k
0.1k
4k
0.2k
0.1k
2k
0.2k
0.2k
0k
0k
0.5k
0k
0.9k
0.1k
1k
0.9k
2k
1k
2k
0.9k
1k
0k
1k
0k
1k
1k
1k
1k
0k
1k
1k
1k
0k
3k
1k
0k
0.3k
1k
0.3k
0.9k
0k
8k
9k
6k
2k
1k
2k
1k
1k
2k
0.6k
1k
0.6k
1k
0.5k
0.2k
2k
2k
2k
1k
2k
0k
0.8k
0.8k
1k
0k
0k
0k
0k
0k
0k
0k
0k
0.3k
0.4k
0.8k
0.3k
5k
1k
3k
7k
6k
3k
3k
1k
0.2k
2k
3k
2k
0.4k
0.5k
3k
2k
7k
3k
4k
2k
1k
6k
6k
1k
1k
0.9k
0.2k
0.3k
0.9k
1k
0k
0.8k
2k
0k
0.4k
0.1k
1k
0.9k
0.2k
1k
1k
0.5k
0k
0k
0.4k
4k
0.4k
2k
3k
1k
1k
1k
3k
5k
0k
1k
2k
0.5k
0k
1k
0k
1k
0.5k
0.8k
返回Unity - 游戏引擎栏目
作者:
贺及楼
成为作者
更新日期:2023-09-17 10:58:53
public class PlayerManager : BaseManager
{
public PlayerManager(GameFacade facade) : base(facade) { }
private UserData userData;
private Dictionary<RoleType, RoleData> roleDataDict = new Dictionary<RoleType, RoleData>();
private Transform rolePositions;
private RoleType currentRoleType;
private GameObject currentRoleGameObject;
private GameObject playerSyncRequest;
private GameObject remoteRoleGameObject;
private ShootRequest shootRequest;
private AttackRequest attackRequest;
public void UpdateResult(int totalCount,int winCount){}
public void SetCurrentRoleType(RoleType rt){}
public UserData UserData{set { userData = value; }get { return userData; }}
public override void OnInit(){}
private void InitRoleDataDict(){}
public void SpawnRoles(){}
public GameObject GetCurrentRoleGameObject(){}
private RoleData GetRoleData(RoleType rt){}
public void AddControlScript(){}
public void CreateSyncRequest(){}
public void Shoot(箭预制体,V3位置, V3方向){}
public void RemoteShoot(RoleType rt, V3位置, V3方向){}
public void SendAttack(伤害){}
public void GameOver() {}
}
public class PlayerManager : BaseManager
{
public PlayerManager(GameFacade facade) : base(facade) { }
private UserData userData;
private Dictionary<RoleType, RoleData> roleDataDict = new Dictionary<RoleType, RoleData>();
private Transform rolePositions;
private RoleType currentRoleType;
private GameObject currentRoleGameObject;
private GameObject playerSyncRequest;
private GameObject remoteRoleGameObject;
private ShootRequest shootRequest;
private AttackRequest attackRequest;
public void UpdateResult(int totalCount,int winCount){}
public void SetCurrentRoleType(RoleType rt){}
public UserData UserData{set { userData = value; }get { return userData; }}
public override void OnInit(){}
private void InitRoleDataDict(){}
public void SpawnRoles(){}
public GameObject GetCurrentRoleGameObject(){}
private RoleData GetRoleData(RoleType rt){}
public void AddControlScript(){}
public void CreateSyncRequest(){}
public void Shoot(GameObject arrowPrefab,Vector3 pos,Quaternion rotation){}
public void RemoteShoot(RoleType rt, Vector3 pos, Vector3 rotation){}
public void SendAttack(int damage){}
public void GameOver() {}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Common;
public class PlayerManager : BaseManager
{
public PlayerManager(GameFacade facade) : base(facade) { }
private UserData userData;
private Dictionary<RoleType, RoleData> roleDataDict = new Dictionary<RoleType, RoleData>();
private Transform rolePositions;
private RoleType currentRoleType;
private GameObject currentRoleGameObject;
private GameObject playerSyncRequest;
private GameObject remoteRoleGameObject;
private ShootRequest shootRequest;
private AttackRequest attackRequest;
public void UpdateResult(int totalCount,int winCount)
{
userData.TotalCount = totalCount;
userData.WinCount = winCount;
}
public void SetCurrentRoleType(RoleType rt)
{
currentRoleType = rt;
}
public UserData UserData
{
set { userData = value; }
get { return userData; }
}
public override void OnInit()
{
rolePositions = GameObject.Find("RolePositions").transform;
InitRoleDataDict();
}
private void InitRoleDataDict()
{
roleDataDict.Add(RoleType.Blue, new RoleData(RoleType.Blue, "Hunter_BLUE", "Arrow_BLUE", "Explosion_BLUE",rolePositions.Find("Position1")));
roleDataDict.Add(RoleType.Red, new RoleData(RoleType.Red, "Hunter_RED", "Arrow_RED", "Explosion_RED", rolePositions.Find("Position2")));
}
public void SpawnRoles()
{
foreach(RoleData rd in roleDataDict.Values)
{
GameObject go= GameObject.Instantiate(rd.RolePrefab, rd.SpawnPosition, Quaternion.identity);
go.tag = "Player";
if (rd.RoleType == currentRoleType)
{
currentRoleGameObject = go;
currentRoleGameObject.GetComponent<PlayerInfo>().isLocal = true;
}
else
{
remoteRoleGameObject = go;
}
}
}
public GameObject GetCurrentRoleGameObject()
{
return currentRoleGameObject;
}
private RoleData GetRoleData(RoleType rt)
{
RoleData rd = null;
roleDataDict.TryGetValue(rt, out rd);
return rd;
}
public void AddControlScript()
{
currentRoleGameObject.AddComponent<PlayerMove>();
PlayerAttack playerAttack = currentRoleGameObject.AddComponent<PlayerAttack>();
RoleType rt = currentRoleGameObject.GetComponent<PlayerInfo>().roleType;
RoleData rd = GetRoleData(rt);
playerAttack.arrowPrefab = rd.ArrowPrefab;
playerAttack.SetPlayerMng(this);
}
public void CreateSyncRequest()
{
playerSyncRequest=new GameObject("PlayerSyncRequest");
playerSyncRequest.AddComponent<MoveRequest>().SetLocalPlayer(currentRoleGameObject.transform, currentRoleGameObject.GetComponent<PlayerMove>())
.SetRemotePlayer(remoteRoleGameObject.transform);
shootRequest=playerSyncRequest.AddComponent<ShootRequest>();
shootRequest.playerMng = this;
attackRequest = playerSyncRequest.AddComponent<AttackRequest>();
}
public void Shoot(GameObject arrowPrefab,Vector3 pos,Quaternion rotation)
{
facade.PlayNormalSound(AudioManager.Sound_Timer);
GameObject.Instantiate(arrowPrefab, pos, rotation).GetComponent<Arrow>().isLocal = true;
shootRequest.SendRequest(arrowPrefab.GetComponent<Arrow>().roleType, pos, rotation.eulerAngles);
}
public void RemoteShoot(RoleType rt, Vector3 pos, Vector3 rotation)
{
GameObject arrowPrefab = GetRoleData(rt).ArrowPrefab;
Transform transform = GameObject.Instantiate(arrowPrefab).GetComponent<Transform>();
transform.position = pos;
transform.eulerAngles = rotation;
}
public void SendAttack(int damage)
{
attackRequest.SendRequest(damage);
}
public void GameOver()
{
//private GameObject currentRoleGameObject;
//private GameObject playerSyncRequest;
//private GameObject remoteRoleGameObject;
//private ShootRequest shootRequest;
//private AttackRequest attackRequest;
GameObject.Destroy(currentRoleGameObject);
GameObject.Destroy(playerSyncRequest);
GameObject.Destroy(remoteRoleGameObject);
shootRequest = null;
attackRequest = null;
}
}
Unity - 游戏引擎
整章节共151节
快分享给你的小伙伴吧 ~