Exemplo n.º 1
0
 protected virtual void Reset()
 {
     CachedRenderer.sprite         = AssetDatabaseUtility.LoadAssetInFolder <Sprite>("SquareSprite.png", "GraphicsTools");
     CachedRenderer.sharedMaterial = AssetDatabaseUtility.LoadAssetInFolder <Material>("FogOfWar.mat", "FogOfWar");
     renderQueue = CachedRenderer.sharedMaterial.renderQueue;
     Definition  = 1;
 }
Exemplo n.º 2
0
    public static RBPaletteGroup CreatePaletteGroupFromPaletteTexture(string path, string filename, Texture2D sourceTexture, bool overwriteExisting)
    {
        ValidateSaveLocation(path + filename, overwriteExisting);
        RBPaletteGroup paletteGroup = RBPaletteGroup.CreateInstanceFromPaletteTexture(sourceTexture, sourceTexture.name + suffix);

        return((RBPaletteGroup)AssetDatabaseUtility.SaveObject(paletteGroup, path, filename));
    }
Exemplo n.º 3
0
        private static void SaveState(FileInfo file, Project project)
        {
            var editorSceneManager = project.Session.GetManager <IEditorSceneManager>();

            var scenes = new List <Scene>();

            for (var i = 0; i < editorSceneManager.LoadedSceneCount; i++)
            {
                scenes.Add(editorSceneManager.GetLoadedSceneAtIndex(i));
            }

            var assetGuid     = AssetDatabaseUtility.GetAssetGuid(Application.AuthoringProject.GetProjectFile());
            var entityManager = project.Session.GetManager <IWorldManager>().EntityManager;

            // This does not scale!
            // @TODO Stream API
            var json = JsonSerialization.Serialize(new SessionState
            {
                ProjectAssetGuid = assetGuid,
                EntityManager    = entityManager,
                Scenes           = scenes
            }, new EntityJsonVisitor(entityManager));

            file.WriteAllText(json);
        }
//            private void InitBuildinSprites()
//            {
//                var buildSpIds = YuLegoConstant.YuSpriteIds;
//                foreach (var spId in buildSpIds)
//                {
//                    var sp = Resources.Load<Sprite>("YuSprite/" + spId);
//                    buildinSpriteDict.Add(sp.name, sp);
//                }
//            }

            public Sprite GetSprite(string spName)
            {
                if (string.IsNullOrEmpty(spName))
                {
                    throw new Exception("精灵资源Id不能为空!");
                }

                //if (buildinSpriteDict.ContainsKey(spName))
                //{
                //    return buildinSpriteDict[spName];
                //}

                var lowerAssetId = spName.ToLower();

                if (appSpriteDict.ContainsKey(lowerAssetId))
                {
                    return(appSpriteDict[lowerAssetId]);
                }

                ////var path = currentU3DApp.Helper.OriginAtlasSpriteDir
                ////           + spName + ".png";
                var sp = AssetDatabaseUtility.LoadAssetAtPath <Sprite>("");

                if (sp == null)
                {
                    Debug.Log($"目标精灵{spName}在内建和应用精灵中都不存在!");
                }

                appSpriteDict.Add(lowerAssetId, sp);
                return(sp);
            }
Exemplo n.º 5
0
        static void CreateParticle()
        {
            if (Array.TrueForAll(Selection.objects, selected => !(selected is Texture)))
            {
                Debug.LogError("No textures were selected.");
                return;
            }

            for (int i = 0; i < Selection.objects.Length; i++)
            {
                Texture texture = Selection.objects[i] as Texture;

                if (texture == null)
                {
                    continue;
                }

                string textureName  = texture.name.EndsWith("Texture") ? texture.name.Substring(0, texture.name.Length - "Texture".Length) : texture.name;
                string texturePath  = AssetDatabase.GetAssetPath(texture);
                string materialPath = Path.GetDirectoryName(texturePath) + "/" + textureName + ".mat";

                AssetDatabase.CopyAsset(AssetDatabaseUtility.GetAssetPath("GraphicsTools/ParticleMaterial.mat"), materialPath);
                AssetDatabase.Refresh();

                Material material = AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material)) as Material;
                material.mainTexture = texture;
            }
        }
