Made children spawn
This commit is contained in:
7
Assets/Scripts/BasicWindow.cs
Normal file
7
Assets/Scripts/BasicWindow.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace InterfaceOff
|
||||
{
|
||||
public class BasicWindow : WindowBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/BasicWindow.cs.meta
Normal file
3
Assets/Scripts/BasicWindow.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eac7797c414842e59b3acc1c0d6a542d
|
||||
timeCreated: 1768298931
|
||||
3
Assets/Scripts/Extensions.meta
Normal file
3
Assets/Scripts/Extensions.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90a599d4c2654a3793b34809ea82ead1
|
||||
timeCreated: 1768299034
|
||||
10
Assets/Scripts/Extensions/ListExtensions.cs
Normal file
10
Assets/Scripts/Extensions/ListExtensions.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
public static class ListExtensions
|
||||
{
|
||||
public static T GetRandom<T>(this List<T> list)
|
||||
{
|
||||
int index = UnityEngine.Random.Range(0, list.Count);
|
||||
return list[index];
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Extensions/ListExtensions.cs.meta
Normal file
3
Assets/Scripts/Extensions/ListExtensions.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf13893a58ea446491ffdf8b92ddd426
|
||||
timeCreated: 1768299042
|
||||
33
Assets/Scripts/NullCheckers.cs
Normal file
33
Assets/Scripts/NullCheckers.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using JetBrains.Annotations;
|
||||
using Unity.VisualScripting;
|
||||
|
||||
namespace InterfaceOff
|
||||
{
|
||||
public class DebugUtils
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining), AssertionMethod, ContractAnnotation("null => true")]
|
||||
public static bool IsNull(UnityEngine.Object obj)
|
||||
{
|
||||
return obj.IsUnityNull();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining), AssertionMethod, ContractAnnotation("null => true")]
|
||||
public static bool IsNull(object obj)
|
||||
{
|
||||
return obj == null;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining), AssertionMethod, ContractAnnotation("null => false")]
|
||||
public static bool IsNotNull(UnityEngine.Object obj)
|
||||
{
|
||||
return !obj.IsUnityNull();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining), AssertionMethod, ContractAnnotation("null => true")]
|
||||
public static bool IsNotNull(object obj)
|
||||
{
|
||||
return obj != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NullCheckers.cs.meta
Normal file
3
Assets/Scripts/NullCheckers.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f00bdf5606894d12a4cb4335afd5bf54
|
||||
timeCreated: 1768299617
|
||||
11
Assets/Scripts/WindowBase.cs
Normal file
11
Assets/Scripts/WindowBase.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace InterfaceOff
|
||||
{
|
||||
public abstract class WindowBase : MonoBehaviour
|
||||
{
|
||||
public void InstantiateWindowBase()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/WindowBase.cs.meta
Normal file
11
Assets/Scripts/WindowBase.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 032b6f3e9e786884085cabb655a4ad31
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
52
Assets/Scripts/WindowSpawner.cs
Normal file
52
Assets/Scripts/WindowSpawner.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace InterfaceOff
|
||||
{
|
||||
public class WindowSpawner : MonoBehaviour
|
||||
{
|
||||
private List<Type> WindowTypes { get; } = new();
|
||||
|
||||
[field: SerializeField] private Canvas GameCanvas { get; set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
/* Fetches all window types created */
|
||||
Type[] types = typeof(WindowBase).Assembly.GetTypes();
|
||||
foreach (Type t in types)
|
||||
{
|
||||
if (t.IsSubclassOf(typeof(WindowBase)))
|
||||
{
|
||||
WindowTypes.Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
/* Logs the amount of types found and errors if there is none */
|
||||
Debug.Log($"Found [{WindowTypes.Count}] different window types ");
|
||||
if (WindowTypes.Count == 0)
|
||||
{
|
||||
Debug.LogError("Could not find any window types");
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
Type type = WindowTypes.GetRandom();
|
||||
GameObject go = new();
|
||||
go.transform.SetParent(GameCanvas.transform);
|
||||
|
||||
WindowBase windowBase = go.AddComponent(type) as WindowBase;
|
||||
if (DebugUtils.IsNull(windowBase))
|
||||
{
|
||||
Debug.LogError("How did this happen");
|
||||
return;
|
||||
}
|
||||
|
||||
windowBase.InstantiateWindowBase();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/WindowSpawner.cs.meta
Normal file
11
Assets/Scripts/WindowSpawner.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83fa400829eb6494796e00cfbb1c5d71
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user