示例#1
0
            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);
                }
            }
示例#2
0
        static string[] excludedShaders = { "Texture Core" };         // manually set up

        public static void Generate()
        {
            // load core files
            TextAsset[] coreShaders = ShapesIO.LoadCoreShaders()
                                      .Where(t => excludedShaders.Contains(t.name) == false)
                                      .OrderBy(x => x.name)
                                      .ToArray();

            // Dictionary for (_X) to (ShapesMaterialUtils.propX)
            propToVarName = LoadPropertyNames();

            // generate code
            code = new CodeWriter();
            using (code.MainScope(typeof(CodegenMpbs), "System.Collections.Generic", "UnityEngine")) {
                // main shaders
                coreShaders.ForEach(GenerateMpbClass);
                // text is a special case
                code.Spacer();
                using (code.Scope("internal class MpbText : MetaMpb"))
                    code.Append(SIMPLE_TRANSFER);
            }

            // save
            string path = ShapesIO.RootFolder + "/Scripts/Runtime/Immediate Mode/MetaMpbShapes.cs";

            code.WriteTo(path);
        }
示例#3
0
        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);
     }
 }
示例#6
0
 public void WriteTo(string path)
 {
     if (ShapesIO.TryMakeAssetsEditable(path))
     {
         File.WriteAllLines(path, code);
         AssetDatabase.Refresh();                 // reload scripts
     }
 }
示例#7
0
        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");
            }
        }
示例#8
0
 public static void OpenShaderSettings() => ShapesIO.OpenConfigShaders();
示例#9
0
 public static void OpenCsharpSettings() => ShapesIO.OpenConfigCsharp();
示例#10
0
 internal static URP_RND_DATA[] LoadAllURPRenderData() => ShapesIO.LoadAllAssets <URP_RND_DATA>("Assets/").ToArray();