Exemplo n.º 6
0
        private static void AddAddressGroup(AssetPackerConfig assetPackerConfig)
        {
            if (assetPackerConfig != null)
            {
                RemoveAddressGroup(assetPackerConfig);

                string[] assetPaths = AssetDatabaseUtility.FindAssets <AssetAddressConfig>();
                if (assetPaths == null || assetPaths.Length == 0)
                {
                    Debug.LogError("AssetPackUtil::AddAddressGroup->AssetAddressConfig is not found!");
                    return;
                }

                AssetPackerGroupData groupData = new AssetPackerGroupData()
                {
                    groupName = AddressGroupName,
                };
                AssetPackerAddressData addressData = new AssetPackerAddressData()
                {
                    assetAddress  = AssetConst.ASSET_ADDRESS_CONFIG_NAME,
                    assetPath     = assetPaths[0],
                    bundlePath    = AssetConst.ASSET_ADDRESS_BUNDLE_NAME,
                    bundlePathMd5 = MD5Crypto.Md5(AssetConst.ASSET_ADDRESS_BUNDLE_NAME).ToLower(),
                };
                groupData.assetFiles.Add(addressData);

                assetPackerConfig.groupDatas.Add(groupData);
            }
        }
Exemplo n.º 7
0
        private void FindBundleDepends(Action <string, string, float> progressAction)
        {
            int m_FindIndex = 0;

            m_BundleAssetPathList.ForEach((path) =>
            {
                if (!(Path.GetExtension(path).ToLower() == ".spriteatlas"))
                {
                    progressAction?.Invoke("Find Depends", path, m_FindIndex / (float)m_BundleAssetPathList.Count);
                    m_FindIndex++;

                    List <string> depends = new List <string>();

                    string[] childDepends = AssetDatabaseUtility.GetDirectlyDependencies(path, new string[] { ".cs", ".txt" });
                    if (childDepends != null && childDepends.Length > 0)
                    {
                        foreach (var cd in childDepends)
                        {
                            FindDpends(cd, depends);
                        }
                    }
                    depends.Remove(path);
                    m_BundleDependAssetDic.Add(path, depends);
                }
            });
        }
Exemplo n.º 8
0
        public static AssetPackerConfig GetAssetPackerConfig()
        {
            AssetPackerConfig packerConfig = new AssetPackerConfig();

            AssetAddressGroup[] groups = AssetDatabaseUtility.FindInstances <AssetAddressGroup>();
            if (groups != null && groups.Length > 0)
            {
                foreach (var group in groups)
                {
                    AssetPackerGroupData groupData = new AssetPackerGroupData();
                    groupData.groupName      = group.groupName;
                    groupData.isMain         = group.isMain;
                    groupData.isPreload      = group.isPreload;
                    groupData.isNeverDestroy = group.isNeverDestroy;

                    groupData.assetFiles = GetAssetsInGroup(group);

                    packerConfig.groupDatas.Add(groupData);
                }
            }
            packerConfig.Sort();

            AddAddressGroup(packerConfig);

            return(packerConfig);
        }
Exemplo n.º 9
0
        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     = AssetDatabaseUtility.FindAssetInFolder <Sprite>(folderPath);
                        spriteAssetPathList.AddRange(assets);
                    }
                }
                spriteAssetPathList.Distinct();
                foreach (var path in spriteAssetPathList)
                {
                    AssetImporter ai = AssetImporter.GetAtPath(path);
                    ai.assetBundleName = bundlePath;
                }
            }
        }
