private static IEnumerable <SpringBoneSerializer> SerializeSpringBoneRecords ( IEnumerable <TextRecordParsing.Record> sourceRecords, List <DynamicsSetup.ParseMessage> errorRecords ) { var validRecords = new List <SpringBoneSerializer>(sourceRecords.Count()); foreach (var sourceRecord in sourceRecords) { var itemQueue = sourceRecord.ToQueue(); SpringBoneBaseSerializer newBaseRecord = null; DynamicsSetup.ParseMessage error = null; try { newBaseRecord = itemQueue.DequeueObject <SpringBoneBaseSerializer>(); } catch (System.Exception exception) { error = new DynamicsSetup.ParseMessage("Error building SpringBoneBaseSerializer", sourceRecord.Items, exception.ToString()); } if (newBaseRecord != null) { // The rest of the queue should be collider names var colliderNames = new List <string>(itemQueue).Where(item => item.Length > 0); var newRecord = new SpringBoneSerializer { baseData = newBaseRecord, colliderNames = colliderNames.ToArray() }; validRecords.Add(newRecord); } else { errorRecords.Add(error); } } return(validRecords); }
private static bool BuildSpringBoneFromSerializer ( SpringBoneSetupMaps setupMaps, SpringBoneSerializer serializer ) { var baseData = serializer.baseData; Transform childBone = null; if (!setupMaps.allChildren.TryGetValue(baseData.boneName, out childBone)) { Debug.LogError("ボーンが見つかりません: " + baseData.boneName); return(false); } var springBone = childBone.gameObject.AddComponent <SpringBone>(); springBone.stiffnessForce = baseData.stiffness; springBone.dragForce = baseData.drag; springBone.springForce = baseData.springForce; springBone.windInfluence = baseData.windInfluence; springBone.angularStiffness = baseData.angularStiffness; springBone.yAngleLimits = BuildAngleLimitsFromSerializer(baseData.yAngleLimits); springBone.zAngleLimits = BuildAngleLimitsFromSerializer(baseData.zAngleLimits); springBone.radius = baseData.radius; springBone.lodLevel = baseData.lodLevel; springBone.lodMode = (SpringBone.LODMode)baseData.lodMode; springBone.lengthLimitStiffness = baseData.lengthLimitStiffness; springBone.isLengthLimitPercentage = baseData.isLengthLimitPercentage; springBone.lengthLimitMode = (SpringBone.LengthLimitMode)baseData.lengthLimitMode; // Pivot node var pivotNodeName = baseData.pivotName; Transform pivotNode = null; if (pivotNodeName.Length > 0) { if (!setupMaps.allChildren.TryGetValue(pivotNodeName, out pivotNode)) { Debug.LogError("Pivotオブジェクトが見つかりません: " + pivotNodeName); pivotNode = null; } } if (pivotNode == null) { pivotNode = springBone.transform.parent ?? springBone.transform; } else { var skinBones = GameObjectUtil.GetAllBones(springBone.transform.root.gameObject); if (pivotNode.GetComponent <SpringBonePivot>() && SpringBoneSetup.IsPivotProbablySafeToDestroy(pivotNode, skinBones)) { pivotNode.position = springBone.transform.position; } } springBone.pivotNode = pivotNode; springBone.lengthLimitTargets = baseData.lengthLimits .Where(lengthLimit => setupMaps.allChildren.ContainsKey(lengthLimit.objectName)) .Select(lengthLimit => setupMaps.allChildren[lengthLimit.objectName]) .ToArray(); springBone.sphereColliders = serializer.colliderNames .Where(name => setupMaps.sphereColliders.ContainsKey(name)) .Select(name => setupMaps.sphereColliders[name]) .ToArray(); springBone.capsuleColliders = serializer.colliderNames .Where(name => setupMaps.capsuleColliders.ContainsKey(name)) .Select(name => setupMaps.capsuleColliders[name]) .ToArray(); springBone.panelColliders = serializer.colliderNames .Where(name => setupMaps.panelColliders.ContainsKey(name)) .Select(name => setupMaps.panelColliders[name]) .ToArray(); return(true); }