284 lines
6.2 KiB
C#
284 lines
6.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BitStrap;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class jkmStatistic : MonoBehaviour
|
|
{
|
|
[Serializable]
|
|
public struct stFishesWeight
|
|
{
|
|
[SerializeField]
|
|
public string rang;
|
|
|
|
[SerializeField]
|
|
public int nActive;
|
|
}
|
|
|
|
[Serializable]
|
|
public struct stTimer
|
|
{
|
|
[SerializeField]
|
|
public string name;
|
|
|
|
[SerializeField]
|
|
public float deltaTime;
|
|
|
|
[SerializeField]
|
|
public int counter;
|
|
|
|
public float startTime;
|
|
|
|
public float endTime;
|
|
|
|
public stTimer(string name)
|
|
{
|
|
this.name = name;
|
|
startTime = Time.time;
|
|
endTime = Time.time;
|
|
counter = 0;
|
|
deltaTime = 0f;
|
|
}
|
|
|
|
public void End()
|
|
{
|
|
endTime = Time.time;
|
|
deltaTime = endTime - startTime;
|
|
}
|
|
|
|
public void AddToCountr(int num)
|
|
{
|
|
counter += num;
|
|
}
|
|
}
|
|
|
|
public jkmFishPanel fishPanel;
|
|
|
|
public Text baitPosY;
|
|
|
|
public Text baitRange;
|
|
|
|
public Text spinnigMethod;
|
|
|
|
[ReadOnly]
|
|
public int numSpawnPoints;
|
|
|
|
[ReadOnly]
|
|
[SerializeField]
|
|
public int numSpawnFish;
|
|
|
|
[SerializeField]
|
|
[ReadOnly]
|
|
private int numActiveFish;
|
|
|
|
[SerializeField]
|
|
private stFishesWeight[] numActiveFishInBaitSize;
|
|
|
|
[SerializeField]
|
|
public List<stTimer> timers = new List<stTimer>();
|
|
|
|
public LogsWindow logsWindow;
|
|
|
|
private static jkmStatistic instance;
|
|
|
|
public Bait activeBait;
|
|
|
|
public FishDebugMarker fishDebugMarkerPrefab;
|
|
|
|
public static jkmStatistic Instance
|
|
{
|
|
get
|
|
{
|
|
if (!instance)
|
|
{
|
|
instance = UnityEngine.Object.FindObjectOfType<jkmStatistic>();
|
|
if ((bool)instance)
|
|
{
|
|
instance.Init();
|
|
}
|
|
}
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
|
|
}
|
|
|
|
[Button]
|
|
public void ShowFishStatistics()
|
|
{
|
|
if ((bool)logsWindow)
|
|
{
|
|
logsWindow.ShowWindow(true);
|
|
logsWindow.text.text = string.Empty;
|
|
}
|
|
HUDMultiplayer hUDMultiplayer = UnityEngine.Object.FindObjectOfType<HUDMultiplayer>();
|
|
Bait[] array = UnityEngine.Object.FindObjectsOfType<Bait>();
|
|
Bait[] array2 = array;
|
|
foreach (Bait bait in array2)
|
|
{
|
|
string text = string.Concat(bait.name, " length range = ", bait.fishLengthRange, ", weight range = ", bait.fishWeightRang);
|
|
if ((bool)logsWindow)
|
|
{
|
|
Text text2 = logsWindow.text;
|
|
text2.text = text2.text + text + " \n";
|
|
}
|
|
Debug.Log("<color=blue>" + text + " </color>");
|
|
}
|
|
Debug.Log("<color=blue>-----------------------------------------------</color>");
|
|
Fish[] array3 = UnityEngine.Object.FindObjectsOfType<Fish>();
|
|
Dictionary<Fish.Species, List<Fish>> dictionary = new Dictionary<Fish.Species, List<Fish>>();
|
|
Fish[] array4 = array3;
|
|
foreach (Fish fish in array4)
|
|
{
|
|
List<Fish> value;
|
|
if (!dictionary.TryGetValue(fish.species, out value))
|
|
{
|
|
dictionary[fish.species] = new List<Fish>();
|
|
}
|
|
dictionary[fish.species].Add(fish);
|
|
}
|
|
foreach (List<Fish> value2 in dictionary.Values)
|
|
{
|
|
Vector3 vector = new Vector3(99999f, 0f, -99999f);
|
|
Vector3 vector2 = new Vector3(99999f, 0f, -99999f);
|
|
foreach (Fish item in value2)
|
|
{
|
|
if (vector2.x > item.Length)
|
|
{
|
|
vector2.x = item.Length;
|
|
}
|
|
if (vector2.z < item.Length)
|
|
{
|
|
vector2.z = item.Length;
|
|
}
|
|
vector2.y += item.Length;
|
|
if (vector.x > item.Weight)
|
|
{
|
|
vector.x = item.Weight;
|
|
}
|
|
if (vector.z < item.Weight)
|
|
{
|
|
vector.z = item.Weight;
|
|
}
|
|
vector.y += item.Weight;
|
|
}
|
|
vector2.y /= value2.Count;
|
|
vector.y /= value2.Count;
|
|
string text3 = string.Concat(value2[0].name, " number = ", value2.Count, ", length(min,med,max) = ", vector2, ", weight = ", vector);
|
|
Bait[] array5 = array;
|
|
foreach (Bait bait2 in array5)
|
|
{
|
|
FishLikesParams component = bait2.GetComponent<FishLikesParams>();
|
|
foreach (FishLikesParams.FishInterest fishInterest in component.fishInterests)
|
|
{
|
|
if (fishInterest.species == value2[0].species)
|
|
{
|
|
string text4 = text3;
|
|
text3 = text4 + ",Like(" + bait2.name + ", " + fishInterest.interest + " )";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if ((bool)logsWindow)
|
|
{
|
|
Text text5 = logsWindow.text;
|
|
text5.text = text5.text + text3 + " \n";
|
|
}
|
|
Debug.Log("<color=blue>" + text3 + " </color>");
|
|
}
|
|
}
|
|
|
|
private void Init()
|
|
{
|
|
numActiveFishInBaitSize = new stFishesWeight[18];
|
|
for (int i = 0; i < numActiveFishInBaitSize.Length; i++)
|
|
{
|
|
numActiveFishInBaitSize[i] = default(stFishesWeight);
|
|
numActiveFishInBaitSize[i].nActive = 0;
|
|
}
|
|
}
|
|
|
|
public static void AddSpawnedFish()
|
|
{
|
|
if (!(Instance == null))
|
|
{
|
|
instance.numSpawnFish++;
|
|
}
|
|
}
|
|
|
|
public static void AddActiveFish(Fish fish, int num)
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
return;
|
|
}
|
|
instance.numActiveFish += num;
|
|
if (num == 0)
|
|
{
|
|
num = 1;
|
|
}
|
|
if (!GlobalSettings.Instance || !GlobalSettings.Instance.fishManager)
|
|
{
|
|
return;
|
|
}
|
|
for (int i = 0; i < GlobalSettings.Instance.fishManager.hookToFishWeight.Count; i++)
|
|
{
|
|
if (fish.Weight >= GlobalSettings.Instance.fishManager.hookToFishWeight[i].x && fish.Weight <= GlobalSettings.Instance.fishManager.hookToFishWeight[i].y)
|
|
{
|
|
if (num > 0 || instance.numActiveFishInBaitSize[i].nActive > 0)
|
|
{
|
|
instance.numActiveFishInBaitSize[i].nActive += num;
|
|
}
|
|
instance.numActiveFishInBaitSize[i].rang = instance.numActiveFishInBaitSize[i].nActive + " (" + GlobalSettings.Instance.fishManager.hookToFishWeight[i].x + "=>" + GlobalSettings.Instance.fishManager.hookToFishWeight[i].y + ")";
|
|
}
|
|
}
|
|
}
|
|
|
|
public static int AddTimeCounter(string name)
|
|
{
|
|
stTimer item = new stTimer(name);
|
|
if ((bool)Instance)
|
|
{
|
|
instance.timers.Add(item);
|
|
return instance.timers.Count - 1;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public static void EndTimeCounter(int timerId)
|
|
{
|
|
if (!(Instance == null) && timerId >= 0)
|
|
{
|
|
instance.timers[timerId].End();
|
|
int num = 0;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if ((bool)activeBait)
|
|
{
|
|
baitPosY.text = "BaitPosY = " + activeBait.transform.position.y;
|
|
}
|
|
}
|
|
|
|
public static void NewBaitSize(Bait bait)
|
|
{
|
|
if ((bool)Instance)
|
|
{
|
|
Instance.activeBait = bait;
|
|
FishDebugMarker[] array = UnityEngine.Object.FindObjectsOfType<FishDebugMarker>();
|
|
FishDebugMarker[] array2 = array;
|
|
foreach (FishDebugMarker fishDebugMarker in array2)
|
|
{
|
|
fishDebugMarker.NewBait(bait);
|
|
}
|
|
Instance.baitRange.text = "BaitRang:" + bait.fishWeightRang.ToString();
|
|
}
|
|
}
|
|
}
|