mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交
This commit is contained in:
@@ -5,5 +5,14 @@ namespace Script.battle
|
||||
public abstract class GBaseMode<T> : JNGSyncFrame<T>
|
||||
{
|
||||
|
||||
public override void OnSyncUpdate(int dt, JNFrameInfo frame, T input)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void OnLateSyncUpdate(int dt, JNFrameInfo frame, T input)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
34
JNFrame/Assets/Game/Script/battle/mode/GWorldSync01Mode.cs
Normal file
34
JNFrame/Assets/Game/Script/battle/mode/GWorldSync01Mode.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using Game.Script.battle.mode.GWorldSync01ModeScript;
|
||||
using Script.battle;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Script.battle.mode
|
||||
{
|
||||
public class GWorldSync01ModeInput
|
||||
{
|
||||
//控制玩家的唯一标识
|
||||
public long Key;
|
||||
public Boolean IsAdd; //是否加入游戏
|
||||
|
||||
}
|
||||
public class GWorldSync01Mode : GBaseMode<GWorldSync01ModeInput>
|
||||
{
|
||||
|
||||
|
||||
public GameObject player;
|
||||
|
||||
public override void OnSyncUpdate(int dt, JNFrameInfo frame, GWorldSync01ModeInput input)
|
||||
{
|
||||
base.OnSyncUpdate(dt, frame, input);
|
||||
|
||||
if (input != null && input.IsAdd)
|
||||
{
|
||||
//加入一个玩家
|
||||
var player1 = Instantiate(this.player, this.transform);
|
||||
player1.GetComponent<PlayerBot>().key = input.Key;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5536f3a48beb4a27b08820e600cf6982
|
||||
timeCreated: 1706841871
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1cf1311852d0d34b9a93318beafc3bd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Game.Script.battle.mode;
|
||||
using Game.Script.battle.mode.GWorldSync01ModeScript;
|
||||
using UnityEngine;
|
||||
|
||||
public class GWorldSync01UI : MonoBehaviour
|
||||
{
|
||||
|
||||
public GWorldSync01Mode mode;
|
||||
|
||||
//玩家所属的Id
|
||||
private long playerId;
|
||||
|
||||
public Camera cam;
|
||||
public LayerMask mask;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
playerId = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
//添加玩家
|
||||
mode.NInput.Key = this.playerId;
|
||||
mode.NInput.IsAdd = true;
|
||||
}
|
||||
|
||||
|
||||
//控制玩家
|
||||
public void Update()
|
||||
{
|
||||
var players = mode.GetComponentsInChildren<PlayerBot>();
|
||||
|
||||
foreach (var playerBot in players.Where(item => item.key == playerId))
|
||||
{
|
||||
|
||||
Vector3 newPosition = Vector3.zero;
|
||||
bool positionFound = false;
|
||||
|
||||
RaycastHit hit;
|
||||
if (cam.pixelRect.Contains(Input.mousePosition) && Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, mask)) {
|
||||
newPosition = hit.point;
|
||||
positionFound = true;
|
||||
}
|
||||
|
||||
if (positionFound) {
|
||||
playerBot.NInput.IsPos = true;
|
||||
playerBot.NInput.x = newPosition.x;
|
||||
playerBot.NInput.y = newPosition.y;
|
||||
playerBot.NInput.z = newPosition.z;
|
||||
// if (onlyOnDoubleClick) {
|
||||
// for (int i = 0; i < ais.Length; i++) {
|
||||
// if (ais[i] != null) ais[i].SearchPath();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e61b94b311b605b4195e022f5370e558
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Game.Plugins.App.Sync;
|
||||
using Pathfinding;
|
||||
using UnityEngine;
|
||||
using Game.Script.battle.mode;
|
||||
|
||||
namespace Game.Script.battle.mode.GWorldSync01ModeScript
|
||||
{
|
||||
public class PlayerBotInput
|
||||
{
|
||||
//移动
|
||||
public Boolean IsPos;
|
||||
public float x;
|
||||
public float y;
|
||||
public float z;
|
||||
}
|
||||
public class PlayerBot : JNGSyncFrame<PlayerBotInput>
|
||||
{
|
||||
|
||||
//移动控制
|
||||
private AIDestinationSetter move;
|
||||
public long key;
|
||||
|
||||
public override void OnSyncLoad()
|
||||
{
|
||||
base.OnSyncLoad();
|
||||
this.move = this.GetComponent<AIDestinationSetter>();
|
||||
}
|
||||
|
||||
//设置目标位置
|
||||
public void SetTarget(Vector3 pos)
|
||||
{
|
||||
this.move.SetTarget(pos);
|
||||
}
|
||||
|
||||
public override void OnSyncUpdate(int dt, JNFrameInfo frame, PlayerBotInput input)
|
||||
{
|
||||
base.OnSyncUpdate(dt, frame, input);
|
||||
if (input != null && input.IsPos)
|
||||
{
|
||||
//设置位置
|
||||
this.SetTarget(new Vector3(input.x,input.y,input.z));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//这里直接每帧调用更新位置 理论上 下面这些代码是写在UI上的 现在为了方便直接调了
|
||||
private void Update()
|
||||
{
|
||||
UpdateTargetPosition();
|
||||
}
|
||||
|
||||
public void UpdateTargetPosition () {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92bb9edc6770cfd47830748c4ca30c59
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user