// Start is called before the first frame update void Awake() { subbutton = GameObject.Find("Submit").GetComponent <Button>(); subbutton.onClick.AddListener(delegate { PopulateList(); newgraph.ShowGraph(hoursSlept); }); hourinput = GameObject.Find("Input").GetComponent <TMP_InputField>(); drawbutton = GameObject.Find("Draw").GetComponent <Button>(); drawbutton.onClick.AddListener(delegate { newgraph.ShowGraph(hoursSlept); }); }
public void Generate() { records = new List <Record>(dbHandler.GetRecords()); GetAllPoints(att1, att2); //points = new List<Point>() {new Point(1,9), //new Point(2,10), //new Point(4,8), //new Point(5,6), //new Point(6,7), //new Point(9,10), //new Point(9,1), //new Point(3,2), //new Point(6,2), //new Point(4,3), //new Point(8,3), //new Point(10,4), //new Point(7,5)}; var temp = Time.realtimeSinceStartup; List <Point> skyline; skyline = GetSkyline(); skyline.Sort((p1, p2) => p1.x.CompareTo(p2.x)); Debug.Log("Time for n: " + (Time.realtimeSinceStartup - temp).ToString("f6") + " sec."); GraphInit(); graph.ShowGraph(skyline); graph.ShowCircles(points.Except(skyline).ToList()); }
// Start is called before the first frame update void Start() { // Welcome Message, showing that the communication between C++ dll and Unity was established correctly. Debug.Log("Connection between C++ Interface and Unity established with success !\n"); PluxDevManager = new PluxDeviceManager(ScanResults, ConnectionDone); int welcomeNumber = PluxDevManager.WelcomeFunctionUnity(); Debug.Log("Welcome Number: " + welcomeNumber); // Initialization of Variables. MultiThreadList = new List <List <int> >(); ActiveChannels = new List <int>(); // Initialization of graphical zone. WindowGraph.IGraphVisual graphVisual = new WindowGraph.LineGraphVisual(GraphContainer, DotSprite, new Color(0, 158, 227, 0), new Color(0, 158, 227)); GraphContainer = graphVisual.GetGraphContainer(); GraphZone = new WindowGraph(GraphContainer, graphVisual); GraphZone.ShowGraph(new List <int>() { 0 }, graphVisual, -1, (int _i) => "" + (_i), (float _f) => Mathf.RoundToInt(_f) + "k"); // Create a timer that controls the update of real-time plot. System.Timers.Timer waitForPlotTimer = new System.Timers.Timer(); waitForPlotTimer.Elapsed += new ElapsedEventHandler(OnWaitingTimeEnds); waitForPlotTimer.Interval = 1000; // 1 second. waitForPlotTimer.Enabled = true; waitForPlotTimer.AutoReset = true; }
// wellnes [0-100] // if bellow 30 people get unhappy and die private void UpdateWellness(float epochWellness) { // wellness calculation is abit more complicated historyPopulation[epoch] = GetPopulation(); // float C02Desire = 800; // less than, for the world float NuclearDesire = 80; // less than, for the world float powerDesire = GetPowerDesire(); // float powerWellness = Math.Max(0, 100 * ( (historyPower[epoch] - powerDesire*0.1f)/ powerDesire)); float b = 27; // historyPower[epoch] float x = Mathf.Max(0f, powerDesire - historyPower[epoch]); float powerWellness = Mathf.Min(1f, (b / (x + 0.8f * b)) - 0.2466f); x = historyC02[epoch]; float C02Wellness = 1; if (x > 0) { C02Wellness = Mathf.Min(1f, -(x * x) / (280 * 280) + 1); } // float C02Wellness = 30 * Mathf.Clamp((historyC02[epoch] - C02Desire)/ C02Desire,0, 9999); // float NuclearWellness = 30 * Mathf.Clamp((historyNuclear[epoch] - NuclearDesire) / NuclearDesire, 0, 9999); // historyWellness[epoch] = historyWellness[epoch-1] + epochWellness + powerWellness +C02Wellness + NuclearWellness; // historyWellness[epoch] = powerWellness*100; if (powerWellness < 0.1 || C02Wellness < 0.1) { inGame = false; gameOverController.YouLost(); Debug.Log("powerWellness = " + powerWellness); Debug.Log("C02Wellness = " + C02Wellness); } historyWellness[epoch] = C02Wellness * 50 + powerWellness * 50; historyPowerPlot[epoch] = powerWellness * 100; historyC02Plot[epoch] = C02Wellness * 100; if (epoch > 1) { windowGraph.ShowGraph(historyWellness, epoch, 0, 100); windowGraphPower.ShowGraph(historyPowerPlot, epoch, 0, 100); windowGraphCO2.ShowGraph(historyC02Plot, epoch, 0, 100); /* * string s=""; * for (int i = 0; i < historyC02Plot.Length; i++) * { * s += historyC02Plot[i] + " , "; * } * Debug.Log("C02Wellness = " + s); */ } }
// Start is called before the first frame update void Start() { // Welcome Message, showing that the communication between C++ dll and Unity was established correctly. Debug.Log("Connection between C++ Interface and Unity established with success !\n"); PluxDevManager = new PluxDeviceManager(); int welcomeNumber = PluxDevManager.WelcomeFunctionUnity(); Debug.Log("Welcome Number: " + welcomeNumber); // Initialization of Variables. MultiThreadList = new List <List <int> >(); ActiveChannels = new List <int>(); // Initialization of graphical zone. WindowGraph.IGraphVisual graphVisual = new WindowGraph.LineGraphVisual(GraphContainer, DotSprite, new Color(0, 158, 227, 0), new Color(0, 158, 227)); GraphContainer = graphVisual.GetGraphContainer(); GraphZone = new WindowGraph(GraphContainer, graphVisual); GraphZone.ShowGraph(new List <int>() { 0 }, graphVisual, -1, (int _i) => "" + (_i), (float _f) => Mathf.RoundToInt(_f) + "k"); }
public void Initialize() { var is360Level = _beatmapData.spawnRotationEventsCount > 0; var pos = is360Level ? _config.Chart360LevelPosition : _config.ChartStandardLevelPosition; var rot = is360Level ? Quaternion.Euler(_config.Chart360LevelRotation) : Quaternion.Euler(_config.ChartStandardLevelRotation); _floatingScreen = FloatingScreen.CreateFloatingScreen(_config.ChartSize, false, pos, rot, curvatureRadius: 0f, hasBackground: _config.HasBackground); _floatingScreen.SetRootViewController(this, AnimationType.None); _floatingScreen.name = nameof(SongChartVisualizer); if (_config.HasBackground) { var imageView = _floatingScreen.GetComponentInChildren <ImageView>(); imageView.material = _assetLoader.UINoGlowMaterial; imageView.color = _config.CombinedBackgroundColor; transform.SetParent(imageView.transform); } if (_audioTimeSyncController.songLength < 0) { _shouldNotRunTick = true; return; } // _siraLog.Debug($"There are {_beatmapData.beatmapObjectsData.Count(x => x.beatmapObjectType == BeatmapObjectType.Note)} notes"); // _siraLog.Debug($"There are {_beatmapData.beatmapLinesData.Count} lines"); _npsSections = GetNpsSections(_beatmapData); #if DEBUG for (var i = 0; i < _npsSections.Count; i++) { var npsInfos = _npsSections[i]; _siraLog.Debug($"Nps at section {i + 1}: {npsInfos.Nps} (from [{npsInfos.FromTime}] to [{npsInfos.ToTime}])"); } #endif _siraLog.Debug("Loading assetbundle.."); var assembly = Assembly.GetExecutingAssembly(); using (var stream = assembly.GetManifestResourceStream("SongChartVisualizer.UI.linegraph")) { _assetBundle = AssetBundle.LoadFromStream(stream); } if (!_assetBundle) { _siraLog.Warn("Failed to load AssetBundle! The chart will not work properly.."); } else { var prefab = _assetBundle.LoadAsset <GameObject>("LineGraph"); var sprite = _assetBundle.LoadAsset <Sprite>("Circle"); var go = Instantiate(prefab, transform); go.transform.Translate(0.04f, 0, 0); _windowGraph = go.AddComponent <WindowGraph>(); _windowGraph.circleSprite = sprite; _windowGraph.transform.localScale /= 10; var npsValues = _npsSections.Select(info => info.Nps).ToList(); _windowGraph.ShowGraph(npsValues, false, linkColor: _config.LineColor); _currentSectionIdx = 0; _currentSection = _npsSections[_currentSectionIdx]; CreateSelfCursor(_config.PointerColor); if (_config.PeakWarning) { var highestValue = _npsSections.Max(info => info.Nps); _hardestSectionIdx = _npsSections.FindIndex(info => Math.Abs(info.Nps - highestValue) < 0.001f); PrepareWarningText(); FadeInTextIfNeeded(); } } }
// Update function, being constantly invoked by Unity. void Update() { try { // Get packages of data. int[] pacakgeOfData = PluxDevManager.GetPackageOfData(VisualizationChannel, ActiveChannels, UpdatePlotFlag); // Check if there it was communicated an event/error code. if (pacakgeOfData != null) { if (pacakgeOfData.Length != 0) { // Creation of the first graphical representation of the results. if (MultiThreadList[VisualizationChannel].Count >= 0) { if (FirstPlot == true) { // Update flag (after this step we won't enter again on this statement). FirstPlot = false; // Plot first set of data. // Subsampling if sampling rate is bigger than 100 Hz. List <int> subSamplingList = GetSubSampleList(new int[GraphWindSize], SamplingRate, GraphWindSize); GraphZone.ShowGraph(subSamplingList, null, -1, (int _i) => "-" + (GraphWindSize - _i), (float _f) => Mathf.RoundToInt(_f / 1000) + "k"); } // Update plot. else if (FirstPlot == false) { // This if clause ensures that the real-time plot will only be updated every 1 second (Memory Restrictions). if (UpdatePlotFlag == true && pacakgeOfData != null) { // Get the values linked with the last 10 seconds of information. MultiThreadSubList = GetSubSampleList(pacakgeOfData, SamplingRate, GraphWindSize); GraphZone.UpdateValue(MultiThreadSubList); // Reboot flag. UpdatePlotFlag = false; } } } } } } catch (ArgumentOutOfRangeException exception) { Debug.Log("Exception in the Update method: " + exception.StackTrace); Console.WriteLine("Current Thread: " + Thread.CurrentThread.Name); } catch (ExternalException exc) { Debug.Log("ExternalException in the Update() callback:\n" + exc.Message + "\n" + exc.StackTrace); // Stop Acquisition in a secure way. StopButtonFunction(-1); } catch (Exception exc) { Debug.Log("Unidentified Exception inside Update() callback:\n" + exc.Message + "\n" + exc.StackTrace); } }
// Update function, being constantly invoked by Unity. void Update() { // Lock is an essential step to ensure that variables shared by the same thread will not be accessed at the same time. lock (MultiThreadString) { if (MultiThreadString.Length > 0) { // Update counter, preparing for the next iterations. LastLenMultiThreadString = MultiThreadString.Length; // Split our string, taking into consideration our separator. string[] MultiThreadArray = MultiThreadString.Split('#'); // Each entry of the MultiThreadArray will contain a package of data from the different active channels. for (int i = 0; i < MultiThreadArray.Length; i++) { string[] MultiThreadSubArray = MultiThreadArray[i].Split('&'); for (int j = 0; j < MultiThreadSubArray.Length - 1; j++) { // Inclusion of acquired data in our global data structure. if (MultiThreadSubArray[j] != "") { tempInt = Int32.Parse(MultiThreadSubArray[j]); MultiThreadList[ActiveChannels[j]].Add(tempInt); } } } // Reboot string. MultiThreadString = ""; // Check if there it was communicated an event/error code. int lastCommunicatedData = MultiThreadList[ActiveChannels[0]][MultiThreadList[ActiveChannels[0]].Count - 1]; if (lastCommunicatedData >= 0) { // Check if list contains more than 20 seconds of data [Memory Release]. if (MultiThreadList[VisualizationChannel].Count > 2 * GraphWindSize) { for (int k = 1; k < MultiThreadList.Count; k++) { // Check if the current channel is an active channel. if (ActiveChannels.Contains(k)) { MultiThreadList[k] = MultiThreadList[k].GetRange(MultiThreadList[k].Count - 2 * GraphWindSize, 2 * GraphWindSize); } } } // Creation of the first graphical representation of the results. if (MultiThreadList[VisualizationChannel].Count >= 0) { if (MultiThreadList[VisualizationChannel].Count != 0 && MultiThreadList[VisualizationChannel].Count > GraphWindSize && FirstPlot == true) { // Update flag (after this step we won't enter again on this statement). FirstPlot = false; // Hide Acquiring Icon Image. //AcquiringIcon.SetActive(false); // Plot first set of data. // Subsampling if sampling rate is bigger than 100 Hz. List <int> subSamplingList = GetSubSampleList(MultiThreadList[VisualizationChannel], SamplingRate, GraphWindSize); GraphZone.ShowGraph(subSamplingList, null, -1, (int _i) => "-" + (GraphWindSize - _i), (float _f) => Mathf.RoundToInt(_f / 1000) + "k"); } // Update plot. else if (FirstPlot == false) { // Get the values linked with the last 10 seconds of information. MultiThreadSubList = GetSubSampleList(MultiThreadList[VisualizationChannel], SamplingRate, GraphWindSize); for (int j = 0; j < MultiThreadSubList.Count; j++) { GraphZone.UpdateValue(j, MultiThreadSubList[j]); } } } } // If an event/error code was sent by PluxDeviceManager then the acquisition should be stopped. else { // Stop Acquisition in a secure way. StopButtonFunction(lastCommunicatedData); } } } }