/// <summary> /// Get attribute value. /// </summary> /// <typeparam name="TSource"></typeparam> /// <param name="enumValue"></param> /// <param name="attributeType"></param> /// <returns></returns> internal static string GetAttributeValue <TSource>(string enumValue, EnumAttributeTypes attributeType) where TSource : struct { TSource tValue; if (Enum.TryParse <TSource>(enumValue, true, out tValue)) { if (attributeType.Equals(EnumAttributeTypes.Description)) { return(AttributeExtensions.GetDescriptionAttribute <TSource>(tValue)); } else if (attributeType.Equals(EnumAttributeTypes.Category)) { return(AttributeExtensions.GetCategoryAttribute <TSource>(tValue)); } else if (attributeType.Equals(EnumAttributeTypes.DisplayIcon)) { return(AttributeExtensions.GetDisplayIconAttribute <TSource>(tValue)); } else if (attributeType.Equals(EnumAttributeTypes.ReportDefinition)) { return(AttributeExtensions.GetReportDefinitionAttribute <TSource>(tValue)); } return(AttributeExtensions.GetDescriptionAttribute <TSource>(tValue)); } else { return(null); } }
/// <summary> /// Renders the currently selected step /// </summary> /// <param name="rStep"></param> private bool DrawAttributeItemDetail(BasicAttribute rItem) { bool lIsDirty = false; EditorHelper.DrawSmallTitle("Attribute - " + EnumAttributeTypes.GetName(rItem.ValueType)); bool lIsValueDirty = rItem.OnInspectorGUI(mTarget); if (lIsValueDirty) { lIsDirty = true; } return(lIsDirty); }
/// <summary> /// Get enum attribute value from enum type. /// </summary> /// <typeparam name="TSource"></typeparam> /// <param name="enumValue"></param> /// <param name="attributeType"></param> /// <returns></returns> public static string GetEnumAttributeFromValue <TSource>(this TSource enumValue, EnumAttributeTypes attributeType = EnumAttributeTypes.Description) where TSource : struct { return(GetAttributeValue <TSource>(Convert.ToString(enumValue), attributeType)); }
/// <summary> /// Get enum attribute value input object value. /// </summary> /// <typeparam name="TSource"></typeparam> /// <param name="enumValue"></param> /// <param name="attributeType"></param> /// <returns></returns> public static string GetEnumAttributeFromValue <TSource>(this object enumValue, EnumAttributeTypes attributeType = EnumAttributeTypes.Description) where TSource : struct { string stringEnum = enumValue.GetDefaultValueIfNull <string>(); return(GetAttributeValue <TSource>(stringEnum, attributeType)); }
/// <summary> /// Renders the currently selected step /// </summary> /// <param name="rStep"></param> private bool DrawItemDetail(BasicAttribute rItem) { bool lIsDirty = false; EditorHelper.DrawSmallTitle(rItem.ID.Length > 0 ? rItem.ID : "Attribute Item"); float lLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 70f; if (EditorHelper.TextField("ID", "Unique ID of the Item", rItem.ID, mTarget)) { lIsDirty = true; rItem.ID = EditorHelper.FieldStringValue; } int lIndex = EnumAttributeTypes.GetEnum(rItem.ValueType); if (EditorHelper.PopUpField("Type", "Data type the attribute holds", lIndex, EnumAttributeTypes.Names, mTarget)) { lIsDirty = true; rItem.ValueType = EnumAttributeTypes.Types[EditorHelper.FieldIntValue]; } if (rItem.ValueType != null) { GUILayout.Space(5f); } if (rItem.ValueType == typeof(float)) { if (EditorHelper.FloatField("Value", "Value of the attribute", rItem.GetValue <float>(), mTarget)) { lIsDirty = true; rItem.SetValue <float>(EditorHelper.FieldFloatValue); } } else if (rItem.ValueType == typeof(int)) { if (EditorHelper.IntField("Value", "Value of the attribute", rItem.GetValue <int>(), mTarget)) { lIsDirty = true; rItem.SetValue <int>(EditorHelper.FieldIntValue); } } else if (rItem.ValueType == typeof(bool)) { if (EditorHelper.BoolField("Value", "Value of the attribute", rItem.GetValue <bool>(), mTarget)) { lIsDirty = true; rItem.SetValue <bool>(EditorHelper.FieldBoolValue); } } else if (rItem.ValueType == typeof(string)) { if (EditorHelper.TextField("Value", "Value of the attribute", rItem.GetValue <string>(), mTarget)) { lIsDirty = true; rItem.SetValue <string>(EditorHelper.FieldStringValue); } } else if (rItem.ValueType == typeof(Vector2)) { if (EditorHelper.Vector2Field("Value", "Value of the attribute", rItem.GetValue <Vector2>(), mTarget)) { lIsDirty = true; rItem.SetValue <Vector2>(EditorHelper.FieldVector2Value); } } else if (rItem.ValueType == typeof(Vector3)) { if (EditorHelper.Vector3Field("Value", "Value of the attribute", rItem.GetValue <Vector3>(), mTarget)) { lIsDirty = true; rItem.SetValue <Vector3>(EditorHelper.FieldVector3Value); } } else if (rItem.ValueType == typeof(Vector4)) { #if UNITY_5_0 || UNITY_5_1 || UNITY_5_2 || UNITY_5_3 || UNITY_5_4 Vector4 lValue = EditorGUILayout.Vector4Field("Value", rItem.GetValue <Vector4>()); #else Vector4 lValue = EditorGUILayout.Vector4Field(new GUIContent("Value", "Value of the attribute"), rItem.GetValue <Vector4>()); #endif if (lValue != rItem.GetValue <Vector4>()) { lIsDirty = true; rItem.SetValue <Vector4>(lValue); } } else if (rItem.ValueType == typeof(Quaternion)) { if (EditorHelper.QuaternionField("Value", "Value of the attribute", rItem.GetValue <Quaternion>(), mTarget)) { lIsDirty = true; rItem.SetValue <Quaternion>(EditorHelper.FieldQuaternionValue); } } else if (rItem.ValueType == typeof(Transform)) { if (EditorHelper.ObjectField <Transform>("Value", "Value of the attribute", rItem.GetValue <Transform>(), mTarget)) { lIsDirty = true; rItem.SetValue <Transform>(EditorHelper.FieldObjectValue as Transform); } } else if (rItem.ValueType == typeof(GameObject)) { if (EditorHelper.ObjectField <GameObject>("Value", "Value of the attribute", rItem.GetValue <GameObject>(), mTarget)) { lIsDirty = true; rItem.SetValue <GameObject>(EditorHelper.FieldObjectValue as GameObject); } } EditorGUIUtility.labelWidth = lLabelWidth; return(lIsDirty); }