forked from sipsorcery-org/sipsorcery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerController.cs
More file actions
96 lines (79 loc) · 2.68 KB
/
PlayerController.cs
File metadata and controls
96 lines (79 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.InputSystem;
using TMPro;
public class PlayerController : MonoBehaviour
{
public float speed = 0f;
public TextMeshProUGUI countText;
public GameObject winTextObject;
private Rigidbody rb;
private int count;
private float movementX;
private float movementY;
#pragma warning disable 0649
[SerializeField] private Camera cam;
#pragma warning restore 0649
private RenderTexture _mainCamDupRenderTexture;
private Texture2D _mainCamTexture2D;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText();
winTextObject.SetActive(false);
var texture = cam.targetTexture;
_mainCamDupRenderTexture = texture;
_mainCamTexture2D = new Texture2D(texture.width, texture.height);
}
void OnMove(InputValue movementValue)
{
Vector2 movementVector = movementValue.Get<Vector2>();
movementX = movementVector.x;
movementY = movementVector.y;
}
void SetCountText()
{
countText.text = $"Count: {count.ToString()}";
if (count >= 10)
{
winTextObject.SetActive(true);
}
}
void FixedUpdate()
{
Vector3 movement = new Vector3(movementX, 0.0f, movementY);
rb.AddForce(movement * speed);
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("PickUp"))
{
other.gameObject.SetActive(false);
count++;
SetCountText();
}
}
//private void OnRenderObject()
//{
// RenderTexture.active = _mainCamDupRenderTexture;
// _mainCamTexture2D.ReadPixels(new Rect(0, 0, _mainCamTexture2D.width, _mainCamTexture2D.height), 0, 0);
// _mainCamTexture2D.Apply();
// RenderTexture.active = null;
// // This call to get the raw pixels seems to be the biggest performance hit. On my Win10 i7 machine
// // frame rate reduces from approx. 200 fps to around 20fps with this call.
// var arr = _mainCamTexture2D.GetRawTextureData();
// byte[] flipped = new byte[arr.Length];
// int width = _mainCamTexture2D.width;
// int height = _mainCamTexture2D.height;
// int pixelSize = 4;
// int stride = width * pixelSize;
// for (int row = height - 1; row >= 0; row--)
// {
// Buffer.BlockCopy(arr, row * stride, flipped, (height - row - 1) * stride, stride);
// }
//}
}