You need to sign in or sign up before continuing.
Commit d7bdc6ba authored by 15박보승's avatar 15박보승

Drawing agent's path with LineRenderer. Implementing Enemy Editor for editing roamingPath easily.

parent 4547eb1c
This diff is collapsed.
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEditor;
public class Enemy : Actor public class Enemy : Actor
{ {
...@@ -13,11 +14,30 @@ public class Enemy : Actor ...@@ -13,11 +14,30 @@ public class Enemy : Actor
[SerializeField] [SerializeField]
private List<Vector3> roamingPath; private List<Vector3> roamingPath;
public List<Vector3> RoamingPath { get { return roamingPath; } }
[SerializeField] [SerializeField]
private LayerMask blockEyesightMask; private LayerMask blockEyesightMask;
#if UNITY_EDITOR #if UNITY_EDITOR
void OnSceneGUI()
{
}
private void OnDrawGizmosSelected()
{
for (int i = 0; i < roamingPath.Count; i++)
{
EditorGUI.BeginChangeCheck();
Vector3 newPosition = Handles.FreeMoveHandle(roamingPath[i], Quaternion.identity, 1f, Vector3.one, Handles.CircleHandleCap);
if (EditorGUI.EndChangeCheck())
{
roamingPath[i] = newPosition;
}
}
}
private void OnDrawGizmos() private void OnDrawGizmos()
{ {
if (roamingPath.Count < 1) if (roamingPath.Count < 1)
...@@ -29,6 +49,8 @@ public class Enemy : Actor ...@@ -29,6 +49,8 @@ public class Enemy : Actor
{ {
Gizmos.DrawLine(roamingPath[i], roamingPath[(i + 1) % roamingPath.Count]); Gizmos.DrawLine(roamingPath[i], roamingPath[(i + 1) % roamingPath.Count]);
} }
} }
#endif #endif
......
...@@ -16,17 +16,25 @@ public abstract class PlayableCharacter : Actor ...@@ -16,17 +16,25 @@ public abstract class PlayableCharacter : Actor
public float shotRange = 5.0f; public float shotRange = 5.0f;
public LayerMask shotBlockMask; public LayerMask shotBlockMask;
protected LineRenderer lr; protected LineRenderer shotRangeRenderer;
[SerializeField]
protected LineRenderer pathRenderer;
private float r = 0.0f; private float r = 0.0f;
public bool isSelected = false; public bool isSelected = false;
private Transform target;
protected override void Start() protected override void Start()
{ {
base.Start(); base.Start();
lr = GetComponent<LineRenderer>(); if (shotRangeRenderer == null)
selectRing = transform.Find("SelectRing").gameObject; shotRangeRenderer = GetComponent<LineRenderer>();
if (pathRenderer == null)
pathRenderer = GetComponentInChildren<LineRenderer>();
if (selectRing == null)
selectRing = transform.Find("SelectRing").gameObject;
} }
protected virtual void Update() protected virtual void Update()
...@@ -47,7 +55,7 @@ public abstract class PlayableCharacter : Actor ...@@ -47,7 +55,7 @@ public abstract class PlayableCharacter : Actor
} }
vertices[360] = vertices[0]; vertices[360] = vertices[0];
lr.SetPositions(vertices); shotRangeRenderer.SetPositions(vertices);
} }
} }
...@@ -55,7 +63,7 @@ public abstract class PlayableCharacter : Actor ...@@ -55,7 +63,7 @@ public abstract class PlayableCharacter : Actor
public override void OnSelected() public override void OnSelected()
{ {
isSelected = true; isSelected = true;
lr.enabled = true; shotRangeRenderer.enabled = true;
selectRing?.SetActive(true); selectRing?.SetActive(true);
r = 0; r = 0;
} }
...@@ -63,7 +71,7 @@ public abstract class PlayableCharacter : Actor ...@@ -63,7 +71,7 @@ public abstract class PlayableCharacter : Actor
public override void OnUnselected() public override void OnUnselected()
{ {
isSelected = false; isSelected = false;
lr.enabled = false; shotRangeRenderer.enabled = false;
selectRing?.SetActive(false); selectRing?.SetActive(false);
} }
...@@ -73,6 +81,11 @@ public abstract class PlayableCharacter : Actor ...@@ -73,6 +81,11 @@ public abstract class PlayableCharacter : Actor
agent.MoveTo(destination); agent.MoveTo(destination);
} }
public void DrawPath()
{
}
protected abstract void DefaultControl(); protected abstract void DefaultControl();
protected abstract void AimingControl(); protected abstract void AimingControl();
} }
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
#if UNITY_EDITOR
[CustomEditor(typeof(Enemy))]
public class EnemyEditor : Editor
{
private Enemy enemy;
private void OnEnable()
{
enemy = (Enemy)target;
}
private void OnSceneGUI()
{
for (int i = 0; i < enemy.RoamingPath.Count; i++)
{
EditorGUI.BeginChangeCheck();
Vector3 newPosition = Handles.FreeMoveHandle(enemy.RoamingPath[i], Quaternion.identity, 1f, Vector3.one, Handles.CircleHandleCap);
if (EditorGUI.EndChangeCheck())
{
enemy.RoamingPath[i] = newPosition;
}
}
SceneView.RepaintAll();
}
}
#endif
\ No newline at end of file
fileFormatVersion: 2
guid: 25eb5da6a91d1dc4fbc8c47c1e18cc83
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -17,7 +17,12 @@ namespace BS { ...@@ -17,7 +17,12 @@ namespace BS {
private Rigidbody2D rb; private Rigidbody2D rb;
public bool isGizmos = true; public bool isDrawingPath = false;
[SerializeField]
private LineRenderer pathRenderer;
public bool isGizmos = true;
private void OnDrawGizmos() private void OnDrawGizmos()
{ {
...@@ -45,7 +50,13 @@ namespace BS { ...@@ -45,7 +50,13 @@ namespace BS {
rb = GetComponent<Rigidbody2D>(); rb = GetComponent<Rigidbody2D>();
} }
public void MoveTo(Vector3 destination) private void Update()
{
if (isDrawingPath)
DrawPath();
}
public void MoveTo(Vector3 destination)
{ {
this.destination = destination; this.destination = destination;
//path = pathFinder.GetPathGreedy(transform.position, destination); //path = pathFinder.GetPathGreedy(transform.position, destination);
...@@ -69,9 +80,14 @@ namespace BS { ...@@ -69,9 +80,14 @@ namespace BS {
this.path = newPath; this.path = newPath;
} }
public void Move(Vector2 direction) public void DrawPath()
{ {
pathRenderer.positionCount = path.Count + 1;
pathRenderer.SetPosition(0, transform.position);
for (int i = 0; i < path.Count; i++)
{
pathRenderer.SetPosition(i + 1, path[i]);
}
} }
private void FixedUpdate() private void FixedUpdate()
......
fileFormatVersion: 2
guid: f3c97a168612e5440b8969d67cd6d58d
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
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
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 0
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 1, y: 1, z: 1, w: 1}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 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
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment