Skip to content

Commit

Permalink
perf: BreakShineController
Browse files Browse the repository at this point in the history
  • Loading branch information
LeZi9916 committed Oct 25, 2024
1 parent 07b81da commit 439324a
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 13 deletions.
65 changes: 65 additions & 0 deletions Assets/Script/Game/Controllers/BreakSlideShineController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using MajdataPlay.Extensions;
using MajdataPlay.Interfaces;
using MajdataPlay.Types;
using MajdataPlay.Utils;
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
#nullable enable
namespace MajdataPlay.Game.Controllers
{
public class BreakSlideShineController : MonoBehaviour
{
public IFlasher? Parent { get; set; } = null;
public SpriteRenderer[] Renderers { get; set; } = ArrayPool<SpriteRenderer>.Shared.Rent(0);

NoteStatus _state = NoteStatus.Start;
GamePlayManager _gpManager;

public void Initialize()
{
if (_state >= NoteStatus.Initialized)
return;
else if (Parent is null)
throw new NullReferenceException();
_gpManager = MajInstanceHelper<GamePlayManager>.Instance!;
if (Renderers.IsEmpty())
{
var parentObject = Parent.GameObject;
var barCount = parentObject.transform.childCount - 1;
Renderers = ArrayPool<SpriteRenderer>.Shared.Rent(barCount);
for (int i = 0; i < barCount; i++)
Renderers[i] = parentObject.transform.GetChild(i).GetComponent<SpriteRenderer>();
}
}
void Start()
{
Initialize();
}
void Update()
{
if (Renderers.IsEmpty())
return;
if (Parent is not null && Parent.CanShine)
{
var param = _gpManager.BreakParam;
foreach (var renderer in Renderers)
{
if (renderer is null)
continue;
renderer.material.SetFloat("_Brightness", param.Brightness);
renderer.material.SetFloat("_Contrast", param.Contrast);
}
}
}
void OnDestroy()
{
ArrayPool<SpriteRenderer>.Shared.Return(Renderers);
}
}

}
11 changes: 11 additions & 0 deletions Assets/Script/Game/Controllers/BreakSlideShineController.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Assets/Script/Game/Notes/SlideBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ public virtual void End(bool forceEnd = false)

foreach (GameObject obj in _slideBars)
obj.SetActive(false);

DestroyStars();
}
/// <summary>
Expand Down
7 changes: 5 additions & 2 deletions Assets/Script/Game/Notes/SlideDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@ protected override void LoadSkin()
barSprite = skin.Break;
starSprite = skin.Star.Break;
breakMaterial = skin.BreakMaterial;
var controller = gameObject.AddComponent<BreakSlideShineController>();
controller.Parent = this;
controller.Initialize();
}

foreach(var bar in bars)
Expand All @@ -474,8 +477,8 @@ protected override void LoadSkin()
if(breakMaterial != null)
{
barRenderer.material = breakMaterial;
var controller = bar.AddComponent<BreakShineController>();
controller.Parent = this;
//var controller = bar.AddComponent<BreakShineController>();
//controller.Parent = this;
}
}

Expand Down
7 changes: 5 additions & 2 deletions Assets/Script/Game/Notes/WifiDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ protected override void LoadSkin()
barSprites = skin.Break;
starSprite = skin.Star.Break;
breakMaterial = skin.BreakMaterial;
var controller = gameObject.AddComponent<BreakSlideShineController>();
controller.Parent = this;
controller.Initialize();
}
foreach(var (i,bar) in bars.WithIndex())
{
Expand All @@ -341,8 +344,8 @@ protected override void LoadSkin()
if (breakMaterial != null)
{
barRenderer.material = breakMaterial;
var controller = bar.AddComponent<BreakShineController>();
controller.Parent = this;
//var controller = bar.AddComponent<BreakShineController>();
//controller.Parent = this;
}
}
foreach(var (i, star) in _stars.WithIndex())
Expand Down
2 changes: 1 addition & 1 deletion Assets/Script/Interfaces/IFlasher.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace MajdataPlay.Interfaces
{
public interface IFlasher
public interface IFlasher : IGameObjectProvider
{
bool CanShine { get; }
}
Expand Down
15 changes: 8 additions & 7 deletions Assets/Script/Utils/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace MajdataPlay.Utils
public static class Localization
{
public static event EventHandler<Language>? OnLanguageChanged;
public static Language Current
public static Language Current
{
get => _current;
get => _current;
set
{
_current = value;
Expand All @@ -36,20 +36,20 @@ public static Language Current
public static void Initialize()
{
var path = GameManager.LangPath;
if(!Directory.Exists(path))
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
return;
}
var files = new DirectoryInfo(path).GetFiles()
.Where(x => x.Extension == ".json");
List<Language> loadedLangs = new();
foreach(var fileInfo in files)
foreach (var fileInfo in files)
{
var filePath = fileInfo.FullName;
var json = File.ReadAllText(filePath);
Language? lang = null;
if (Serializer.Json.TryDeserialize(json, out lang,jsonReaderOption) && lang is not null)
if (Serializer.Json.TryDeserialize(json, out lang, jsonReaderOption) && lang is not null)
loadedLangs.Add(lang);
else
continue;
Expand All @@ -58,7 +58,7 @@ public static void Initialize()
return;
var grouped = loadedLangs.GroupBy(x => x.ToString());
Available = new Language[grouped.Count()];
foreach(var (i, grouping) in grouped.WithIndex())
foreach (var (i, grouping) in grouped.WithIndex())
Available[i] = grouping.First();
}
/// <summary>
Expand Down Expand Up @@ -97,10 +97,11 @@ public static string GetLocalizedText(string origin)

return result?.Content ?? origin;
}
public static void GetLocalizedText(MajText textType,out string origin)
public static void GetLocalizedText(MajText textType, out string origin)
{
origin = GetLocalizedText(textType);
}
static Language _current = Language.Default;
}
}

0 comments on commit 439324a

Please sign in to comment.