добавил немного функционала

This commit is contained in:
2022-10-31 17:56:35 +05:00
parent 0c76285e81
commit 1ddd2439ee
1092 changed files with 92598 additions and 5951 deletions
+56
View File
@@ -0,0 +1,56 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameSystem : MonoBehaviour
{
public static GameSystem Instance { get; private set; }
public List<IGameComponent> gameComponents { get; private set; } = new List<IGameComponent>();
public void AddGameComponent(IGameComponent component)
{
if(!gameComponents.Contains(component))
gameComponents.Add(component);
}
void Awake()
{
Instance = this;
}
void Start()
{
GameSystem[] gameSystems = FindObjectsOfType<GameSystem>();
if(gameSystems.Length > 1)
{
Destroy(this.gameObject);
return;
}
DontDestroyOnLoad(this);
}
void Update()
{
for(int i = 0; i < gameComponents.Count; i++)
gameComponents[i].OnUpdate();
}
void FixedUpdate()
{
for(int i = 0; i < gameComponents.Count; i++)
gameComponents[i].OnFixedUpdate();
}
void LateUpdate()
{
for(int i = 0; i < gameComponents.Count; i++)
gameComponents[i].OnLateUpdate();
}
public void RemoveGameComponent(IGameComponent component)
{
if(gameComponents.Contains(component))
gameComponents.Remove(component);
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: eedf487efc314024aa2bbf4aba853c65
guid: ea2d6e51c51990a4bbfea3836ff3508c
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -1,14 +0,0 @@
using System.Collections;
using System.Threading.Tasks;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class HolographicEffectHandler : MonoBehaviour
{
void Start()
{
}
}
+54
View File
@@ -0,0 +1,54 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class InputHandler : MonoBehaviour, IGameComponent
{
private Controls inputSystem;
private Transform cameraTransform;
void Awake()
{
inputSystem = new Controls();
cameraTransform = transform;
}
void Start()
{
GameSystem.Instance.AddGameComponent(this);
}
void OnEnable()
{
inputSystem.Enable();
InputSystem.EnableDevice(UnityEngine.InputSystem.AttitudeSensor.current);
}
void OnDisable()
{
InputSystem.DisableDevice(UnityEngine.InputSystem.AttitudeSensor.current);
inputSystem.Disable();
}
public void OnUpdate()
{
var phoneRotation = inputSystem
.Rotation
.Gyroscope
.ReadValue<Quaternion>();
cameraTransform.rotation = phoneRotation;
cameraTransform.Rotate(0, 0, 180, Space.Self);
cameraTransform.Rotate(90, 180, 0, Space.World);
}
public void OnFixedUpdate() { }
public void OnLateUpdate() { }
public void OnDestroy()
{
GameSystem.Instance.RemoveGameComponent(this);
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 619f23720390a5346b50c495d0c723e9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ab70fa86deff72f4dbcf947f455a9586
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,7 @@
public interface IGameComponent
{
public void OnUpdate();
public void OnFixedUpdate();
public void OnLateUpdate();
public void OnDestroy();
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ad40bd6cd2ecbd14cbce01dbd4688382
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+108
View File
@@ -0,0 +1,108 @@
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using ZXing;
using UnityEngine;
using UnityEngine.UI;
public class QRCodeReader : MonoBehaviour
{
[SerializeField] AspectRatioFitter aspectRatioFitter;
[SerializeField] RawImage rawImage;
[SerializeField] GameObject scanFrame;
private WebCamTexture camTexture;
private Coroutine c_QRScanningRoutine;
void Start()
{
int backCameraId = 0;
bool backCameraEnabled = false;
List<int> backCameraIDs = new List<int>();
WebCamDevice[] devices = WebCamTexture.devices;
if(devices.Length != 0)
{
for(int i = 0; i < devices.Length; i++)
{
if(Application.platform == RuntimePlatform.Android && !devices[i].isFrontFacing)
{
backCameraEnabled = true;
backCameraIDs.Add(i);
}
else
{
backCameraEnabled = true;
backCameraId = 0;
}
}
if(backCameraIDs.Count != 0)
backCameraId = backCameraIDs.First();
}
if(!backCameraEnabled) return;
camTexture = new WebCamTexture(devices[backCameraId].name);
rawImage.texture = camTexture;
camTexture.Play();
int orientation = -camTexture.videoRotationAngle;
rawImage.rectTransform.localEulerAngles = Vector3.forward * orientation;
var ratio = (float)camTexture.width / (float)camTexture.height;
aspectRatioFitter.aspectRatio = ratio;
float scaleY = camTexture.videoVerticallyMirrored ? -1f : 1f;
rawImage.rectTransform.localScale = new Vector3(1f, scaleY, 1f);
ScanningQRCode();
}
public void ScanningQRCode()
{
if(c_QRScanningRoutine != null)
{
StopCoroutine(c_QRScanningRoutine);
c_QRScanningRoutine = null;
}
c_QRScanningRoutine = StartCoroutine(ScanQRCode());
}
IEnumerator ScanQRCode()
{
Result result;
while(true)
{
try
{
IBarcodeReader barcodeReader = new BarcodeReader();
result = barcodeReader.Decode
(
camTexture.GetPixels32(),
camTexture.width,
camTexture.height
);
if(result != null)
{
break;
}
}
catch
{
}
yield return new WaitForSeconds(1f);
}
camTexture.Stop();
Debug.Log(result.Text);
gameObject.SetActive(false);
scanFrame.SetActive(false);
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6b48a36dff366224eba85f913f0e7348
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: