1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
|
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
namespace XUtliPoolLib
{
public class XCommon : XSingleton<XCommon>
{
public static float XEps
{
get
{
return XCommon._eps;
}
}
public int New_id
{
get
{
int num = this._new_id + 1;
this._new_id = num;
return num;
}
}
public long UniqueToken
{
get
{
return DateTime.Now.Ticks + (long)this.New_id;
}
}
public readonly float FrameStep = 0.0333333351f;
private static readonly float _eps = 0.0001f;
private System.Random _random = new System.Random(DateTime.Now.Millisecond);
private int _idx = 0;
private uint[] _seeds = new uint[]
{
17u,
33u,
65u,
129u
};
private int _new_id = 0;
public StringBuilder shareSB = new StringBuilder();
public static List<Renderer> tmpRender = new List<Renderer>();
public static List<ParticleSystem> tmpParticle = new List<ParticleSystem>();
public static List<SkinnedMeshRenderer> tmpSkinRender = new List<SkinnedMeshRenderer>();
public static List<MeshRenderer> tmpMeshRender = new List<MeshRenderer>();
public XCommon()
{
this._idx = 5;
}
//c 从string生成一个ID
public uint XHash(string str)
{
bool flag = str == null;
uint result;
if (flag)
{
result = 0u;
}
else
{
uint num = 0u;
for (int i = 0; i < str.Length; i++)
{
num = (num << this._idx) + num + (uint)str[i];
}
result = num;
}
return result;
}
public uint XHashLowerRelpaceDot(uint hash, string str)
{
bool flag = str == null;
uint result;
if (flag)
{
result = hash;
}
else
{
for (int i = 0; i < str.Length; i++)
{
char c = char.ToLower(str[i]);
bool flag2 = c == '/' || c == '\\';
if (flag2)
{
c = '.';
}
hash = (hash << this._idx) + hash + (uint)c;
}
result = hash;
}
return result;
}
public uint XHash(uint hash, string str)
{
bool flag = str == null;
uint result;
if (flag)
{
result = hash;
}
else
{
foreach (char c in str)
{
hash = (hash << this._idx) + hash + (uint)c;
}
result = hash;
}
return result;
}
public uint XHash(StringBuilder str)
{
bool flag = str == null;
uint result;
if (flag)
{
result = 0u;
}
else
{
uint num = 0u;
for (int i = 0; i < str.Length; i++)
{
num = (num << this._idx) + num + (uint)str[i];
}
result = num;
}
return result;
}
public bool IsEqual(float a, float b)
{
return a == b;
}
public bool IsLess(float a, float b)
{
return a < b;
}
public int Range(int value, int min, int max)
{
value = Math.Max(value, min);
return Math.Min(value, max);
}
public bool IsGreater(float a, float b)
{
return a > b;
}
public bool IsEqualLess(float a, float b)
{
return a <= b;
}
public bool IsEqualGreater(float a, float b)
{
return a >= b;
}
public uint GetToken()
{
return (uint)DateTime.Now.Millisecond;
}
public void ProcessValueDamp(ref float values, float target, ref float factor, float deltaT)
{
bool flag = XSingleton<XCommon>.singleton.IsEqual(values, target);
if (flag)
{
values = target;
factor = 0f;
}
else
{
values += (target - values) * Mathf.Min(1f, deltaT * factor);
}
}
public void ProcessValueEvenPace(ref float value, float target, float speed, float deltaT)
{
float num = target - value;
float num2 = target - (num - speed * deltaT);
bool flag = XSingleton<XCommon>.singleton.IsGreater((target - num2) * num, 0f);
if (flag)
{
value = num2;
}
else
{
value = target;
}
}
public bool IsRectCycleCross(float rectw, float recth, Vector3 c, float r)
{
Vector3 vector;
vector=new Vector3(Mathf.Max(Mathf.Abs(c.x) - rectw, 0f), 0f, Mathf.Max(Mathf.Abs(c.z) - recth, 0f));
return vector.sqrMagnitude < r * r;
}
public bool Intersection(Vector2 begin, Vector2 end, Vector2 center, float radius, out float t)
{
t = 0f;
float num = radius * radius;
Vector2 vector = center - begin;
float sqrMagnitude = vector.sqrMagnitude;
bool flag = sqrMagnitude < num;
bool result;
if (flag)
{
result = true;
}
else
{
Vector2 vector2 = end - begin;
bool flag2 = vector2.sqrMagnitude > 0f;
if (flag2)
{
float num2 = Mathf.Sqrt(sqrMagnitude) * Mathf.Cos(Vector2.Angle(vector, vector2));
bool flag3 = num2 >= 0f;
if (flag3)
{
float num3 = sqrMagnitude - num2 * num2;
bool flag4 = num3 < num;
if (flag4)
{
float num4 = num - num3;
t = num2 - Mathf.Sqrt(num4);
return true;
}
}
}
result = false;
}
return result;
}
private float CrossProduct(float x1, float z1, float x2, float z2)
{
return x1 * z2 - x2 * z1;
}
public bool IsLineSegmentCross(Vector3 p1, Vector3 p2, Vector3 q1, Vector3 q2)
{
bool flag = Mathf.Min(p1.x, p2.x) <= Mathf.Max(q1.x, q2.x) && Mathf.Min(q1.x, q2.x) <= Mathf.Max(p1.x, p2.x) && Mathf.Min(p1.z, p2.z) <= Mathf.Max(q1.z, q2.z) && Mathf.Min(q1.z, q2.z) <= Mathf.Max(p1.z, p2.z);
bool result;
if (flag)
{
float num = this.CrossProduct(p1.x - q1.x, p1.z - q1.z, q2.x - q1.x, q2.z - q1.z);
float num2 = this.CrossProduct(p2.x - q1.x, p2.z - q1.z, q2.x - q1.x, q2.z - q1.z);
float num3 = this.CrossProduct(q1.x - p1.x, q1.z - p1.z, p2.x - p1.x, p2.z - p1.z);
float num4 = this.CrossProduct(q2.x - p1.x, q2.z - p1.z, p2.x - p1.x, p2.z - p1.z);
result = (num * num2 <= 0f && num3 * num4 <= 0f);
}
else
{
Vector3 vector = Vector3.Project(p1, Vector3.up);
result = false;
}
return result;
}
public Vector3 Horizontal(Vector3 v)
{
v.y = 0f;
return v.normalized;
}
public void Horizontal(ref Vector3 v)
{
v.y = 0f;
v.Normalize();
}
public float AngleNormalize(float basic, float degree)
{
Vector3 vector = this.FloatToAngle(basic);
Vector3 vector2 = this.FloatToAngle(degree);
float num = Vector3.Angle(vector, vector2);
return this.Clockwise(vector, vector2) ? (basic + num) : (basic - num);
}
public Vector2 HorizontalRotateVetor2(Vector2 v, float degree, bool normalized = true)
{
degree = -degree;
float num = degree * 0.0174532924f;
float num2 = Mathf.Sin(num);
float num3 = Mathf.Cos(num);
float x = v.x * num3 - v.y * num2;
float y = v.x * num2 + v.y * num3;
v.x = x;
v.y = y;
return normalized ? v.normalized : v;
}
public Vector3 HorizontalRotateVetor3(Vector3 v, float degree, bool normalized = true)
{
degree = -degree;
float num = degree * 0.0174532924f;
float num2 = Mathf.Sin(num);
float num3 = Mathf.Cos(num);
float x = v.x * num3 - v.z * num2;
float z = v.x * num2 + v.z * num3;
v.x = x;
v.z = z;
return normalized ? v.normalized : v;
}
public float TicksToSeconds(long tick)
{
long num = tick / 10000L;
return (float)num / 1000f;
}
public long SecondsToTicks(float time)
{
long num = (long)(time * 1000f);
return num * 10000L;
}
public float AngleToFloat(Vector3 dir)
{
float num = Vector3.Angle(Vector3.forward, dir);
return XSingleton<XCommon>.singleton.Clockwise(Vector3.forward, dir) ? num : (-num);
}
public float AngleWithSign(Vector3 from, Vector3 to)
{
float num = Vector3.Angle(from, to);
return this.Clockwise(from, to) ? num : (-num);
}
public Vector3 FloatToAngle(float angle)
{
return Quaternion.Euler(0f, angle, 0f) * Vector3.forward;
}
public Quaternion VectorToQuaternion(Vector3 v)
{
return XSingleton<XCommon>.singleton.FloatToQuaternion(XSingleton<XCommon>.singleton.AngleWithSign(Vector3.forward, v));
}
public Quaternion FloatToQuaternion(float angle)
{
return Quaternion.Euler(0f, angle, 0f);
}
public Quaternion RotateToGround(Vector3 pos, Vector3 forward)
{
RaycastHit raycastHit;
bool flag = Physics.Raycast(new Ray(pos + Vector3.up, Vector3.down), out raycastHit, 5f, 513);
Quaternion result;
if (flag)
{
Vector3 normal = raycastHit.normal;
Vector3 vector = forward;
Vector3.OrthoNormalize(ref normal, ref vector);
result = Quaternion.LookRotation(vector, normal);
}
else
{
result = Quaternion.identity;
}
return result;
}
public bool Clockwise(Vector3 fiduciary, Vector3 relativity)
{
float num = fiduciary.z * relativity.x - fiduciary.x * relativity.z;
return num > 0f;
}
public bool Clockwise(Vector2 fiduciary, Vector2 relativity)
{
float num = fiduciary.y * relativity.x - fiduciary.x * relativity.y;
return num > 0f;
}
public bool IsInRect(Vector3 point, Rect rect, Vector3 center, Quaternion rotation)
{
float num = -(rotation.eulerAngles.y % 360f) / 180f * 3.14159274f;
Quaternion identity = Quaternion.identity;
identity.w = Mathf.Cos(num / 2f);
identity.x = 0f;
identity.y = Mathf.Sin(num / 2f);
identity.z = 0f;
point = identity * (point - center);
return point.x > rect.xMin && point.x < rect.xMax && point.z > rect.yMin && point.z < rect.yMax;
}
public float RandomPercentage()
{
return (float)this._random.NextDouble();
}
public float RandomPercentage(float min)
{
bool flag = this.IsEqualGreater(min, 1f);
float result;
if (flag)
{
result = 1f;
}
else
{
float num = (float)this._random.NextDouble();
bool flag2 = this.IsGreater(num, min);
if (flag2)
{
result = num;
}
else
{
result = num / min * (1f - min) + min;
}
}
return result;
}
public float RandomFloat(float max)
{
return this.RandomPercentage() * max;
}
public float RandomFloat(float min, float max)
{
return min + this.RandomFloat(max - min);
}
public int RandomInt(int min, int max)
{
return this._random.Next(min, max);
}
public int RandomInt(int max)
{
return this._random.Next(max);
}
public int RandomInt()
{
return this._random.Next();
}
public bool IsInteger(float n)
{
return Mathf.Abs(n - (float)((int)n)) < XCommon._eps || Mathf.Abs(n - (float)((int)n)) > 1f - XCommon._eps;
}
public float GetFloatingValue(float value, float floating)
{
bool flag = this.IsEqualLess(floating, 0f) || this.IsEqualGreater(floating, 1f);
float result;
if (flag)
{
result = value;
}
else
{
float num = this.IsLess(this.RandomPercentage(), 0.5f) ? (1f - floating) : (1f + floating);
result = value * num;
}
return result;
}
public float GetSmoothFactor(float distance, float timespan, float nearenough)
{
float result = 0f;
distance = Mathf.Abs(distance);
bool flag = distance > XCommon.XEps;
if (flag)
{
float smoothDeltaTime = Time.smoothDeltaTime;
float num = nearenough / distance;
float num2 = timespan / smoothDeltaTime;
bool flag2 = num2 > 1f;
if (flag2)
{
float num3 = Mathf.Pow(num, 1f / num2);
result = (1f - num3) / smoothDeltaTime;
}
else
{
result = float.PositiveInfinity;
}
}
return result;
}
public float GetJumpForce(float airTime, float g)
{
return 0f;
}
public string SecondsToString(int time)
{
int num = time / 60;
int num2 = time % 60;
return string.Format("{0:D2}:{1}", num, num2);
}
public double Clamp(double value, double min, double max)
{
return Math.Min(Math.Max(min, value), max);
}
public Transform FindChildRecursively(Transform t, string name)
{
bool flag = t.name == name;
Transform result;
if (flag)
{
result = t;
}
else
{
for (int i = 0; i < t.childCount; i++)
{
Transform transform = this.FindChildRecursively(t.GetChild(i), name);
bool flag2 = transform != null;
if (flag2)
{
return transform;
}
}
result = null;
}
return result;
}
public void CleanStringCombine()
{
this.shareSB.Length = 0;
}
public StringBuilder GetSharedStringBuilder()
{
return this.shareSB;
}
public string GetString()
{
return this.shareSB.ToString();
}
public XCommon AppendString(string s)
{
this.shareSB.Append(s);
return this;
}
public XCommon AppendString(string s0, string s1)
{
this.shareSB.Append(s0);
this.shareSB.Append(s1);
return this;
}
public XCommon AppendString(string s0, string s1, string s2)
{
this.shareSB.Append(s0);
this.shareSB.Append(s1);
this.shareSB.Append(s2);
return this;
}
public string StringCombine(string s0, string s1)
{
this.shareSB.Length = 0;
this.shareSB.Append(s0);
this.shareSB.Append(s1);
return this.shareSB.ToString();
}
public string StringCombine(string s0, string s1, string s2)
{
this.shareSB.Length = 0;
this.shareSB.Append(s0);
this.shareSB.Append(s1);
this.shareSB.Append(s2);
return this.shareSB.ToString();
}
public string StringCombine(string s0, string s1, string s2, string s3)
{
this.shareSB.Length = 0;
this.shareSB.Append(s0);
this.shareSB.Append(s1);
this.shareSB.Append(s2);
this.shareSB.Append(s3);
return this.shareSB.ToString();
}
public uint CombineAdd(uint value, int heigh, int low)
{
int num = (int)((value >> 16) + (uint)heigh);
int num2 = (int)((value & 65535u) + (uint)low);
return (uint)(num << 16 | num2);
}
public void CombineSetHeigh(ref uint value, uint heigh)
{
value = (heigh << 16 | (value & 65535u));
}
public ushort CombineGetHeigh(uint value)
{
return (ushort)(value >> 16);
}
public void CombineSetLow(ref uint value, uint low)
{
value = ((value & 4294901760u) | (low & 65535u));
}
public ushort CombineGetLow(uint value)
{
return (ushort)(value & 65535u);
}
public void EnableParticleRenderer(GameObject go, bool enable)
{
Animator componentInChildren = go.GetComponentInChildren<Animator>();
bool flag = componentInChildren != null;
if (flag)
{
componentInChildren.enabled = enable;
}
}
public void EnableParticle(GameObject go, bool enable)
{
go.GetComponentsInChildren<ParticleSystem>(XCommon.tmpParticle);
int i = 0;
int count = XCommon.tmpParticle.Count;
while (i < count)
{
ParticleSystem particleSystem = XCommon.tmpParticle[i];
if (enable)
{
particleSystem.Play();
}
else
{
particleSystem.Stop();
}
i++;
}
XCommon.tmpParticle.Clear();
}
public static UnityEngine.Object Instantiate(UnityEngine.Object prefab)
{
return UnityEngine.Object.Instantiate(prefab, null);
}
public static T Instantiate<T>(T original) where T : UnityEngine.Object
{
return UnityEngine.Object.Instantiate<T>(original, null);
}
public override bool Init()
{
return true;
}
public override void Uninit()
{
}
}
}
|