Beispiel #1
0
        public override void OnInitialize(InitializeConverterContext context, Action callback)
        {
            Renderer2DData data = Light2DEditorUtility.GetRenderer2DData();

            if (data != null)
            {
                m_SpriteLitDefaultMat = data.GetDefaultMaterial(DefaultMaterialType.Sprite);
            }
            else
            {
                m_SpriteLitDefaultMat = AssetDatabase.LoadAssetAtPath <Material>("Packages/com.unity.render-pipelines.universal/Runtime/Materials/Sprite-Lit-Default.mat");
            }

            m_SpritesDefaultMat      = AssetDatabase.GetBuiltinExtraResource <Material>("Sprites-Default.mat");
            m_SpriteMaskDefaultMat   = AssetDatabase.LoadAssetAtPath <Material>("Packages/com.unity.render-pipelines.universal/Runtime/Materials/SpriteMask-Default.mat");
            m_SpritesMaskMat         = AssetDatabase.GetBuiltinExtraResource <Material>("Sprites-Mask.mat");
            m_SpriteLitDefaultShader = m_SpriteLitDefaultMat.shader;
            m_SpritesDefaultShader   = m_SpritesDefaultMat.shader;
            m_SpritesDefaultShaderId = URP2DConverterUtility.GetObjectIDString(m_SpritesDefaultShader);
            m_SpritesDefaultMatId    = URP2DConverterUtility.GetObjectIDString(m_SpritesDefaultMat);
            m_SpritesMaskMatId       = URP2DConverterUtility.GetObjectIDString(m_SpritesMaskMat);

            string[] allAssetPaths = AssetDatabase.GetAllAssetPaths();

            foreach (string path in allAssetPaths)
            {
                if (URP2DConverterUtility.IsMaterialPath(path, m_SpritesDefaultShaderId) || URP2DConverterUtility.IsPrefabOrScenePath(path, new string[] { m_SpritesDefaultMatId, m_SpritesMaskMatId }))
                {
                    ConverterItemDescriptor desc = new ConverterItemDescriptor()
                    {
                        name           = Path.GetFileNameWithoutExtension(path),
                        info           = path,
                        warningMessage = String.Empty,
                        helpLink       = String.Empty
                    };

                    // Each converter needs to add this info using this API.
                    m_AssetsToConvert.Add(path);
                    context.AddAssetToConvert(desc);
                }
            }

            callback.Invoke();
        }
