Exemplo n.º 1
0
        private static Version UpdateVersionAsset(int buildNumber, string version, string branch)
        {
            Version versionInfo;
            bool    foundExistingAsset = AssetDatabaseUtil.LoadAsset <Version>(out versionInfo);

            if (!foundExistingAsset)
            {
                Debug.LogWarning("NO VERSION ASSET FOUND");
                versionInfo = ScriptableObject.CreateInstance <Version>();
            }
            versionInfo.buildNumber = buildNumber;
            if (!string.IsNullOrEmpty(version)) // only override existing value when passed
            {
                versionInfo.versionString = version;
            }

            if (!string.IsNullOrEmpty(branch))
            {
                versionInfo.branchName = branch;
            }

            EditorUtility.SetDirty(versionInfo);
            AssetDatabase.SaveAssets();

            return(versionInfo);
        }
Exemplo n.º 2
0
 private void Reset()
 {
     viewPrefab_ = AssetDatabaseUtil.LoadSpecificAssetNamed <GameObject>("DebugMenuView");
     menuItems_  = new DebugMenuItem[] {
         AssetDatabaseUtil.LoadSpecificAssetNamed <DebugMenuItem>("ConsoleLogDebugMenuItem"),
     };
 }
Exemplo n.º 3
0
        //自动查找 Group 配置插入到assetGroups 执行显示
        public void AutoFindGroup()
        {
            string[]          assetPaths = AssetDatabaseUtil.FindAssets <AssetGroup>();
            List <AssetGroup> groupList  = new List <AssetGroup>();

            foreach (var assetPath in assetPaths)
            {
                AssetGroup group = AssetDatabase.LoadAssetAtPath <AssetGroup>(assetPath);
                if (group != null && group.m_AssetAssemblyType == (AssetAssemblyType)m_AssetAssemblyType.intValue) //资源集合类型一致
                {
                    if (group.name.IndexOf(m_TestGroupPrefix.stringValue) == 0)
                    {
                        continue;
                    }

                    groupList.Add(group);
                }
            }
            m_AssetGroups.ClearArray();
            for (int i = 0; i < groupList.Count; ++i)
            {
                m_AssetGroups.InsertArrayElementAtIndex(i);                                  //插入
                m_AssetGroups.GetArrayElementAtIndex(i).objectReferenceValue = groupList[i]; //引用赋值
            }

            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 4
0
        private static bool UpdateUpdaterAsset(string setupName, string branch)
        {
            UpdaterSettings updaterSettings;
            bool            foundExistingAsset = AssetDatabaseUtil.LoadAsset <UpdaterSettings>(out updaterSettings);

            if (!foundExistingAsset)
            {
                Debug.LogWarning("NO UPDATER SETTINGS ASSET FOUND");
                return(false);
            }

            if (!string.IsNullOrEmpty(setupName))
            {
                updaterSettings.SetupName = setupName;
            }
            if (!string.IsNullOrEmpty(branch))
            {
                updaterSettings.ProjectName = branch;
            }

            EditorUtility.SetDirty(updaterSettings);
            AssetDatabase.SaveAssets();

            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 由于UGUI中SpriteAtlas的特殊性,为了防止UI的Prefab打包无法与Atlas关联,
        /// 从而设定将SpriteAtlas所使用的Sprite一起打包
        /// </summary>
        /// <param name="atlasAssetPath">SpriteAtlas所在的资源路径</param>
        /// <param name="bundlePath">需要设置的BundleName</param>
        private static void SetSpriteBundleNameByAtlas(string atlasAssetPath, string bundlePath)
        {
            SpriteAtlas atlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(atlasAssetPath);

            if (atlas != null)
            {
                List <string> spriteAssetPathList = new List <string>();
                UnityObject[] objs = atlas.GetPackables();
                foreach (var obj in objs)
                {
                    if (obj.GetType() == typeof(Sprite))
                    {
                        spriteAssetPathList.Add(AssetDatabase.GetAssetPath(obj));
                    }
                    else if (obj.GetType() == typeof(DefaultAsset))
                    {
                        string   folderPath = AssetDatabase.GetAssetPath(obj);
                        string[] assets     = AssetDatabaseUtil.FindAssetInFolder <Sprite>(folderPath);
                        spriteAssetPathList.AddRange(assets);
                    }
                }
                spriteAssetPathList.Distinct();
                foreach (var path in spriteAssetPathList)
                {
                    AssetImporter ai = AssetImporter.GetAtPath(path);
                    ai.assetBundleName = bundlePath;
                }
            }
        }
Exemplo n.º 6
0
 private void GetTodoData()
 {
     data = AssetDatabaseUtil.GetAllAssetsOfType <TodoData>().FirstOrDefault();
     if (data == null)
     {
         TodoData temp = ScriptableObject.CreateInstance <TodoData>();
         AssetDatabaseUtil.CreateAsset(temp, "Assets/Scripts/Editor/TODO", "TODO Data");
         data = AssetDatabaseUtil.GetAllAssetsOfType <TodoData>().FirstOrDefault();
     }
 }
Exemplo n.º 7
0
        public static Dictionary <string, string> CollectionAssetPathToBundleNames()
        {
            Dictionary <string, string> pathToNames = new Dictionary <string, string>();

            pathToNames[AssetAddressConfig.CONFIG_PATH] = AssetAddressConfig.CONFIG_ASSET_BUNDLE_NAME.ToLower();

            #region Collection
            AssetBundleTagConfig tagConfig = Util.FileUtil.ReadFromBinary <AssetBundleTagConfig>(BundlePackUtil.GetTagConfigPath());
            AssetAddressData[]   datas     = (from groupData in tagConfig.GroupDatas
                                              from detailData in groupData.AssetDatas
                                              select detailData).ToArray();

            long elapsedMS = Leyoutech.Utility.DebugUtility.GetMillisecondsSinceStartup();
            for (int iData = 0; iData < datas.Length; iData++)
            {
                AssetAddressData iterData   = datas[iData];
                string           assetPath  = iterData.AssetPath;
                string           bundleName = iterData.BundlePath.ToLower();
                pathToNames[assetPath] = bundleName;

                if (Path.GetExtension(assetPath).ToLower() != ".spriteatlas")
                {
                    continue;
                }

                SpriteAtlas atlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(assetPath);
                if (atlas == null)
                {
                    continue;
                }

                UnityObject[] packables = atlas.GetPackables();
                for (int iPackable = 0; iPackable < packables.Length; iPackable++)
                {
                    UnityObject iterPackable = packables[iPackable];
                    if (iterPackable.GetType() == typeof(Sprite))
                    {
                        pathToNames[AssetDatabase.GetAssetPath(iterPackable)] = bundleName;
                    }
                    else if (iterPackable.GetType() == typeof(DefaultAsset))
                    {
                        string   folderPath = AssetDatabase.GetAssetPath(iterPackable);
                        string[] assets     = AssetDatabaseUtil.FindAssetInFolder <Sprite>(folderPath);
                        for (int iAsset = 0; iAsset < assets.Length; iAsset++)
                        {
                            pathToNames[assets[iAsset]] = bundleName;
                        }
                    }
                }
            }
            elapsedMS = Leyoutech.Utility.DebugUtility.GetMillisecondsSinceStartup() - elapsedMS;
            Leyoutech.Utility.DebugUtility.Log(Leyoutech.BuildPipeline.BuildPipelineGraph.LOG_TAG, $"Collection all bundleName count ({pathToNames.Count}) elapsed {Leyoutech.Utility.DebugUtility.FormatMilliseconds(elapsedMS)}");
            #endregion
            return(pathToNames);
        }
Exemplo n.º 8
0
        // PRAGMA MARK - ICommandLoader
        public ICommand[] Load()
        {
            List <T> assets = AssetDatabaseUtil.AllAssetsOfType <T>();

            List <ICommand> objects = new List <ICommand>();

            foreach (var asset in assets)
            {
                objects.Add(new AssetCommand <T>(asset, HandleAssetExecuted));
            }
            return(objects.ToArray());
        }
Exemplo n.º 9
0
        private void SaveDataToEditor()
        {
            editArena_.SaveDynamicArenaDataJson(dynamicArenaData_.Serialize());

            // if UNITY_EDITOR, check that the asset already exists - use editorUtility to save changes instead
                        #if UNITY_EDITOR
            string assetsBasedDirectoryPath = "Assets/CustomArenas";

            List <ArenaConfig> arenaConfigs = AssetDatabaseUtil.AllAssetsOfType <ArenaConfig>();
            if (arenaConfigs.Any(ac => ac == editArena_))
            {
                EditorUtility.SetDirty(editArena_);
                AssetDatabase.SaveAssets();
                return;
            }

            // if not new asset, save to new asset
            int    index = 0;
            string path;
            do
            {
                path = Path.Combine(assetsBasedDirectoryPath, string.Format(kDefaultNameFormat, index));
                index++;
            } while (AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object)) != null);

            string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path);
            AssetDatabase.CreateAsset(editArena_, assetPathAndName);
            AssetDatabase.SaveAssets();
                        #else
            string directoryPath = Path.Combine(Application.dataPath, "CustomArenas");
            Directory.CreateDirectory(directoryPath);

            var filenames = new HashSet <string>(Directory.GetFiles(directoryPath));

            string filename        = editArena_.name;
            bool   findDefaultName = string.IsNullOrEmpty(filename);
            if (findDefaultName)
            {
                int index = 1;
                do
                {
                    filename = string.Format("CustomArena{0}", index);
                    index++;
                } while (filenames.Contains(filename + ".asset"));
            }


            File.WriteAllText(Path.Combine(directoryPath, filename + ".asset"), JsonUtility.ToJson(editArena_));
                        #endif
        }
    public static void RemoveAssetsAtPath <T>(string path) where T : UnityEngine.Object
    {
        var preloadedAssets = AssetDatabaseUtil.GetAllAssetsOfType <T>("t:" + typeof(T).Name, new string[] { path });

        if (preloadedAssets.Count > 0)
        {
            foreach (var item in preloadedAssets)
            {
                AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(item));
            }
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            Debug.Log("Removing all assets in Directory " + path);
        }
    }
