Skip to content

Commit 061388c

Browse files
committed
add lora and model download attributes
1 parent 889b018 commit 061388c

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

Editor/LLMEditor.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,14 @@ public void AddModelAddonLoaders(SerializedObject llmScriptSO, LLM llmScript, bo
8686
public void AddModelSettings(SerializedObject llmScriptSO)
8787
{
8888
List<Type> attributeClasses = new List<Type> { typeof(ModelAttribute) };
89+
List<Type> excludeAttributeClasses = new List<Type> { typeof(ModelDownloadAttribute), typeof(ModelDownloadAdvancedAttribute) };
90+
if (llmScriptSO.FindProperty("downloadOnBuild").boolValue) excludeAttributeClasses.Remove(typeof(ModelDownloadAttribute));
8991
if (llmScriptSO.FindProperty("advancedOptions").boolValue)
9092
{
9193
attributeClasses.Add(typeof(ModelAdvancedAttribute));
94+
if (llmScriptSO.FindProperty("downloadOnBuild").boolValue) excludeAttributeClasses.Remove(typeof(ModelDownloadAdvancedAttribute));
9295
}
93-
if (llmScriptSO.FindProperty("downloadOnBuild").boolValue)
94-
{
95-
attributeClasses.Add(typeof(ModelDownloadAttribute));
96-
}
97-
ShowPropertiesOfClass("", llmScriptSO, attributeClasses, false);
96+
ShowPropertiesOfClass("", llmScriptSO, attributeClasses, false, excludeAttributeClasses);
9897
Space();
9998
}
10099

Editor/PropertyEditor.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,23 @@ public List<SerializedProperty> GetPropertiesOfClass(SerializedObject so, List<T
9494
return properties;
9595
}
9696

97-
public void ShowPropertiesOfClass(string title, SerializedObject so, List<Type> attributeClasses, bool addSpace = true)
97+
public void ShowPropertiesOfClass(string title, SerializedObject so, List<Type> attributeClasses, bool addSpace = true, List<Type> excludeAttributeClasses = null)
9898
{
9999
// display a property if it belongs to a certain class and/or has a specific attribute class
100100
List<SerializedProperty> properties = GetPropertiesOfClass(so, attributeClasses);
101+
if (excludeAttributeClasses != null)
102+
{
103+
List<SerializedProperty> excludeProperties = GetPropertiesOfClass(so, excludeAttributeClasses);
104+
List<SerializedProperty> removeProperties = new List<SerializedProperty>();
105+
foreach (SerializedProperty excprop in excludeProperties)
106+
{
107+
foreach (SerializedProperty prop in properties)
108+
{
109+
if (prop.displayName == excprop.displayName) removeProperties.Add(prop);
110+
}
111+
}
112+
foreach (SerializedProperty prop in removeProperties) properties.Remove(prop);
113+
}
101114
if (properties.Count == 0) return;
102115
if (title != "") EditorGUILayout.LabelField(title, EditorStyles.boldLabel);
103116
foreach (SerializedProperty prop in properties)
@@ -141,7 +154,7 @@ public Attribute GetPropertyAttribute(SerializedProperty prop, Type attributeCla
141154
{
142155
foreach (Attribute attr in fieldInfo.GetCustomAttributes(attributeClass, true))
143156
{
144-
if (attr.GetType() == attributeClass)
157+
if (attributeClass.IsAssignableFrom(attr.GetType()))
145158
return attr;
146159
}
147160
}

Runtime/LLMUnitySetup.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public class LocalRemoteAttribute : PropertyAttribute {}
4545
public class RemoteAttribute : PropertyAttribute {}
4646
public class LocalAttribute : PropertyAttribute {}
4747
public class ModelAttribute : PropertyAttribute {}
48-
public class ModelDownloadAttribute : PropertyAttribute {}
48+
public class ModelDownloadAttribute : ModelAttribute {}
49+
public class ModelDownloadAdvancedAttribute : ModelAdvancedAttribute {}
4950
public class ModelAdvancedAttribute : PropertyAttribute {}
5051
public class ChatAttribute : PropertyAttribute {}
5152
public class ChatAdvancedAttribute : PropertyAttribute {}

0 commit comments

Comments
 (0)