mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交
This commit is contained in:
@@ -4,7 +4,12 @@ namespace Script.battle
|
||||
{
|
||||
public abstract class GBaseMode<T> : JNGSyncFrame<T>
|
||||
{
|
||||
|
||||
public override void OnSyncLoad()
|
||||
{
|
||||
base.OnSyncLoad();
|
||||
GBattleModeManager.Instance.root = this;
|
||||
}
|
||||
|
||||
public override void OnSyncUpdate(int dt, JNFrameInfo frame, T input)
|
||||
{
|
||||
|
||||
@@ -14,5 +19,6 @@ namespace Script.battle
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -31,13 +31,20 @@ namespace Script.battle
|
||||
//当前模式
|
||||
private GBattleMode _current = GBattleMode.Not;
|
||||
|
||||
//当前模式实体
|
||||
public Object root;
|
||||
|
||||
//获取当前模式
|
||||
public T GetMode<T>() where T : class
|
||||
{
|
||||
return root as T;
|
||||
}
|
||||
|
||||
//初始化管理器
|
||||
public void Init(GBattleModeInfo info)
|
||||
{
|
||||
|
||||
// App.Event.AddListener(JNSyncFrameEvent.CREATE,LoadScene);
|
||||
// App.Event.AddListener(JNSyncFrameEvent.CLEAR,UnloadScene);
|
||||
|
||||
}
|
||||
|
||||
//打开指定模式
|
||||
|
@@ -16,7 +16,8 @@ namespace Script.battle.mode
|
||||
|
||||
public override void OnSyncLoad()
|
||||
{
|
||||
|
||||
|
||||
base.OnSyncLoad();
|
||||
Physics = new();
|
||||
// BufferPool pool = new BufferPool();
|
||||
// Simulation.Create(pool, new DemoNarrowPhaseCallbacks(), new DemoPoseIntegratorCallbacks(new System.Numerics.Vector3(0, -10, 0)), new PositionFirstTimestepper());
|
||||
|
@@ -10,7 +10,8 @@ namespace Game.Script.battle.mode
|
||||
//控制玩家的唯一标识
|
||||
public long Key;
|
||||
public Boolean IsAdd; //是否加入游戏
|
||||
|
||||
public Boolean IsRobot; //是否是人机
|
||||
|
||||
}
|
||||
public class GWorldSync01Mode : GBaseMode<GWorldSync01ModeInput>
|
||||
{
|
||||
@@ -27,6 +28,7 @@ namespace Game.Script.battle.mode
|
||||
//加入一个玩家
|
||||
var player1 = Instantiate(this.player, this.transform);
|
||||
player1.GetComponent<PlayerBot>().key = input.Key;
|
||||
player1.GetComponent<PlayerBot>().isRobot = input.IsRobot;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,34 +2,57 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Game.Plugins.App;
|
||||
using Game.Script.battle.mode;
|
||||
using Game.Script.battle.mode.GWorldSync01ModeScript;
|
||||
using Script.battle;
|
||||
using UnityEngine;
|
||||
|
||||
public class GWorldSync01UI : MonoBehaviour
|
||||
{
|
||||
|
||||
public GWorldSync01Mode mode;
|
||||
|
||||
//玩家所属的Id
|
||||
private long playerId;
|
||||
|
||||
public Camera cam;
|
||||
// public Camera cam;
|
||||
public LayerMask mask;
|
||||
|
||||
private void Start()
|
||||
|
||||
//获取模式
|
||||
private GWorldSync01Mode Mode => GBattleModeManager.Instance.GetMode<GWorldSync01Mode>();
|
||||
|
||||
//获取相机
|
||||
private Camera Cam => (Mode != null ? Mode.GetComponentInChildren<Camera>() : null);
|
||||
|
||||
//当前控制的玩家
|
||||
public long playerId = 0;
|
||||
|
||||
//添加玩家
|
||||
public void AddPlayer(Boolean isRobot = false)
|
||||
{
|
||||
playerId = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
//添加玩家
|
||||
mode.NInput.Key = this.playerId;
|
||||
mode.NInput.IsAdd = true;
|
||||
Mode.NInput.Key = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
Mode.NInput.IsAdd = true;
|
||||
Mode.NInput.IsRobot = isRobot;
|
||||
if (!isRobot)
|
||||
{
|
||||
playerId = Mode.NInput.Key;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//控制玩家
|
||||
public void Update()
|
||||
//点击加入人机
|
||||
public void OnClickJoinRobot()
|
||||
{
|
||||
var players = mode.GetComponentsInChildren<PlayerBot>();
|
||||
this.AddPlayer(true);
|
||||
}
|
||||
|
||||
//点击加入游戏
|
||||
public void OnClickJoinGame()
|
||||
{
|
||||
this.AddPlayer();
|
||||
}
|
||||
|
||||
//点击场景
|
||||
public void OnClickScene()
|
||||
{
|
||||
|
||||
var players = Mode.GetComponentsInChildren<PlayerBot>();
|
||||
|
||||
foreach (var playerBot in players.Where(item => item.key == playerId))
|
||||
{
|
||||
@@ -38,7 +61,7 @@ public class GWorldSync01UI : MonoBehaviour
|
||||
bool positionFound = false;
|
||||
|
||||
RaycastHit hit;
|
||||
if (cam.pixelRect.Contains(Input.mousePosition) && Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, mask)) {
|
||||
if (Cam.pixelRect.Contains(Input.mousePosition) && Physics.Raycast(Cam.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, mask)) {
|
||||
newPosition = hit.point;
|
||||
positionFound = true;
|
||||
}
|
||||
@@ -56,6 +79,11 @@ public class GWorldSync01UI : MonoBehaviour
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(this.Cam != null)
|
||||
this.Cam.enabled = !App.Sync.IsLoop;
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,8 @@ using Game.Plugins.App.Sync;
|
||||
using Pathfinding;
|
||||
using UnityEngine;
|
||||
using Game.Script.battle.mode;
|
||||
using Plugins.JNGame.Sync.Frame.game.Time;
|
||||
using Plugins.JNGame.Util;
|
||||
|
||||
namespace Game.Script.battle.mode.GWorldSync01ModeScript
|
||||
{
|
||||
@@ -21,16 +23,25 @@ namespace Game.Script.battle.mode.GWorldSync01ModeScript
|
||||
//移动控制
|
||||
private AIDestinationSetter move;
|
||||
public long key;
|
||||
public Boolean isRobot = false;
|
||||
public Vector3 target;
|
||||
|
||||
public override void OnSyncLoad()
|
||||
{
|
||||
base.OnSyncLoad();
|
||||
this.move = this.GetComponent<AIDestinationSetter>();
|
||||
//一秒中自动寻路
|
||||
SingletonUtil<JNFrameTime>.Instance.SetTimeout(() =>
|
||||
{
|
||||
if(this.isRobot)
|
||||
this.SetTarget(new Vector3(GetSync().nRandomInt(-30,50),1,GetSync().nRandomInt(-60,20)));
|
||||
},1000);
|
||||
}
|
||||
|
||||
//设置目标位置
|
||||
public void SetTarget(Vector3 pos)
|
||||
{
|
||||
this.target = pos;
|
||||
this.move.SetTarget(pos);
|
||||
}
|
||||
|
||||
@@ -42,6 +53,7 @@ namespace Game.Script.battle.mode.GWorldSync01ModeScript
|
||||
//设置位置
|
||||
this.SetTarget(new Vector3(input.x,input.y,input.z));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -0,0 +1,20 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Game.Script.battle.mode.GWorldSync01ModeScript;
|
||||
using Pathfinding;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerBotAIPath : AIPath
|
||||
{
|
||||
public override void OnTargetReached()
|
||||
{
|
||||
|
||||
base.OnTargetReached();
|
||||
//如果寻路结束 自己是AI 则 随机寻路
|
||||
if (this.GetComponent<PlayerBot>().isRobot)
|
||||
{
|
||||
this.GetComponent<PlayerBot>().SetTarget(new Vector3(GetSync().nRandomInt(-30,50),1,GetSync().nRandomInt(-60,20)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 459952d6a3efe0145b231a636579f95c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user