Initial commit
This commit is contained in:
6
Assets/Scripts/IInputReader.cs
Normal file
6
Assets/Scripts/IInputReader.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public interface IInputReader
|
||||
{
|
||||
Vector2 DragInput { get; }
|
||||
}
|
||||
2
Assets/Scripts/IInputReader.cs.meta
Normal file
2
Assets/Scripts/IInputReader.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fd243b30ced38840a3173920b99929f
|
||||
26
Assets/Scripts/InputReader.cs
Normal file
26
Assets/Scripts/InputReader.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using static GameInputs;
|
||||
|
||||
public class InputReader : ScriptableObject, IInputReader, IPlayerActions
|
||||
{
|
||||
private GameInputs _inputActions;
|
||||
|
||||
public Vector2 DragInput { get; private set;}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (_inputActions == null)
|
||||
{
|
||||
_inputActions = new GameInputs();
|
||||
_inputActions.Player.SetCallbacks(this);
|
||||
}
|
||||
_inputActions.Enable();
|
||||
}
|
||||
public void OnDrag(InputAction.CallbackContext context)
|
||||
{
|
||||
DragInput = context.ReadValue<Vector2>();
|
||||
Debug.Log(DragInput);
|
||||
}
|
||||
|
||||
}
|
||||
2
Assets/Scripts/InputReader.cs.meta
Normal file
2
Assets/Scripts/InputReader.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf23afefa375da349994d4977b4ffe60
|
||||
8
Assets/Scripts/LifeTimeScope.meta
Normal file
8
Assets/Scripts/LifeTimeScope.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b41ba7e7c457a844493479d95fe677f9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Assets/Scripts/LifeTimeScope/GameLifeTimeScope.cs
Normal file
22
Assets/Scripts/LifeTimeScope/GameLifeTimeScope.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using JetBrains.Annotations;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
using VContainer.Unity;
|
||||
|
||||
public class GameLifeTimeScope : LifetimeScope
|
||||
{
|
||||
[SerializeField] private InputReader inputReader;
|
||||
protected override void Configure(IContainerBuilder builder)
|
||||
{
|
||||
|
||||
builder.RegisterComponentInHierarchy<PlatformPool>();
|
||||
builder.RegisterComponentInHierarchy<JumpingBall>();
|
||||
builder.RegisterComponentInHierarchy<PlatformManager>();
|
||||
builder.RegisterComponent<IInputReader>(inputReader);
|
||||
}
|
||||
|
||||
public void IsWorking()
|
||||
{
|
||||
Debug.Log("True");
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/LifeTimeScope/GameLifeTimeScope.cs.meta
Normal file
2
Assets/Scripts/LifeTimeScope/GameLifeTimeScope.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f8d7d43c7f4a3d4d876897769dbf418
|
||||
8
Assets/Scripts/PlatformScript.meta
Normal file
8
Assets/Scripts/PlatformScript.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9b8db002cacc004caf00038e55a001f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Assets/Scripts/PlatformScript/Platform.cs
Normal file
27
Assets/Scripts/PlatformScript/Platform.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
public class Platform : MonoBehaviour
|
||||
{
|
||||
private Transform playerTransform;
|
||||
[Inject] private PlatformPool pool;
|
||||
[Inject] private PlatformManager manager;
|
||||
[Inject] private IInputReader inputReader;
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if((playerTransform.position.y-transform.position.y)<-5)
|
||||
{
|
||||
pool.ReturnToPool(this.gameObject);
|
||||
manager.BuildPlatform();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/PlatformScript/Platform.cs.meta
Normal file
2
Assets/Scripts/PlatformScript/Platform.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67c2916908f5f5e4b80dc9c59b8b1592
|
||||
38
Assets/Scripts/PlatformScript/PlatformManager.cs
Normal file
38
Assets/Scripts/PlatformScript/PlatformManager.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
public class PlatformManager : MonoBehaviour
|
||||
{
|
||||
private GameObject currentPlatfrom;
|
||||
[Inject] private PlatformPool pool;
|
||||
|
||||
private int yPos=0;
|
||||
|
||||
void Start()
|
||||
{
|
||||
ShowInitialPlatforms();
|
||||
}
|
||||
|
||||
public void ShowInitialPlatforms()
|
||||
{
|
||||
|
||||
foreach(var platfrom in pool.platformPool)
|
||||
{
|
||||
platfrom.gameObject.SetActive(true);
|
||||
platfrom.transform.position = new Vector3(0,yPos,0);
|
||||
yPos--;
|
||||
}
|
||||
}
|
||||
public void BuildPlatform()
|
||||
{
|
||||
currentPlatfrom = pool.GetPlatformFromPool();
|
||||
if(currentPlatfrom!=null)
|
||||
{
|
||||
currentPlatfrom.transform.position = new Vector3(0,yPos,0);
|
||||
currentPlatfrom.SetActive(true);
|
||||
yPos--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
2
Assets/Scripts/PlatformScript/PlatformManager.cs.meta
Normal file
2
Assets/Scripts/PlatformScript/PlatformManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5581fca74af43824995a825437415c12
|
||||
52
Assets/Scripts/PlatformScript/PlatformPool.cs
Normal file
52
Assets/Scripts/PlatformScript/PlatformPool.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
using VContainer.Unity;
|
||||
|
||||
public class PlatformPool : MonoBehaviour
|
||||
{
|
||||
public List<GameObject> platformPool = new List<GameObject>();
|
||||
public int amountToPool=10;
|
||||
public GameObject[] platformPrefab;
|
||||
public GameObject PlatformContainer; //parent
|
||||
[Inject] private IObjectResolver container;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
for(int i=0; i<amountToPool;i++)
|
||||
{
|
||||
GameObject obj = Instantiate(platformPrefab[Random.Range(0,platformPrefab.Length)]);
|
||||
obj.SetActive(false);
|
||||
obj.transform.SetParent(PlatformContainer.transform);
|
||||
container.InjectGameObject(obj);
|
||||
platformPool.Add(obj);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public GameObject GetPlatformFromPool()
|
||||
{
|
||||
for(int i=0;i<platformPool.Count;i++)
|
||||
{
|
||||
if(!platformPool[i].activeInHierarchy)
|
||||
{
|
||||
return platformPool[i];
|
||||
}
|
||||
}
|
||||
|
||||
GameObject newObj = Instantiate(platformPrefab[Random.Range(0,platformPrefab.Length)]);
|
||||
platformPool.Add(newObj);
|
||||
newObj.transform.SetParent(PlatformContainer.transform);
|
||||
container.InjectGameObject(newObj);
|
||||
return newObj;
|
||||
}
|
||||
|
||||
public void ReturnToPool(GameObject obj)
|
||||
{
|
||||
obj.SetActive(false);
|
||||
}
|
||||
|
||||
}
|
||||
2
Assets/Scripts/PlatformScript/PlatformPool.cs.meta
Normal file
2
Assets/Scripts/PlatformScript/PlatformPool.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d775e1dfaaa1884088214bc3e182dfa
|
||||
8
Assets/Scripts/PlayerScript.meta
Normal file
8
Assets/Scripts/PlayerScript.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69ce4caca76952d48b6e1ee91464c551
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/Scripts/PlayerScript/JumpingBall.cs
Normal file
25
Assets/Scripts/PlayerScript/JumpingBall.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
public class JumpingBall : MonoBehaviour
|
||||
{
|
||||
public float jumpforce = 4f;
|
||||
public Rigidbody BallRb;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if(BallRb==null)
|
||||
{
|
||||
BallRb = GetComponent<Rigidbody>();
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if(collision.collider.CompareTag("Platform"))
|
||||
{
|
||||
BallRb.linearVelocity = new Vector3(0, jumpforce, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
2
Assets/Scripts/PlayerScript/JumpingBall.cs.meta
Normal file
2
Assets/Scripts/PlayerScript/JumpingBall.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 747f7dce18fb6a548bafaf8388f331e4
|
||||
Reference in New Issue
Block a user