Exemplo n.º 11
0
        // PRAGMA MARK - Static Public Interface
        public static GoogleTranslate FindAndCreate()
        {
            var sources = AssetDatabaseUtil.AllAssetsOfType <GoogleTranslateSource>();

            if (sources.Count <= 0)
            {
                Debug.LogWarning("No GoogleTranslateSources found in project!");
                return(null);
            }

            if (sources.Count > 1)
            {
                Debug.LogWarning("Multiple GoogleTranslateSources found in project - choosing first!");
            }
            return(sources[0].Create());
        }
Exemplo n.º 12
0
 /// <summary>
 /// 根据配置的AssetAddressAssembly更新资源的分组
 /// </summary>
 public static void UpdateTagConfig()
 {
     string[] settingPaths = AssetDatabaseUtil.FindAssets <AssetAddressAssembly>();
     if (settingPaths == null || settingPaths.Length == 0)
     {
         Debug.LogError("AssetBundleSchemaUtil::UpdateTagConfigBySchema->Not found schema Setting;");
         return;
     }
     foreach (var assetPath in settingPaths)
     {
         AssetAddressAssembly aaAssembly = AssetDatabase.LoadAssetAtPath <AssetAddressAssembly>(assetPath);
         if (aaAssembly != null)
         {
             aaAssembly.AutoFind();
             aaAssembly.Execute();
         }
     }
 }
