Skip to content

Commit

Permalink
Update Avatar Plugin Samples & Version to 4.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
jeoungjukim committed Jan 8, 2024
1 parent 0e250f1 commit b913c45
Show file tree
Hide file tree
Showing 91 changed files with 2,939 additions and 1,151 deletions.
46 changes: 40 additions & 6 deletions Editor/DrawIfAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,63 @@
* limitations under the License.
*
******************************************************************/
#if (UNITY_EDITOR || UNITY_STANDALONE_WIN)
using UnityEngine;
using System;
#if (UNITY_EDITOR || UNITY_STANDALONE_WIN)

namespace AvatarPluginForUnity.Editor
{
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
/// <summary>
///
/// </summary>
/// <seealso cref="UnityEngine.PropertyAttribute" />
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = true)]
public class DrawIfAttribute : PropertyAttribute
{
#region Fields
/// <summary>
/// Gets the name of the compared property.
/// </summary>
/// <value>
/// The name of the compared property.
/// </value>
public string comparedPropertyName { get; private set; }
/// <summary>
/// Gets the compared value.
/// </summary>
/// <value>
/// The compared value.
/// </value>
public object comparedValue { get; private set; }
/// <summary>
/// Gets the type of the disabling.
/// </summary>
/// <value>
/// The type of the disabling.
/// </value>
public DisablingType disablingType { get; private set; }


/// <summary>
///
/// </summary>
public enum DisablingType
{
ReadOnly = 2,
Draw = 3,
DrawExclude = 4
Draw = 1,
/// <summary>
/// The draw exclude
/// </summary>
DrawExclude = 2

}

#endregion

/// <summary>
/// Initializes a new instance of the <see cref="DrawIfAttribute"/> class.
/// </summary>
/// <param name="comparedPropertyName">Name of the compared property.</param>
/// <param name="comparedValue">The compared value.</param>
/// <param name="disablingType">Type of the disabling.</param>
public DrawIfAttribute(string comparedPropertyName, object comparedValue, DisablingType disablingType = DisablingType.Draw)
{
this.comparedPropertyName = comparedPropertyName;
Expand Down
93 changes: 59 additions & 34 deletions Editor/DrawIfPropertyDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,49 @@
* limitations under the License.
*
******************************************************************/
using UnityEditor;
using UnityEngine;
#if (UNITY_EDITOR || UNITY_STANDALONE_WIN)
using UnityEngine;
using UnityEditor;

namespace AvatarPluginForUnity.Editor
{
[CustomPropertyDrawer(typeof(DrawIfAttribute))]
/// <summary>
///
/// </summary>
/// <seealso cref="UnityEditor.PropertyDrawer" />
[CustomPropertyDrawer(typeof(DrawIfAttribute))]
public class DrawIfPropertyDrawer : PropertyDrawer
{
#region Fields
/// <summary>
/// The draw if
/// </summary>
DrawIfAttribute drawIf;
/// <summary>
/// The compared field
/// </summary>
SerializedProperty comparedField;

#endregion


/// <summary>
/// Override this method to specify how tall the GUI for this field is in pixels.
/// </summary>
/// <param name="property">The SerializedProperty to make the custom GUI for.</param>
/// <param name="label">The label of this property.</param>
/// <returns>
/// The height in pixels.
/// </returns>
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (!ShowMe(property) && drawIf.disablingType == DrawIfAttribute.DisablingType.Draw){
return 0f;
}

if (ShowMe(property) && drawIf.disablingType == DrawIfAttribute.DisablingType.DrawExclude){
return 0f;
}

return base.GetPropertyHeight(property, label);
return 0f;
}

private bool ShowMe(SerializedProperty property)

/// <summary>
/// Shows me.
/// </summary>
/// <param name="property">The property.</param>
/// <returns></returns>
private bool IsTrue(SerializedProperty property)
{
drawIf = attribute as DrawIfAttribute;

Expand All @@ -52,34 +67,44 @@ private bool ShowMe(SerializedProperty property)
if (comparedField == null)
{
Debug.LogError("Cannot find property with name: " + path);
return true;
return false;
}

switch (comparedField.type)
if (path.Contains("Flags"))
{
case "bool":
return comparedField.boolValue.Equals(drawIf.comparedValue);
case "Enum":
return comparedField.enumValueIndex.Equals((int)drawIf.comparedValue);
default:
Debug.LogError("Error: " + comparedField.type + " is not supported of " + path);
if ((comparedField.enumValueFlag & (int)drawIf.comparedValue) != 0)
return true;
else
return false;
}
else
switch (comparedField.type)
{
case "bool":
return comparedField.boolValue.Equals(drawIf.comparedValue);
case "Enum":
return comparedField.enumValueIndex.Equals((int)drawIf.comparedValue);
default:
Debug.LogError("Error: " + comparedField.type + " is not supported of " + path);
return false;
}
}


/// <summary>
/// Override this method to make your own IMGUI based GUI for the property.
/// </summary>
/// <param name="position">Rectangle on the screen to use for the property GUI.</param>
/// <param name="property">The SerializedProperty to make the custom GUI for.</param>
/// <param name="label">The label of this property.</param>
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (ShowMe(property) && drawIf.disablingType != DrawIfAttribute.DisablingType.DrawExclude){
EditorGUI.PropertyField(position, property, label);
}
else if(!ShowMe(property) && drawIf.disablingType == DrawIfAttribute.DisablingType.DrawExclude){
EditorGUI.PropertyField(position, property, label);
if (IsTrue(property) && (drawIf.disablingType != DrawIfAttribute.DisablingType.DrawExclude))
{
EditorGUILayout.PropertyField(property, label);
}
else if (drawIf.disablingType == DrawIfAttribute.DisablingType.ReadOnly)
else if (!IsTrue(property) && drawIf.disablingType == DrawIfAttribute.DisablingType.DrawExclude)
{
GUI.enabled = false;
EditorGUI.PropertyField(position, property, label);
GUI.enabled = true;
EditorGUILayout.PropertyField(property, label);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Editor/DrawIfPropertyDrawer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 0 additions & 49 deletions Editor/HelpBoxAttribute.cs

This file was deleted.

92 changes: 0 additions & 92 deletions Editor/HelpBoxDrawer.cs

This file was deleted.

Loading

0 comments on commit b913c45

Please sign in to comment.