Exemplo n.º 10
0
        void OnEnable()
        {
            string[] assetPaths = AssetDatabaseUtility.FindAssets <AvatarCreatorData>();

            dataListView = new EGUIListView <string>
            {
                Header           = "Data List",
                OnSelectedChange = OnListViewItemSelected,
                OnDrawItem       = (rect, index) =>
                {
                    string assetPath = dataListView.GetItem(index);
                    EditorGUI.LabelField(rect, Path.GetFileNameWithoutExtension(assetPath), EGUIStyles.BoldLabelStyle);
                },
            };
            dataListView.AddItems(assetPaths);

            AvatarPartCreatorDataDrawer.CreatePartBtnClick = (data) =>
            {
                CreatePart(data);
            };
            AvatarPartCreatorDataDrawer.PreviewPartBtnClick = (data) =>
            {
                PreviewPart(data);
            };

            previewer = new AvatarPreviewer();
        }
Exemplo n.º 11
0
    public static RBPaletteGroup CreatePaletteGroup(string path, string filename, bool overwriteExisting)
    {
        ValidateSaveLocation(path + filename, overwriteExisting);
        RBPaletteGroup paletteAsset = RBPaletteGroup.CreateInstance();

        return((RBPaletteGroup)AssetDatabaseUtility.SaveObject(paletteAsset, path, filename));
    }
Exemplo n.º 12
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        string        path               = AssetDatabaseUtility.GetAssetDirectory(target);
        PaletteMapJob targetJob          = (PaletteMapJob)target;
        bool          generationDisabled = targetJob.PaletteGroup == null;

        // Palette Group Button
        EditorGUI.BeginDisabledGroup(!generationDisabled);
        if (GUILayout.Button("Create New PaletteGroup from Texture"))
        {
            targetJob.CreatePaletteGroupForTexture();
        }
        EditorGUI.EndDisabledGroup();

        EditorGUILayout.Separator();

        // Generate Palette Map Button
        EditorGUI.BeginDisabledGroup(generationDisabled);
        if (GUILayout.Button("Generate PaletteMap"))
        {
            try {
                RBPaletteMapper.CreatePaletteMapAndKey(path, targetJob.SourceTexture, targetJob.PaletteGroup, false, targetJob.OverwriteExistingPaletteMap,
                                                       "Key", targetJob.PaletteMapName);
                Debug.Log("<color=green>Palette Map created successfully for job: </color>" + targetJob.name +
                          "\n<color=green>Updated PaletteGroup: </color>" + targetJob.PaletteGroup);
            } catch (System.Exception e) {
                Debug.LogError(e, targetJob);
            }
        }
        EditorGUI.EndDisabledGroup();
    }
        /// <summary>
        /// 获取单例配置数据
        /// 编辑器环境下:第一次打开,将保存的 txt 文件反序列化为所需资料数据,
        /// 如没有找到对应的 Txt,将自动创建一份 Asset 文件,以保存持久化数据。
        /// 点击保存资料文件以将Asset序列化为 txt,以更安全地保存持久化数据。
        /// </summary>
        /// <returns></returns>
        public static GenericSingleDati <TActual, TImpl> GetSingleDati()
        {
            var implType = typeof(TImpl);

            if (instance != null)
            {
                return(instance);
            }

            //获取 ScriptableObject Asset 文件路径
            var assetFilePath = DatiUtility.GetSingleScriptObjectPath(implType);

#if UNITY_EDITOR
            //在编辑器下,直接加载 Asset 文件
            if (UnityModeUtility.IsEditorMode)
            {
                if (File.Exists(assetFilePath))
                {
                    var scriptAsset = AssetDatabaseUtility.LoadAssetAtPath(assetFilePath, implType);
                    instance = (GenericSingleDati <TActual, TImpl>)scriptAsset;
                }
            }
#endif
            // Asset 文件加载失败或在运行时,加载序列化文件
            if (instance == null)
            {
                var originPath = DatiUtility.GetSingleSerializeDataPath(implType);
                instance = UnityModeUtility.IsEditorMode
                    ? LoadSingleOriginAtEditor(implType, originPath, assetFilePath)
                    : LoadSingleOriginAtPlay(implType, originPath);
            }
            instance.LoadDetailHelp();
            return(instance);
        }
