Answer the question
In order to leave comments, you need to log in
How to add constants to public enum from another script?
The bottom line is this: there is a compiled dll (Game.dll, there is ALL the game logic, there is no way to rebuild) containing a list of AmmoType.cs constants used both in the game and in the Inspector (custom editor, drop-down list in the Inspector). Task: add constants so that they are visible and selectable in the Inspector. How to implement it? There are no problems for the new constants to work in the game, but they are not visible in the Inspector and the asset has to be edited with a notepad.
List:
Original AmmoType.cs:
using System;
public enum AmmoType
{
AmmoNone,
Ammo10mm,
Ammo5_45mm,
Ammo9mm,
Ammo12g,
Ammo7_62mm,
Ammo307cal,
Ammo14_5mm,
Ammo7mm_54R,
AmmoBB,
AmmoBolt,
Ammo356cal,
AmmoPB,
AmmoFuel,
Ammo6_49mm,
AmmoRubber
}
using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
//Эксперимент: Добавил 2 типа патронов, работают, но не видны в Inspector
public enum AmmoType
{
Ammo45g = 16,
Ammo5_7mm = 17
}
using System;
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(EnumFlagsAttribute))]
public class EnumFlagsAttributeDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
bool flag = !property.hasMultipleDifferentValues;
if (flag)
{
property.intValue = EditorGUI.MaskField(position, label, property.intValue, property.enumNames);
}
else
{
EditorGUI.LabelField(position, label);
}
}
}
Answer the question
In order to leave comments, you need to log in
https://habr.com/ru/post/331042/
You need the item "Execution in the editor". Just ask the script for a list of constants, or come up with something else.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question