Exemplo n.º 13
0
        private void ShowLoadMenu()
        {
            MenuView.Hide();

            var levelOpenActions = new Dictionary <string, Action>();

                        #if UNITY_EDITOR
            var arenaConfigs = AssetDatabaseUtil.AllAssetsOfType <ArenaConfig>();
            foreach (var arenaConfig in arenaConfigs)
            {
                levelOpenActions[arenaConfig.name] = () => {
                    editArenaCallback_.Invoke(arenaConfig);
                    HideMenu();
                };
            }
                        #endif
            // TODO (darren): support loading from custom levels saved outside of editor
            MenuView.Show(new InputWrapperDevice(inputDevice_), "LOAD LEVEL TO EDIT", levelOpenActions);
        }
Exemplo n.º 14
0
        // PRAGMA MARK - Setup
        private static string FindSandboxSetupPrefabPath()
        {
            string guid = AssetDatabaseUtil.FindSpecificAsset(kSandboxSetupPrefabName + " t:Prefab", required: false);

            if (guid.IsNullOrEmpty())
            {
                return("");
            }

            string path = AssetDatabase.GUIDToAssetPath(guid);

            if (PathUtil.IsPrefab(path))
            {
                return(path);
            }
            else
            {
                Debug.LogError(string.Format("Path for sandbox setup prefab ({0}) is not a prefab", path));
                return("");
            }
        }
        public static void DownloadAndBakeAllUsedLocalizationCharactersIntoFonts()
        {
            var charSet = new HashSet <char>();

            LocalizationTable[] allTables = UnityEngine.Object.FindObjectsOfType <LocalizationConfiguration>().SelectMany(config => config.TableSources).Select(s => s.LoadTable()).ToArray();
            foreach (var table in allTables)
            {
                foreach (var culture in table.AllCultures)
                {
                    var textMap = table.GetTextMapFor(culture);
                    foreach (string translatedText in textMap.Values)
                    {
                        charSet.UnionWith(translatedText);
                    }
                }
            }

            string charactersString = new String(charSet.ToArray());

            var bakedFontConfigurations = AssetDatabaseUtil.AllAssetsOfType <BakedLocalizedFontConfiguration>();

            if (bakedFontConfigurations.Count <= 0)
            {
                Debug.LogWarning("Cannot bake used localization characters without any BakedLocalizedFontConfigurations in the project!");
                return;
            }

            foreach (var config in bakedFontConfigurations)
            {
                // No need to bake a font that already contains all the characters
                if (TMP_FontAssetUtil.DoesFontContainAllCharacters(config.OutputFontAsset, charactersString))
                {
                    continue;
                }

                string outputFilePath = AssetDatabase.GetAssetPath(config.OutputFontAsset);
                TMPFontAssetBaker.Bake(config.Font, config.useAutoSizing, config.FontSize, config.CharacterPadding, config.FontPackingMode, config.AtlasWidth, config.AtlasHeight, config.FontStyle, config.FontStyleMod, config.FontRenderMode, charactersString, outputFilePath);
            }
        }
