Made children spawn

This commit is contained in:
Pasha Bibko
2026-01-13 10:23:50 +00:00
parent d54a99874f
commit 8b648fd690
17 changed files with 441 additions and 9 deletions

View File

@@ -0,0 +1,7 @@
namespace InterfaceOff
{
public class BasicWindow : WindowBase
{
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: eac7797c414842e59b3acc1c0d6a542d
timeCreated: 1768298931

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 90a599d4c2654a3793b34809ea82ead1
timeCreated: 1768299034

View 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];
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: cf13893a58ea446491ffdf8b92ddd426
timeCreated: 1768299042

View 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;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f00bdf5606894d12a4cb4335afd5bf54
timeCreated: 1768299617

View File

@@ -0,0 +1,11 @@
using UnityEngine;
namespace InterfaceOff
{
public abstract class WindowBase : MonoBehaviour
{
public void InstantiateWindowBase()
{
}
}
}

View File

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

View 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();
}
}
}
}

View File

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