82 Commits

Author SHA1 Message Date
2784544884 Fix memory leak from object pools. 2023-04-21 12:18:29 +08:00
c39a02a1c2 Fix event priority. (2) 2023-04-21 00:56:58 +08:00
4c397ab2f7 Switch serialization mode to text mode. 2023-04-21 00:03:13 +08:00
6b3a9c9f0a Fix event priority. 2023-04-20 20:05:59 +08:00
1c1560f17f Fix transition clipping. 2023-04-20 19:47:35 +08:00
0699bc5614 Code cleanup. 2023-04-20 19:47:10 +08:00
d86da00258 Fix unexpected shared vector references. 2023-04-20 19:46:46 +08:00
d1ad68debe Share realtime relative motion nodes across state clones. 2023-04-20 19:45:25 +08:00
b937285a74 Fix polysec not generating mesh if body not specified. 2023-04-20 19:40:50 +08:00
69fe03475b Fix mesh.color not working on polysec. 2023-04-20 19:40:12 +08:00
e5956f2b34 Fix position anchoring. (2) 2023-04-20 14:31:49 +08:00
fdb4ab55a3 (Amend to 61b72107) 2023-04-20 14:31:03 +08:00
e30df8bdbc Fix pre-graphical update not ended within a frame. 2023-04-20 14:29:50 +08:00
251b7bc352 Matches root transform with tag. 2023-04-20 11:37:19 +08:00
61b72107ae Pull up TransformHandler. 2023-04-20 11:36:38 +08:00
d6208f19fb Fix position anchoring. 2023-04-20 00:21:39 +08:00
93d9fdd4b8 Code cleanup. 2023-04-20 00:20:28 +08:00
8670482c04 Implement new transition. 2023-04-20 00:18:49 +08:00
d2b71e41c9 Fix CubicBezier algorithm. 2023-04-20 00:15:06 +08:00
29a8ac2136 Code cleanup. 2023-04-19 15:33:45 +08:00
a9fc5130bb Move BeatTime to separate file. 2023-04-19 15:33:17 +08:00
b51c7d2352 Add chart compatibility handler. 2023-04-19 15:32:16 +08:00
56fd0936bb Fix the recycle of RMV. 2023-04-19 13:56:13 +08:00
2b3898655f Re-implement relative motion. 2023-04-19 13:54:35 +08:00
1b30d3e62c Code cleanup. 2023-04-19 13:52:55 +08:00
bdbb1fcb07 Optimize GC caused by playing motions. 2023-04-19 13:49:55 +08:00
659f2165ff Remove motion lerper. Reconstruct RMV and motion node. Add motion node pool. 2023-04-19 13:48:06 +08:00
a5439430fb Fix the position of the head anchors of tracks. 2023-04-19 13:33:41 +08:00
0f683e403c Resets object on return instead of on rent. 2023-04-19 13:32:06 +08:00
cf6a7a795b Code cleanup. 2023-04-19 13:31:17 +08:00
f664708165 Optimize GC for motion string parsing. 2023-04-18 10:10:11 +08:00
a7be55f2b0 (Amend to f4411629) 2023-04-18 10:05:14 +08:00
398cec1fc5 Code cleanup. 2023-04-18 09:47:37 +08:00
a8b9ba0af4 Loads ruleset before chart loading. 2023-04-18 09:47:07 +08:00
f54564c567 Unify VecPtComp with Vec1, and VecPt with Vec2. 2023-04-18 09:45:46 +08:00
a2c5850fcd Optimize GC while prehandling. 2023-04-18 09:35:37 +08:00
f4411629e4 Obsolete transition and rate, and add end time for relative motion node. 2023-04-18 09:33:47 +08:00
17d620ff0c Fix error on element/property list is null. (2) 2023-04-14 20:32:00 +08:00
5887b1267a Fix relative node interpolation. 2023-04-14 14:47:07 +08:00
400723d83b Make parameters of relative node optional. 2023-04-14 14:46:03 +08:00
07babcb0ff Fix position and rotation of track anchors not set. 2023-04-14 14:39:48 +08:00
f7bfe07660 Fix multiple init calls on skin components. 2023-04-14 14:32:31 +08:00
3690adf5dd Add component linesec. 2023-04-14 14:31:08 +08:00
48349b598d Separate PolygonSGO to individual file. 2023-04-14 14:29:17 +08:00
d6e3d3ad00 Make clip field in JudgeDefinition dynamic. 2023-04-09 22:13:50 +08:00
c57c82bdd1 Add progress tracking for chart loading. 2023-04-09 22:11:29 +08:00
4bc921d47e Fix error on element/property list is null. 2023-04-08 13:39:00 +08:00
8907dd19b0 Remove methods for constructor in ReflectionHelper. 2023-04-08 13:36:52 +08:00
2221658e7a Fix error when member is not found with string key during PDT interpretation. 2023-04-08 13:34:37 +08:00
916c55b4b2 Fix error when trying to generate PDT error message at the very beginning or end of the source. 2023-04-08 13:31:26 +08:00
3d8a4a64a9 Fix potential order inconsistency of pass and score lists. 2023-04-07 13:56:21 +08:00
6cb36a7064 Clean up logic of object interpretation in PDT interpreter. 2023-04-07 12:21:20 +08:00
1fc5ea8ac6 Resource cleanup. 2023-04-04 22:54:11 +08:00
6fd8e44d10 Update project settings. 2023-04-04 22:12:22 +08:00
ff19b45a9f Code cleanup. 2023-04-04 22:12:10 +08:00
f467832115 Fix logic of lerping a missing relative motion node. 2023-04-04 22:11:36 +08:00
0a25b5260d Restore PDT evaluator exception. 2023-04-04 22:09:57 +08:00
c877437ab6 Fix optimization for collapse operators. 2023-04-04 22:08:38 +08:00
676d19f452 Unify absolute value and relative node of motion event. 2023-04-04 21:18:34 +08:00
fd7c1e6635 Fix constant expression flagging in PDT evaluator. 2023-04-04 20:49:46 +08:00
c98536e8ab Prune and clean up code. 2023-04-04 20:48:17 +08:00
a013d59379 Disable warnings from TextMesh Pro. 2023-04-04 20:40:12 +08:00
2e69035618 Returns whether PDT evaluation succeeded. 2023-04-03 17:00:05 +08:00
072703efe7 Pull up error handling in PDT evaluator. 2023-04-03 16:49:34 +08:00
0c796c4d7a Fix "at anchor" selector not working in effects. 2023-03-30 14:16:25 +08:00
ee4b0c5483 Adjust steps for some settings. 2023-03-30 12:20:49 +08:00
ba7a458e7c Update Cryville.Audio. 2023-03-30 12:20:03 +08:00
06d9df304e Add start offset settings. 2023-03-30 10:37:59 +08:00
578e10bbd7 Update Cryville.Audio. 2023-03-30 10:37:08 +08:00
c685e634d5 Documentation cleanup. 2023-03-27 12:52:58 +08:00
824f401b77 Fix encoding. 2023-03-26 23:25:20 +08:00
aafc326f95 Fix collapse operators not correctly parsed after the scope is downgraded. 2023-03-26 22:40:19 +08:00
88a6410439 Re-enable mipmaps for dynamic sprites. 2023-03-26 17:09:02 +08:00
d6e1b19d32 Prevents dynamically loaded sprites from creating physical shapes. 2023-03-26 17:07:19 +08:00
6fa459e5d3 Update Unity to 2021.3.21. 2023-03-26 17:06:09 +08:00
bde6216295 Optimize GC for enumeration in context cascade insertion. 2023-03-24 20:58:45 +08:00
e03dbef5ff Optimize GC for mesh wrapper. 2023-03-24 17:10:30 +08:00
e2c683567e Introduce IntKeyedDictionary to improve performance. 2023-03-24 17:06:47 +08:00
89f391f040 Update project version. 2023-03-23 19:28:18 +08:00
92a3d5018f Merge 'dev-extension' into 'master'. 2023-03-23 19:25:14 +08:00
d510fec57b Update version. 2023-03-23 19:11:24 +08:00
c5214dd477 Update gitignore. 2023-03-17 18:08:11 +08:00
295 changed files with 3995 additions and 2670 deletions

