浏览代码

Updated NaughtyAttributes to b933f7e - Apr 21 2019

/main
Thomas ICHÉ 5 年前
当前提交
c080b085
共有 22 个文件被更改,包括 221 次插入51 次删除
  1. 3
      Editor/GameplayIngredients-Editor.asmdef
  2. 2
      NaughtyAttributes/Editor/CodeGeneration/CodeGenerator.cs
  3. 2
      NaughtyAttributes/Editor/CodeGeneration/PropertyDrawerDatabase.cs
  4. 17
      NaughtyAttributes/Editor/Editors/InspectorEditor.cs
  5. 11
      NaughtyAttributes/Editor/PropertyDrawers/ReorderableListPropertyDrawer.cs
  6. 11
      Runtime/GameplayIngredients.asmdef
  7. 18
      NaughtyAttributes/Core/DrawerAttributes/LabelAttribute.cs
  8. 11
      NaughtyAttributes/Core/DrawerAttributes/LabelAttribute.cs.meta
  9. 12
      NaughtyAttributes/Core/DrawerAttributes/TagAttribute.cs
  10. 11
      NaughtyAttributes/Core/DrawerAttributes/TagAttribute.cs.meta
  11. 12
      NaughtyAttributes/Core/NaughtyAttributes.Core.asmdef
  12. 7
      NaughtyAttributes/Core/NaughtyAttributes.Core.asmdef.meta
  13. 16
      NaughtyAttributes/Editor/NaughtyAttributes.Editor.asmdef
  14. 7
      NaughtyAttributes/Editor/NaughtyAttributes.Editor.asmdef.meta
  15. 16
      NaughtyAttributes/Editor/PropertyDrawers/LabelPropertyDrawer.cs
  16. 11
      NaughtyAttributes/Editor/PropertyDrawers/LabelPropertyDrawer.cs.meta
  17. 56
      NaughtyAttributes/Editor/PropertyDrawers/TagPropertyDrawer.cs
  18. 11
      NaughtyAttributes/Editor/PropertyDrawers/TagPropertyDrawer.cs.meta
  19. 8
      NaughtyAttributes/Core/NaughtyAttributes.asmdef
  20. 7
      NaughtyAttributes/Core/NaughtyAttributes.asmdef.meta
  21. 16
      NaughtyAttributes/Editor/NaughtyAttributes-Editor.asmdef
  22. 7
      NaughtyAttributes/Editor/NaughtyAttributes-Editor.asmdef.meta

3
Editor/GameplayIngredients-Editor.asmdef


