예제 #1
0
        public static void ValidateVCIObject(VCIObject vo)
        {
            // VCIObject
            var vciObjectCount  = 0;
            var gameObjectCount = 0;

            foreach (var t in vo.transform.Traverse())
            {
                if (t.GetComponent <VCIObject>() != null)
                {
                    vciObjectCount++;
                }
                gameObjectCount++;
            }

            if (vciObjectCount > 1)
            {
                throw new VCIValidatorException(ValidationErrorType.MultipleVCIObject);
            }

            // Scripts
            if (vo.Scripts.Any())
            {
                if (vo.Scripts[0].name != "main")
                {
                    throw new VCIValidatorException(ValidationErrorType.FirstScriptNameNotValid);
                }

                var empties = vo.Scripts.Where(x => string.IsNullOrEmpty(x.name));
                if (empties.Any())
                {
                    throw new VCIValidatorException(ValidationErrorType.NoScriptName);
                }

                var duplicates = vo.Scripts.GroupBy(script => script.name)
                                 .Where(name => name.Count() > 1)
                                 .Select(group => group.Key).ToList();
                if (duplicates.Any())
                {
                    throw new VCIValidatorException(ValidationErrorType.ScriptNameConfliction);
                }

                var invalidChars = Path.GetInvalidFileNameChars().Concat(new [] { '.' }).ToArray();
                foreach (var script in vo.Scripts)
                {
                    if (script.name.IndexOfAny(invalidChars) >= 0)
                    {
                        throw new VCIValidatorException(ValidationErrorType.InvalidCharacter,
                                                        string.Format(VCIConfig.GetText($"error{(int)ValidationErrorType.InvalidCharacter}"), script.name));
                    }
                }
                ;
            }

            VCIMetaValidator.Validate(vo);

            // Invalid Components
            CheckInvalidComponent <MeshCollider>(vo.gameObject);

            // Spring Bone
            var springBones = vo.GetComponents <VCISpringBone>();

            if (springBones != null && springBones.Length > 0)
            {
                ValidateSpringBones(springBones);
            }
        }
예제 #2
0
파일: VCIValidator.cs 프로젝트: notargs/VCI
        public static void ValidateVCIObject(VCIObject vo)
        {
            // VCIObject
            var vciObjectCount        = 0;
            var gameObjectCount       = 0;
            var playerSpawnPointsList = new List <VCIPlayerSpawnPoint>();
            var locationBoundsList    = new List <VCILocationBounds>();

            foreach (var t in vo.transform.Traverse())
            {
                if (t.GetComponent <VCIObject>() != null)
                {
                    vciObjectCount++;
                }

                var psp = t.GetComponent <VCIPlayerSpawnPoint>();
                if (psp != null)
                {
                    playerSpawnPointsList.Add(psp);
                }

                var locationBounds = t.GetComponent <VCILocationBounds>();
                if (locationBounds != null)
                {
                    locationBoundsList.Add(locationBounds);
                }

                gameObjectCount++;
            }

            if (vciObjectCount > 1)
            {
                throw new VCIValidatorException(ValidationErrorType.MultipleVCIObject);
            }

            // Scripts
            if (vo.Scripts.Any())
            {
                if (vo.Scripts[0].name != "main")
                {
                    throw new VCIValidatorException(ValidationErrorType.FirstScriptNameNotValid);
                }

                var empties = vo.Scripts.Where(x => string.IsNullOrEmpty(x.name));
                if (empties.Any())
                {
                    throw new VCIValidatorException(ValidationErrorType.NoScriptName);
                }

                var duplicates = vo.Scripts.GroupBy(script => script.name)
                                 .Where(name => name.Count() > 1)
                                 .Select(group => group.Key).ToList();
                if (duplicates.Any())
                {
                    throw new VCIValidatorException(ValidationErrorType.ScriptNameConfliction);
                }

                var invalidChars = Path.GetInvalidFileNameChars().Concat(new [] { '.' }).ToArray();
                foreach (var script in vo.Scripts)
                {
                    if (script.name.IndexOfAny(invalidChars) >= 0)
                    {
                        throw new VCIValidatorException(ValidationErrorType.InvalidCharacter,
                                                        string.Format(VCIConfig.GetText($"error{(int)ValidationErrorType.InvalidCharacter}"), script.name));
                    }
                }
                ;
            }

            VCIMetaValidator.Validate(vo);

            // Invalid Components
            CheckInvalidComponent <MeshCollider>(vo.gameObject);

            // Spring Bone
            var springBones = vo.GetComponents <VCISpringBone>();

            if (springBones != null && springBones.Length > 0)
            {
                ValidateSpringBones(springBones);
            }

            // PlayerSpawnPoint
            foreach (var psp in playerSpawnPointsList)
            {
                var pspT = psp.gameObject.transform;
                if (Math.Abs(pspT.position.y) > SpawnPointAllowedHeightRange)
                {
                    throw new VCIValidatorException(ValidationErrorType.SpawnPointHeightRangeNotAllowed,
                                                    VCIConfig.GetText($"error{(int)ValidationErrorType.SpawnPointHeightRangeNotAllowed}"));
                }

                if (Math.Abs(pspT.rotation.x) > 0.001f || Math.Abs(pspT.rotation.z) > 0.001f)
                {
                    throw new VCIValidatorException(ValidationErrorType.SpawnPointNotHorizontal,
                                                    VCIConfig.GetText($"error{(int)ValidationErrorType.SpawnPointNotHorizontal}"));
                }

                var pspR = psp.GetComponent <VCIPlayerSpawnPointRestriction>();
                if (pspR == null)
                {
                    continue;
                }

                if (pspR.LimitRectLeft > 0 ||
                    pspR.LimitRectRight < 0 ||
                    pspR.LimitRectForward < 0 ||
                    pspR.LimitRectBackward > 0)
                {
                    throw new VCIValidatorException(ValidationErrorType.SpawnPointOriginNotInRange,
                                                    VCIConfig.GetText($"error{(int)ValidationErrorType.SpawnPointOriginNotInRange}"));
                }
            }

            // LocationBounds
            if (locationBoundsList.Count >= 2)
            {
                throw new VCIValidatorException(ValidationErrorType.LocationBoundsCountLimitOver,
                                                VCIConfig.GetText($"error{(int)ValidationErrorType.LocationBoundsCountLimitOver}"));
            }
            if (locationBoundsList.Count > 0)
            {
                var locationBounds = locationBoundsList[0];
                var min            = locationBounds.Bounds.min;
                var max            = locationBounds.Bounds.max;

                // 10000fを超えてないかだけチェック
                if (Mathf.Abs(min.x) > 10000f || Mathf.Abs(min.y) > 10000f || Mathf.Abs(min.z) > 10000f ||
                    Mathf.Abs(max.x) > 10000f || Mathf.Abs(max.y) > 10000f || Mathf.Abs(max.z) > 10000f)
                {
                    throw new VCIValidatorException(ValidationErrorType.LocationBoundsValueExceeded,
                                                    VCIConfig.GetText($"error{(int)ValidationErrorType.LocationBoundsValueExceeded}"));
                }
            }
        }