update
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 691bfac972ac94f93808693e63b5465a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Rive.EditorTools
|
||||
{
|
||||
/// <summary>
|
||||
/// Attribute to create a dropdown field in the inspector that can be populated from a field, property, or method.
|
||||
/// </summary>
|
||||
internal class DropdownAttribute : PropertyAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the member (field, property, or method) that provides the dropdown options.
|
||||
/// </summary>
|
||||
public string OptionsMemberName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the method that provides the default index for the dropdown.
|
||||
/// If not specified, FallbackDefaultIndex will be used.
|
||||
/// </summary>
|
||||
public string DefaultIndexMethodName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The default index to use when no DefaultIndexMethodName is specified or when it returns an invalid value.
|
||||
/// </summary>
|
||||
public int FallbackDefaultIndex { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to continuously track changes to the options source using EditorApplication.update.
|
||||
/// Enable this if your options can change dynamically during editor time.
|
||||
/// </summary>
|
||||
public bool TrackChanges { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a dropdown attribute that populates its options from a specified member.
|
||||
/// </summary>
|
||||
/// <param name="optionsMemberName">Name of the field, property, or method that provides the options.</param>
|
||||
/// <param name="defaultIndexMethodName">Optional method name that provides the default selected index.</param>
|
||||
/// <param name="fallbackDefaultIndex">Default index to use when no method is specified or when it returns an invalid value.</param>
|
||||
/// <param name="trackChanges">Whether to continuously check for changes to the options.</param>
|
||||
public DropdownAttribute(
|
||||
string optionsMemberName,
|
||||
string defaultIndexMethodName = null,
|
||||
int fallbackDefaultIndex = 0,
|
||||
bool trackChanges = false)
|
||||
{
|
||||
OptionsMemberName = optionsMemberName;
|
||||
DefaultIndexMethodName = defaultIndexMethodName;
|
||||
FallbackDefaultIndex = fallbackDefaultIndex;
|
||||
TrackChanges = trackChanges;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ce214f532a414d06aaea47e0249d426
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 350858
|
||||
packageName: Rive
|
||||
packageVersion: 0.4.2
|
||||
assetPath: Packages/app.rive.rive-unity/Runtime/Components/EditorOnly/Inspectors/DropdownAttribute.cs
|
||||
uploadId: 896810
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Rive.EditorTools
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to hide components in the inspector.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
||||
internal class HideComponentsAttribute : Attribute
|
||||
{
|
||||
public Type[] ComponentTypes { get; private set; }
|
||||
public HideFlags HideFlags { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies which components should be hidden in the inspector.
|
||||
/// </summary>
|
||||
/// <param name="componentTypes">The types of components to hide</param>
|
||||
public HideComponentsAttribute(params Type[] componentTypes) : this(HideFlags.HideInInspector | HideFlags.HideAndDontSave, componentTypes)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies which components should be hidden in the inspector with custom hide flags.
|
||||
/// </summary>
|
||||
/// <param name="hideFlags">The HideFlags to apply to the components</param>
|
||||
/// <param name="componentTypes">The types of components to hide</param>
|
||||
public HideComponentsAttribute(HideFlags hideFlags, params Type[] componentTypes)
|
||||
{
|
||||
ComponentTypes = componentTypes;
|
||||
HideFlags = hideFlags;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3c73b7f189f5491d935f52adb37f73f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 350858
|
||||
packageName: Rive
|
||||
packageVersion: 0.4.2
|
||||
assetPath: Packages/app.rive.rive-unity/Runtime/Components/EditorOnly/Inspectors/HideComponentsAttribute.cs
|
||||
uploadId: 896810
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Rive.EditorTools
|
||||
{
|
||||
/// <summary>
|
||||
/// Attribute to hide a field in the inspector if a condition is met. Only works with custom inspectors that inherit from RiveBaseEditor.
|
||||
/// </summary>
|
||||
internal class HideIfAttribute : PropertyAttribute
|
||||
{
|
||||
public string ConditionName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Attribute to hide a field in the inspector if a condition is met.
|
||||
/// </summary>
|
||||
/// <param name="conditionName"> The name of the condition method to check. This can also be a property name.</param>
|
||||
public HideIfAttribute(string conditionName)
|
||||
{
|
||||
ConditionName = conditionName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d108bfb7a8e34141a262e27c4b14183
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 350858
|
||||
packageName: Rive
|
||||
packageVersion: 0.4.2
|
||||
assetPath: Packages/app.rive.rive-unity/Runtime/Components/EditorOnly/Inspectors/HideIfAttribute.cs
|
||||
uploadId: 896810
|
||||
@@ -0,0 +1,54 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Rive.EditorTools
|
||||
{
|
||||
/// <summary>
|
||||
/// Attribute to mark a field to be displayed in a custom inspector for a Rive component.
|
||||
/// </summary>
|
||||
internal class InspectorFieldAttribute : PropertyAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// The section ID this field belongs to. If null, the field will be displayed outside any section.
|
||||
/// </summary>
|
||||
public string SectionId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The display name shown in the inspector UI. If null, defaults to the field name.
|
||||
/// </summary>
|
||||
public string DisplayName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The order this field appears relative to other fields. Lower numbers appear first.
|
||||
/// </summary>
|
||||
public int Order { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional URL to open when the help/info button is clicked in the inspector.
|
||||
/// </summary>
|
||||
public string HelpUrl { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Convenience flag to check if a help URL was supplied.
|
||||
/// </summary>
|
||||
public bool HasHelpUrl => !string.IsNullOrEmpty(HelpUrl);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new field attribute for the inspector.
|
||||
/// </summary>
|
||||
/// <param name="sectionId">Section ID this field belongs to. If null, displays outside sections</param>
|
||||
/// <param name="displayName">Display name shown in UI. If null, uses field name</param>
|
||||
/// <param name="order">Order relative to other fields. Lower numbers appear first</param>
|
||||
/// <param name="helpUrl">Optional URL opened when the info button is clicked</param>
|
||||
public InspectorFieldAttribute(
|
||||
string sectionId = null,
|
||||
string displayName = null,
|
||||
int order = 0,
|
||||
string helpUrl = null)
|
||||
{
|
||||
SectionId = sectionId;
|
||||
DisplayName = displayName;
|
||||
Order = order;
|
||||
HelpUrl = helpUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37b38a029e00a4277a06763e2eedb3e3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 350858
|
||||
packageName: Rive
|
||||
packageVersion: 0.4.2
|
||||
assetPath: Packages/app.rive.rive-unity/Runtime/Components/EditorOnly/Inspectors/InspectorFieldAttribute.cs
|
||||
uploadId: 896810
|
||||
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
|
||||
namespace Rive.EditorTools
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
|
||||
/// <summary>
|
||||
/// Attribute to mark a section in a custom inspector for a Rive component.
|
||||
/// </summary>
|
||||
internal class InspectorSectionAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for this section.
|
||||
/// </summary>
|
||||
public string Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The display name shown in the inspector UI. If not specified, defaults to the Id.
|
||||
/// </summary>
|
||||
public string DisplayName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The order this section appears relative to other sections. Lower numbers appear first.
|
||||
/// </summary>
|
||||
public int Order { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The style used to display this section - either as a header or foldout.
|
||||
/// </summary>
|
||||
public SectionStyle Style { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether a foldout section should start expanded. Only applies when Style is Foldout.
|
||||
/// </summary>
|
||||
public bool StartExpanded { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new section in the inspector.
|
||||
/// </summary>
|
||||
/// <param name="id">Unique identifier for the section</param>
|
||||
/// <param name="displayName">Display name shown in UI. Defaults to id if null</param>
|
||||
/// <param name="order">Order relative to other sections. Lower numbers appear first</param>
|
||||
/// <param name="style">How to display the section - as a header or foldout</param>
|
||||
/// <param name="startExpanded">Whether a foldout section starts expanded</param>
|
||||
public InspectorSectionAttribute(
|
||||
string id,
|
||||
string displayName = null,
|
||||
int order = 0,
|
||||
SectionStyle style = SectionStyle.Header,
|
||||
bool startExpanded = false)
|
||||
{
|
||||
Id = id;
|
||||
DisplayName = displayName ?? id;
|
||||
Order = order;
|
||||
Style = style;
|
||||
StartExpanded = startExpanded;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines how a section should be displayed in the inspector.
|
||||
/// </summary>
|
||||
public enum SectionStyle
|
||||
{
|
||||
/// <summary>
|
||||
/// Shows a header label above the section content.
|
||||
/// </summary>
|
||||
Header = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Shows the section as a foldout that can be expanded/collapsed.
|
||||
/// </summary>
|
||||
Foldout = 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: affca4152ad384ed3a6c300dbd82c1ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 350858
|
||||
packageName: Rive
|
||||
packageVersion: 0.4.2
|
||||
assetPath: Packages/app.rive.rive-unity/Runtime/Components/EditorOnly/Inspectors/InspectorSectionAttribute.cs
|
||||
uploadId: 896810
|
||||
@@ -0,0 +1,51 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#if UNITY_6000_3_OR_NEWER
|
||||
using MaterialShaderPropertyType = UnityEngine.Rendering.ShaderPropertyType;
|
||||
#else
|
||||
using MaterialShaderPropertyType = UnityEditor.ShaderUtil.ShaderPropertyType;
|
||||
#endif
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
namespace Rive.EditorTools
|
||||
{
|
||||
/// <summary>
|
||||
/// Attribute for drawing material property lists for each material.
|
||||
/// </summary>
|
||||
internal class MaterialPropertiesAttribute : PropertyAttribute
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// Name of the member that provides the materials (can be a field, property, or method).
|
||||
/// </summary>
|
||||
public string MaterialsSourceName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The type of shader properties to display (e.g., TexEnv, Float, Color).
|
||||
/// </summary>
|
||||
public MaterialShaderPropertyType PropertyType { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new MaterialPropertiesAttribute.
|
||||
/// </summary>
|
||||
/// <param name="materialsSourceName">Name of the member that provides the materials.</param>
|
||||
/// <param name="propertyType">Type of shader properties to display.</param>
|
||||
public MaterialPropertiesAttribute(
|
||||
string materialsSourceName,
|
||||
MaterialShaderPropertyType propertyType =
|
||||
#if UNITY_6000_3_OR_NEWER
|
||||
MaterialShaderPropertyType.Texture
|
||||
#else
|
||||
MaterialShaderPropertyType.TexEnv
|
||||
#endif
|
||||
)
|
||||
{
|
||||
MaterialsSourceName = materialsSourceName;
|
||||
PropertyType = propertyType;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b990db98a04454ef4a47cf84a8acc6d4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 350858
|
||||
packageName: Rive
|
||||
packageVersion: 0.4.2
|
||||
assetPath: Packages/app.rive.rive-unity/Runtime/Components/EditorOnly/Inspectors/MaterialPropertiesAttribute.cs
|
||||
uploadId: 896810
|
||||
@@ -0,0 +1,31 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Rive.EditorTools
|
||||
{
|
||||
/// <summary>
|
||||
/// Attribute to invoke a callback method when a property value changes. Only works with custom editors that inherit from RiveBaseEditor.
|
||||
/// </summary>
|
||||
internal class OnValueChangedAttribute : PropertyAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the callback method to invoke when the value changes.
|
||||
/// </summary>
|
||||
public string CallbackName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to invoke the callback during the initial setup of the property drawer.
|
||||
/// </summary>
|
||||
public bool InvokeOnInitialization { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Attribute to invoke a callback method when a property value changes.
|
||||
/// </summary>
|
||||
/// <param name="callbackName">The name of the method to call when the value changes.</param>
|
||||
/// <param name="invokeOnInitialization">Whether to invoke the callback during initialization (default: false). This is useful for setting up initial values.</param>
|
||||
public OnValueChangedAttribute(string callbackName, bool invokeOnInitialization = false)
|
||||
{
|
||||
CallbackName = callbackName;
|
||||
InvokeOnInitialization = invokeOnInitialization;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 46b0ca8e95502493798e11215c5030c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 350858
|
||||
packageName: Rive
|
||||
packageVersion: 0.4.2
|
||||
assetPath: Packages/app.rive.rive-unity/Runtime/Components/EditorOnly/Inspectors/OnValueChangedAttribute.cs
|
||||
uploadId: 896810
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Rive.EditorTools
|
||||
{
|
||||
/// <summary>
|
||||
/// Attribute to show a property in the inspector if a condition is met. Only works with custom inspectors that inherit from RiveBaseEditor.
|
||||
/// </summary>
|
||||
internal class ShowIfAttribute : PropertyAttribute
|
||||
{
|
||||
public string ConditionName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Attribute to show a property in the inspector if a condition is met.
|
||||
/// </summary>
|
||||
/// <param name="conditionName"> The name of the condition method to check. This can also be a property name.</param>
|
||||
public ShowIfAttribute(string conditionName)
|
||||
{
|
||||
ConditionName = conditionName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc3324a0b6c744395ad566e3aeaa25dd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 350858
|
||||
packageName: Rive
|
||||
packageVersion: 0.4.2
|
||||
assetPath: Packages/app.rive.rive-unity/Runtime/Components/EditorOnly/Inspectors/ShowIfAttribute.cs
|
||||
uploadId: 896810
|
||||
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Rive.EditorTools
|
||||
{
|
||||
/// <summary>
|
||||
/// Attribute to specify that a property is a width/height dimensions pair for a Vector2.
|
||||
/// </summary>
|
||||
internal class WidthHeightDimensionsAttribute : PropertyAttribute
|
||||
{
|
||||
public string Label { get; private set; }
|
||||
public string WidthLabel { get; private set; }
|
||||
public string HeightLabel { get; private set; }
|
||||
|
||||
public WidthHeightDimensionsAttribute(
|
||||
string label,
|
||||
string widthLabel = "Width",
|
||||
string heightLabel = "Height")
|
||||
{
|
||||
Label = label;
|
||||
WidthLabel = widthLabel;
|
||||
HeightLabel = heightLabel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e21cd09e2f0e54a718cac38b1b165986
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 350858
|
||||
packageName: Rive
|
||||
packageVersion: 0.4.2
|
||||
assetPath: Packages/app.rive.rive-unity/Runtime/Components/EditorOnly/Inspectors/WidthHeightDimensionsAttribute.cs
|
||||
uploadId: 896810
|
||||
@@ -0,0 +1,420 @@
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace Rive.Components
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Helper class for converting default RP materials to Rive variants.
|
||||
/// </summary>
|
||||
internal static class MaterialConversionUtility
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// Exposed constants so tests and editor code can reference folder and name conventions from one place.
|
||||
internal static class Constants
|
||||
{
|
||||
public const string PackageName = Rive.EditorTools.PackageInfo.PACKAGE_NAME;
|
||||
public const string RPFolderRoot = "RenderPipelines";
|
||||
public const string URPFolder = "URP";
|
||||
public const string HDRPFolder = "HDRP";
|
||||
public const string BuiltInFolder = "BuiltIn";
|
||||
public const string MaterialsFolder = "Materials";
|
||||
|
||||
public const string BaseRiveLit = "RiveLit";
|
||||
public const string BaseRiveUnlit = "RiveUnlit";
|
||||
|
||||
public const string SuffixURP = "URP";
|
||||
public const string SuffixHDRP = "HDRP";
|
||||
public const string SuffixBiRP = "BiRP";
|
||||
|
||||
// Unity default shader names for detection (used to identify pipeline defaults)
|
||||
public const string UnityDefaultShaderURPLit = "Universal Render Pipeline/Lit";
|
||||
public const string UnityDefaultShaderURPUnlit = "Universal Render Pipeline/Unlit";
|
||||
public const string UnityDefaultShaderHDRPLit = "HDRP/Lit";
|
||||
public const string UnityDefaultShaderHDRPUnlit = "HDRP/Unlit";
|
||||
public const string UnityDefaultShaderBuiltInLit = "Standard";
|
||||
public const string UnityDefaultShaderBuiltInUnlitPrefix = "Unlit/";
|
||||
|
||||
// Expected material names for the current render pipeline
|
||||
internal static string ExpectedLitNameForCurrentPipeline
|
||||
{
|
||||
get
|
||||
{
|
||||
return BaseRiveLit + GetCurrentPipelineSuffix();
|
||||
}
|
||||
}
|
||||
internal static string ExpectedUnlitNameForCurrentPipeline
|
||||
{
|
||||
get
|
||||
{
|
||||
return BaseRiveUnlit + GetCurrentPipelineSuffix();
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetCurrentPipelineSuffix()
|
||||
{
|
||||
switch (GetCurrentPipeline())
|
||||
{
|
||||
case Pipeline.URP:
|
||||
return SuffixURP;
|
||||
case Pipeline.HDRP:
|
||||
return SuffixHDRP;
|
||||
default:
|
||||
return SuffixBiRP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum Pipeline
|
||||
{
|
||||
BuiltIn = 0,
|
||||
URP = 1,
|
||||
HDRP = 2,
|
||||
}
|
||||
|
||||
private static Pipeline GetCurrentPipeline()
|
||||
{
|
||||
var rp = UnityEngine.Rendering.GraphicsSettings.currentRenderPipeline;
|
||||
if (rp == null)
|
||||
{
|
||||
return Pipeline.BuiltIn;
|
||||
}
|
||||
var typeName = rp.GetType().FullName;
|
||||
if (!string.IsNullOrEmpty(typeName))
|
||||
{
|
||||
if (typeName.Contains("UniversalRenderPipelineAsset"))
|
||||
{
|
||||
return Pipeline.URP;
|
||||
}
|
||||
if (typeName.Contains("HDRenderPipelineAsset"))
|
||||
{
|
||||
return Pipeline.HDRP;
|
||||
}
|
||||
}
|
||||
return Pipeline.BuiltIn;
|
||||
}
|
||||
|
||||
// ---------------------------
|
||||
// Project-material resolution
|
||||
// ---------------------------
|
||||
private static Material s_cachedLitMaterial;
|
||||
private static Material s_cachedUnlitMaterial;
|
||||
|
||||
private static string GetTargetFolderPath()
|
||||
{
|
||||
return "Assets/Plugins/Rive/Materials";
|
||||
}
|
||||
|
||||
private static string GetBaseName(bool lit)
|
||||
{
|
||||
return lit ? Constants.BaseRiveLit : Constants.BaseRiveUnlit;
|
||||
}
|
||||
|
||||
private static string GetRPFolder(out string suffix)
|
||||
{
|
||||
switch (GetCurrentPipeline())
|
||||
{
|
||||
case Pipeline.URP:
|
||||
suffix = Constants.SuffixURP;
|
||||
return Constants.URPFolder;
|
||||
case Pipeline.HDRP:
|
||||
suffix = Constants.SuffixHDRP;
|
||||
return Constants.HDRPFolder;
|
||||
default:
|
||||
suffix = Constants.SuffixBiRP;
|
||||
return Constants.BuiltInFolder;
|
||||
}
|
||||
}
|
||||
|
||||
private static void EnsureAssetFolder(string path)
|
||||
{
|
||||
var parts = path.Split('/');
|
||||
if (parts.Length == 0 || parts[0] != "Assets") return;
|
||||
string current = "Assets";
|
||||
for (int i = 1; i < parts.Length; i++)
|
||||
{
|
||||
string next = current + "/" + parts[i];
|
||||
if (!AssetDatabase.IsValidFolder(next))
|
||||
{
|
||||
AssetDatabase.CreateFolder(current, parts[i]);
|
||||
}
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
|
||||
private static Shader LoadShaderFromRenderPipelinesFolder(string rpFolder, bool lit, out string resolvedName)
|
||||
{
|
||||
// Attempt to load shader directly from RP ShaderGraph asset
|
||||
string litOrUnlit = lit ? "Lit" : "Unlit";
|
||||
string shaderGraphPath = $"Packages/{Constants.PackageName}/Runtime/Components/Public/RenderPipelines/{rpFolder}/Shaders/{litOrUnlit}.shadergraph";
|
||||
var shader = AssetDatabase.LoadAssetAtPath<Shader>(shaderGraphPath);
|
||||
if (shader != null)
|
||||
{
|
||||
resolvedName = shader.name;
|
||||
return shader;
|
||||
}
|
||||
// Fallback search within the RP Shaders folder for any Shader assets and pick by name hint
|
||||
string folder = $"Packages/{Constants.PackageName}/Runtime/Components/Public/RenderPipelines/{rpFolder}/Shaders";
|
||||
string[] guids = AssetDatabase.FindAssets("t:Shader", new[] { folder });
|
||||
for (int i = 0; i < guids.Length; i++)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guids[i]);
|
||||
var s = AssetDatabase.LoadAssetAtPath<Shader>(path);
|
||||
if (s != null && s.name.IndexOf(litOrUnlit, System.StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
{
|
||||
resolvedName = s.name;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
resolvedName = $"<missing RP shader {rpFolder}/{litOrUnlit}>";
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Shader GetPipelineShader(bool lit, out string shaderName)
|
||||
{
|
||||
switch (GetCurrentPipeline())
|
||||
{
|
||||
case Pipeline.URP:
|
||||
return LoadShaderFromRenderPipelinesFolder(Constants.URPFolder, lit, out shaderName);
|
||||
case Pipeline.HDRP:
|
||||
return LoadShaderFromRenderPipelinesFolder(Constants.HDRPFolder, lit, out shaderName);
|
||||
default:
|
||||
return LoadShaderFromRenderPipelinesFolder(Constants.BuiltInFolder, lit, out shaderName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static System.Collections.Generic.List<Material> FindProjectMaterialsUsingShader(Shader shader)
|
||||
{
|
||||
var results = new System.Collections.Generic.List<Material>();
|
||||
if (shader == null)
|
||||
{
|
||||
return results;
|
||||
}
|
||||
var guids = AssetDatabase.FindAssets("t:material", new[] { "Assets" });
|
||||
for (int i = 0; i < guids.Length; i++)
|
||||
{
|
||||
var path = AssetDatabase.GUIDToAssetPath(guids[i]);
|
||||
var mat = AssetDatabase.LoadAssetAtPath<Material>(path);
|
||||
if (mat != null && mat.shader == shader)
|
||||
{
|
||||
results.Add(mat);
|
||||
}
|
||||
}
|
||||
results.Sort((a, b) =>
|
||||
{
|
||||
string ta = AssetDatabase.GetAssetPath(a);
|
||||
string tb = AssetDatabase.GetAssetPath(b);
|
||||
bool aPrefer = ta.StartsWith(GetTargetFolderPath());
|
||||
bool bPrefer = tb.StartsWith(GetTargetFolderPath());
|
||||
if (aPrefer == bPrefer) return string.Compare(ta, tb, System.StringComparison.OrdinalIgnoreCase);
|
||||
return aPrefer ? -1 : 1;
|
||||
});
|
||||
return results;
|
||||
}
|
||||
|
||||
private static bool ShaderMatches(Shader candidate, Shader target, string targetName)
|
||||
{
|
||||
if (candidate == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (target != null && candidate == target)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(targetName) &&
|
||||
string.Equals(candidate.name, targetName, System.StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolve or create a project-local Rive material with exact-name-first strategy:
|
||||
/// 1) Use Assets/Plugins/Rive/Materials/<Base+Suffix>.mat if present.
|
||||
/// 2) Else use any material in Assets with that exact name and matching shader.
|
||||
/// 3) Else, if materials exist with the matching shader, optionally prompt to use suggested; otherwise create.
|
||||
/// 4) Else create under Assets/Plugins/Rive/Materials with a unique name.
|
||||
/// </summary>
|
||||
private static Material LoadOrCreateProjectRiveMaterial(bool lit)
|
||||
{
|
||||
if (lit && s_cachedLitMaterial != null) return s_cachedLitMaterial;
|
||||
if (!lit && s_cachedUnlitMaterial != null) return s_cachedUnlitMaterial;
|
||||
|
||||
string suffix;
|
||||
string rpFolder = GetRPFolder(out suffix);
|
||||
string expectedName = GetBaseName(lit) + suffix;
|
||||
|
||||
// 1) Exact expected path in Assets/Plugins/Rive/Materials
|
||||
string targetFolder = GetTargetFolderPath();
|
||||
string targetPath = $"{targetFolder}/{expectedName}.mat";
|
||||
var atTarget = AssetDatabase.LoadAssetAtPath<Material>(targetPath);
|
||||
if (atTarget != null)
|
||||
{
|
||||
if (lit) s_cachedLitMaterial = atTarget; else s_cachedUnlitMaterial = atTarget;
|
||||
return atTarget;
|
||||
}
|
||||
|
||||
// Resolve shader
|
||||
var shader = GetPipelineShader(lit, out var shaderName);
|
||||
if (shader == null)
|
||||
{
|
||||
Debug.LogWarning($"Rive: Could not resolve shader for current render pipeline (lit={lit}).");
|
||||
}
|
||||
|
||||
// 2) Exact-name anywhere in Assets with matching shader
|
||||
string[] nameMatches = AssetDatabase.FindAssets($"t:material {expectedName}", new[] { "Assets" });
|
||||
for (int i = 0; i < nameMatches.Length; i++)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(nameMatches[i]);
|
||||
var mat = AssetDatabase.LoadAssetAtPath<Material>(path);
|
||||
// If the user has a material with the exact expected name, prefer it regardless of shader;
|
||||
// this allows overriding shader source differences (Graph vs HLSL) while honoring the name contract.
|
||||
if (mat != null && mat.name == expectedName)
|
||||
{
|
||||
if (lit) s_cachedLitMaterial = mat; else s_cachedUnlitMaterial = mat;
|
||||
return mat;
|
||||
}
|
||||
}
|
||||
|
||||
// 3) If no exact-name match is found, always create a new material in the Plugins folder.
|
||||
|
||||
// 4) Create new in Assets/Plugins/Rive/Materials with unique name if needed
|
||||
EnsureAssetFolder(targetFolder);
|
||||
string basePath = $"{targetFolder}/{expectedName}.mat";
|
||||
string uniquePath = AssetDatabase.GenerateUniqueAssetPath(basePath);
|
||||
|
||||
Material toSave = new Material(shader != null ? shader : Shader.Find("Hidden/InternalErrorShader"));
|
||||
|
||||
AssetDatabase.CreateAsset(toSave, uniquePath);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.ImportAsset(uniquePath);
|
||||
|
||||
if (lit) s_cachedLitMaterial = toSave; else s_cachedUnlitMaterial = toSave;
|
||||
return toSave;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the given renderer has Rive materials assigned for any default materials. Unlike ReplaceMaterialsWithRive, this only replaces materials that appear to be Unity default materials that Unity would assign automatically.
|
||||
/// </summary>
|
||||
/// <param name="renderer"></param>
|
||||
internal static void EnsureRiveMaterialsOnRenderer(UnityEngine.Renderer renderer)
|
||||
{
|
||||
if (renderer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var materials = renderer.sharedMaterials;
|
||||
bool changed = false;
|
||||
for (int i = 0; i < materials.Length; i++)
|
||||
{
|
||||
var mat = materials[i];
|
||||
if (mat == null || mat.shader == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string shaderName = mat.shader.name;
|
||||
bool isDefaultLit = false;
|
||||
bool isDefaultUnlit = false;
|
||||
|
||||
|
||||
switch (GetCurrentPipeline())
|
||||
{
|
||||
case Pipeline.URP:
|
||||
isDefaultLit = shaderName == Constants.UnityDefaultShaderURPLit ||
|
||||
shaderName == "Universal Render Pipeline/Simple Lit";
|
||||
isDefaultUnlit = shaderName == Constants.UnityDefaultShaderURPUnlit;
|
||||
break;
|
||||
case Pipeline.HDRP:
|
||||
isDefaultLit = shaderName == Constants.UnityDefaultShaderHDRPLit;
|
||||
isDefaultUnlit = shaderName == Constants.UnityDefaultShaderHDRPUnlit;
|
||||
break;
|
||||
default:
|
||||
isDefaultLit = shaderName == Constants.UnityDefaultShaderBuiltInLit;
|
||||
isDefaultUnlit = shaderName.StartsWith(Constants.UnityDefaultShaderBuiltInUnlitPrefix);
|
||||
break;
|
||||
}
|
||||
|
||||
if (isDefaultLit || isDefaultUnlit)
|
||||
{
|
||||
var target = LoadOrCreateProjectRiveMaterial(lit: !isDefaultUnlit);
|
||||
if (target != null && target != mat)
|
||||
{
|
||||
materials[i] = target;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
renderer.sharedMaterials = materials;
|
||||
EditorUtility.SetDirty(renderer);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Replaces any non-Rive materials on the given renderer with Rive equivalents. Unlike EnsureRiveMaterialsOnRenderer, this will replace any material that is not already a Rive material, even if it's a custom material.
|
||||
/// </summary>
|
||||
/// <param name="renderer"></param>
|
||||
internal static void ReplaceMaterialsWithRive(UnityEngine.Renderer renderer)
|
||||
{
|
||||
if (renderer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var materials = renderer.sharedMaterials;
|
||||
// If there are no materials at all, assign a single lit material.
|
||||
if (materials == null || materials.Length == 0)
|
||||
{
|
||||
var targetIfNone = LoadOrCreateProjectRiveMaterial(lit: true);
|
||||
if (targetIfNone != null)
|
||||
{
|
||||
renderer.sharedMaterials = new[] { targetIfNone };
|
||||
EditorUtility.SetDirty(renderer);
|
||||
}
|
||||
return;
|
||||
}
|
||||
bool changed = false;
|
||||
for (int i = 0; i < materials.Length; i++)
|
||||
{
|
||||
var mat = materials[i];
|
||||
if (mat == null || mat.shader == null)
|
||||
{
|
||||
// Replace missing/invalid material with a lit material by default.
|
||||
var defaultLit = LoadOrCreateProjectRiveMaterial(lit: true);
|
||||
if (defaultLit != null)
|
||||
{
|
||||
materials[i] = defaultLit;
|
||||
changed = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
string shaderName = mat.shader.name ?? string.Empty;
|
||||
bool appearsUnlit =
|
||||
shaderName.IndexOf("unlit", System.StringComparison.OrdinalIgnoreCase) >= 0 ||
|
||||
shaderName.StartsWith("Unlit/", System.StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
var target = LoadOrCreateProjectRiveMaterial(lit: !appearsUnlit);
|
||||
if (target != null && target != mat)
|
||||
{
|
||||
materials[i] = target;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
renderer.sharedMaterials = materials;
|
||||
EditorUtility.SetDirty(renderer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a7e31256da344ea6847dbe0dde1888a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 350858
|
||||
packageName: Rive
|
||||
packageVersion: 0.4.2
|
||||
assetPath: Packages/app.rive.rive-unity/Runtime/Components/EditorOnly/MaterialConversionUtility.cs
|
||||
uploadId: 896810
|
||||
Reference in New Issue
Block a user