Unit selection

This commit is contained in:
Stedd 2023-09-03 20:12:57 +02:00
parent 0e27831cf7
commit ec10c43228
11 changed files with 571 additions and 0 deletions

View File

@ -13,6 +13,8 @@ GameObject:
- component: {fileID: 2439696136893951540}
- component: {fileID: 6123744421715133446}
- component: {fileID: 8681090027785358193}
- component: {fileID: 7770459125504658227}
- component: {fileID: 5384588383080796762}
m_Layer: 0
m_Name: Unit
m_TagString: Untagged
@ -34,6 +36,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 4352769845730777867}
- {fileID: 6948037795542299232}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5351038950168726961
@ -126,6 +129,157 @@ MonoBehaviour:
syncMode: 0
syncInterval: 0
_navMeshAgent: {fileID: 6123744421715133446}
--- !u!114 &7770459125504658227
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5181188659209802552}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2a7a4f02bd4e3e34b92eebf0b754ccdc, type: 3}
m_Name:
m_EditorClassIdentifier:
syncDirection: 0
syncMode: 0
syncInterval: 0
_onSelect:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 6358282482050904411}
m_TargetAssemblyTypeName: UnityEngine.GameObject, UnityEngine
m_MethodName: SetActive
m_Mode: 6
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 1
m_CallState: 2
_onDeSelect:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 6358282482050904411}
m_TargetAssemblyTypeName: UnityEngine.GameObject, UnityEngine
m_MethodName: SetActive
m_Mode: 6
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!65 &5384588383080796762
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5181188659209802552}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 2.749671, y: 2.2733965, z: 3.884873}
m_Center: {x: -0.00000047683716, y: 1.1574342, z: 0.7134073}
--- !u!1 &6358282482050904411
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6948037795542299232}
- component: {fileID: 1194532061746196526}
m_Layer: 0
m_Name: UnitHighlight
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!4 &6948037795542299232
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6358282482050904411}
serializedVersion: 2
m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 4.26, y: 4.26, z: 4.26}
m_ConstrainProportionsScale: 1
m_Children: []
m_Father: {fileID: 2385999535964237451}
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!212 &1194532061746196526
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6358282482050904411}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: -2413806693520163455, guid: aabb129e84861924788362fbbdd3a6fc,
type: 3}
m_Color: {r: 0.025763188, g: 1, b: 0.0047169924, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!1001 &4315183336175566048
PrefabInstance:
m_ObjectHideFlags: 0

View File

@ -793,6 +793,53 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 41f84591ce72545258ea98cb7518d8b9, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1784456512
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1784456514}
- component: {fileID: 1784456513}
m_Layer: 0
m_Name: UnitSelectionHandler
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1784456513
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: 3cb0958ad41f7384d870591fbd0df32a, type: 3}
m_Name:
m_EditorClassIdentifier:
_layerMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!4 &1784456514
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1784456512}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1896718083
GameObject:
m_ObjectHideFlags: 0
@ -1107,3 +1154,4 @@ SceneRoots:
- {fileID: 1904145807}
- {fileID: 168675456}
- {fileID: 578241694}
- {fileID: 1784456514}

View File