Exemplo n.º 16
0
        void GetSpriteAssetitem(string atlasAssetPath, ref List <string> spriteAssetPathList)
        {
            SpriteAtlas atlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(atlasAssetPath);

            if (atlas != null)
            {
                UnityObject[] objs = atlas.GetPackables();
                foreach (var obj in objs)
                {
                    if (obj.GetType() == typeof(Sprite))
                    {
                        spriteAssetPathList.Add(AssetDatabase.GetAssetPath(obj));
                    }
                    else if (obj.GetType() == typeof(DefaultAsset))
                    {
                        string   folderPath = AssetDatabase.GetAssetPath(obj);
                        string[] assets     = AssetDatabaseUtil.FindAssetInFolder <Sprite>(folderPath);
                        spriteAssetPathList.AddRange(assets);
                    }
                }
                spriteAssetPathList.Distinct();
            }
        }
Exemplo n.º 17
0
 public static string DrawObjectField <T>(string label, string path) where T : UnityEngine.Object
 {
     return(AssetDatabaseUtil.GetAssetPath(EditorGUILayout.ObjectField(label, Resources.Load(path), typeof(T), false)));
 }
Exemplo n.º 18
0
 private void Reset()
 {
     viewPrefab_ = AssetDatabaseUtil.LoadSpecificAssetNamed <GameObject>("TimeScaleScrubberView");
 }
