Skip to content

Commit

Permalink
SORRY FOR HARDCODING :'(
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardel-DW committed Jul 6, 2021
1 parent 0405281 commit 347b288
Show file tree
Hide file tree
Showing 6 changed files with 324 additions and 3 deletions.
42 changes: 42 additions & 0 deletions Harion/Data/GroundData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace Harion.Data {
public class GroundData {

public Vector2 OriginalPosition { get; } = new Vector2();
public float OriginalRadius { get; } = 1f;
public int NummberOfCloestElement { get; internal set; } = 0;
public List<Collider2D> GameObjectsFounds { get; internal set; } = new();
public bool GroundIsFound { get; internal set; } = false;
public GameObject Ground { get; internal set; }

public GroundData(Vector2 originalPosition, float originalRadius) {
OriginalPosition = originalPosition;
OriginalRadius = originalRadius;
}

public static GroundData GroundIsNearest(Vector2 Position, float radius) {
GroundData groundData = new GroundData(Position, radius);
GameObject ground = null;

List<Collider2D> GameObjects = Physics2D.OverlapCircleAll(Position, radius).ToList();
groundData.GameObjectsFounds = GameObjects;
if (GameObjects.Count > 0) {
groundData.NummberOfCloestElement = GameObjects.Count;
foreach (Collider2D collider in GameObjects) {
GameObject go = collider.gameObject;
if (go.name == "Ground") {
groundData.Ground = go;
ground = go;
break;
}
}
}

groundData.GroundIsFound = ground != null;
return groundData;
}
}
}
6 changes: 3 additions & 3 deletions Harion/Enumerations/MapType.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Harion.Enumerations {
public enum MapType
{
public enum MapType {
Skeld = 0,
MiraHQ = 1,
Polus = 2,
Airship = 3, // Just guessing
Dlesk = 3,
Airship = 4
}
}
2 changes: 2 additions & 0 deletions Harion/ResourceLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ public static class ResourceLoader {
private static readonly Assembly myAsembly = Assembly.GetExecutingAssembly();
public static Material ArialFont;
public static Material Liberia;
public static GameObject NavigationObject;

public static void LoadAssets() {
Stream resourceSteam = myAsembly.GetManifestResourceStream("Harion.Resources.Harion");
AssetBundle assetBundle = AssetBundle.LoadFromMemory(resourceSteam.ReadFully());

ArialFont = assetBundle.LoadAsset<Material>("ArialMasked.mat").DontDestroy();
Liberia = assetBundle.LoadAsset<Material>("LiberationSans SDF - Mask.mat").DontDestroy();
NavigationObject = assetBundle.LoadAsset<GameObject>("NavigationMesh.prefab").DontDestroy();
}
}
}
55 changes: 55 additions & 0 deletions Harion/Resources/NavigationMesh.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &5364299042878532103
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3460033891019039650}
- component: {fileID: 3258885039038995231}
m_Layer: 0
m_Name: NavigationMesh
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3460033891019039650
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5364299042878532103}
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_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!195 &3258885039038995231
NavMeshAgent:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5364299042878532103}
m_Enabled: 1
m_AgentTypeID: 0
m_Radius: 0.5
m_Speed: 3.5
m_Acceleration: 8
avoidancePriority: 50
m_AngularSpeed: 120
m_StoppingDistance: 0.1
m_AutoTraverseOffMeshLink: 1
m_AutoBraking: 1
m_AutoRepath: 1
m_Height: 0.2
m_BaseOffset: 0
m_WalkableMask: 4294967295
m_ObstacleAvoidanceType: 4
31 changes: 31 additions & 0 deletions Harion/Utility/Utils/GameObjectUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

Expand Down Expand Up @@ -148,5 +149,35 @@ public static void ChangeY(this ref Vector3 v, float y) {
public static void ChangeZ(this ref Vector3 v, float z) {
v = new Vector3(v.x, v.y, z);
}

public static void IterateChildren(GameObject gameObject, bool recursive, Action<GameObject> action) => DoIterate(gameObject, recursive, action);

private static void DoIterate(GameObject gameObject, bool recursive, Action<GameObject> action) {
for (int i = 0; i < gameObject.transform.childCount; i++) {
Transform child = gameObject.transform.GetChild(i);
if (recursive) {
action(child.gameObject);
DoIterate(child.gameObject, true, action);
}
}
}

public static List<GameObject> GetGameObjects(Vector2 Position) {
List<GameObject> Objets = new();
if (ShipStatus.Instance == null)
return null;

IterateChildren(ShipStatus.Instance.gameObject, true, (GameObject go) => {
if (go.GetComponent<SpriteRenderer>() == null)
return;

Vector3 Postions = new Vector3(Position.x, Position.y, go.transform.position.z);
Bounds bounds = go.GetComponent<SpriteRenderer>().bounds;
if (bounds.Contains(Postions))
Objets.Add(go);
});

return Objets;
}
}
}
Loading

0 comments on commit 347b288

Please sign in to comment.