Ejemplo n.º 1
0
        protected void SetupActiveShaderStackList()
        {
            shaderStackList.data.Clear();
            shaderStackList.tableView.ClearSelection();

            Dictionary <string, Material> matCache = _shaderManager.MaterialCache;

            foreach (string id in matCache.Keys)
            {
                matCache.TryGetValue(id, out Material mat);

                ShaderEffectData sfx = _shaderManager.GetShaderEffectByMaterial(mat);

                if (sfx == null)
                {
                    continue;
                }

                /*Sprite icon = Util.SEUtilities.GetDefaultShaderIcon();
                 *
                 * if (sfx.previewImage != null && _spriteCache.TryGetValue(sfx.previewImage, out Sprite image)) {
                 *  icon = image;
                 * }
                 *
                 * //CustomListTableData.CustomCellInfo customCellInfo = new CustomListTableData.CustomCellInfo(sfx.name, sfx.author, icon);*/
                shaderStackList.data.Add(new ActiveShaderElement(sfx.ReferenceName, id));
            }

            shaderStackList.tableView.ReloadData();
        }
Ejemplo n.º 2
0
        public void LoadShaders()
        {
            Directory.CreateDirectory(Plugin.PluginAssetPath);

            shaderFiles = Directory.GetFiles(Plugin.PluginAssetPath, "*.bsfx");

            ShaderEffectList = new List <ShaderEffectData>();

            foreach (string sh in shaderFiles)
            {
                ShaderEffectData shaderEffect = null;

                try
                {
                    shaderEffect = LoadShaderEffectAssetBundleFromPath(sh);
                    Logger.log.Info("Loading Shader: " + sh);
                    LogShaderFX(shaderEffect);
                    ShaderEffectList.Add(shaderEffect);
                }
                catch (Exception ex)
                {
                    Logger.log.Error("Error loading shader \"" + sh + "\"! - " + ex.Message);
                    Logger.log.Error(ex.StackTrace);
                }
            }
        }
Ejemplo n.º 3
0
        protected void Select(TableView _, int row)
        {
            _selection = row;
            ShaderEffectData sfx = _shaderAssetLoader.ShaderEffectList[_selection];

            Logger.log.Info("Selected: " + sfx.Name + " by " + sfx.Author);
            shaderSelected?.Invoke(sfx);
        }
Ejemplo n.º 4
0
 public static void LogShaderFX(ShaderEffectData shaderEffect)
 {
     Logger.log?.Debug("ShaderEffect.material: " + shaderEffect.Material);
     Logger.log?.Debug("ShaderEffect.referenceName: " + shaderEffect.ReferenceName);
     Logger.log?.Debug("ShaderEffect.name: " + shaderEffect.Name);
     Logger.log?.Debug("ShaderEffect.author: " + shaderEffect.Author);
     Logger.log?.Debug("ShaderEffect.description: " + shaderEffect.Description);
     Logger.log?.Debug("ShaderEffect.isScreenSpace: " + shaderEffect.IsScreenSpace);
     Logger.log?.Debug("ShaderEffect.previewImage: " + shaderEffect.PreviewImage);
 }
Ejemplo n.º 5
0
 public Sprite GetPreviewImage(ShaderEffectData sfx)
 {
     if (sfx == null || sfx.PreviewImage == null)
     {
         return(SEUtilities.GetDefaultShaderIcon());
     }
     if (_spriteCache.TryGetValue(sfx.PreviewImage, out Sprite image))
     {
         return(image);
     }
     return(Util.SEUtilities.GetDefaultShaderIcon());
 }