View File

@@ -1,6 +1,9 @@
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true
[*]
charset = utf-8
# C# files
[*.cs]

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,4 @@
using System;
using System;
namespace Cryville.Common {
/// <summary>

View File

@@ -13,7 +13,7 @@ namespace Cryville.Common {
public static Binder CreateBinderOfType(Type type) {
var l = type.GetCustomAttributes(typeof(BinderAttribute), true);
if (l.Length > 0) {
return (Binder)ReflectionHelper.InvokeEmptyConstructor(
return (Binder)Activator.CreateInstance(
((BinderAttribute)l[0]).BinderType
);
}

View File

@@ -1,4 +1,4 @@
namespace Cryville.Common.Buffers {
namespace Cryville.Common.Buffers {
/// <summary>
/// A resource pool that allows reusing instances of arrays of type <typeparamref name="T" />.
/// </summary>

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
namespace Cryville.Common.Buffers {
/// <summary>

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
namespace Cryville.Common.Buffers {
/// <summary>

View File

@@ -1,4 +1,4 @@
namespace Cryville.Common.Buffers {
namespace Cryville.Common.Buffers {
/// <summary>
/// A resource pool that allows reusing instances of type <typeparamref name="T" />.
/// </summary>
@@ -28,7 +28,6 @@
_objs[_index++] = null;
}
if (obj == null) obj = Construct();
else Reset(obj);
return obj;
}
/// <summary>
@@ -36,7 +35,10 @@
/// </summary>
/// <param name="obj">The object to return.</param>
public void Return(T obj) {
if (_index > 0) _objs[--_index] = obj;
if (_index > 0) {
Reset(obj);
_objs[--_index] = obj;
}
}
/// <summary>
/// Constructs a new instance of type <typeparamref name="T" />.

View File

@@ -1,4 +1,4 @@
namespace Cryville.Common.Buffers {
namespace Cryville.Common.Buffers {
/// <summary>
/// A resource pool that allows reusing instances of type <typeparamref name="T" />, which has a parameterless constructor.
/// </summary>

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
namespace Cryville.Common.Collections.Generic {
public interface IPairList<TKey, TValue> : IList<KeyValuePair<TKey, TValue>> {

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -28,6 +28,10 @@ namespace Cryville.Common.Collections.Generic {
if (_pairList != null) _pairList.CopyTo(array, index);
else _dictionary.CopyTo(array, index);
}
public static bool IsPairCollection(Type type) {
return typeof(IPairList<TKey, TValue>).IsAssignableFrom(type) || typeof(IDictionary<TKey, TValue>).IsAssignableFrom(type);
}
}
internal class PairCollectionDebugView<TKey, TValue> {
readonly PairCollection<TKey, TValue> _self;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;

View File

@@ -0,0 +1,106 @@
using System;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.Serialization;
using System.Threading;
namespace Cryville.Common.Collections {
internal static class HashHelpers {
#if FEATURE_RANDOMIZED_STRING_HASHING
public const int HashCollisionThreshold = 100;
public static bool s_UseRandomizedStringHashing = String.UseRandomizedHashing();
#endif
// Table of prime numbers to use as hash table sizes.
// A typical resize algorithm would pick the smallest prime number in this array
// that is larger than twice the previous capacity.
// Suppose our Hashtable currently has capacity x and enough elements are added
// such that a resize needs to occur. Resizing first computes 2x then finds the
// first prime in the table greater than 2x, i.e. if primes are ordered
// p_1, p_2, ..., p_i, ..., it finds p_n such that p_n-1 < 2x < p_n.
// Doubling is important for preserving the asymptotic complexity of the
// hashtable operations such as add. Having a prime guarantees that double
// hashing does not lead to infinite loops. IE, your hash function will be
// h1(key) + i*h2(key), 0 <= i < size. h2 and the size must be relatively prime.
public static readonly int[] primes = {
3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919,
1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591,
17519, 21023, 25229, 30293, 36353, 43627, 52361, 62851, 75431, 90523, 108631, 130363, 156437,
187751, 225307, 270371, 324449, 389357, 467237, 560689, 672827, 807403, 968897, 1162687, 1395263,
1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369};
// Used by Hashtable and Dictionary's SeralizationInfo .ctor's to store the SeralizationInfo
// object until OnDeserialization is called.
private static ConditionalWeakTable<object, SerializationInfo> s_SerializationInfoTable;
internal static ConditionalWeakTable<object, SerializationInfo> SerializationInfoTable {
get {
if (s_SerializationInfoTable == null) {
ConditionalWeakTable<object, SerializationInfo> newTable = new ConditionalWeakTable<object, SerializationInfo>();
Interlocked.CompareExchange(ref s_SerializationInfoTable, newTable, null);
}
return s_SerializationInfoTable;
}
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static bool IsPrime(int candidate) {
if ((candidate & 1) != 0) {
int limit = (int)System.Math.Sqrt (candidate);
for (int divisor = 3; divisor <= limit; divisor += 2) {
if ((candidate % divisor) == 0)
return false;
}
return true;
}
return (candidate == 2);
}
internal const Int32 HashPrime = 101;
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static int GetPrime(int min) {
if (min < 0)
throw new ArgumentException("Hashtable's capacity overflowed and went negative. Check load factor, capacity and the current size of the table.");
Contract.EndContractBlock();
for (int i = 0; i < primes.Length; i++) {
int prime = primes[i];
if (prime >= min) return prime;
}
//outside of our predefined table.
//compute the hard way.
for (int i = (min | 1); i < Int32.MaxValue; i += 2) {
if (IsPrime(i) && ((i - 1) % HashPrime != 0))
return i;
}
return min;
}
public static int GetMinPrime() {
return primes[0];
}
// Returns size of hashtable to grow to.
public static int ExpandPrime(int oldSize) {
int newSize = 2 * oldSize;
// Allow the hashtables to grow to maximum possible size (~2G elements) before encoutering capacity overflow.
// Note that this check works even when _items.Length overflowed thanks to the (uint) cast
if ((uint)newSize > MaxPrimeArrayLength && MaxPrimeArrayLength > oldSize) {
Contract.Assert(MaxPrimeArrayLength == GetPrime(MaxPrimeArrayLength), "Invalid MaxPrimeArrayLength");
return MaxPrimeArrayLength;
}
return GetPrime(newSize);
}
// This is the maximum prime smaller than Array.MaxArrayLength
public const int MaxPrimeArrayLength = 0x7FEFFFFD;
}
}

View File

@@ -1,8 +1,7 @@
fileFormatVersion: 2
guid: 499dc47d3f108de4eb80b2d73e5851c5
timeCreated: 1608801352
licenseType: Free
guid: e7fe2c6f3299681448c1a546cce4dc65
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0

View File

@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
namespace Cryville.Common.Collections {
public interface IPairList : IList {

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
@@ -29,6 +29,10 @@ namespace Cryville.Common.Collections {
if (_pairList != null) _pairList.CopyTo(array, index);
else _dictionary.CopyTo(array, index);
}
public static bool IsPairCollection(Type type) {
return typeof(IPairList).IsAssignableFrom(type) || typeof(IDictionary).IsAssignableFrom(type);
}
}
internal class PairCollectionDebugView {
readonly PairCollection _self;

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics;
namespace Cryville.Common.Collections {

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f68b44d5226a73441b94e7dd5873529f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,7 @@
fileFormatVersion: 2
guid: de5a0d32ac5669347ac4570c014967d1
timeCreated: 1608801356
licenseType: Free
guid: 634536d804abc784394d4ac028a77879
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0

View File

@@ -1,4 +1,4 @@
using System;
using System;
namespace Cryville.Common.ComponentModel {
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]

View File

@@ -1,4 +1,4 @@
using System;
using System;
namespace Cryville.Common.ComponentModel {
[AttributeUsage(AttributeTargets.Property, Inherited = false)]

View File

@@ -1,4 +1,4 @@
using System;
using System;
namespace Cryville.Common.ComponentModel {
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]

View File

@@ -1,4 +1,4 @@
using System;
using System;
namespace Cryville.Common.ComponentModel {
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]

View File

@@ -0,0 +1,26 @@
using System.Collections.Generic;
using System.Diagnostics;
namespace Cryville.Common {
public class Coroutine {
readonly IEnumerator<float> _enumerator;
readonly Stopwatch _stopwatch = new Stopwatch();
public float Progress { get; private set; }
public Coroutine(IEnumerator<float> enumerator) {
_enumerator = enumerator;
}
public bool TickOnce() {
if (!_enumerator.MoveNext()) return false;
Progress = _enumerator.Current;
return true;
}
public bool Tick(double minTime) {
_stopwatch.Restart();
while (_stopwatch.Elapsed.TotalSeconds < minTime) {
if (!_enumerator.MoveNext()) return false;
Progress = _enumerator.Current;
}
return true;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 387adc7d494be0147b7cb930bc2e726b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;

View File

@@ -1,4 +1,4 @@
using System;
using System;
namespace Cryville.Common {
public class FileStringAttribute : Attribute {

View File

@@ -1,4 +1,4 @@
using Cryville.Common.IO;
using Cryville.Common.IO;
using System;
using System.Collections;
using System.Collections.Generic;

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;

View File

@@ -1,4 +1,4 @@
using Cryville.Common.Culture;
using Cryville.Common.Culture;
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

View File

@@ -1,4 +1,4 @@
using System.IO;
using System.IO;
using System.Linq;
namespace Cryville.Common.Font {

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Text;

View File

@@ -1,4 +1,4 @@
using System;
using System;
namespace Cryville.Common {
public struct Identifier : IEquatable<Identifier> {

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
namespace Cryville.Common {
/// <summary>

View File

@@ -1,44 +1,27 @@
using SMath = System.Math;
using SMath = System.Math;
namespace Cryville.Common.Math {
// Ported from https://github.com/arian/cubic-bezier/blob/master/index.js
public static class CubicBezier {
public static float Evaluate(float t, float x1, float y1, float x2, float y2, float epsilon) {
float x = t, t0, t1, t2, tx, d2, i;
for (t2 = x, i = 0; i < 8; i++) {
tx = CurveX(t2, x1, x2) - x;
if (SMath.Abs(tx) < epsilon) return CurveY(t2, y1, y2);
d2 = DerivativeCurveX(t2, x1, x2);
if (SMath.Abs(d2) < 1e-6) break;
t2 -= tx / d2;
}
float x = t, t0 = 0, t1 = 1, t2 = x;
t0 = 0; t1 = 1; t2 = x;
if (t2 < t0) return CurveY(t0, y1, y2);
if (t2 > t1) return CurveY(t1, y1, y2);
if (t2 < t0) return Curve(t0, y1, y2);
if (t2 > t1) return Curve(t1, y1, y2);
while (t0 < t1) {
tx = CurveX(t2, x1, x2);
if (SMath.Abs(tx - x) < epsilon) return CurveY(t2, y1, y2);
float tx = Curve(t2, x1, x2);
if (SMath.Abs(tx - x) < epsilon) return Curve(t2, y1, y2);
if (x > tx) t0 = t2;
else t1 = t2;
t2 = (t1 - t0) * .5f + t0;
}
return CurveY(t2, y1, y2);
return Curve(t2, y1, y2);
}
static float CurveX(float t, float x1, float x2) {
static float Curve(float t, float p1, float p2) {
float v = 1 - t;
return 3 * v * v * t * x1 + 3 * v * t * t * x2 + t * t * t;
}
static float CurveY(float t, float y1, float y2) {
float v = 1 - t;
return 3 * v * v * t * y1 + 3 * v * t * t * y2 + t * t * t;
}
static float DerivativeCurveX(float t, float x1, float x2) {
float v = 1 - t;
return 3 * (2 * (t - 1) * t + v * v) * x1 + 3 * (-t * t * t + 2 * v * t) * x2;
return 3 * v * v * t * p1 + 3 * v * t * t * p2 + t * t * t;
}
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
namespace Cryville.Common.Math {
/// <summary>

View File

@@ -1,4 +1,4 @@
using UnsafeIL;
using UnsafeIL;
namespace Cryville.Common.Math {
/// <summary>

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
@@ -130,4 +130,4 @@ namespace Cryville.Common.Network {
}
}
}
}
}

View File

@@ -1,11 +1,11 @@
using System;
using System;
namespace Cryville.Common.Pdt {
/// <summary>
/// Indicates that the attributed member is an element list.
/// </summary>
/// <remarks>
/// <para>An element list is a <see cref="System.Collections.IDictionary" /> or <see cref="Cryville.Common.Collections.Generic.IPairList" /> that represents a collection of PDT elements. There must be at most one element list in a class.</para>
/// <para>An element list is a <see cref="System.Collections.IDictionary" /> or <see cref="Cryville.Common.Collections.IPairList" /> that represents a collection of PDT elements. There must be at most one element list in a class.</para>
/// </remarks>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class ElementListAttribute : Attribute { }
@@ -14,7 +14,7 @@ namespace Cryville.Common.Pdt {
/// Indicates that the attributed member is a property list.
/// </summary>
/// <remarks>
/// <para>A property list is a <see cref="System.Collections.IDictionary" /> or <see cref="Cryville.Common.Collections.Generic.IPairList" /> that represents a collection of PDT properties. There must be at most one property list in a class.</para>
/// <para>A property list is a <see cref="System.Collections.IDictionary" /> or <see cref="Cryville.Common.Collections.IPairList" /> that represents a collection of PDT properties. There must be at most one property list in a class.</para>
/// </remarks>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class PropertyListAttribute : Attribute { }

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
@@ -17,22 +17,23 @@ namespace Cryville.Common.Pdt {
readonly StackFrame[] _stack = new StackFrame[256];
readonly byte[] _mem = new byte[0x100000];
bool _revokepttconst;
LinkedListNode<PdtInstruction> _rip;
LinkedListNode<PdtInstruction> _ip;
/// <summary>
/// Evaluates an expression and passes the result to a target operator.
/// </summary>
/// <param name="target">The target operator.</param>
/// <param name="exp">The expression to evaluate.</param>
public void Evaluate(PdtOperator target, PdtExpression exp) {
/// <returns>Whether the evaluaton succeeded.</returns>
public bool Evaluate(PdtOperator target, PdtExpression exp) {
_framecount = 0;
_goffset = 0;
_revokepttconst = false;
for (_rip = exp.Instructions.First; _rip != null; _rip = _rip.Next)
_rip.Value.Execute(this);
Operate(target, _framecount, true);
for (_ip = exp.Instructions.First; _ip != null; _ip = _ip.Next)
_ip.Value.Execute(this);
if (exp.IsPotentialConstant) {
exp.IsConstant = exp.IsPotentialConstant = !_revokepttconst;
}
return Operate(target, _framecount, true);
}
/// <summary>
/// Patches an expression with a lefthand variable and a compound operator.
@@ -54,8 +55,10 @@ namespace Cryville.Common.Pdt {
List<PdtInstruction.Collapse> ct;
var cols = new Dictionary<LinkedListNode<PdtInstruction>, List<PdtInstruction.Collapse>>();
var il = exp.Instructions;
for (_rip = il.First; _rip != null; _rip = _rip == null ? il.First : _rip.Next) {
var i = _rip.Value;
_ip = il.First;
while (_ip != null) {
bool nextFlag = false;
var i = _ip.Value;
if (i is PdtInstruction.Operate) {
int fc0 = _framecount;
int fc1 = ((PdtInstruction.Operate)i).Signature.ParamCount;
@@ -71,29 +74,36 @@ namespace Cryville.Common.Pdt {
}
else {
var frame = _stack[_framecount - 1];
_rip = il.AddAfter(_rip, new PdtInstruction.PushConstant(frame.Type, _mem, frame.Offset, frame.Length));
for (var j = 0; j <= fc1; j++) il.Remove(_rip.Previous);
ReplaceIP(il, new PdtInstruction.PushConstant(frame.Type, _mem, frame.Offset, frame.Length), cols);
for (var j = 0; j < fc1; j++) il.Remove(_ip.Previous);
}
}
else if (i is PdtInstruction.Collapse) {
var t = (PdtInstruction.Collapse)i;
try {
var pins = _rip;
var pins = _ip;
i.Execute(this);
if (_rip == pins) {
_rip = _rip.Next;
il.Remove(_rip.Previous);
il.Remove(_rip.Previous);
_rip = _rip.Previous;
if (_stack[_framecount - 1].Type == PdtInternalType.Error) {
throw new EvaluationFailureException();
}
if (_ip == pins) {
_ip = _ip.Next;
il.Remove(_ip.Previous);
il.Remove(_ip.Previous);
_ip = _ip.Previous;
if (_ip == null) {
_ip = il.First;
nextFlag = true;
}
}
else {
_rip = pins.Previous;
while (_rip.Next != t.Target) il.Remove(_rip.Next);
il.Remove(_rip.Next);
_ip = pins.Previous;
while (_ip.Next != t.Target) il.Remove(_ip.Next);
il.Remove(_ip.Next);
if (cols.TryGetValue(t.Target, out ct)) {
foreach (var u in ct) u.Target = _rip;
foreach (var u in ct) u.Target = _ip;
cols.Remove(t.Target);
cols.Add(_rip, ct);
cols.Add(_ip, ct);
}
}
}
@@ -106,12 +116,11 @@ namespace Cryville.Common.Pdt {
i.Execute(this);
var frame = _stack[_framecount - 1];
if (frame.Type != PdtInternalType.Undefined && frame.Type != PdtInternalType.Error) {
_rip = il.AddAfter(_rip, new PdtInstruction.PushConstant(frame.Type, _mem, frame.Offset, frame.Length));
il.Remove(_rip.Previous);
ReplaceIP(il, new PdtInstruction.PushConstant(frame.Type, _mem, frame.Offset, frame.Length), cols);
}
}
else i.Execute(this);
if (_rip != null && cols.TryGetValue(_rip, out ct)) {
if (_ip != null && cols.TryGetValue(_ip, out ct)) {
unsafe {
fixed (StackFrame* frame = &_stack[_framecount - 1]) {
frame->Type = PdtInternalType.Error;
@@ -120,6 +129,7 @@ namespace Cryville.Common.Pdt {
}
}
}
if (!nextFlag) _ip = _ip.Next;
}
exp.IsConstant = true;
exp.IsPotentialConstant = true;
@@ -133,6 +143,13 @@ namespace Cryville.Common.Pdt {
}
}
}
void ReplaceIP(LinkedList<PdtInstruction> il, PdtInstruction ins, Dictionary<LinkedListNode<PdtInstruction>, List<PdtInstruction.Collapse>> cols) {
List<PdtInstruction.Collapse> cins;
if (cols.TryGetValue(_ip, out cins)) cols.Remove(_ip);
_ip = il.AddAfter(_ip, ins);
il.Remove(_ip.Previous);
if (cins != null) cols.Add(_ip, cins);
}
/// <summary>
/// Revokes the potential constant mark of the current expression.
/// </summary>
@@ -184,23 +201,34 @@ namespace Cryville.Common.Pdt {
/// <returns>An operator of the specific name.</returns>
/// <remarks>The parameter count of the returned operator does not necessarily equal to <paramref name="pc" />.</remarks>
protected abstract PdtOperator GetOperator(PdtOperatorSignature sig);
unsafe void Operate(PdtOperator op, int pc, bool noset = false) {
unsafe bool Operate(PdtOperator op, int pc, bool noset = false) {
fixed (byte* pmem = _mem) {
op.Begin(this, pc);
for (int i = 0; i < pc; i++) {
var frame = _stack[--_framecount];
if (frame.Type == PdtInternalType.Error) {
_framecount -= pc - i;
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = _goffset, Length = 0 };
return false;
}
op.LoadOperand(new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length));
_goffset -= frame.Length;
}
op.Call(pmem + _goffset, noset);
return true;
}
}
internal unsafe void Collapse(int name, LinkedListNode<PdtInstruction> target) {
fixed (byte* pmem = _mem) {
var frame = _stack[--_framecount];
if (frame.Type == PdtInternalType.Error) {
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = _goffset, Length = 0 };
_ip = target;
return;
}
if (Collapse(name, new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length))) {
_framecount++;
_rip = target;
_ip = target;
}
}
}
@@ -226,7 +254,7 @@ namespace Cryville.Common.Pdt {
}
/// <summary>
/// The exception that is thrown when the evalution of a <see cref="PdtExpression" /> fails.
/// The exception that is thrown when the evaluation of a <see cref="PdtExpression" /> fails.
/// </summary>
public class EvaluationFailureException : Exception {
/// <inheritdoc />

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;
@@ -195,7 +195,7 @@ namespace Cryville.Common.Pdt {
default: pc++; break;
}
}
else if (OP_TYPE[t2.Value[0]] == 1) {
if (OP_TYPE[t2.Value[0]] == 1) {
colp = new Dictionary<LinkedListNode<PdtInstruction>, string> { { ins.Last, t2.Value } };
}
t1 = t2;

View File

@@ -0,0 +1,59 @@
using System;
using System.Reflection;
namespace Cryville.Common.Pdt {
/// <summary>
/// Interpreter for fragments in Property Definition Tree (PDT) file format.
/// </summary>
public class PdtFragmentInterpreter : PdtInterpreter {
public PdtFragmentInterpreter() : base(null, new EmptyBinder()) { }
/// <summary>
/// Sets the new source string for the fragment interpreter and resets the position.
/// </summary>
/// <param name="value">The new source string.</param>
public void SetSource(string value) {
Source = value;
Position = 0;
}
/// <summary>
/// The binder.
/// </summary>
public Binder Binder {
get { return _binder; }
set { _binder = value; }
}
/// <summary>
/// Reads the current character and increments the position.
/// </summary>
/// <returns>The current character.</returns>
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
public new char GetChar() { return base.GetChar(); }
/// <summary>
/// Reads an identifier.
/// </summary>
/// <returns>An identifier.</returns>
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
public new string GetIdentifier() { return base.GetIdentifier(); }
/// <summary>
/// Reads a number.
/// </summary>
/// <returns>A number.</returns>
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
public new string GetNumber() { return base.GetNumber(); }
/// <summary>
/// Reads a string.
/// </summary>
/// <returns>A string.</returns>
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
public new string GetString() { return base.GetString(); }
/// <summary>
/// Reads an expression.
/// </summary>
/// <returns>An expression.</returns>
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
public new PdtExpression GetExp() { return base.GetExp(); }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f7088ba23ed4b424eadaf664be48e376
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,4 +1,4 @@
namespace Cryville.Common.Pdt {
namespace Cryville.Common.Pdt {
/// <summary>
/// The identifiers of the internal types of PDT.
/// </summary>

View File

@@ -1,10 +1,10 @@
using Cryville.Common.Collections;
using Cryville.Common.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using CMath = System.Math;
namespace Cryville.Common.Pdt {
/// <summary>
@@ -61,12 +61,12 @@ namespace Cryville.Common.Pdt {
/// <summary>
/// The source string.
/// </summary>
public string Source { get; private set; }
Binder _binder;
public string Source { get; protected set; }
protected Binder _binder;
/// <summary>
/// The current position in the string being parsed by the interpreter.
/// </summary>
public int Position { get; private set; }
public int Position { get; protected set; }
#pragma warning disable IDE1006
/// <summary>
/// The character at the current position.
@@ -228,8 +228,8 @@ namespace Cryville.Common.Pdt {
if (!flag) throw new FormatException("Format directive not found");
}
object InterpretObject(Type type) {
var result = ReflectionHelper.InvokeEmptyConstructor(type);
bool dictflag = typeof(IDictionary).IsAssignableFrom(type);
var result = Activator.CreateInstance(type);
bool pcflag = PairCollection.IsPairCollection(type);
while (true) {
try { ws(); }
catch (IndexOutOfRangeException) { return result; }
@@ -241,69 +241,51 @@ namespace Cryville.Common.Pdt {
char c = GetChar();
switch (c) {
case '{':
if (dictflag) {
var ktype = type.GetGenericArguments()[0];
var ptype = type.GetGenericArguments()[1];
object key = _binder.ChangeType(pkey, ktype, null);
object value = InterpretObject(ptype);
((IDictionary)result).Add(key, value);
}
else {
MemberInfo prop = null;
bool flag = false;
if (pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
if (prop == null) flag = ReflectionHelper.TryFindMemberWithAttribute<ElementListAttribute>(type, out prop);
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
Type ptype = ReflectionHelper.GetMemberType(prop);
if (flag) {
using (var collection = new PairCollection(ReflectionHelper.GetValue(prop, result))) {
var ktype = ptype.GetGenericArguments()[0];
var vtype = ptype.GetGenericArguments()[1];
object key = _binder.ChangeType(pkey, ktype, null);
object value = InterpretObject(vtype);
collection.Add(key, value);
}
}
else ReflectionHelper.SetValue(prop, result, InterpretObject(ptype));
}
InterpretObjectInternal<ElementListAttribute>(pcflag, type, pkey, result, type => InterpretObject(type));
break;
case ':':
case ';':
var exp = c == ';' ? _emptyexp : GetExp();
if (dictflag) {
var ktype = type.GetGenericArguments()[0];
var vtype = type.GetGenericArguments()[1];
object key = _binder.ChangeType(pkey, ktype, null);
object value = _binder.ChangeType(exp, vtype, null);
((IDictionary)result).Add(key, value);
}
else {
MemberInfo prop = null;
bool flag = false;
if (pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
if (prop == null) flag = ReflectionHelper.TryFindMemberWithAttribute<PropertyListAttribute>(type, out prop);
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
var ptype = ReflectionHelper.GetMemberType(prop);
if (flag) {
using (var collection = new PairCollection(ReflectionHelper.GetValue(prop, result))) {
var ktype = ptype.GetGenericArguments()[0];
var vtype = ptype.GetGenericArguments()[1];
object key = _binder.ChangeType(pkey, ktype, null);
object value = _binder.ChangeType(exp, vtype, null);
collection.Add(key, value);
}
}
else {
object value = _binder.ChangeType(exp, ptype, null);
ReflectionHelper.SetValue(prop, result, value, _binder);
}
}
InterpretObjectInternal<PropertyListAttribute>(pcflag, type, pkey, result, type => _binder.ChangeType(exp, type, null));
break;
default:
throw new InvalidOperationException("Internal error: Invalid key interpretation");
}
}
}
void InterpretObjectInternal<T>(bool pcflag, Type type, object pkey, object result, Func<Type, object> vfunc) where T : Attribute {
if (pcflag) {
using (var collection = new PairCollection(result)) {
var ktype = type.GetGenericArguments()[0];
var ptype = type.GetGenericArguments()[1];
object key = _binder.ChangeType(pkey, ktype, null);
object value = vfunc(ptype);
collection.Add(key, value);
}
}
else {
MemberInfo prop = null;
bool flag = false;
if (pkey is string) prop = ReflectionHelper.TryGetMember(type, (string)pkey);
if (prop == null) flag = ReflectionHelper.TryFindMemberWithAttribute<T>(type, out prop);
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
Type ptype = ReflectionHelper.GetMemberType(prop);
if (flag) {
var origCollection = ReflectionHelper.GetValue(prop, result);
if (origCollection == null) {
ReflectionHelper.SetValue(prop, result, origCollection = Activator.CreateInstance(ptype));
}
using (var collection = new PairCollection(origCollection)) {
var ktype = ptype.GetGenericArguments()[0];
var vtype = ptype.GetGenericArguments()[1];
object key = _binder.ChangeType(pkey, ktype, null);
object value = vfunc(vtype);
collection.Add(key, value);
}
}
else ReflectionHelper.SetValue(prop, result, vfunc(ptype), _binder);
}
}
/// <summary>
/// Interprets a key from the current position.
/// </summary>
@@ -324,13 +306,13 @@ namespace Cryville.Common.Pdt {
int pos = interpreter.Position;
if (pos >= src.Length) return "Failed to interpret the PDT: There are some missing or redundant tokens";
int lineStartPos = src.LastIndexOf('\n', pos) + 1;
int previewStartPos = src.LastIndexOf('\n', pos, 64);
int previewStartPos = src.LastIndexOf('\n', pos, CMath.Min(64, pos));
if (previewStartPos == -1) {
previewStartPos = pos - 64;
if (previewStartPos < 0) previewStartPos = 0;
}
else previewStartPos++;
int previewEndPos = src.IndexOf('\n', pos, 64);
int previewEndPos = src.IndexOf('\n', pos, CMath.Min(64, src.Length - pos));
if (previewEndPos == -1) {
previewEndPos = pos + 64;
if (previewEndPos > src.Length) previewEndPos = src.Length;

View File

@@ -1,4 +1,4 @@
using System;
using System;
namespace Cryville.Common.Pdt {
/// <summary>
@@ -116,4 +116,4 @@ namespace Cryville.Common.Pdt {
return string.Format("{0}({1})", IdentifierManager.SharedInstance.Retrieve(Name), ParamCount);
}
}
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using UnsafeIL;
namespace Cryville.Common.Pdt {

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@@ -8,24 +8,7 @@ namespace Cryville.Common {
/// Provides a set of <see langword="static" /> methods for refletion.
/// </summary>
public static class ReflectionHelper {
static readonly Type[] emptyTypeArray = {};
/// <summary>
/// Gets the parameterless constructor of a type.
/// </summary>
/// <param name="type">The type.</param>
/// <returns>The parameterless constructor of the type.</returns>
public static ConstructorInfo GetEmptyConstructor(Type type) {
return type.GetConstructor(emptyTypeArray);
}
static readonly object[] emptyObjectArray = {};
/// <summary>
/// Invokes the parameterless constructor of a type and returns the result.
/// </summary>
/// <param name="type">The type.</param>
/// <returns>The created instance.</returns>
public static object InvokeEmptyConstructor(Type type) {
return GetEmptyConstructor(type).Invoke(emptyObjectArray);
}
/// <summary>
/// Tries to find a member with the specified attribute type in a type.
@@ -90,6 +73,22 @@ namespace Cryville.Common {
return mil[0];
}
/// <summary>
/// Tries to get the member from a type with the specified name.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="name">The name of the member.</param>
/// <returns>The member. <see langword="null" /> when not found.</returns>
public static MemberInfo TryGetMember(Type type, string name) {
var mil = type.GetMember(
name,
MemberTypes.Field | MemberTypes.Property,
BindingFlags.Public | BindingFlags.Instance
);
if (mil.Length != 1) return null;
return mil[0];
}
/// <summary>
/// Gets the type of a member.
/// </summary>

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Text;
using System.Text.RegularExpressions;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using UnityEngine;
namespace Cryville.Common.Unity {

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using UnityEngine;
namespace Cryville.Common.Unity.Input {

View File

@@ -17,7 +17,7 @@ namespace Cryville.Common.Unity.Input {
foreach (var t in HandlerRegistries) {
try {
if (!typeof(InputHandler).IsAssignableFrom(t)) continue;
var h = (InputHandler)ReflectionHelper.InvokeEmptyConstructor(t);
var h = (InputHandler)Activator.CreateInstance(t);
_typemap.Add(t, h);
_handlers.Add(h);
Logger.Log("main", 1, "Input", "Initialized {0}", ReflectionHelper.GetSimpleName(t));

View File

@@ -1,4 +1,4 @@
namespace Cryville.Common.Unity.Input {
namespace Cryville.Common.Unity.Input {
public enum WindowMessages : uint {
WM_NULL = 0x0000,
WM_CREATE = 0x0001,

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.InteropServices;
using System.Text;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
namespace Cryville.Common.Unity.Input {

View File

@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
namespace Cryville.Common.Unity.Input {
public static class UnityCameraUtils {

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using UnityEngine;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_5_4_OR_NEWER
@@ -179,7 +179,7 @@ namespace Cryville.Common.Unity {
if (!www.isDone) return false;
if (handler.isDone && handler.texture != null) {
var buffer = handler.texture;
/*var result = new Texture2D(buffer.width, buffer.height, buffer.format, true);
var result = new Texture2D(buffer.width, buffer.height, buffer.format, true);
if (SystemInfo.copyTextureSupport.HasFlag(CopyTextureSupport.Basic)) {
Graphics.CopyTexture(buffer, 0, 0, result, 0, 0);
}
@@ -188,8 +188,8 @@ namespace Cryville.Common.Unity {
}
result.Apply(true, true);
Texture2D.Destroy(buffer);
Callback(true, result);*/
Callback(true, buffer);
Callback(true, result);
// Callback(true, buffer);
}
else {
Callback(false, null);

View File

@@ -1,145 +0,0 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Cryville.Common.Unity {
public class PropItem : MonoBehaviour {
public object Target;
public PropertyEditor editor;
public DirectoryInfo ContextPath;
public string PropertyName = "";
InputField valueObj;
string value;
string desc = "";
PropertyInfo prop;
Type bindToType;
TypeConverter converter;
bool mustExpand = false;
bool readOnly = false;
string[] filter = null;
FileDialog fdialog;
#pragma warning disable IDE0051
void Awake() {
transform.Find("Value").GetComponent<InputField>().onEndEdit.AddListener(s => OnValueChanged(s));
var entry = new EventTrigger.Entry(){
eventID = EventTriggerType.PointerClick,
callback = new EventTrigger.TriggerEvent()
};
entry.callback.AddListener(e => OnClick(e));
transform.Find("Value").GetComponent<EventTrigger>().triggers.Add(entry);
}
void Start() {
transform.Find("Name").GetComponent<Text>().text = PropertyName;
valueObj = transform.Find("Value").GetComponent<InputField>();
prop = Target.GetType().GetProperty(PropertyName);
bindToType = prop.PropertyType;
converter = TypeDescriptor.GetConverter(bindToType);
var descattr = (DescriptionAttribute[])prop.GetCustomAttributes(typeof(DescriptionAttribute), true);
if (descattr.Length > 0) desc = descattr[0].Description;
var roattr = (ReadOnlyAttribute[])prop.GetCustomAttributes(typeof(ReadOnlyAttribute), true);
if (roattr.Length > 0) if (roattr[0].IsReadOnly == true) {
readOnly = true;
valueObj.enabled = false;
valueObj.transform.Find("ValueString").GetComponent<Text>().color = Color.gray;
}
if (converter == null || !converter.CanConvertFrom(typeof(string)) || converter.GetPropertiesSupported()){
mustExpand = true;
valueObj.enabled = false;
}
var fsattr = (FileStringAttribute[])prop.GetCustomAttributes(typeof(FileStringAttribute), true);
if (fsattr.Length > 0) {
valueObj.enabled = false;
filter = fsattr[0].Filter;
}
UpdateValue();
}
#pragma warning restore IDE0051
void OnFileDialogClosed() {
var file = fdialog.GetComponent<FileDialog>().FileName;
if (file != "") {
var f = new FileInfo(file);
if (f.Directory.FullName != ContextPath.FullName) {
string targetFile = ContextPath.FullName + "\\" + f.Name;
f.CopyTo(targetFile, true);
}
OnValueChanged(f.Name);
}
}
void UpdateValue() {
object v;
valueObj.placeholder.GetComponent<Text>().text = "";
v = prop.GetValue(Target, new object[]{ });
if (v == null) {
DefaultValueAttribute[] defvattr = (DefaultValueAttribute[])prop.GetCustomAttributes(typeof(DefaultValueAttribute), true);
if (defvattr.Length > 0) {
v = defvattr[0].Value;
if (v == null) {
v = "";
valueObj.placeholder.GetComponent<Text>().text = "null";
}
}
else {
v = "";
valueObj.placeholder.GetComponent<Text>().text = "null";
}
}
if (mustExpand || readOnly || filter != null) {
valueObj.transform.Find("ValueString").GetComponent<Text>().text = v.ToString();
}
else {
valueObj.text = v.ToString();
}
value = valueObj.text;
}
void OnClick(BaseEventData e) {
if (mustExpand && !readOnly) {
GameObject subeditor = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/PropertyEditor"));
object obj = prop.GetValue(Target, new object[]{ });
subeditor.GetComponent<PropertyEditor>().TargetObject = obj;
}
else if (filter != null && !readOnly) {
fdialog = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
fdialog.Filter = filter;
fdialog.CurrentDirectory = ContextPath;
fdialog.OnClose += OnFileDialogClosed;
}
editor.SetDescription(PropertyName, desc);
UpdateValue();
}
void OnValueChanged(string s) {
if (s == value) return;
object v = null;
if (!(mustExpand || readOnly)) {
try {
v = converter.ConvertFrom(s);
prop.SetValue(Target, v, new object[]{ });
}
catch (TargetInvocationException ex) {
// CallHelper.ShowMessageBox(ex.InnerException.Message);
}
catch (Exception ex) {
// CallHelper.ShowMessageBox(ex.Message);
}
}
UpdateValue();
}
}
}

View File

@@ -1,60 +0,0 @@
using System;
using System.ComponentModel;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Common.Unity {
public class PropertyEditor : MonoBehaviour {
private object target;
public object TargetObject {
get { return target; }
set {
target = value;
ReloadProperties();
}
}
private Text desc;
private Transform list;
public Action Callback;
private void ReloadProperties() {
foreach (Transform p in list) {
GameObject.Destroy(p.gameObject);
}
PropertyInfo[] props = target.GetType().GetProperties();
foreach (PropertyInfo m in props) {
var brattr = (BrowsableAttribute[])m.GetCustomAttributes(typeof(BrowsableAttribute), true);
if (brattr.Length > 0)
if (brattr[0].Browsable == false)
continue;
GameObject mi = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/PropItem"));
mi.transform.SetParent(list, false);
mi.GetComponent<PropItem>().PropertyName = m.Name;
mi.GetComponent<PropItem>().Target = target;
mi.GetComponent<PropItem>().editor = this;
}
}
#pragma warning disable IDE0051
void Awake() {
Transform panel = transform.Find("Panel");
desc = panel.Find("Description").GetComponent<Text>();
list = panel.Find("PropList").Find("PropListInner");
SetDescription("(Property)", "");
}
#pragma warning restore IDE0051
public void SetDescription(string n, string d) {
desc.text = "<b>" + n + "</b>\n" + d;
}
public void Close() {
if (Callback != null) Callback.Invoke();
GameObject.Destroy(gameObject);
}
}
}

View File

@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

View File

@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
namespace Cryville.Common.Unity.UI {
/// <summary>

View File

@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Common.Unity.UI {

View File

@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
namespace Cryville.Common.Unity.UI {
/// <summary>

View File

@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Common.Unity.UI {

View File

@@ -1,4 +1,4 @@
using System;
using System;
using UnityEngine;
using UnityEngine.Sprites;
using UnityEngine.UI;

View File

@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Common.Unity.UI {

View File

@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Common.Unity.UI {

View File

@@ -1,4 +1,4 @@
using System;
using System;
using UnityEngine;
using UnityEngine.UI;

View File

@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
namespace Cryville.Common.Unity.UI {
public class SetIntegerParameterBehaviour : SetParameterBehaviour {

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using Cryville.Common.Collections.Specialized;
using UnityEngine;
namespace Cryville.Crtr {
@@ -6,12 +6,12 @@ namespace Cryville.Crtr {
public int Name { get; private set; }
public Transform Transform { get; private set; }
public SkinContext SkinContext { get; private set; }
public Dictionary<int, PropSrc> PropSrcs { get; private set; }
public IntKeyedDictionary<PropSrc> PropSrcs { get; private set; }
public Anchor(int name, Transform transform, int propSrcCount = 0) {
Name = name;
Transform = transform;
if (propSrcCount > 0) PropSrcs = new Dictionary<int, PropSrc>(propSrcCount);
if (propSrcCount > 0) PropSrcs = new IntKeyedDictionary<PropSrc>(propSrcCount);
SkinContext = new SkinContext(transform, PropSrcs);
}
}
}
}

View File

@@ -0,0 +1,79 @@
using Newtonsoft.Json;
using System;
namespace Cryville.Crtr {
[JsonConverter(typeof(BeatTimeConverter))]
public struct BeatTime : IComparable<BeatTime>, IEquatable<BeatTime> {
public BeatTime(int _b, int _n, int _d) {
b = _b;
n = _n;
d = _d;
}
public BeatTime(int _n, int _d) {
b = _n / _d;
n = _n % _d;
d = _d;
}
[JsonIgnore]
public int b;
[JsonIgnore]
public int n;
[JsonIgnore]
public int d;
[JsonIgnore]
public double Decimal { get { return b + (double)n / d; } }
public int CompareTo(BeatTime other) {
var c = b.CompareTo(other.b);
if (c != 0) return c;
return ((double)n / d).CompareTo((double)other.n / other.d);
}
public override bool Equals(object obj) {
if (!(obj is BeatTime)) return false;
return Equals((BeatTime)obj);
}
public bool Equals(BeatTime other) {
return b.Equals(other.b) && ((double)n / d).Equals((double)other.n / other.d);
}
public override int GetHashCode() {
return Decimal.GetHashCode();
}
public static bool operator ==(BeatTime left, BeatTime right) {
return left.Equals(right);
}
public static bool operator !=(BeatTime left, BeatTime right) {
return !left.Equals(right);
}
}
public class BeatTimeConverter : JsonConverter {
public override bool CanConvert(Type objectType) {
return objectType == typeof(int[]);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
int b = (int)reader.ReadAsInt32();
int n = (int)reader.ReadAsInt32();
int d = (int)reader.ReadAsInt32();
reader.Read();
return new BeatTime(b, n, d);
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
BeatTime obj = (BeatTime)value;
writer.WriteStartArray();
writer.WriteValue(obj.b);
writer.WriteValue(obj.n);
writer.WriteValue(obj.d);
writer.WriteEndArray();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f29ed034a9faa27409d153dbd9a46f95
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,4 +1,4 @@
using Cryville.Common;
using Cryville.Common;
using UnityEngine;
namespace Cryville.Crtr.Browsing {
@@ -18,4 +18,4 @@ namespace Cryville.Crtr.Browsing {
public string DescriptionMain { get; set; }
public string DescriptionSub { get; set; }
}
}
}

View File

@@ -1,4 +1,4 @@
using TMPro;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@@ -40,7 +40,7 @@ namespace Cryville.Crtr.Browsing {
}
private void DisplayCover(bool succeeded, Texture2D tex) {
if (succeeded) {
_icon.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
_icon.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero, 160, 0, SpriteMeshType.FullRect);
}
}
public void OnClick() {
@@ -50,4 +50,4 @@ namespace Cryville.Crtr.Browsing {
else resourceBrowser.OnObjectItemClicked(Id.Value);
}
}
}
}

View File

@@ -1,4 +1,4 @@
using Cryville.Common;
using Cryville.Common;
using Cryville.Common.Unity.UI;
using System;
using TMPro;
@@ -57,7 +57,7 @@ namespace Cryville.Crtr.Browsing {
}
private void DisplayCover(bool succeeded, Texture2D tex) {
if (succeeded) {
_cover.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
_cover.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero, 160, 0, SpriteMeshType.FullRect);
}
}
public void OnPlay() {
@@ -67,4 +67,4 @@ namespace Cryville.Crtr.Browsing {
Master.OpenConfig(_id, _data);
}
}
}
}

View File

@@ -1,4 +1,4 @@
using Cryville.Common;
using Cryville.Common;
using Cryville.Crtr.Extension;
using Mono.Cecil;
using System;

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
namespace Cryville.Crtr.Browsing {
public interface IResourceManager<T> {
@@ -14,4 +14,4 @@ namespace Cryville.Crtr.Browsing {
string[] GetSupportedFormats();
IReadOnlyDictionary<string, string> GetPresetPaths();
}
}
}

View File

@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using UnityEngine.EventSystems;
namespace Cryville.Crtr.Browsing {

View File

@@ -1,4 +1,4 @@
using System;
using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
@@ -131,7 +131,7 @@ namespace Cryville.Crtr.Browsing {
else result = (1 - ratio) * Range.Value.x + ratio * Range.Value.y;
}
else {
double delta = (ratio - 0.5f) * 2 * MaxStep * Time.deltaTime;
double delta = (ratio > 0.5 ? 1 : -1) * Math.Pow((ratio - 0.5f) * 2, 2) * MaxStep * Time.deltaTime;
if (LogarithmicMode) result = Math.Pow(Math.E, Math.Log(m_value) + delta);
else result = m_value + delta;
}

View File

@@ -1,4 +1,4 @@
using UnityEngine.UI;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
public class PVPString : PropertyValuePanel {

View File

@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
@@ -24,4 +24,4 @@ namespace Cryville.Crtr.Browsing {
GetComponentInParent<ResourceBrowser>().OnPathClicked(_id);
}
}
}
}

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;
@@ -48,4 +48,4 @@ namespace Cryville.Crtr.Browsing {
_nameLabel.text = (Collapsed ? "+ " : "- ") + Name;
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More