Jump to content
Unity Insider Forum

Script Asset mit Classe Erweitern


Entus_Brutalus

Recommended Posts

Hallo,

Ich bastel grade an einem Inventar System,

Meine Items erstelle ich mit Hilfe der Asset Funktion.

nun habe ich mir Gedacht wenn meine Waffen bestimmte Attribute brauchen kann ich ja eine Allgemeine Attribute Klasse machen und diese dan beim Charakter auch verwenden.

Nur wie stelle ich das ganze an ?

Ich habe mein Item Asset Script.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


[CreateAssetMenu(fileName = "Item", menuName = "Custom/Item/New Item", order = 1)]
public class Item_Asset : ScriptableObject
{
    private const int V = 0;
    [SerializeField, Tooltip("Item Name")]
    public new string Item_Name;
    [Header("Normal")]
    [SerializeField, Tooltip("Item Description")]
    public string Item_desc;

    [HideInInspector]
        public int Item_Type;
    [HideInInspector]
    public string[] Item_Type_String = new string[] {"Unone", "Weapon", "Usable", "Material", "Armor", "Quest"};

    [HideInInspector]
    public int WeaponType;
    [HideInInspector]
    public string[] WeaponTypeString = new string[] { "None", "Sword", "Hammer", "Staff" };
    [SerializeField, Tooltip("Item Handelbar")]
    public bool Item_Tranferable;

    public WeaponTypeAttribute Weapon = new WeaponTypeAttribute();
/*     
    [HideInInspector]
    public int Weapon_DMG;
    [HideInInspector]
    public int Weapon_Attributes; */




    
}

Dann Habe ich mein Inspector Editor Script.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;


 [CustomEditor(typeof(Item_Asset))]
public class Item_Asset_Inspc : Editor {
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        Item_Asset Item_Asset = (Item_Asset)target;
        GUIContent arrayLabel = new GUIContent("Item_Asset");
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Item Type");
        
        Item_Asset.Item_Type = EditorGUILayout.Popup(Item_Asset.Item_Type, Item_Asset.Item_Type_String);
        EditorGUILayout.EndHorizontal();
        if(Item_Asset.Item_Type == 1){
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Wepon Type");
            Item_Asset.WeaponType = EditorGUILayout.Popup(Item_Asset.WeaponType, Item_Asset.WeaponTypeString);
            EditorGUILayout.EndHorizontal();
            // Wepon Dmg
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Wepon DMG");
            Item_Asset.WeWeapon_DMG = EditorGUILayout.IntField(Item_Asset.Weapon_DMG);
            Item_Asset.Weapon.WeaponType_INT;
            EditorGUILayout.EndHorizontal();

        }





        //skill_Asset.WriteWeponUsable(EditorGUILayout.Popup(arrayLabel, skill_Asset.ReadWeponUsable(), skill_Asset.WeponFunc));

    }

}

Und meine Extension Class

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WeaponTypeAttribute : MonoBehaviour
{
    public int WeaponType_INT;
    public int Weapon_DMG;
    public int Weapon_Attributes;
}

Ich bekomme den fehler

Zitat

'Item_Asset' does not contain a definition for 'WeWeapon_DMG' and no accessible extension method 'WeWeapon_DMG' accepting a first argument of type 'Item_Asset'

Weis jemand wie ich das bewerkstelligen kann ? habe schon mit PropertyAttribute rumgespielt weis aber nicht ob das der Richtige weg ist.

Link zu diesem Kommentar
Auf anderen Seiten teilen

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Auf dieses Thema antworten...

×   Du hast formatierten Text eingefügt.   Formatierung jetzt entfernen

  Only 75 emoji are allowed.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Lädt...
×
×
  • Neu erstellen...