Update
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class vDisplayValueFade : MonoBehaviour
|
||||
{
|
||||
public CanvasGroup group;
|
||||
public AnimationCurve groupAlphaCurve;
|
||||
public float upSpeed;
|
||||
|
||||
public float timeToDestroy = 4f;
|
||||
float currentTime;
|
||||
Transform rotateTransform;
|
||||
void Awake()
|
||||
{
|
||||
group.alpha = 0;
|
||||
}
|
||||
public void Update()
|
||||
{
|
||||
if (rotateTransform == null)
|
||||
{
|
||||
if (Camera.current)
|
||||
{
|
||||
rotateTransform = Camera.current.transform;
|
||||
transform.forward = rotateTransform.position - transform.position;
|
||||
group.alpha = 1;
|
||||
}
|
||||
else group.alpha = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
transform.Translate(Vector3.up * upSpeed * Time.deltaTime);
|
||||
|
||||
transform.forward = rotateTransform.position - transform.position;
|
||||
currentTime += Time.deltaTime;
|
||||
var eval = currentTime / timeToDestroy;
|
||||
|
||||
if (group) group.alpha = groupAlphaCurve.Evaluate(1f - eval);
|
||||
|
||||
if (currentTime >= timeToDestroy) Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d491209383dfe34fb49b0e43b6df964
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class vScoreDataDisplay : MonoBehaviour
|
||||
{
|
||||
public UnityEngine.UI.Text index;
|
||||
public UnityEngine.UI.Text score;
|
||||
public UnityEngine.UI.Text[] hits;
|
||||
|
||||
public void Show(int index, float? score, List<float> hits)
|
||||
{
|
||||
if (this.index) this.index.text = (index).ToString("00");
|
||||
if (this.score) this.score.text = score != null ? ((float)score).ToString("00") : "--";
|
||||
if (hits != null)
|
||||
for (int i = 0; i < this.hits.Length; i++)
|
||||
{
|
||||
var text = this.hits[i];
|
||||
if (i < hits.Count)
|
||||
{
|
||||
text.text = hits[i].ToString("00");
|
||||
}
|
||||
else break;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < this.hits.Length; i++)
|
||||
{
|
||||
var text = this.hits[i];
|
||||
text.text = "--";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4d5045929fc84648a2296654062fa24
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,36 @@
|
||||
using UnityEngine;
|
||||
[RequireComponent(typeof(UnityEngine.UI.Text))]
|
||||
public class vScorePointDisplay : MonoBehaviour
|
||||
{
|
||||
[SerializeField] protected UnityEngine.UI.Text _display;
|
||||
public string stringFormat;
|
||||
public UnityEngine.UI.InputField.OnChangeEvent onChangeDisplayText;
|
||||
|
||||
bool withOutDisplay;
|
||||
public UnityEngine.UI.Text display
|
||||
{
|
||||
get
|
||||
{
|
||||
if (withOutDisplay) return null;
|
||||
if (_display == null && !withOutDisplay) _display = GetComponent<UnityEngine.UI.Text>();
|
||||
|
||||
if (_display == null) withOutDisplay = true;
|
||||
return _display;
|
||||
}
|
||||
}
|
||||
|
||||
const string StringFormatDefault = "{0}";
|
||||
|
||||
public void ShowValue(float value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(stringFormat)) stringFormat = StringFormatDefault;
|
||||
string text = string.Format(stringFormat, value.ToString());
|
||||
if (display) display.text = text;
|
||||
onChangeDisplayText.Invoke(text);
|
||||
}
|
||||
|
||||
public void ShowValue(int value)
|
||||
{
|
||||
ShowValue((float)value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d958ed1b50d6c754699ed54bffa5c25c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class vSendScore : MonoBehaviour
|
||||
{
|
||||
public int displayID;
|
||||
public vShooterScore shooterScore;
|
||||
public UnityEngine.Events.UnityEvent onAdd;
|
||||
public void SendScore(float value)
|
||||
{
|
||||
if (shooterScore == null)
|
||||
{
|
||||
shooterScore = FindObjectOfType<vShooterScore>();
|
||||
}
|
||||
|
||||
if (shooterScore != null)
|
||||
{
|
||||
shooterScore.AddScore(new vShooterScore.ScorePoint(displayID, value));
|
||||
}
|
||||
onAdd.Invoke();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fdb1a130178fa84e8d6c7645c526576
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,183 @@
|
||||
using Invector;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
public class vShooterScore : MonoBehaviour
|
||||
{
|
||||
[vButton("ShowData", "ShowData", typeof(vShooterScore), false)]
|
||||
[vButton("ClearData", "ClearData", typeof(vShooterScore), false)]
|
||||
public TargetPointCounter scoreDisplay;
|
||||
public TargetPointCounter[] hitCounters;
|
||||
public vScoreDataDisplay[] dataDisplays;
|
||||
|
||||
ScoreDATAList scoreDATAList;
|
||||
[System.Serializable]
|
||||
public class TargetPointCounter
|
||||
{
|
||||
[Invector.vReadOnly(false)] public float currentScore;
|
||||
public vScorePointDisplay display;
|
||||
public void ShowValue()
|
||||
{
|
||||
display.ShowValue(currentScore);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddScore(ScorePoint score)
|
||||
{
|
||||
scoreDisplay.currentScore += score.value;
|
||||
scoreDisplay.ShowValue();
|
||||
|
||||
if (hitCounters.Length > 0 && score.id < hitCounters.Length)
|
||||
{
|
||||
TargetPointCounter targetPoint = hitCounters[score.id];
|
||||
|
||||
if (targetPoint != null)
|
||||
{
|
||||
targetPoint.currentScore++;
|
||||
targetPoint.ShowValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ScorePoint
|
||||
{
|
||||
public int id;
|
||||
public float value;
|
||||
|
||||
public ScorePoint(float value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
public ScorePoint(int id, float value)
|
||||
{
|
||||
this.id = id;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal void StartScore()
|
||||
{
|
||||
scoreDisplay.currentScore = 0;
|
||||
foreach (var s in hitCounters)
|
||||
{
|
||||
s.currentScore = 0;
|
||||
}
|
||||
|
||||
scoreDATAList = LoadData("ShooterScore");
|
||||
}
|
||||
internal void FinishScore()
|
||||
{
|
||||
if (scoreDATAList != null)
|
||||
{
|
||||
//Debug.Log("FINISH SCORE");
|
||||
var data = new ScoreDATA();
|
||||
data.score = this.scoreDisplay.currentScore;
|
||||
data.hits = new List<float>();
|
||||
foreach (var s in hitCounters)
|
||||
{
|
||||
data.hits.Add(s.currentScore);
|
||||
}
|
||||
if (scoreDATAList.datas.Count < dataDisplays.Length)
|
||||
{
|
||||
scoreDATAList.datas.Add(data);
|
||||
scoreDATAList.datas = scoreDATAList.datas.OrderBy(d => d.score).Reverse().ToList();
|
||||
//Debug.Log("ADD NEW SCORE");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
scoreDATAList.datas.Add(data);
|
||||
scoreDATAList.datas = scoreDATAList.datas.OrderBy(d => d.score).Reverse().ToList();
|
||||
var dataCount = scoreDATAList.datas.Count - dataDisplays.Length;
|
||||
bool add = true;
|
||||
for (int i = 0; i < dataCount; i++)
|
||||
{
|
||||
if (scoreDATAList.datas[scoreDATAList.datas.Count - 1].Equals(data))
|
||||
{
|
||||
add = false;
|
||||
}
|
||||
scoreDATAList.datas.RemoveAt(scoreDATAList.datas.Count - 1);
|
||||
}
|
||||
if (add)
|
||||
{
|
||||
//Debug.Log("ADD NEW SCORE");
|
||||
}
|
||||
}
|
||||
|
||||
SaveData("ShooterScore");
|
||||
ShowData();
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearData()
|
||||
{
|
||||
this.scoreDATAList = new ScoreDATAList();
|
||||
SaveData("ShooterScore");
|
||||
}
|
||||
|
||||
public void ShowData()
|
||||
{
|
||||
if (scoreDATAList == null || !Application.isPlaying)
|
||||
{
|
||||
scoreDATAList = LoadData("ShooterScore");
|
||||
}
|
||||
|
||||
//Debug.Log("SHOW DATA");
|
||||
for (int i = 0; i < dataDisplays.Length; i++)
|
||||
{
|
||||
if (scoreDATAList.datas.Count > 0 && i < scoreDATAList.datas.Count)
|
||||
{
|
||||
var d = scoreDATAList.datas[i];
|
||||
dataDisplays[i].Show(i + 1, d.score, d.hits);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataDisplays[i].Show(i + 1, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveData(string dataName)
|
||||
{
|
||||
if (scoreDATAList == null)
|
||||
{
|
||||
scoreDATAList = new ScoreDATAList();
|
||||
}
|
||||
|
||||
string data = JsonUtility.ToJson(scoreDATAList);
|
||||
string path = Application.dataPath + $"/{dataName}.json";
|
||||
System.IO.File.WriteAllText(path, data);
|
||||
//Debug.Log("SAVE SCORE FILE");
|
||||
}
|
||||
|
||||
public ScoreDATAList LoadData(string dataName)
|
||||
{
|
||||
string path = Application.dataPath + $"/{dataName}.json";
|
||||
if (!System.IO.File.Exists(path))
|
||||
{
|
||||
//Debug.Log("CREATE SCORE FILE");
|
||||
SaveData("ShooterScore");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Debug.Log("LOAD SCORE FILE");
|
||||
string data = System.IO.File.ReadAllText(path);
|
||||
scoreDATAList = JsonUtility.FromJson<ScoreDATAList>(data);
|
||||
}
|
||||
return scoreDATAList;
|
||||
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class ScoreDATAList
|
||||
{
|
||||
public List<ScoreDATA> datas = new List<ScoreDATA>();
|
||||
}
|
||||
[System.Serializable]
|
||||
public class ScoreDATA
|
||||
{
|
||||
public float score;
|
||||
public List<float> hits = new List<float>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4baf9145075b9948ad61a1c170850af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,93 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class vShooterTrainingController : MonoBehaviour
|
||||
{
|
||||
public vShooterScore shooterScore;
|
||||
public float timeToStartTraining = 3f;
|
||||
public float timeToFinishTraining = 60f;
|
||||
public UnityEngine.UI.Text timeDisplay;
|
||||
|
||||
public UnityEngine.Events.UnityEvent onInit, onStartCounter, onFinishCounter, onCancelTraining;
|
||||
|
||||
Coroutine currentRoutine;
|
||||
float currentTime;
|
||||
public bool initOnStart;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
if (shooterScore)
|
||||
{
|
||||
if (initOnStart) StartTraining();
|
||||
}
|
||||
|
||||
}
|
||||
public void StartTraining()
|
||||
{
|
||||
if (!shooterScore) return;
|
||||
shooterScore.StartScore();
|
||||
FinishTraining();
|
||||
currentRoutine = StartCoroutine(RunTraining());
|
||||
|
||||
}
|
||||
public void CancelTraining()
|
||||
{
|
||||
if (!shooterScore) return;
|
||||
if (currentRoutine != null)
|
||||
{
|
||||
StopCoroutine(currentRoutine);
|
||||
currentRoutine = null;
|
||||
onCancelTraining.Invoke();
|
||||
}
|
||||
}
|
||||
public void FinishTraining()
|
||||
{
|
||||
if (!shooterScore) return;
|
||||
if (currentRoutine != null)
|
||||
{
|
||||
StopCoroutine(currentRoutine);
|
||||
currentRoutine = null;
|
||||
shooterScore.FinishScore();
|
||||
}
|
||||
|
||||
timeDisplay.text = "";
|
||||
|
||||
}
|
||||
|
||||
IEnumerator RunTraining()
|
||||
{
|
||||
onInit.Invoke();
|
||||
yield return new WaitForSeconds(1f);
|
||||
timeDisplay.text = "";
|
||||
var timeToEnd = Time.time + timeToStartTraining;
|
||||
while (timeToEnd > Time.time)
|
||||
{
|
||||
|
||||
timeDisplay.text = (timeToEnd - Time.time).ToString("00");
|
||||
yield return null;
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(.2f);
|
||||
timeDisplay.text = "";
|
||||
yield return new WaitForSeconds(.2f);
|
||||
timeDisplay.text = "GO!";
|
||||
yield return new WaitForSeconds(1f);
|
||||
timeDisplay.text = "";
|
||||
onStartCounter.Invoke();
|
||||
yield return new WaitForSeconds(.2f);
|
||||
timeToEnd = Time.time + timeToFinishTraining;
|
||||
|
||||
while (timeToEnd > Time.time)
|
||||
{
|
||||
|
||||
|
||||
timeDisplay.text = (timeToEnd - Time.time).ToString("00");
|
||||
yield return null;
|
||||
}
|
||||
onFinishCounter.Invoke();
|
||||
|
||||
shooterScore.FinishScore();
|
||||
timeDisplay.text = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b1c25e3921d23142b08a1b4a752721f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user