Beispiel #2
0
        static void UpgradeGameObject(GameObject go)
        {
            Renderer[]     spriteRenderers = go.GetComponentsInChildren <Renderer>(true);
            Renderer2DData data            = Light2DEditorUtility.GetRenderer2DData();

            if (data != null)
            {
                Material defaultMat = data.GetDefaultMaterial(DefaultMaterialType.Sprite);

                bool upgraded = false;
                foreach (Renderer renderer in spriteRenderers)
                {
                    int        materialCount = renderer.sharedMaterials.Length;
                    Material[] newMaterials  = new Material[materialCount];

                    for (int i = 0; i < materialCount; i++)
                    {
                        Material mat = renderer.sharedMaterials[i];

                        if (mat != null && mat.shader.name == "Sprites/Default")
                        {
                            newMaterials[i] = defaultMat;
                            upgraded        = true;
                        }
                        else
                        {
                            newMaterials[i] = renderer.sharedMaterials[i];
                        }
                    }

                    if (upgraded)
                    {
                        renderer.sharedMaterials = newMaterials;
                    }
                }

                if (upgraded)
                {
                    Debug.Log(go.name + " was upgraded.", go);
                    EditorSceneManager.MarkSceneDirty(go.scene);
                }
            }
        }
        void OnEnable()
        {
            m_WasModified    = false;
            m_Renderer2DData = (Renderer2DData)serializedObject.targetObject;

            m_TransparencySortMode        = serializedObject.FindProperty("m_TransparencySortMode");
            m_TransparencySortAxis        = serializedObject.FindProperty("m_TransparencySortAxis");
            m_HDREmulationScale           = serializedObject.FindProperty("m_HDREmulationScale");
            m_LightRenderTextureScale     = serializedObject.FindProperty("m_LightRenderTextureScale");
            m_LightBlendStyles            = serializedObject.FindProperty("m_LightBlendStyles");
            m_MaxLightRenderTextureCount  = serializedObject.FindProperty("m_MaxLightRenderTextureCount");
            m_MaxShadowRenderTextureCount = serializedObject.FindProperty("m_MaxShadowRenderTextureCount");
            m_PostProcessData             = serializedObject.FindProperty("m_PostProcessData");

            m_CameraSortingLayersTextureBound      = serializedObject.FindProperty("m_CameraSortingLayersTextureBound");
            m_UseCameraSortingLayersTexture        = serializedObject.FindProperty("m_UseCameraSortingLayersTexture");
            m_CameraSortingLayerDownsamplingMethod = serializedObject.FindProperty("m_CameraSortingLayerDownsamplingMethod");

            int numBlendStyles = m_LightBlendStyles.arraySize;

            m_LightBlendStylePropsArray = new LightBlendStyleProps[numBlendStyles];

            for (int i = 0; i < numBlendStyles; ++i)
            {
                SerializedProperty       blendStyleProp = m_LightBlendStyles.GetArrayElementAtIndex(i);
                ref LightBlendStyleProps props          = ref m_LightBlendStylePropsArray[i];

                props.name = blendStyleProp.FindPropertyRelative("name");
                props.maskTextureChannel        = blendStyleProp.FindPropertyRelative("maskTextureChannel");
                props.blendMode                 = blendStyleProp.FindPropertyRelative("blendMode");
                props.blendFactorMultiplicative = blendStyleProp.FindPropertyRelative("customBlendFactors.multiplicative");
                props.blendFactorAdditive       = blendStyleProp.FindPropertyRelative("customBlendFactors.additive");

                if (props.blendFactorMultiplicative == null)
                {
                    props.blendFactorMultiplicative = blendStyleProp.FindPropertyRelative("customBlendFactors.modulate");
                }
                if (props.blendFactorAdditive == null)
                {
                    props.blendFactorAdditive = blendStyleProp.FindPropertyRelative("customBlendFactors.additve");
                }
            }
Beispiel #4
0
        public static Renderer2DData GetRenderer2DData()
        {
            UniversalRenderPipelineAsset pipelineAsset = UniversalRenderPipeline.asset;
            Renderer2DData rendererData = pipelineAsset != null ? pipelineAsset.scriptableRendererData as Renderer2DData : null;

            if (rendererData == null)
            {
                foreach (Camera camera in Camera.allCameras)
                {
                    UniversalAdditionalCameraData additionalCameraData = camera.GetComponent <UniversalAdditionalCameraData>();
                    ScriptableRenderer            renderer             = additionalCameraData.scriptableRenderer;
                    Renderer2D renderer2D = renderer as Renderer2D;
                    if (renderer2D != null)
                    {
                        return(renderer2D.GetRenderer2DData());
                    }
                }
            }

            return(rendererData);
        }
Beispiel #5
0
        static bool CreateLightValidation()
        {
            UniversalRenderPipeline pipeline = UnityEngine.Rendering.RenderPipelineManager.currentPipeline as UniversalRenderPipeline;

            if (pipeline != null)
            {
                UniversalRenderPipelineAsset asset = UniversalRenderPipeline.asset;
                if (asset != null)
                {
                    Renderer2DData assetData = asset.scriptableRendererData as Renderer2DData;
                    //if (assetData == null)
                    //    assetData = Renderer2DData.s_Renderer2DDataInstance;

                    if (assetData != null)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        void OnEnable()
        {
            m_WasModified    = false;
            m_Renderer2DData = (Renderer2DData)serializedObject.targetObject;

            m_TransparencySortMode = serializedObject.FindProperty("m_TransparencySortMode");
            m_TransparencySortAxis = serializedObject.FindProperty("m_TransparencySortAxis");
            m_HDREmulationScale    = serializedObject.FindProperty("m_HDREmulationScale");
            m_LightBlendStyles     = serializedObject.FindProperty("m_LightBlendStyles");
            RenderFeatures         = serializedObject.FindProperty("RenderFeatures");
            //
            int numBlendStyles = m_LightBlendStyles.arraySize;

            m_LightBlendStylePropsArray = new LightBlendStyleProps[numBlendStyles];

            for (int i = 0; i < numBlendStyles; ++i)
            {
                SerializedProperty       blendStyleProp = m_LightBlendStyles.GetArrayElementAtIndex(i);
                ref LightBlendStyleProps props          = ref m_LightBlendStylePropsArray[i];

                props.name = blendStyleProp.FindPropertyRelative("name");
                props.maskTextureChannel        = blendStyleProp.FindPropertyRelative("maskTextureChannel");
                props.renderTextureScale        = blendStyleProp.FindPropertyRelative("renderTextureScale");
                props.blendMode                 = blendStyleProp.FindPropertyRelative("blendMode");
                props.blendFactorMultiplicative = blendStyleProp.FindPropertyRelative("customBlendFactors.multiplicative");
                props.blendFactorAdditive       = blendStyleProp.FindPropertyRelative("customBlendFactors.additive");

                if (props.blendFactorMultiplicative == null)
                {
                    props.blendFactorMultiplicative = blendStyleProp.FindPropertyRelative("customBlendFactors.modulate");
                }
                if (props.blendFactorAdditive == null)
                {
                    props.blendFactorAdditive = blendStyleProp.FindPropertyRelative("customBlendFactors.additve");
                }
            }