Exemplo n.º 14
0
    static RBPaletteGroup CreatePaletteGroup()
    {
        string         unformattedFilename = "RBPaletteGroup{0}.asset";
        string         formattedFilename   = string.Empty;
        string         path         = AssetDatabaseUtility.GetDirectoryOfSelection();
        RBPaletteGroup createdGroup = null;

        for (int i = 0; i < 100; i++)
        {
            formattedFilename = string.Format(unformattedFilename, i);
            try {
                createdGroup = CreatePaletteGroup(path, formattedFilename, false);
                break;
            } catch (IOException) {
                // Do nothing, move on to next index
            }
        }

        if (createdGroup == null)
        {
            throw new IOException("Failed to create file. Too many generic RBPaletteGroups exist in save location.");
        }

        // Unlock standalone palette groups by default.
        createdGroup.Locked = false;

        AssetDatabaseUtility.SelectObject(createdGroup);

        return(createdGroup);
    }
Exemplo n.º 15
0
 void Awake()
 {
     BitmapFontConfig[] datas = AssetDatabaseUtility.FindInstances <BitmapFontConfig>();
     if (datas != null && datas.Length > 0)
     {
         fontConfigs.AddRange(datas);
     }
 }
Exemplo n.º 16
0
 static WwiseDefineSymbol()
 {
     if (AssetDatabaseUtility.HasAsset("AkSoundEngine"))
     {
         Common.EditorUtilities.DefineSymbolsUtility.AddDefineSymbol("Wwise");
         Debug.Log("Add Wwise Define Symbol");
     }
 }
Exemplo n.º 17
0
    public void LoadEditorResourceInPackageFolder()
    {
        const string packageName    = "io.github.idreamsofgame.resharp.core";
        var          searchInFolder = $"{EditorEnvironment.PackagesFolderName}/{packageName}";
        var          assets         = AssetDatabaseUtility.LoadEditorResources <TextAsset>("package", searchInFolder);

        Assert.Greater(assets.Length, 0);
    }
Exemplo n.º 18
0
        static void CreateMesh()
        {
            var mesh = new Mesh();
            var path = AssetDatabaseUtility.GenerateUniqueAssetPath("Mesh");

            AssetDatabase.CreateAsset(mesh, path);
            Selection.activeObject = mesh;
        }
        public static AssetDependencyConfig FindAllAssetData()
        {
            List <string> assetPaths          = new List <string>();
            string        assetDirectory      = PathUtility.GetDiskPath("Assets");
            List <string> assetSubdirectories = new List <string>()
            {
                assetDirectory
            };

            while (assetSubdirectories.Count > 0)
            {
                string dir = assetSubdirectories[0].Replace("\\", "/");
                assetSubdirectories.RemoveAt(0);

                var isIngore = (from folder in IngoreFolders where dir.IndexOf(folder) >= 0 select folder).Any();
                if (isIngore)
                {
                    continue;
                }

                (from file in Directory.GetFiles(dir, "*.*", SearchOption.TopDirectoryOnly)
                 let ext = Path.GetExtension(file).ToLower()
                           where Array.IndexOf(IngoreFileExts, ext) < 0
                           select PathUtility.GetAssetPath(file)
                ).ToList().ForEach((f) => { assetPaths.Add(f); });

                string[] subdirectories = Directory.GetDirectories(dir, "*", SearchOption.TopDirectoryOnly);
                if (subdirectories != null && subdirectories.Length > 0)
                {
                    assetSubdirectories.AddRange(subdirectories);
                }
            }

            AssetDependencyConfig dependencyConfig = new AssetDependencyConfig();

            if (assetPaths.Count > 0)
            {
                for (int i = 0; i < assetPaths.Count; ++i)
                {
                    AssetDependency dependency = new AssetDependency()
                    {
                        assetPath       = assetPaths[i],
                        directlyDepends = AssetDatabaseUtility.GetDirectlyDependencies(assetPaths[i], IngoreFileExts),
                        allDepends      = AssetDatabaseUtility.GetDependencies(assetPaths[i], IngoreFileExts),
                    };

                    dependencyConfig.AddData(dependency);
                }
            }

            string filePath = GetConfigFilePath();

            JSONWriter.WriteToFile(dependencyConfig, filePath);

            return(dependencyConfig);
        }