Exemplo n.º 19
0
 private void LoadListInGame()
 {
     _list = new List <T>(Resources.LoadAll <T>(AssetDatabaseUtil.GetResourceFolderPath(path)));
     _list.RemoveAll(x => x.removedFromList);
 }
Exemplo n.º 20
0
        public static IList <ValidationError> Validate(GameObject gameObject)
        {
            if (gameObject == null)
            {
                return(null);
            }

            List <ValidationError> validationErrors = null;

            Queue <GameObject> queue = new Queue <GameObject>();

            queue.Enqueue(gameObject);

            while (queue.Count > 0)
            {
                GameObject current = queue.Dequeue();

                Component[] components = current.GetComponents <Component>();
                if (components == null)
                {
                    continue;
                }

                foreach (Component c in components)
                {
                    if (c == null)
                    {
                        continue;
                    }

                    Type componentType = c.GetType();

                    // allow user defined ignores for namespaces
                    bool inIgnoredNamespace = false;
                    foreach (var validatorIgnoredNamespace in AssetDatabaseUtil.AllAssetsOfType <ValidatorIgnoredNamespace>())
                    {
                        if (validatorIgnoredNamespace == null)
                        {
                            Debug.LogWarning("Bad state - validatorIgnoredNamespace is null!");
                            continue;
                        }

                        if (componentType.Namespace == null)
                        {
                            continue;
                        }

                        if (componentType.Namespace.Contains(validatorIgnoredNamespace.Namespace))
                        {
                            inIgnoredNamespace = true;
                            break;
                        }
                    }

                    if (inIgnoredNamespace)
                    {
                        continue;
                    }

                    foreach (FieldInfo fieldInfo in TypeUtil.GetInspectorFields(componentType)
                             .Where(f => typeof(UnityEventBase).IsAssignableFrom(f.FieldType))
                             .Where(f => !Attribute.IsDefined(f, typeof(OptionalAttribute)) && !Attribute.IsDefined(f, typeof(HideInInspector))))
                    {
                        // NOTE (darren): check UnityEvents for all classes
                        UnityEventBase unityEvent = (UnityEventBase)fieldInfo.GetValue(c);
                        if (unityEvent == null)
                        {
                            Debug.LogError("Unexpected null UnityEvent in GameObjectValidator!");
                            continue;
                        }

                        for (int i = 0; i < unityEvent.GetPersistentEventCount(); i++)
                        {
                            UnityEngine.Object target       = unityEvent.GetPersistentTarget(i);
                            string             targetMethod = unityEvent.GetPersistentMethodName(i);

                            if (target == null || string.IsNullOrEmpty(targetMethod) || target.GetType().GetMethod(targetMethod) == null)
                            {
                                validationErrors = validationErrors ?? new List <ValidationError>();
                                validationErrors.Add(new ValidationError(c, componentType, fieldInfo));
                                break;
                            }
                        }
                    }

                    if (kUnityAssemblies.Contains(componentType.Assembly))
                    {
                        continue;
                    }

                    foreach (FieldInfo fieldInfo in TypeUtil.GetInspectorFields(componentType)
                             .Where(f => !Attribute.IsDefined(f, typeof(OptionalAttribute)) && !Attribute.IsDefined(f, typeof(HideInInspector))))
                    {
                        // NOTE (darren): this is to ignore fields that declared in super-classes out of our control (Unity)
                        if (kUnityAssemblies.Contains(fieldInfo.DeclaringType.Assembly))
                        {
                            continue;
                        }

                        bool isInvalid = fieldInfo.GetUnityEngineObjects(c).Any(o => o == null);
                        if (isInvalid)
                        {
                            validationErrors = validationErrors ?? new List <ValidationError>();
                            validationErrors.Add(new ValidationError(c, componentType, fieldInfo));
                        }
                    }
                }

                foreach (GameObject child in current.GetChildren())
                {
                    queue.Enqueue(child);
                }
            }

            return(validationErrors);
        }