Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions 3 Editor/GUI/Windows/SaveSpringBoneSetupWindow.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Linq;
using UnityEditor;
using UnityEngine;
#if UNITY_2020_2_OR_NEWER
Expand Down
5 changes: 2 additions & 3 deletions 5 Runtime/Setup/SpringColliderImporting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ private static Transform CreateNewGameObject(Transform parent, string name)
private static Transform GetChildByName(Transform parent, string name)
{
return Enumerable.Range(0, parent.childCount)
.Select(index => parent.GetChild(index))
.Where(child => child.name == name)
.FirstOrDefault();
.Select(parent.GetChild)
.FirstOrDefault(child => child.name == name);
}

private static T TryToFindComponent<T>(GameObject gameObject, string name) where T : Component
Expand Down
32 changes: 15 additions & 17 deletions 32 Runtime/Utility/ObjectBuilding/StringQueueObjectBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class ObjectBuilder
{
public static float DequeueFloat(this Queue<string> queue)
{
return float.Parse(queue.Dequeue());
return float.Parse(queue.Dequeue(), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
}

public static int DequeueInt(this Queue<string> queue)
Expand All @@ -21,9 +21,9 @@ public static int DequeueInt(this Queue<string> queue)

public static Vector3 DequeueVector3(this Queue<string> queue)
{
var x = float.Parse(queue.Dequeue());
var y = float.Parse(queue.Dequeue());
var z = float.Parse(queue.Dequeue());
var x = float.Parse(queue.Dequeue(), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
var y = float.Parse(queue.Dequeue(), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
var z = float.Parse(queue.Dequeue(), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
return new Vector3(x, y, z);
}

Expand All @@ -34,10 +34,9 @@ public static Transform DequeueTransform(this Queue<string> queue, GameObject ga
if (parentName.Length > 0)
{
var children = gameObject.GetComponentsInChildren<Transform>(true);
newParent = Object.FindObjectsOfType<Transform>()
.Where(item => item.name == parentName
&& !children.Contains(item))
.FirstOrDefault();
newParent = Object
.FindObjectsOfType<Transform>()
.FirstOrDefault(item => item.name == parentName && !children.Contains(item));
if (newParent == null)
{
Debug.LogError("Valid parent not found: " + parentName);
Expand Down Expand Up @@ -162,15 +161,15 @@ public static System.Object DequeueObject

private static System.Object ParsePrimitiveType(System.Type type, string valueSource)
{
var parseMethod = type.GetMethods()
.Where(method => method.Name == "Parse"
&& method.IsStatic
&& method.GetParameters().Length == 1)
.FirstOrDefault();
var parseMethodFormatProvider = type.GetMethod("Parse", BindingFlags.Public | BindingFlags.Static, null,
new [] { typeof(string), typeof(System.IFormatProvider) }, null);
if (parseMethodFormatProvider != null)
return parseMethodFormatProvider.Invoke(null, new System.Object[] { valueSource, System.Globalization.CultureInfo.InvariantCulture });

var parseMethod = type.GetMethod("Parse", BindingFlags.Public | BindingFlags.Static, null,
new [] { typeof(string) }, null);
if (parseMethod != null)
{
return parseMethod.Invoke(null, new System.Object[] { valueSource });
}

Debug.LogError("Parse not found: " + type.ToString());
return null;
Expand Down Expand Up @@ -209,8 +208,7 @@ IEnumerable<TypedStringToValueMap> valueMaps
if (valueMaps != null)
{
var matchingMap = valueMaps
.Where(map => map.Type == type)
.FirstOrDefault();
.FirstOrDefault(map => map.Type == type);
if (matchingMap != null)
{
return matchingMap[queue.Dequeue()];
Expand Down
2 changes: 1 addition & 1 deletion 2 Runtime/Utility/ObjectBuilding/TypedStringToValueMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public string GetKey(System.Object value)
.Where(item => item.Value == value)
.Select(item => item.Key)
.FirstOrDefault();
return (key != null) ? key : "";
return key ?? "";
}

// private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ List<string> outputStrings
if (valueMaps != null)
{
var matchingMap = valueMaps
.Where(map => map.Type == type)
.FirstOrDefault();
.FirstOrDefault(map => map.Type == type);
if (matchingMap != null)
{
outputStrings.Add(matchingMap.GetKey(sourceObject));
Expand All @@ -98,14 +97,12 @@ List<string> outputStrings
// Arrays are messy...
var publicMethods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);
var countMethod = publicMethods
.Where(method => method.Name == "GetLength")
.First();
.First(method => method.Name == "GetLength");
var itemCount = (int)countMethod.Invoke(sourceObject, new object[] { 0 });
var getValueMethod = publicMethods
.Where(method => method.Name == "GetValue"
&& method.GetParameters().Count() == 1
&& method.GetParameters()[0].ParameterType == typeof(int))
.First();
.First(method => method.Name == "GetValue"
&& method.GetParameters().Count() == 1
&& method.GetParameters()[0].ParameterType == typeof(int));
var items = new List<System.Object>(itemCount);
for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
{
Expand Down
17 changes: 9 additions & 8 deletions 17 Runtime/Utility/TextRecordParsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ public static IEnumerable<string> DefaultCommentPrefixes
get { return new string[] { "//", "#", ";" }; }
}

private static readonly ICollection<string> BoolFalseItems = new[] { "0", "false" };

public class Record
{
private List<string> items;

public Record(IEnumerable<string> initialItems)
{
items = initialItems.ToList();
Expand Down Expand Up @@ -52,8 +56,6 @@ public Queue<string> ToQueue()
{
return new Queue<string>(items);
}

private List<string> items = new List<string>();
}

// レコードのアイテムを取得。存在しない場合は空の文字列を返す。
Expand All @@ -65,9 +67,8 @@ public static string GetString(List<string> items, int index)
// レコードの数字を取得します。アイテムが空・false・0の場合はfalseを返します
public static bool GetBool(List<string> items, int index)
{
var falseItems = new List<string> { "0", "false" };
var itemString = GetString(items, index).Trim().ToLowerInvariant();
return itemString.Length > 0 && !falseItems.Contains(itemString);
return itemString.Length > 0 && !BoolFalseItems.Contains(itemString);
}

// レコードの数字を取得します。できなかった場合はfalseを返す。
Expand All @@ -88,7 +89,7 @@ public static bool GetFloat(List<string> items, int index, ref float output)
{
var item = GetString(items, index);
float newValue;
var succeeded = float.TryParse(item, out newValue);
var succeeded = float.TryParse(item, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out newValue);
if (succeeded)
{
output = newValue;
Expand All @@ -105,9 +106,9 @@ public static bool GetVector3(List<string> items, int startIndex, ref Vector3 ou
float x = 0f;
float y = 0f;
float z = 0f;
succeeded = float.TryParse(items[startIndex], out x)
&& float.TryParse(items[startIndex + 1], out y)
&& float.TryParse(items[startIndex + 2], out z);
succeeded = float.TryParse(items[startIndex], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out x)
&& float.TryParse(items[startIndex + 1], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out y)
&& float.TryParse(items[startIndex + 2], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out z);
if (succeeded)
{
output.Set(x, y, z);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.