{
"name": "GameplayIngredients-Editor",
"references": [
"NaughtyAttributes",
"NaughtyAttributes.Core",
"NaughtyAttributes>Editor",
"GameplayIngredients",
"Unity.ugui",
"Unity.Timeline"

2
NaughtyAttributes/Editor/CodeGeneration/CodeGenerator.cs


private static readonly string DRAW_CONDITION_ENTRY_FORMAT = "drawConditionsByAttributeType[typeof({0})] = new {1}();" + Environment.NewLine;
//[UnityEditor.Callbacks.DidReloadScripts]
//[MenuItem("Tools/NaughtyAttributes/Update Attributes Database")]
[MenuItem("Tools/NaughtyAttributes/Update Attributes Database")]
private static void GenerateCode()
{
GenerateScript<PropertyMeta, PropertyMetaAttribute>("PropertyMetaDatabase", "PropertyMetaDatabaseTemplate", META_ENTRY_FORMAT);

2
NaughtyAttributes/Editor/CodeGeneration/PropertyDrawerDatabase.cs


drawersByAttributeType[typeof(DisableIfAttribute)] = new DisableIfPropertyDrawer();
drawersByAttributeType[typeof(DropdownAttribute)] = new DropdownPropertyDrawer();
drawersByAttributeType[typeof(EnableIfAttribute)] = new EnableIfPropertyDrawer();
drawersByAttributeType[typeof(LabelAttribute)] = new LabelPropertyDrawer();
drawersByAttributeType[typeof(MinMaxSliderAttribute)] = new MinMaxSliderPropertyDrawer();
drawersByAttributeType[typeof(ProgressBarAttribute)] = new ProgressBarPropertyDrawer();
drawersByAttributeType[typeof(ReadOnlyAttribute)] = new ReadOnlyPropertyDrawer();

drawersByAttributeType[typeof(SliderAttribute)] = new SliderPropertyDrawer();
drawersByAttributeType[typeof(TagAttribute)] = new TagPropertyDrawer();
}

17
NaughtyAttributes/Editor/Editors/InspectorEditor.cs


private void ValidateAndDrawField(FieldInfo field)
{
if (!ShouldDrawField(field))
{
return;
}
this.ValidateField(field);
this.ApplyFieldMeta(field);
this.DrawField(field);

}
}
private void DrawField(FieldInfo field)
private bool ShouldDrawField(FieldInfo field)
{
// Check if the field has draw conditions
PropertyDrawCondition drawCondition = this.GetPropertyDrawConditionForField(field);

if (!canDrawProperty)
{
return;
return false;
}
}

{
return;
return false;
// Draw the field
return true;
}
private void DrawField(FieldInfo field)
{
EditorGUI.BeginChangeCheck();
PropertyDrawer drawer = this.GetPropertyDrawerForField(field);
if (drawer != null)

11
NaughtyAttributes/Editor/PropertyDrawers/ReorderableListPropertyDrawer.cs


drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
{
var element = property.GetArrayElementAtIndex(index);
rect.y += 2f;
rect.y += 1.0f;
rect.x += 10.0f;
rect.width -= 10.0f;
EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, 0.0f), element, true);
},
EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), element);
elementHeightCallback = (int index) =>
{
return EditorGUI.GetPropertyHeight(property.GetArrayElementAtIndex(index)) + 4.0f;
}
};

11
Runtime/GameplayIngredients.asmdef


{
"name": "GameplayIngredients",
"references": [
"GUID:8159fdb6c7801b34fb01c3bf046a6e57",
"GUID:4307f53044263cf4b835bd812fc161a4",
"GUID:f06555f75b070af458a003d92f9efb00",
"GUID:2bafac87e7f4b9b418d9448d219b01ab"
"NaughtyAttributes.Core",
"Cinemachine",
"Unity.Timeline",
"UnityEngine.UI"
],
"includePlatforms": [],
"excludePlatforms": [],

"autoReferenced": true,
"defineConstraints": [],
"versionDefines": []
"versionDefines": [],
"noEngineReferences": false
}

18
NaughtyAttributes/Core/DrawerAttributes/LabelAttribute.cs


using System;
namespace NaughtyAttributes
{
/// <summary>
/// Override default label
/// </summary>
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public class LabelAttribute : DrawerAttribute
{
public string Label { get; private set; }
public LabelAttribute(string label)
{
this.Label = label;
}
}
}

11
NaughtyAttributes/Core/DrawerAttributes/LabelAttribute.cs.meta


fileFormatVersion: 2
guid: e58df0ada05db63488ddd96c571d7bc1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
NaughtyAttributes/Core/DrawerAttributes/TagAttribute.cs


using System;
namespace NaughtyAttributes
{
/// <summary>
/// Make tags appear as tag popup fields
/// </summary>
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public class TagAttribute : DrawerAttribute
{
}
}

11
NaughtyAttributes/Core/DrawerAttributes/TagAttribute.cs.meta


fileFormatVersion: 2
guid: ad140cd5debdba44aa6db74894a5e913
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
NaughtyAttributes/Core/NaughtyAttributes.Core.asmdef


{
"name": "NaughtyAttributes.Core",
"references": [],
"optionalUnityReferences": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
}

7
NaughtyAttributes/Core/NaughtyAttributes.Core.asmdef.meta


