public AssetEditScope(UnityEngine.Object asset) { if (ShapesIO.IsUsingVcWithCheckoutEnabled) { bool canEdit = ShapesIO.AssetCanBeEdited(asset); GUILayout.BeginVertical(); using ( Horizontal ) { if (canEdit) { using (new EditorGUI.DisabledScope(true)) GUILayout.Toggle(true, editButtonContent, EditorStyles.miniButton, editButtonLayout); // just, show that, you know GUILayout.Label("(open for editing)", EditorStyles.miniLabel); } else { if (GUILayout.Button(editButtonContent, EditorStyles.miniButton, editButtonLayout)) { _ = ShapesIO.TryMakeAssetsEditable(asset); // will show error if it fails } GUILayout.Label("(currently locked by version control)", EditorStyles.miniLabel); } } EditorGUI.BeginDisabledGroup(canEdit == false); } }
static void SetPreprocessorRpSymbols(RenderPipeline rpTarget) { Debug.Log($"Setting preprocessor symbols for {rpTarget.PrettyName()}"); List <string> symbols = GetCurrentKeywords(); bool changed = false; void CheckRpSymbol(RenderPipeline rp) { bool on = rp == rpTarget; string ppName = rp.PreprocessorDefineName(); if (on && symbols.Contains(ppName) == false) { symbols.Add(ppName); changed = true; } else if (on == false && symbols.Remove(ppName)) { changed = true; } } CheckRpSymbol(RenderPipeline.URP); CheckRpSymbol(RenderPipeline.HDRP); if (changed && ShapesIO.TryMakeAssetsEditable(ShapesIO.projectSettingsPath)) { //Debug.Log( $"Shapes updated your project scripting define symbols since you seem to be using {rpTarget.PrettyName()}, I hope that's okay~" ); SetCurrentKeywords(symbols); } }
static void EnsurePreprocessorsAreDefined(RenderPipeline rpTarget) { BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup; List <string> symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup).Split(';').ToList(); bool changed = false; void CheckRpSymbol(RenderPipeline rp) { bool on = rp == rpTarget; string ppName = rp.PreprocessorDefineName(); if (on && symbols.Contains(ppName) == false) { symbols.Add(ppName); changed = true; } else if (on == false && symbols.Remove(ppName)) { changed = true; } } CheckRpSymbol(RenderPipeline.URP); CheckRpSymbol(RenderPipeline.HDRP); if (changed && ShapesIO.TryMakeAssetsEditable(ShapesIO.projectSettingsPath)) { Debug.Log($"Shapes updated your project scripting define symbols since you seem to be using {rpTarget.PrettyName()}, I hope that's okay~"); PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, string.Join(";", symbols)); } }
static void EnsureShapesPassExistsInTheUrpRenderer() { if (UrpRndFuncs.successfullyLoaded) // if our reflected members failed to load, we're kinda screwed :c { if (GraphicsSettings.renderPipelineAsset is UniversalRenderPipelineAsset urpa) // find the URP asset { ScriptableRendererData[] srd = (ScriptableRendererData[])UrpRndFuncs.fRndDataList.GetValue(urpa); foreach (var rndd in srd.Where(x => x is ForwardRendererData)) // only add to forward renderer { if (rndd.rendererFeatures.Any(x => x is ShapesRenderFeature) == false) // does it have Shapes? // does not contain the Shapes render feature, so, oh boy, here we go~ { if (ShapesIO.TryMakeAssetsEditable(urpa)) { ForwardRendererDataEditor fwEditor = (ForwardRendererDataEditor)Editor.CreateEditor(rndd); UrpRndFuncs.fOnEnable.Invoke(fwEditor, null); // you ever just call OnEnable manually UrpRndFuncs.fAddComponent.Invoke(fwEditor, new[] { (object)nameof(ShapesRenderFeature) }); DestroyImmediate(fwEditor); // luv 2 create temporary editors Debug.Log($"Added Shapes renderer feature to {rndd.name}", rndd); } } } } else { Debug.LogWarning($"Shapes failed to load the URP pipeline asset to add the renderer feature. " + $"You might have to add {nameof(ShapesRenderFeature)} to your renderer asset manually"); } } else { Debug.LogError(UrpRndFuncs.failMessage); } }
public void WriteTo(string path) { if (ShapesIO.TryMakeAssetsEditable(path)) { File.WriteAllLines(path, code); AssetDatabase.Refresh(); // reload scripts } }
static void MakeSureSampleMaterialsAreValid() { #if SHAPES_URP || SHAPES_HDRP #if UNITY_2019_1_OR_NEWER Shader targetShader = GraphicsSettings.renderPipelineAsset.defaultShader; #else Shader targetShader = GraphicsSettings.renderPipelineAsset.GetDefaultShader(); #endif #else Shader targetShader = UIAssets.Instance.birpDefaultShader; #endif bool changed = false; if (ShapesIO.TryMakeAssetsEditable(UIAssets.Instance.sampleMaterials)) // ensures version control allows us to edit { foreach (var mat in UIAssets.Instance.sampleMaterials) { if (mat == null) { continue; // samples were probably not imported into this project (or they were deleted) if this is null } if (mat.shader != targetShader) { Undo.RecordObject(mat, "Shapes update sample materials shaders"); Color color = GetMainColor(mat); mat.shader = targetShader; #if SHAPES_URP || SHAPES_HDRP mat.SetColor(ShapesMaterialUtils.propBaseColor, color); #else mat.SetColor(ShapesMaterialUtils.propColor, color); #endif changed = true; } } } if (changed) { Debug.Log("Shapes updated sample material shaders to match your current render pipeline"); } }