修补一些bug

This commit is contained in:
2025-09-15 12:01:54 +08:00
parent 249836d1ec
commit f8aea1c383
18 changed files with 875 additions and 456 deletions

View File

@@ -192,9 +192,7 @@ namespace Convention
get
{
if (source == null)
source = this.SeekComponent<AudioSource>();
if (source == null)
source = this.gameObject.AddComponent<AudioSource>();
source = this.GetOrAddComponent<AudioSource>();
return source;
}
set
@@ -251,7 +249,7 @@ namespace Convention
}
public override void SetSpeed(float speed)
{
SetSpeed(speed, 1.0f, "Master", "MasterPitch", "PitchShifterPitch", true);
SetSpeed(speed, "Master", "MasterPitch", "PitchShifterPitch", true);
}
public override void SetVolume(float volume)
{
@@ -259,7 +257,6 @@ namespace Convention
}
public void SetSpeed(float speed,
float TargetPitchValue,
string TargetGroupName,
string TargetPitch_Attribute_Name,
string TargetPitchshifterPitch_Attribute_Name,
@@ -267,19 +264,19 @@ namespace Convention
{
if (Mixer != null)
{
if (TargetPitchValue > 0)
if (speed > 0)
{
Source.pitch = 1;
Mixer.SetFloat(TargetPitch_Attribute_Name, TargetPitchValue);
float TargetPitchshifterPitchValue = 1.0f / TargetPitchValue;
Mixer.SetFloat(TargetPitch_Attribute_Name, speed);
float TargetPitchshifterPitchValue = 1.0f / speed;
Mixer.SetFloat(TargetPitchshifterPitch_Attribute_Name, TargetPitchshifterPitchValue);
Source.outputAudioMixerGroup = Mixer.FindMatchingGroups(TargetGroupName)[0];
}
else
{
Source.pitch = -1;
Mixer.SetFloat(TargetPitch_Attribute_Name, -TargetPitchValue);
float TargetPitchshifterPitchValue = -1.0f / TargetPitchValue;
Mixer.SetFloat(TargetPitch_Attribute_Name, -speed);
float TargetPitchshifterPitchValue = -1.0f / speed;
Mixer.SetFloat(TargetPitchshifterPitch_Attribute_Name, TargetPitchshifterPitchValue);
Source.outputAudioMixerGroup = Mixer.FindMatchingGroups(TargetGroupName)[0];
}
@@ -424,6 +421,7 @@ namespace Convention
BandNegativeCheck();
}
//void Update()
//{
// float[] spectrum = new float[256];

View File

@@ -90,11 +90,14 @@ namespace Convention
isFocus = false;
if (Keyboard.current[Key.LeftCtrl].isPressed && Keyboard.current[Key.LeftShift].isPressed)
{
TargetFollow.localEulerAngles = new(0, TargetFollow.eulerAngles.y, 0);
if(Keyboard.current[Key.Z].wasPressedThisFrame)
if(Keyboard.current[Key.Z].isPressed)
{
TargetFollow.localPosition = Vector3.zero;
}
else
{
TargetFollow.localEulerAngles = new(0, TargetFollow.eulerAngles.y, 0);
}
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
@@ -2144,5 +2145,21 @@ namespace Convention
return Activator.CreateInstance(type);
}
}
public static partial class ConventionUtility
{
public static byte[] ReadAllBytes(this BinaryReader reader)
{
const int bufferSize = 4096;
using (var ms = new MemoryStream())
{
byte[] buffer = new byte[bufferSize];
int count;
while ((count = reader.Read(buffer, 0, buffer.Length)) != 0)
ms.Write(buffer, 0, count);
return ms.ToArray();
}
}
}
}

View File

@@ -127,12 +127,17 @@ namespace Convention
public class InternalProperty
{
public Dictionary<string, object> property = new();
public Dictionary<string, object> find = new();
}
public GlobalConfig SaveProperties()
{
var configFile = this.ConfigFile;
configFile.SaveAsJson(new InternalProperty() { property = data_pair });
configFile.SaveAsJson(new InternalProperty()
{
property = data_pair,
find = data_find
});
return this;
}
public GlobalConfig LoadProperties()
@@ -196,14 +201,18 @@ namespace Convention
Log("Error", message);
}
private Dictionary<string, object> data_find = new();
public object FindItem(string key, object @default = null)
{
if (Contains(key))
{
data_find.Remove(key);
return this[key];
}
else
{
data_find[key] = @default;
LogPropertyNotFound(key, @default);
return @default;
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Convention
{
@@ -54,6 +55,11 @@ namespace Convention
public readonly Func<T, T, int> _comparer_func = null;
public readonly Comparator _comparator = Comparator.less;
public T GetTP(float p)
{
return _elements[(int)(Mathf.Clamp01(p) * _elements.Length)];
}
public int Size => _size;
public int Capacity => _capacity;
public int Count => _size;