@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using Mirror;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Serialization;
public class Unit : NetworkBehaviour
{
[SerializeField] private UnityEvent _onSelect;
[SerializeField] private UnityEvent _onDeSelect;
#region Client
[Client]
public void Select()
{
if (!isOwned) return;
_onSelect?.Invoke();
}
[Client]
public void DeSelect()
{
if (!isOwned) return;
_onDeSelect?.Invoke();
}
#endregion
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2a7a4f02bd4e3e34b92eebf0b754ccdc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,60 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.InputSystem;
public class UnitSelectionHandler : MonoBehaviour
{
[SerializeField] private LayerMask _layerMask;
private Camera _mainCamera;
private readonly List<Unit> _selectedUnits = new();
private void Start()
{
_mainCamera = Camera.main;
}
private void Update()
{
if (Mouse.current.leftButton.wasPressedThisFrame)
{
ClearSelectedUnits();
//Start selection area
}
else if (Mouse.current.leftButton.wasReleasedThisFrame)
{
ClearSelectionArea();
}
}
private void ClearSelectedUnits()
{
foreach (Unit selectedUnit in _selectedUnits)
{
selectedUnit.DeSelect();
}
_selectedUnits.Clear();
}
private void ClearSelectionArea()
{
Ray ray = _mainCamera.ScreenPointToRay(Mouse.current.position.ReadValue());
if (!Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, _layerMask)) return;
if (!hit.collider.TryGetComponent(out Unit unit)) return;
if (!unit.isOwned) return;
_selectedUnits.Add(unit);
foreach (Unit selectedUnit in _selectedUnits)
{
selectedUnit.Select();
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3cb0958ad41f7384d870591fbd0df32a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/Sprites.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0f20d7b35fe53994493990b9dcf31a19
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

BIN
Assets/Sprites/Circle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

@ -0,0 +1,242 @@
fileFormatVersion: 2
guid: aabb129e84861924788362fbbdd3a6fc
TextureImporter:
internalIDToNameTable:
- first:
213: -2413806693520163455
second: Circle
externalObjects: {}
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 2
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 256
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: 0
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 1
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: iPhone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites:
- serializedVersion: 2
name: Circle
rect:
serializedVersion: 2
x: 0
y: 0
width: 256
height: 256
alignment: 0
pivot: {x: 0.5, y: 0.5}
border: {x: 0, y: 0, z: 0, w: 0}
outline:
- - {x: 33, y: 128}
- {x: -33, y: 128}
- {x: -95, y: 95}
- {x: -128, y: 33}
- {x: -128, y: -33}
- {x: -95, y: -95}
- {x: -33, y: -128}
- {x: 33, y: -128}
- {x: 95, y: -95}
- {x: 128, y: -33}
- {x: 128, y: 33}
- {x: 95, y: 95}
physicsShape:
- - {x: 0, y: 128}
- {x: -39, y: 121}
- {x: -75, y: 103}
- {x: -103, y: 75}
- {x: -121, y: 39}
- {x: -128, y: 0}
- {x: -121, y: -39}
- {x: -103, y: -75}
- {x: -75, y: -103}
- {x: -39, y: -121}
- {x: 0, y: -128}
- {x: 39, y: -121}
- {x: 75, y: -103}
- {x: 103, y: -75}
- {x: 121, y: -39}
- {x: 128, y: 0}
- {x: 121, y: 39}
- {x: 103, y: 75}
- {x: 75, y: 103}
- {x: 39, y: 121}
tessellationDetail: 0
bones: []
spriteID: 18d3544e99f608ed0800000000000000
internalID: -2413806693520163455
vertices: []
indices:
edges: []
weights: []
outline:
- - {x: 33, y: 128}
- {x: -33, y: 128}
- {x: -95, y: 95}
- {x: -128, y: 33}
- {x: -128, y: -33}
- {x: -95, y: -95}
- {x: -33, y: -128}
- {x: 33, y: -128}
- {x: 95, y: -95}
- {x: 128, y: -33}
- {x: 128, y: 33}
- {x: 95, y: 95}
physicsShape:
- - {x: 0, y: 128}
- {x: -39, y: 121}
- {x: -75, y: 103}
- {x: -103, y: 75}
- {x: -121, y: 39}
- {x: -128, y: 0}
- {x: -121, y: -39}
- {x: -103, y: -75}
- {x: -75, y: -103}
- {x: -39, y: -121}
- {x: 0, y: -128}
- {x: 39, y: -121}
- {x: 75, y: -103}
- {x: 103, y: -75}
- {x: 121, y: -39}
- {x: 128, y: 0}
- {x: 121, y: 39}
- {x: 103, y: 75}
- {x: 75, y: 103}
- {x: 39, y: 121}
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable:
Circle: -2413806693520163455
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,5 +1,6 @@
{
"dependencies": {
"com.unity.2d.sprite": "1.0.0",
"com.unity.ai.navigation": "1.1.4",
"com.unity.cinemachine": "2.9.7",
"com.unity.ide.rider": "3.0.24",

View File

@ -1,5 +1,11 @@
{
"dependencies": {
"com.unity.2d.sprite": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.ai.navigation": {
"version": "1.1.4",
"depth": 0,