Added basic bouncing
This commit is contained in:
@@ -800,6 +800,7 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
<SampleChild>k__BackingField: {fileID: 1867692258}
|
||||
<GameCanvas>k__BackingField: {fileID: 1539476654}
|
||||
<AutoSpawn>k__BackingField: 0
|
||||
--- !u!4 &2038986853
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -28,5 +28,13 @@ namespace InterfaceOff
|
||||
|
||||
return new Vector3(x, y, 0f);
|
||||
}
|
||||
|
||||
public static bool IsRectWithinCanvas(Rect rect)
|
||||
{
|
||||
Rect b = Instance.GameCanvas.pixelRect;
|
||||
Rect a = rect;
|
||||
|
||||
return b.xMin <= a.xMin && b.yMin <= a.yMin && b.xMax >= a.xMax && b.yMax >= a.yMax;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@ public static class ListExtensions
|
||||
public static T GetRandom<T>(this List<T> list)
|
||||
{
|
||||
int index = UnityEngine.Random.Range(0, list.Count);
|
||||
return list[index];
|
||||
return list[1];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace InterfaceOff
|
||||
@@ -7,7 +8,10 @@ namespace InterfaceOff
|
||||
public WindowInteractions Interactions { get; set; }
|
||||
public WindowComponents Components { get; set; }
|
||||
|
||||
public Vector3 Velocity { get; set; }
|
||||
protected Vector3 Velocity { get; set; }
|
||||
|
||||
[SerializeField] private int m_FlipCooldown;
|
||||
private static int MAX_FLIP_COOLDOWN = 20;
|
||||
|
||||
public void InstantiateWindowBase()
|
||||
{
|
||||
@@ -16,11 +20,22 @@ namespace InterfaceOff
|
||||
OnWindowInstantiation();
|
||||
}
|
||||
|
||||
public void LateUpdate()
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (!CanvasManager.IsRectWithinCanvas(Components.Rect) && m_FlipCooldown == 0)
|
||||
{
|
||||
m_FlipCooldown = MAX_FLIP_COOLDOWN;
|
||||
Velocity = -Velocity;
|
||||
}
|
||||
|
||||
transform.position += Velocity * Time.deltaTime;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
m_FlipCooldown = Math.Clamp(m_FlipCooldown - 1, 0, MAX_FLIP_COOLDOWN);
|
||||
}
|
||||
|
||||
public virtual void OnWindowInstantiation() { }
|
||||
public virtual void OnWindowClicked() { }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using TreeEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace InterfaceOff
|
||||
@@ -6,5 +7,14 @@ namespace InterfaceOff
|
||||
public class WindowComponents : MonoBehaviour
|
||||
{
|
||||
[field: SerializeField] public Image WindowImage { get; private set; }
|
||||
[field: SerializeField] public RectTransform Transform { get; private set; }
|
||||
|
||||
public Rect Rect => new
|
||||
(
|
||||
Transform.position.x - Transform.rect.width / 2,
|
||||
Transform.position.y - Transform.rect.height / 2,
|
||||
Transform.rect.width,
|
||||
Transform.rect.height
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ namespace InterfaceOff
|
||||
[field: SerializeField] private GameObject SampleChild { get; set; }
|
||||
[field: SerializeField] private Canvas GameCanvas { get; set; }
|
||||
|
||||
[field: SerializeField] public bool AutoSpawn { get; private set; } = true;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
/* Fetches all window types created */
|
||||
@@ -58,11 +60,25 @@ namespace InterfaceOff
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
/* Checks if it should spawn a window */
|
||||
bool shouldSpawn = Random.Range(0, 40) == 0;
|
||||
if (shouldSpawn)
|
||||
if (AutoSpawn)
|
||||
{
|
||||
SpawnNewRandomWindow();
|
||||
/* Checks if it should spawn a window */
|
||||
bool shouldSpawn = Random.Range(0, 40) == 0;
|
||||
if (shouldSpawn)
|
||||
{
|
||||
SpawnNewRandomWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!AutoSpawn)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
SpawnNewRandomWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user