Exemplo n.º 20
0
        private void CreateDefaultSettingsData()
        {
            string path = GetPathToScene();

            AssetDatabase.CreateFolder(path, AssetDatabaseUtility.dataFolderName);
            DigitalPaintingManagerProfile profile = AssetDatabaseUtility.SetupDefaultSettings(path, EditorSceneManager.GetActiveScene().name);
            DigitalPaintingManager        manager = GameObject.FindObjectOfType <DigitalPaintingManager>();

            manager.m_pluginProfile = profile;
        }
Exemplo n.º 21
0
    public static PaletteMapJob CreatePaletteMapJob()
    {
        PaletteMapJob job             = PaletteMapJob.CreateInstance();
        string        directory       = AssetDatabaseUtility.GetDirectoryOfSelection();
        string        filename        = "RBPaletteMapJob.asset";
        string        desiredPath     = directory + filename;
        string        uniqueAssetPath = AssetDatabase.GenerateUniqueAssetPath(desiredPath);

        return((PaletteMapJob)AssetDatabaseUtility.SaveAndSelectObject(job, directory, Path.GetFileName(uniqueAssetPath)));
    }
Exemplo n.º 22
0
        static T CreateAudioContainerSettings <T>(string name, string settingsPath = "") where T : AudioSettingsBase
        {
            T      settings = ScriptableObject.CreateInstance <T>();
            string path     = AssetDatabaseUtility.GenerateUniqueAssetPath(name, path: settingsPath);

            AssetDatabase.CreateAsset(settings, path);
            Selection.activeObject = settings;

            return(settings);
        }
Exemplo n.º 23
0
    public static RBPaletteGroup ExtractPaletteFromSelection()
    {
        Texture2D selectedTexture = (Texture2D)Selection.activeObject;
        string    selectionPath   = AssetDatabaseUtility.GetDirectoryOfSelection();

        RBPaletteGroup extractedPaletteGroup = ExtractPaletteFromTexture(selectedTexture, selectionPath);

        AssetDatabaseUtility.SelectObject(extractedPaletteGroup);

        return(extractedPaletteGroup);
    }
        public static ILegoAtlas Create(string path)
        {
            var atlas = (LegoAtlas)AtlasPool.Take();
            var sps   = AssetDatabaseUtility.LoadAllAssetsAtPath <Sprite>(path);

            foreach (var sp in sps)
            {
                atlas.spriteDict.Add(sp.name.ToLower(), sp);
            }

            return(atlas);
        }
        public override void Save()
        {
            var type       = GetType();
            var originPath = DatiUtility.GetSingleSerializeDataPath(type);

            Serialize(originPath);
            Debug.Log($"目标路径{originPath}的资料文件已更新!");
            AssetDatabaseUtility.Refresh();
            //var asset = YuAssetDatabaseUtility.LoadAssetAtPath(originPath,
            //typeof(TextAsset));
            //YuEditorAPIInvoker.PingObject(asset);
        }