fileFormatVersion: 2
guid: 776d03a35f1b52c4a9aed9f56d7b4229
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

16
NaughtyAttributes/Editor/NaughtyAttributes.Editor.asmdef


{
"name": "NaughtyAttributes.Editor",
"references": [
"NaughtyAttributes.Core"
],
"optionalUnityReferences": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
}

7
NaughtyAttributes/Editor/NaughtyAttributes.Editor.asmdef.meta


fileFormatVersion: 2
guid: f88fb04354076c646a4107a491394033
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

16
NaughtyAttributes/Editor/PropertyDrawers/LabelPropertyDrawer.cs


using UnityEngine;
using UnityEditor;
namespace NaughtyAttributes.Editor
{
[PropertyDrawer(typeof(LabelAttribute))]
public class LabelPropertyDrawer : PropertyDrawer
{
public override void DrawProperty(SerializedProperty property)
{
var labelAttribute = PropertyUtility.GetAttribute<LabelAttribute>(property);
var guiContent = new GUIContent(labelAttribute.Label);
EditorGUILayout.PropertyField(property, guiContent, true);
}
}
}

11
NaughtyAttributes/Editor/PropertyDrawers/LabelPropertyDrawer.cs.meta


fileFormatVersion: 2
guid: efcf74639df2db34c8302355c0d29454
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

56
NaughtyAttributes/Editor/PropertyDrawers/TagPropertyDrawer.cs


using UnityEditor;
using System.Collections.Generic;
namespace NaughtyAttributes.Editor
{
// Original by Dylan Engelman
// http://jupiterlighthousestudio.com/custom-inspectors-unity/
// Altered by Brecht Lecluyse http://www.brechtos.com
// and Sichen Liu https://sichenn.github.io
[PropertyDrawer(typeof(TagAttribute))]
public class TagPropertyDrawer : PropertyDrawer
{
public override void DrawProperty(SerializedProperty property)
{
if (property.propertyType == SerializedPropertyType.String)
{
// generate the taglist + custom tags
List<string> tagList = new List<string>();
tagList.Add("(None)");
tagList.Add("Untagged");
tagList.AddRange(UnityEditorInternal.InternalEditorUtility.tags);
string propertyString = property.stringValue;
int index = 0;
// check if there is an entry that matches the entry and get the index
// we skip index 0 as that is a special custom case
for (int i = 1; i < tagList.Count; i++)
{
if (tagList[i] == propertyString)
{
index = i;
break;
}
}
// Draw the popup box with the current selected index
index = EditorGUILayout.Popup(property.displayName, index, tagList.ToArray());
// Adjust the actual string value of the property based on the selection
if (index > 0)
{
property.stringValue = tagList[index];
}
else
{
property.stringValue = string.Empty;
}
}
else
{
EditorGUILayout.HelpBox(property.type + " is not supported by TagAttribute\n" +
"Use string instead", MessageType.Warning);
}
}
}
}

11
NaughtyAttributes/Editor/PropertyDrawers/TagPropertyDrawer.cs.meta


fileFormatVersion: 2
guid: f915ac324502a0e48990bfe775312665
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
NaughtyAttributes/Core/NaughtyAttributes.asmdef


{
"name": "NaughtyAttributes",
"references": [],
"optionalUnityReferences": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false
}

7
NaughtyAttributes/Core/NaughtyAttributes.asmdef.meta


fileFormatVersion: 2
guid: 8159fdb6c7801b34fb01c3bf046a6e57
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

16
NaughtyAttributes/Editor/NaughtyAttributes-Editor.asmdef


{
"name": "NaughtyAttributes-Editor",
"references": [
"NaughtyAttributes"
],
"optionalUnityReferences": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
}

7
NaughtyAttributes/Editor/NaughtyAttributes-Editor.asmdef.meta


fileFormatVersion: 2
guid: e9a7d298ac7c03846852a1441e745485
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存