Made the moving windows move
This commit is contained in:
@@ -34,7 +34,7 @@ RectTransform:
|
|||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 0, y: -20}
|
||||||
m_SizeDelta: {x: 200, y: 200}
|
m_SizeDelta: {x: 200, y: 200}
|
||||||
m_Pivot: {x: 0.5, y: 0.5}
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
--- !u!222 &9139133142503423203
|
--- !u!222 &9139133142503423203
|
||||||
@@ -154,6 +154,41 @@ MonoBehaviour:
|
|||||||
m_VerticalOverflow: 0
|
m_VerticalOverflow: 0
|
||||||
m_LineSpacing: 1
|
m_LineSpacing: 1
|
||||||
m_Text:
|
m_Text:
|
||||||
|
--- !u!1 &2281649515289431590
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 6489330010487774388}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: CollisionRect
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &6489330010487774388
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2281649515289431590}
|
||||||
|
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_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 7011418079103154681}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||||
|
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||||
|
m_AnchoredPosition: {x: 0, y: 20}
|
||||||
|
m_SizeDelta: {x: 200, y: 240}
|
||||||
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
--- !u!1 &3890928559484794403
|
--- !u!1 &3890928559484794403
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -190,7 +225,7 @@ RectTransform:
|
|||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||||
m_AnchoredPosition: {x: 0, y: 120}
|
m_AnchoredPosition: {x: 0, y: 100}
|
||||||
m_SizeDelta: {x: 200, y: 40}
|
m_SizeDelta: {x: 200, y: 40}
|
||||||
m_Pivot: {x: 0.5, y: 0.5}
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
--- !u!222 &895478976559852706
|
--- !u!222 &895478976559852706
|
||||||
@@ -395,12 +430,13 @@ RectTransform:
|
|||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 25269235060726753}
|
- {fileID: 25269235060726753}
|
||||||
- {fileID: 8377239034391175029}
|
- {fileID: 8377239034391175029}
|
||||||
|
- {fileID: 6489330010487774388}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
m_SizeDelta: {x: 100, y: 100}
|
m_SizeDelta: {x: 205, y: 245}
|
||||||
m_Pivot: {x: 0.5, y: 0.5}
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
--- !u!114 &5345782142064721643
|
--- !u!114 &5345782142064721643
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@@ -415,7 +451,7 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
<WindowImage>k__BackingField: {fileID: 3009414327569646558}
|
<WindowImage>k__BackingField: {fileID: 3009414327569646558}
|
||||||
<Transform>k__BackingField: {fileID: 7011418079103154681}
|
<RectTransform>k__BackingField: {fileID: 7011418079103154681}
|
||||||
<InfoText>k__BackingField: {fileID: 2038821404454815492}
|
<InfoText>k__BackingField: {fileID: 2038821404454815492}
|
||||||
--- !u!114 &3265764588146964386
|
--- !u!114 &3265764588146964386
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
|||||||
@@ -540,6 +540,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: e090ce5928c145c0b2e514412bc9cdb2, type: 3}
|
m_Script: {fileID: 11500000, guid: e090ce5928c145c0b2e514412bc9cdb2, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
<CanvasRect>k__BackingField: {fileID: 1539476655}
|
||||||
<GameCanvas>k__BackingField: {fileID: 1539476654}
|
<GameCanvas>k__BackingField: {fileID: 1539476654}
|
||||||
<ImagePrefab>k__BackingField: {fileID: 1810675969122322477, guid: 792c010445685104eac99ebe5c3831ce,
|
<ImagePrefab>k__BackingField: {fileID: 1810675969122322477, guid: 792c010445685104eac99ebe5c3831ce,
|
||||||
type: 3}
|
type: 3}
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ namespace InterfaceOff
|
|||||||
{
|
{
|
||||||
public class CanvasManager : MonoBehaviour
|
public class CanvasManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
[field: SerializeField] public RectTransform CanvasRect { get; private set; }
|
||||||
[field: SerializeField] public Canvas GameCanvas { get; private set; }
|
[field: SerializeField] public Canvas GameCanvas { get; private set; }
|
||||||
|
|
||||||
[field: SerializeField] public GameObject ImagePrefab { get; private set; }
|
[field: SerializeField] public GameObject ImagePrefab { get; private set; }
|
||||||
[field: SerializeField] public ImageRegistry Images { get; set; }
|
[field: SerializeField] public ImageRegistry Images { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace InterfaceOff
|
namespace InterfaceOff
|
||||||
@@ -7,6 +8,8 @@ namespace InterfaceOff
|
|||||||
public WindowInteractions Interactions { get; set; }
|
public WindowInteractions Interactions { get; set; }
|
||||||
public WindowComponents Components { get; set; }
|
public WindowComponents Components { get; set; }
|
||||||
|
|
||||||
|
protected Vector2 Velocity;
|
||||||
|
|
||||||
public void InstantiateWindowBase()
|
public void InstantiateWindowBase()
|
||||||
{
|
{
|
||||||
transform.position = CanvasManager.GetRandomPositionOnCanvas();
|
transform.position = CanvasManager.GetRandomPositionOnCanvas();
|
||||||
@@ -14,6 +17,42 @@ namespace InterfaceOff
|
|||||||
OnWindowInstantiation();
|
OnWindowInstantiation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void LateUpdate()
|
||||||
|
{
|
||||||
|
/* Moves the component and calculates new position and half size(s) */
|
||||||
|
Components.RectTransform.anchoredPosition += Velocity * Time.deltaTime;
|
||||||
|
Vector2 position = Components.RectTransform.anchoredPosition;
|
||||||
|
|
||||||
|
Vector2 hCanvasSize = CanvasManager.Instance.CanvasRect.sizeDelta * 0.5f;
|
||||||
|
Vector2 hSize = Components.RectTransform.sizeDelta * 0.5f;
|
||||||
|
|
||||||
|
/* Calculates outcome of a horizontal bounce (if there is one) */
|
||||||
|
if (position.x + hSize.x > hCanvasSize.x || position.x - hSize.x < -hCanvasSize.x)
|
||||||
|
{
|
||||||
|
Velocity.x *= -1f; // Inverts X velocity
|
||||||
|
position.x = Math.Clamp
|
||||||
|
(
|
||||||
|
position.x,
|
||||||
|
0 - hCanvasSize.x + hSize.x,
|
||||||
|
0 + hCanvasSize.x - hSize.x
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculates outcome of vertical bounce (if there is one) */
|
||||||
|
if (position.y + hSize.y > hCanvasSize.y || position.y - hSize.y < -hCanvasSize.y)
|
||||||
|
{
|
||||||
|
Velocity.y *= -1f; // Inverts Y velocity
|
||||||
|
position.y = Math.Clamp
|
||||||
|
(
|
||||||
|
position.y,
|
||||||
|
0 - hCanvasSize.y + hSize.y,
|
||||||
|
0 + hCanvasSize.y - hSize.y
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Components.RectTransform.anchoredPosition = position; // Updates position if it is supposed to] change
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void OnWindowInstantiation() { }
|
public virtual void OnWindowInstantiation() { }
|
||||||
public virtual void OnWindowClicked() { }
|
public virtual void OnWindowClicked() { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
namespace InterfaceOff
|
namespace InterfaceOff
|
||||||
{
|
{
|
||||||
public class WindowComponents : MonoBehaviour
|
public class WindowComponents : MonoBehaviour
|
||||||
{
|
{
|
||||||
[field: SerializeField] public Image WindowImage { get; private set; }
|
[field: SerializeField] public Image WindowImage { get; private set; }
|
||||||
[field: SerializeField] public RectTransform Transform { get; private set; }
|
[field: SerializeField] public RectTransform RectTransform { get; private set; }
|
||||||
[field: SerializeField] public Text InfoText { get; private set; }
|
[field: SerializeField] public Text InfoText { get; private set; }
|
||||||
|
|
||||||
public Rect Rect => new
|
public Rect Rect => new
|
||||||
(
|
(
|
||||||
Transform.position.x - Transform.rect.width / 2,
|
RectTransform.position.x - RectTransform.rect.width / 2,
|
||||||
Transform.position.y - Transform.rect.height / 2,
|
RectTransform.position.y - RectTransform.rect.height / 2,
|
||||||
Transform.rect.width,
|
RectTransform.rect.width,
|
||||||
Transform.rect.height
|
RectTransform.rect.height
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,10 +7,10 @@ namespace InterfaceOff
|
|||||||
{
|
{
|
||||||
private static Vector3[] Positions =
|
private static Vector3[] Positions =
|
||||||
{
|
{
|
||||||
new(-45, 45f),
|
new(-45, 25f),
|
||||||
new(45f, 45f),
|
new(45f, 25f),
|
||||||
new(-45, -45),
|
new(-45, -65),
|
||||||
new(45f, -45)
|
new(45f, -65)
|
||||||
};
|
};
|
||||||
|
|
||||||
private int m_TilesRotatedCorrectly;
|
private int m_TilesRotatedCorrectly;
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ namespace InterfaceOff
|
|||||||
/* Creates a random health value */
|
/* Creates a random health value */
|
||||||
m_Health = Random.Range(2, 6);
|
m_Health = Random.Range(2, 6);
|
||||||
Components.InfoText.text = $"{m_Health}";
|
Components.InfoText.text = $"{m_Health}";
|
||||||
|
|
||||||
|
float angle = Random.Range(0, Mathf.PI * 2);
|
||||||
|
Velocity = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnWindowClicked()
|
public override void OnWindowClicked()
|
||||||
|
|||||||
Reference in New Issue
Block a user