Kill feed + Polishings
This commit is contained in:
15
Assets/Game/Scripts/Minigame/AutoConnect.cs
Normal file
15
Assets/Game/Scripts/Minigame/AutoConnect.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
|
||||
public class AutoConnect : MonoBehaviour
|
||||
{
|
||||
public bool isClient;
|
||||
void Start()
|
||||
{
|
||||
if(isClient){
|
||||
FindObjectOfType<NetworkManager>().StartClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/Minigame/AutoConnect.cs.meta
Normal file
11
Assets/Game/Scripts/Minigame/AutoConnect.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa3e9285a9018d093ab853b5f879544f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
42
Assets/Game/Scripts/Minigame/KillFeedEntry.cs
Normal file
42
Assets/Game/Scripts/Minigame/KillFeedEntry.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class KillFeedEntry : MonoBehaviour
|
||||
{
|
||||
private float AliveTime;
|
||||
private float _t;
|
||||
public Text txt;
|
||||
void Awake(){
|
||||
if(txt==null){txt = GetComponent<Text>();}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if(_t < AliveTime){
|
||||
_t+=Time.deltaTime;
|
||||
return;
|
||||
}else if(_t < AliveTime * 2){
|
||||
_t+=Time.deltaTime;
|
||||
float p = (_t - AliveTime)/AliveTime;
|
||||
txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, 1f-p);
|
||||
}else{
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetEntry(string text, float aliveTime = 1){
|
||||
AliveTime=aliveTime;
|
||||
txt.text = text;
|
||||
txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, 1);
|
||||
_t = 0;
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void Die(){
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/Minigame/KillFeedEntry.cs.meta
Normal file
11
Assets/Game/Scripts/Minigame/KillFeedEntry.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18b93df2563983a408102065346bccdc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Assets/Game/Scripts/Minigame/KillfeedMgr.cs
Normal file
33
Assets/Game/Scripts/Minigame/KillfeedMgr.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class KillfeedMgr : MonoBehaviour
|
||||
{
|
||||
public static KillfeedMgr instance;
|
||||
public GameObject prefab;
|
||||
public Transform entryParent;
|
||||
public List<KillFeedEntry> pool = new List<KillFeedEntry>();
|
||||
public float entryAliveTime = 1;
|
||||
|
||||
void Awake(){
|
||||
instance=this;
|
||||
}
|
||||
void Start(){
|
||||
AddNewEntry("Welcome to UPF Minigame 1.2");
|
||||
}
|
||||
|
||||
public void AddNewEntry(string message){
|
||||
for(int i =0; i < pool.Count; i++){
|
||||
if(!pool[i].gameObject.activeSelf){
|
||||
pool[i].SetEntry(message,entryAliveTime);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//No pooled item found, make new
|
||||
GameObject newEntry = Instantiate(prefab, entryParent);
|
||||
pool.Add(newEntry.GetComponent<KillFeedEntry>());
|
||||
newEntry.GetComponent<KillFeedEntry>().SetEntry(message,entryAliveTime);
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/Minigame/KillfeedMgr.cs.meta
Normal file
11
Assets/Game/Scripts/Minigame/KillfeedMgr.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02108f5bf6ebeb244919a7afb3d835f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
45
Assets/Game/Scripts/Minigame/NoLoginScreen.cs
Normal file
45
Assets/Game/Scripts/Minigame/NoLoginScreen.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class NoLoginScreen : MonoBehaviour
|
||||
{
|
||||
public GameObject loadingScreen;
|
||||
public string sceneName;
|
||||
public InputField usernameInput;
|
||||
public Button goBtn;
|
||||
void Start()
|
||||
{
|
||||
if(!HasUsername()){
|
||||
loadingScreen.SetActive(false);
|
||||
}else{
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
|
||||
goBtn.interactable=false;
|
||||
usernameInput.onValueChange.AddListener(OnInputChange);
|
||||
goBtn.onClick.AddListener(LetsGo);
|
||||
}
|
||||
void OnInputChange(string newVal){
|
||||
goBtn.interactable = (usernameInput.text.Length > 2);
|
||||
}
|
||||
public void LetsGo(){
|
||||
PlayerPrefs.SetString("username", usernameInput.text);
|
||||
loadingScreen.SetActive(true);
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
|
||||
bool HasUsername(){
|
||||
if(!PlayerPrefs.HasKey("username")){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(PlayerPrefs.GetString("username").Length < 1){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/Minigame/NoLoginScreen.cs.meta
Normal file
11
Assets/Game/Scripts/Minigame/NoLoginScreen.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a02d43d20c921c19db88f94d975c8687
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -17,7 +17,7 @@ public class PickupItem : NetworkBehaviour
|
||||
|
||||
Collider2D hit = Physics2D.OverlapCircle(transform.position, radius);
|
||||
if(hit!=null && hit.GetComponent<SpaceshipController>()!=null){
|
||||
Debug.Log(hit.GetComponent<SpaceshipController>().pname +$" collected me at {transform.position}");
|
||||
// Debug.Log(hit.GetComponent<SpaceshipController>().pname +$" collected me at {transform.position}");
|
||||
hit.GetComponent<SpaceshipController>().CollectPickup(type);
|
||||
active=false;
|
||||
Deactivate();
|
||||
|
||||
@@ -221,13 +221,15 @@ public class SpaceshipController : NetworkBehaviour
|
||||
void RpcUpdatePosition(Vector2 input, Vector3 position, Quaternion rotation, double sentTime)
|
||||
{
|
||||
if(isLocalPlayer || isServer){return;}
|
||||
double delay = (timeInMillis - sentTime)* 4;
|
||||
int numberOfFrames = (int)((float)(delay) / 20f);
|
||||
Vector3 newPosition = position;
|
||||
double delay = (timeInMillis - sentTime);
|
||||
int numberOfFrames = (int)((float)(delay/1000f) *50f);
|
||||
|
||||
Quaternion newRotation = rotation;
|
||||
Vector3 direction = (rotation * Vector3.forward).normalized;
|
||||
Vector3 newPosition = position + ((direction * speed) * numberOfFrames);
|
||||
|
||||
for (int i = 0; i < numberOfFrames; i++)
|
||||
{
|
||||
newPosition += new Vector3(0, speed);
|
||||
newRotation = Quaternion.Lerp(newRotation, getTurnAngle(input), turningSmoothFactor * input.magnitude);
|
||||
}
|
||||
|
||||
@@ -311,12 +313,14 @@ public class SpaceshipController : NetworkBehaviour
|
||||
if (sentTime < lastRubberBandTime) { Debug.Log("Old rubber band rpc, ignoree..."); return; }
|
||||
//Lag comprehension
|
||||
double delay = timeInMillis - sentTime;
|
||||
int numberOfFrames = (int)((float)(delay*2) / 20f);
|
||||
Vector3 newPosition = position;
|
||||
int numberOfFrames = (int)((float)(delay/1000f) * 50f);
|
||||
|
||||
Quaternion newRotation = rotation;
|
||||
Vector3 direction = (rotation * Vector3.forward).normalized;
|
||||
Vector3 newPosition = position + ((direction * speed) * numberOfFrames);
|
||||
|
||||
for (int i = 0; i < numberOfFrames; i++)
|
||||
{
|
||||
newPosition += new Vector3(0, speed);
|
||||
newRotation = Quaternion.Lerp(newRotation, getTurnAngle(input), turningSmoothFactor * input.magnitude);
|
||||
}
|
||||
int distanceSinceSent = (int)Vector3.Distance(newPosition, position);
|
||||
@@ -456,6 +460,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
[ClientRpc]
|
||||
public void RpcDie(string killer){
|
||||
Debug.Log($"{killer} killed {pname} : isItMe? -> {isLocalPlayer}");
|
||||
KillfeedMgr.instance.AddNewEntry($"<b>{pname}</b> was killed by <b>{killer}</b>");
|
||||
gameObject.SetActive(false);
|
||||
if(isLocalPlayer){
|
||||
//TODO: Death message goes here
|
||||
|
||||
@@ -17,6 +17,7 @@ public class TrailMgr : MonoBehaviour
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
#if PLATFORM_ANDROID
|
||||
positions = new Vector3[trail.positionCount];
|
||||
int length = trail.GetPositions(positions);
|
||||
if(length > trailsPool.Count){
|
||||
@@ -37,6 +38,7 @@ public class TrailMgr : MonoBehaviour
|
||||
trailsPool[i].SetActive(false);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user