Exemplo n.º 26
0
    public override void OnInspectorGUI()
    {
        RBPaletteGroup targetRBPaletteGroup = (RBPaletteGroup)target;

        //DrawDefaultInspector ();
        serializedObject.Update();

        list.elementHeight = GetElementHeight();

        list.DoLayoutList();

        SerializedProperty lockedProperty = serializedObject.FindProperty("Locked");

        lockedProperty.boolValue = EditorGUILayout.Toggle("Locked", lockedProperty.boolValue);
        SetGroupLocked(lockedProperty.boolValue);

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Colors", EditorStyles.boldLabel);

        if (GUILayout.Button("Add Color", GUILayout.ExpandWidth(false)))
        {
            targetRBPaletteGroup.AddColor(RBPaletteGroup.DefaultNewColor);
        }

        colorIndex = EditorGUILayout.IntSlider("Color index: ", colorIndex, 0, targetRBPaletteGroup.NumColorsInPalette - 1);
        if (GUILayout.Button("Remove Color At Index", GUILayout.ExpandWidth(false)))
        {
            targetRBPaletteGroup.RemoveColorAtIndex(colorIndex);
        }

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Utilities", EditorStyles.boldLabel);

        if (GUILayout.Button("Export As Texture", GUILayout.ExpandWidth(false)))
        {
            string outputPath = AssetDatabaseUtility.GetAssetDirectory(targetRBPaletteGroup);
            string extension  = ".png";
            string filename   = targetRBPaletteGroup.GroupName + extension;
            try {
                targetRBPaletteGroup.WriteToFile(outputPath + filename, false);
            } catch (System.AccessViolationException) {
                if (EditorUtility.DisplayDialog("Warning!",
                                                "This will overwrite the existing file, " + filename +
                                                ". Are you sure you want to export the texture?", "Yes", "No"))
                {
                    targetRBPaletteGroup.WriteToFile(outputPath + filename, true);
                }
            }
        }

        serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 27
0
        private void ExportScript()
        {
            Injector.Instance.Get <ExcelCsharpInterfaceScriptCreator>().
            CreateScript(this);
            var scriptFileName = Injector.Instance.Get <ExcelCSharpEntityScriptCreator>().
                                 CreateScript(this);

            GlobalExcelPathMap.Instance.AddAppPathMap(ProjectInfoDati.GetActualInstance(),
                                                      scriptFileName,
                                                      TaregetExcel);
            GlobalExcelPathMap.Instance.Save();
            AssetDatabaseUtility.Refresh();
        }
        public void LoadAllAsync <TAsset>(string bundleId, Action <List <TAsset> > callback) where TAsset : Object
        {
            if (_isLoadBundle)
            {
                var bundleRef = _bundleLoader.Load(bundleId);
                bundleRef.LoadAllAsync(callback);
                return;
            }

            var assets = AssetDatabaseUtility.LoadAllAssetsAtPath <TAsset>(GetAssetPath(bundleId));

            callback(assets);
        }
Exemplo n.º 29
0
        private void PreviewSkeleton()
        {
            AvatarSkeletonCreatorData skeletonCreatorData = currentCreatorData.skeletonData;
            string skeletonAssetPath = skeletonCreatorData.GetSkeletonPrefabPath();

            if (AssetDatabaseUtility.IsAssetAtPath <GameObject>(skeletonAssetPath))
            {
                previewer.LoadSkeleton(skeletonAssetPath);
            }
            else
            {
                EditorUtility.DisplayDialog("Error", $"The prefab is not found in \"{skeletonAssetPath}\"", "OK");
            }
        }
Exemplo n.º 30
0
    public static RBPaletteGroup CreatePaletteGroup(string path, string filename, Texture2D sourceTexture, bool overwriteExisting)
    {
        ValidateSaveLocation(path + filename, overwriteExisting);

        // Create a base palette from the Texture
        RBPalette paletteFromTexture = RBPalette.CreatePaletteFromTexture(sourceTexture);

        paletteFromTexture.PaletteName = "Base Palette";

        // Create the paletteGroup with the base Palette
        RBPaletteGroup paletteGroup = RBPaletteGroup.CreateInstance(sourceTexture.name + suffix, paletteFromTexture);

        return((RBPaletteGroup)AssetDatabaseUtility.SaveObject(paletteGroup, path, filename));
    }