Пример #1
0
        public static void FixSwayReferences([NotNull, ItemNotNull] params SwayController[] controllers)
        {
            var colliders = new List <SwayCollider>();
            var joints    = new List <SwayBone>();

            foreach (var controller in controllers)
            {
                colliders.AddRange(controller.Colliders);
                joints.AddRange(controller.SwayBones);
            }

            foreach (var collider in colliders)
            {
                if (collider.BridgeTargetPath == null)
                {
                    continue;
                }

                var target = colliders.Find(col => col.Path == collider.BridgeTargetPath);

                Debug.Assert(target != null);

                collider.BridgeTarget = target;
            }

            foreach (var joint in joints)
            {
                if (joint.SideLinkPath != null)
                {
                    var sideLink = joints.Find(link => link.Path == joint.SideLinkPath);

                    Debug.Assert(sideLink != null);

                    joint.SideLink = sideLink;
                }

                if (joint.ColliderPaths != null)
                {
                    var swayBoneColliders = new SwayCollider[joint.ColliderPaths.Length];

                    for (var i = 0; i < joint.ColliderPaths.Length; ++i)
                    {
                        // e.g.: MODEL_00/BODY_SCALE/BASE/KOSHI/MOMO_L#0
                        var targetPath = joint.ColliderPaths[i];

                        var indexOfHash = targetPath.IndexOf('#');

                        if (indexOfHash >= 0)
                        {
                            targetPath = targetPath.Substring(0, indexOfHash);
                        }

                        var collider = colliders.Find(col => col.Path == targetPath);

                        if (collider == null)
                        {
                            Debug.WriteLine($"Warning: Cannot find target collider: {targetPath}");
                            continue;
                        }

                        swayBoneColliders[i] = collider;
                    }

                    joint.Colliders = swayBoneColliders;
                }
            }
        }
Пример #2
0
        private static SwayCollider ReadSwayCollider([NotNull, ItemNotNull] string[] lines, [NotNull] string line, ref int i)
        {
            var kv         = ParseKeyValue(line);
            var collider   = new SwayCollider();
            var anyPropSet = false;

            do
            {
                var setAProp = true;

                switch (kv.Key)
                {
                case "SwayCollider":
                    collider.Path = kv.Value;
                    setAProp      = false;
                    break;

                case "type":
                    collider.Type = ParseColliderType(kv.Value);
                    break;

                case "axis":
                    collider.Axis = ParseCollidingAxis(kv.Value);
                    break;

                case "radius":
                    collider.Radius = Convert.ToSingle(kv.Value);
                    break;

                case "distance":
                    collider.Distance = Convert.ToSingle(kv.Value);
                    break;

                case "offset":
                    collider.Offset = ParseVector3(kv.Value);
                    break;

                case "planeAxis":
                    collider.PlaneAxis = ParsePlaneAxis(kv.Value);
                    break;

                case "CapsuleSphere1":
                    collider.CapsuleSphere1 = Convert.ToBoolean(kv.Value);
                    break;

                case "CapsuleSphere2":
                    collider.CapsuleSphere2 = Convert.ToBoolean(kv.Value);
                    break;

                case "clipPlane":
                    collider.ClipPlane = kv.Value;
                    break;

                case "useSkirtBarrier":
                    collider.UseSkirtBarrier = Convert.ToBoolean(kv.Value);
                    break;

                case "planeRotOn":
                    collider.PlaneRotationEnabled = Convert.ToBoolean(kv.Value);
                    break;

                case "planeRotEuler":
                    collider.PlaneRotationEuler = ParseVector3(kv.Value);
                    break;

                case "bridgetgt":
                    collider.BridgeTargetPath = kv.Value;
                    break;

                default:
                    Debug.WriteLine($"Unknown collider property key/value: {kv.Key} / {kv.Value}");
                    setAProp = false;
                    break;
                }

                anyPropSet = anyPropSet || setAProp;

                {
                    ++i;
                    line = lines[i];

                    if (line.Length == 0 || line[0] != ' ')
                    {
                        // A new entry (manager/collider/bone) starts.
                        // Decrease counter so the next reading attempt will work with auto counter increment.
                        --i;
                        break;
                    }

                    kv = ParseKeyValue(line);
                }
            } while (true);

            if (!anyPropSet)
            {
                throw new ArgumentException("Empty SwayCollider body");
            }

            return(collider);
        }