Ejemplo n.º 6
0
        static ShaderEffectData LoadShaderEffectAssetBundleFromPath(string path)
        {
            AssetBundle      bundle    = AssetBundle.LoadFromFile(path);
            var              loadAsset = bundle.LoadAsset <Material>("Assets/ShaderEffect.mat");
            var              shaderEffectMetadataGOPrefab = bundle.LoadAsset <GameObject>("Assets/ShaderEffectMetadata.prefab");
            GameObject       shaderEffectMetadataGO       = UnityEngine.Object.Instantiate(shaderEffectMetadataGOPrefab);
            ShaderEffect     shaderEffect = shaderEffectMetadataGO.GetComponent <ShaderEffect>();
            ShaderEffectData data         = new ShaderEffectData(shaderEffect);

            GameObject.Destroy(shaderEffectMetadataGO);
            bundle.Unload(false);
            return(data);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds a Material based of the ShaderEffect sfx with the specified identifier id
        /// </summary>
        /// <param name="id">the id assigned</param>
        /// <param name="sfx">the shader used</param>
        /// <returns>The created Material</returns>
        public Material AddMaterial(string id, ShaderEffectData sfx)
        {
            string   fullId = GetFID(id, sfx);
            Material mat;

            if (!MaterialCache.ContainsKey(fullId))
            {
                mat = new Material(sfx.Material);
                MaterialCache.Add(fullId, mat);
            }
            else
            {
                return(GetMaterial(id, sfx));
            }
            CameraManager?.AddMaterial(mat);
            return(mat);
        }
Ejemplo n.º 8
0
        private void ShaderEventCallback(CustomEventData customEventData)
        {
            if (customEventData.data == null)
            {
                return;
            }
            try
            {
                TreeDict eventData;
                switch (customEventData.type)
                {
                case EventTypeShader:
                    //Logger.log?.Debug("Shader event received!");

                    eventData = new Dictionary <string, object>(customEventData.data as TreeDict);

                    object        res = Trees.At(eventData, "_shaders");
                    List <object> shaders;
                    if (res != null)
                    {
                        shaders = res as List <object>;
                    }
                    else
                    {
                        shaders = new List <object>();
                    }

                    List <ShaderCommand> scList = new List <ShaderCommand>();

                    foreach (TreeDict shader in shaders)
                    {
                        scList.Add(new ShaderCommand(shader));
                    }

                    foreach (ShaderCommand sc in scList)
                    {
                        ShaderEffectData sfx = _shaderManager.GetShaderEffectByReferenceName(sc.ReferenceName);

                        if (sfx != null)
                        {
                            sc.ShaderEffectData = sfx;

                            Material mat = _shaderManager.GetMaterial(sc.ID, sfx);

                            if (mat == null)
                            {
                                mat = _shaderManager.AddMaterial(sc.ID, sfx);
                            }

                            sc.Material = mat;

                            StartEventCoroutine(sc, customEventData.time);
                        }
                        else
                        {
                            Logger.log.Error($"Unknown Shader reference used: '{sc.ReferenceName}'!");
                        }
                    }
                    break;

                case EventTypeShaderClear:
                    string clearId;
                    string refName;
                    eventData = new Dictionary <string, object>(customEventData.data as TreeDict);
                    clearId   = Trees.At(eventData, "_clearID");
                    if (clearId == null)
                    {
                        clearId = Trees.At(eventData, "_clearId");
                    }
                    refName = Trees.At(eventData, "_ref");
                    Logger.log.Debug($"ShaderClear at : {customEventData.time / 60 * _beatmapObjectSpawnController.currentBpm}");
                    Logger.log.Debug($"_clearId : {clearId}");
                    Logger.log.Debug($"_ref : {refName}");
                    if (clearId != null)
                    {
                        if (clearId.Equals("*"))
                        {
                            List <Material> removedMats = _shaderManager.ClearAllMaterials();
                            if (removedMats.Count > 0)
                            {
                                Logger.log.Debug($"Clearing all {removedMats.Count} Materials!");
                                StopAllCoroutinesModifyingMaterials(removedMats);
                            }
                            break;
                        }
                        ShaderEffectData sfx = _shaderManager.GetShaderEffectByReferenceName(refName);

                        Logger.log.Debug($"sfx reference Name : {sfx?.ReferenceName}");

                        if (sfx != null)
                        {
                            if (!_shaderManager.RemoveMaterial(clearId, sfx))
                            {
                                Logger.log.Notice($"Tried to remove a Shader with an ID that doesn't exist: '{clearId}' at time (in beats) {customEventData.time / 60 * _beatmapObjectSpawnController.currentBpm}!");
                            }
                        }
                        else
                        {
                            Logger.log.Debug($"trying to remove all with clearId");
                            List <Material> removedMats = _shaderManager.RemoveAllMaterialsStartingWithId(clearId);
                            if (removedMats.Count == 0)
                            {
                                Logger.log.Notice($"Tried to remove all Shaders starting with an ID that doesn't exist: '{clearId}' at time (in beats) {customEventData.time / 60 * _beatmapObjectSpawnController.currentBpm}!");
                            }
                            else
                            {
                                Logger.log.Debug($"Clearing {removedMats.Count} Materials with starting ID {clearId}!");
                                StopAllCoroutinesModifyingMaterials(removedMats);
                            }
                        }
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Logger.log.Error($"{nameof(ShaderEventManager)} encountered an exception at time (in beats) {customEventData.time / 60 * _beatmapObjectSpawnController.currentBpm}: {ex.Message}");
                Logger.log.Error(ex.StackTrace);
            }
        }
Ejemplo n.º 9
0
 private string GetFID(string id, ShaderEffectData sfx) => id + "_" + sfx.ReferenceName;
Ejemplo n.º 10
0
 /// <summary>
 /// Returns the Material with the specified identifier id and ShaderEffect sfx
 /// </summary>
 /// <param name="id">the id to look for</param>
 /// <param name="sfx">the shader to look for</param>
 /// <returns>The Material or null</returns>
 internal Material GetMaterial(string id, ShaderEffectData sfx) => GetMaterial(GetFID(id, sfx));
Ejemplo n.º 11
0
 /// <summary>
 /// Removes the Material with the specified identifier id and ShaderEffect sfx
 /// </summary>
 /// <param name="id">the id to look for</param>
 /// <param name="sfx">the shader to look for</param>
 /// <returns>If the Material has been removed</returns>
 public bool RemoveMaterial(string id, ShaderEffectData sfx) => RemoveMaterial(GetFID(id, sfx));