Give MoveCommand to selected units only
This commit is contained in:
parent
ec10c43228
commit
77db237e9e
|
@ -144,6 +144,7 @@ MonoBehaviour:
|
|||
syncDirection: 0
|
||||
syncMode: 0
|
||||
syncInterval: 0
|
||||
_unitMovement: {fileID: 8681090027785358193}
|
||||
_onSelect:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
|
|
|
@ -803,8 +803,9 @@ GameObject:
|
|||
m_Component:
|
||||
- component: {fileID: 1784456514}
|
||||
- component: {fileID: 1784456513}
|
||||
- component: {fileID: 1784456515}
|
||||
m_Layer: 0
|
||||
m_Name: UnitSelectionHandler
|
||||
m_Name: UnitHandlers
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
|
@ -824,7 +825,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
_layerMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_Bits: 1
|
||||
--- !u!4 &1784456514
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -840,6 +841,22 @@ Transform:
|
|||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1784456515
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1784456512}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 74e28a0cf1a767d498b804650f3b1ea1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_unitSelectionHandler: {fileID: 1784456513}
|
||||
_layerMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 1
|
||||
--- !u!1 &1896718083
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -1152,6 +1169,6 @@ SceneRoots:
|
|||
- {fileID: 1954283568}
|
||||
- {fileID: 9051835}
|
||||
- {fileID: 1904145807}
|
||||
- {fileID: 1784456514}
|
||||
- {fileID: 168675456}
|
||||
- {fileID: 578241694}
|
||||
- {fileID: 1784456514}
|
||||
|
|
|
@ -7,9 +7,12 @@ using UnityEngine.Serialization;
|
|||
|
||||
public class Unit : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] private UnitMovement _unitMovement;
|
||||
[SerializeField] private UnityEvent _onSelect;
|
||||
[SerializeField] private UnityEvent _onDeSelect;
|
||||
|
||||
public UnitMovement UnitMovement => _unitMovement;
|
||||
|
||||
#region Client
|
||||
|
||||
[Client]
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class UnitCommandGiver : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private UnitSelectionHandler _unitSelectionHandler;
|
||||
[SerializeField] private LayerMask _layerMask;
|
||||
|
||||
private Camera _camera;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_camera = Camera.main;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!Mouse.current.rightButton.wasPressedThisFrame) return;
|
||||
|
||||
Ray ray = _camera.ScreenPointToRay(Mouse.current.position.ReadValue());
|
||||
|
||||
if (!Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, _layerMask)) return;
|
||||
|
||||
TryMove(hit.point);
|
||||
}
|
||||
|
||||
private void TryMove(Vector3 destination)
|
||||
{
|
||||
foreach (var selectedUnit in _unitSelectionHandler.SelectedUnits)
|
||||
{
|
||||
selectedUnit.UnitMovement.CmdMove(destination);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 74e28a0cf1a767d498b804650f3b1ea1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -12,7 +12,7 @@ public class UnitMovement : NetworkBehaviour
|
|||
|
||||
#region Server
|
||||
|
||||
[Command] private void CmdMove(Vector3 destination)
|
||||
[Command] public void CmdMove(Vector3 destination)
|
||||
{
|
||||
if (NavMesh.SamplePosition(destination, out NavMeshHit hit, 1f, NavMesh.AllAreas))
|
||||
{
|
||||
|
@ -21,28 +21,4 @@ public class UnitMovement : NetworkBehaviour
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Client
|
||||
|
||||
public override void OnStartAuthority()
|
||||
{
|
||||
base.OnStartAuthority();
|
||||
_camera = Camera.main;
|
||||
_mouse = Mouse.current;
|
||||
}
|
||||
|
||||
[ClientCallback]
|
||||
private void Update()
|
||||
{
|
||||
if (!isOwned) return;
|
||||
if (!_mouse.rightButton.wasPressedThisFrame) return;
|
||||
Ray ray = _camera.ScreenPointToRay(_mouse.position.ReadValue());
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity))
|
||||
{
|
||||
CmdMove(hit.point);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -10,7 +10,7 @@ public class UnitSelectionHandler : MonoBehaviour
|
|||
[SerializeField] private LayerMask _layerMask;
|
||||
private Camera _mainCamera;
|
||||
|
||||
private readonly List<Unit> _selectedUnits = new();
|
||||
public List<Unit> SelectedUnits { get; } = new();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
@ -32,12 +32,12 @@ public class UnitSelectionHandler : MonoBehaviour
|
|||
|
||||
private void ClearSelectedUnits()
|
||||
{
|
||||
foreach (Unit selectedUnit in _selectedUnits)
|
||||
foreach (Unit selectedUnit in SelectedUnits)
|
||||
{
|
||||
selectedUnit.DeSelect();
|
||||
}
|
||||
|
||||
_selectedUnits.Clear();
|
||||
SelectedUnits.Clear();
|
||||
}
|
||||
|
||||
private void ClearSelectionArea()
|
||||
|
@ -50,9 +50,9 @@ public class UnitSelectionHandler : MonoBehaviour
|
|||
|
||||
if (!unit.isOwned) return;
|
||||
|
||||
_selectedUnits.Add(unit);
|
||||
SelectedUnits.Add(unit);
|
||||
|
||||
foreach (Unit selectedUnit in _selectedUnits)
|
||||
foreach (Unit selectedUnit in SelectedUnits)
|
||||
{
|
||||
selectedUnit.Select();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,61 @@
|
|||
"key": "lightmapping.autoUnwrapLightmapUV",
|
||||
"value": "{\"m_Value\":true}"
|
||||
},
|
||||
{
|
||||
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||
"key": "mesh.newShapesSnapToGrid",
|
||||
"value": "{\"m_Value\":true}"
|
||||
},
|
||||
{
|
||||
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||
"key": "mesh.meshColliderIsConvex",
|
||||
"value": "{\"m_Value\":false}"
|
||||
},
|
||||
{
|
||||
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||
"key": "editor.autoRecalculateCollisions",
|
||||
"value": "{\"m_Value\":false}"
|
||||
},
|
||||
{
|
||||
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||
"key": "experimental.enabled",
|
||||
"value": "{\"m_Value\":false}"
|
||||
},
|
||||
{
|
||||
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||
"key": "UnityEngine.ProBuilder.ProBuilderEditor-isUtilityWindow",
|
||||
"value": "{\"m_Value\":false}"
|
||||
},
|
||||
{
|
||||
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||
"key": "editor.toolbarIconGUI",
|
||||
"value": "{\"m_Value\":false}"
|
||||
},
|
||||
{
|
||||
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||
"key": "editor.backFaceSelectEnabled",
|
||||
"value": "{\"m_Value\":false}"
|
||||
},
|
||||
{
|
||||
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||
"key": "editor.showSceneInfo",
|
||||
"value": "{\"m_Value\":false}"
|
||||
},
|
||||
{
|
||||
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||
"key": "ShapeComponent.ResetSettings",
|
||||
"value": "{\"m_Value\":false}"
|
||||
},
|
||||
{
|
||||
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||
"key": "editor.showEditorNotifications",
|
||||
"value": "{\"m_Value\":false}"
|
||||
},
|
||||
{
|
||||
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||
"key": "ShapeComponent.SettingsEnabled",
|
||||
"value": "{\"m_Value\":false}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEngine.ProBuilder.LogLevel, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "log.level",
|
||||
|
@ -30,6 +85,86 @@
|
|||
"type": "UnityEngine.ProBuilder.SemVer, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "preferences.version",
|
||||
"value": "{\"m_Value\":{\"m_Major\":5,\"m_Minor\":1,\"m_Patch\":1,\"m_Build\":-1,\"m_Type\":\"\",\"m_Metadata\":\"\",\"m_Date\":\"\"}}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEngine.ProBuilder.PivotLocation, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "mesh.newShapePivotLocation",
|
||||
"value": "{\"m_Value\":1}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEngine.Rendering.ShadowCastingMode, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "mesh.shadowCastingMode",
|
||||
"value": "{\"m_Value\":1}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEngine.Material, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "mesh.userMaterial",
|
||||
"value": "{\"m_Value\":{\"instanceID\":0}}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEditor.StaticEditorFlags, UnityEditor.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "mesh.defaultStaticEditorFlags",
|
||||
"value": "{\"m_Value\":0}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEngine.ProBuilder.ColliderType, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "mesh.newShapeColliderType",
|
||||
"value": "{\"m_Value\":2}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEngine.ProBuilder.UnwrapParameters, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "lightmapping.defaultLightmapUnwrapParameters",
|
||||
"value": "{\"m_Value\":{\"m_HardAngle\":88.0,\"m_PackMargin\":20.0,\"m_AngleError\":8.0,\"m_AreaError\":15.0}}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEngine.ProBuilder.RectSelectMode, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "editor.dragSelectRectMode",
|
||||
"value": "{\"m_Value\":0}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEngine.ProBuilder.SelectionModifierBehavior, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "editor.rectSelectModifier",
|
||||
"value": "{\"m_Value\":2}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEngine.ProBuilder.SelectMode, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "editor.selectMode",
|
||||
"value": "{\"m_Value\":1}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEngine.ProBuilder.SelectMode, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "editor.lastMeshSelectMode",
|
||||
"value": "{\"m_Value\":2}"
|
||||
},
|
||||
{
|
||||
"type": "System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||
"key": "ShapeBuilder.ActiveShapeIndex",
|
||||
"value": "{\"m_Value\":0}"
|
||||
},
|
||||
{
|
||||
"type": "System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||
"key": "ShapeBuilder.LastPivotLocation",
|
||||
"value": "{\"m_Value\":1}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEngine.Vector3, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "ShapeBuilder.LastPivotPosition",
|
||||
"value": "{\"m_Value\":{\"x\":0.0,\"y\":0.0,\"z\":0.0}}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEngine.Vector3, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "ShapeBuilder.LastSize",
|
||||
"value": "{\"m_Value\":{\"x\":1.2949085235595704,\"y\":0.0,\"z\":1.3470239639282227}}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEngine.Quaternion, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "ShapeBuilder.LastRotation",
|
||||
"value": "{\"m_Value\":{\"x\":0.0,\"y\":0.0,\"z\":0.0,\"w\":1.0}}"
|
||||
},
|
||||
{
|
||||
"type": "UnityEngine.ProBuilder.Shapes.Shape, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||
"key": "ShapeBuilder.Sprite",
|
||||
"value": "{}"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue