A 2D Farming RPG
This is just a simple 2D farming RPG game
Loading...
Searching...
No Matches
ItemCodeDescriptionDrawer.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using UnityEngine;
3using UnityEditor;
4
5[CustomPropertyDrawer(typeof(ItemCodeDescriptionAttribute))]
6public class ItemCodeDescriptionDrawer : PropertyDrawer
7{
14 public override float GetPropertyHeight( SerializedProperty property, GUIContent label )
15 {
16 return EditorGUI.GetPropertyHeight( property ) * 2;
17 }
18
25 public override void OnGUI( Rect position, SerializedProperty property, GUIContent label )
26 {
27 EditorGUI.BeginProperty( position, label, property );
28
29 if( property.propertyType == SerializedPropertyType.Integer )
30 {
31 // Start of check for changed values.
32 EditorGUI.BeginChangeCheck();
33
34 // Draw item code
35 var newValue = EditorGUI.IntField( new Rect( position.x, position.y, position.width, position.height / 2 ), label, property.intValue );
36
37 // Draw item description
38 EditorGUI.LabelField( new Rect( position.x, position.y + position.height / 2, position.width, position.height / 2 ), "Item Description", GetItemDescription( property.intValue ) );
39
40 // If item code value has changed, the set value to new value.
41 if( EditorGUI.EndChangeCheck() )
42 {
43 property.intValue = newValue;
44 }
45 }
46
47 EditorGUI.EndProperty();
48 }
49
55 private string GetItemDescription( int itemCode )
56 {
57 SOItemList soItemList;
58
59 soItemList = AssetDatabase.LoadAssetAtPath( "Assets/Scriptable Objects Assets/Item/soItemList.asset", typeof( SOItemList ) ) as SOItemList;
60
61 List<ItemDetails> itemDetailsList = soItemList.m_ItemDetails;
62
63 ItemDetails itemDetail = itemDetailsList.Find( x=>x.m_ItemCode == itemCode );
64
65 if( itemDetail != null )
66 {
67 return itemDetail.m_ItemDescription;
68 }
69
70 return "";
71
72 }
73}
No values need to be held for the item code description attribute Therefore, the class can be empty.
override float GetPropertyHeight(SerializedProperty property, GUIContent label)
Changed the return property height to be double to cater for the additional item code description tha...
string GetItemDescription(int itemCode)
Get the description of the item.
override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
Using BeginProperty / EndProperty on the parent property means that prefab ovrride logic works on the...
This class holds information of items.
Definition: ItemDetails.cs:8
string m_ItemDescription
Definition: ItemDetails.cs:9
List< ItemDetails > m_ItemDetails
Definition: SOItemList.cs:8