コード例 #1
0
        private static void AddRulesForSelection(XAssetBuildRules rules, string searchPattern)
        {
            var isDir = rules.searchPatternDir.Equals(searchPattern);

            foreach (var item in Selection.objects)
            {
                var path = AssetDatabase.GetAssetPath(item);
                var rule = new BuildRule
                {
                    searchPath    = path,
                    searchPattern = searchPattern,
                    nameBy        = isDir ? ENameBy.Directory : ENameBy.Path
                };
                ArrayUtility.Add(ref rules.rules, rule);
            }

            EditorUtility.SetDirty(rules);
            AssetDatabase.SaveAssets();
        }
コード例 #2
0
        private void ApplyRule(BuildRule rule)
        {
            var assets = rule.GetAssets();

            Debug.Log("[XAsset] ApplyRule. assets: " + assets.Length);

            switch (rule.nameBy)
            {
            case ENameBy.Explicit:
            {
                foreach (var asset in assets)
                {
                    _asset2Bundles[asset] = RuledAssetBundleName(rule.assetBundleName);
                }

                break;
            }

            case ENameBy.Path:
            {
                foreach (var asset in assets)
                {
                    _asset2Bundles[asset] = RuledAssetBundleName(asset);
                }

                break;
            }

            case ENameBy.Directory:
            {
                foreach (var asset in assets)
                {
                    _asset2Bundles[asset] = RuledAssetBundleName(Path.GetDirectoryName(asset));
                }

                break;
            }

            case ENameBy.TopDirectory:
            {
                var startIndex = rule.searchPath.Length;
                foreach (var asset in assets)
                {
                    var dir = Path.GetDirectoryName(asset);
                    if (!string.IsNullOrEmpty(dir))
                    {
                        if (!dir.Equals(rule.searchPath))
                        {
                            var pos = dir.IndexOf("/", startIndex + 1, StringComparison.Ordinal);
                            if (pos != -1)
                            {
                                dir = dir.Substring(0, pos);
                            }
                        }
                    }

                    _asset2Bundles[asset] = RuledAssetBundleName(dir);
                }

                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }