using UnityEngine; using UnityEngine.UI; using UnityEditor.Experimental.GraphView; using System.IO; using System.Reflection; using System.Linq; using System; using Boo.Lang; #if UNITY_EDITOR using UnityEditor; #endif public class ShootInfomationCreate : EditorWindow { const int _MinWidth = 480; const int _MinHeight = 300; const string _SavePath = "Assets/Resources"; // or Script/ScriptableObject //const string _InfomationLoadPath = "Assets/Resources/Infomations/Infomation.asset"; int _ShootPatturn; static System.Collections.Generic.List<Infomation> _InfomationClasses; static string[] _InfomationNames; [MenuItem("Window/WeaponCreate")] static void CreateWindow() { var window = GetWindow<ShootInfomationCreate>(); window.minSize = new Vector2(_MinWidth, _MinHeight); //現在のInfomation継承クラスを全取得 _InfomationClasses = Assembly.GetExecutingAssembly().GetTypes().Where(x => x.BaseType == typeof(Infomation)).ToList().ConvertAll(new Converter<Type, Infomation>(TypeToInfomation)); _InfomationClasses.ForEach(x => { x = (Infomation)ScriptableObject.CreateInstance(x.GetType().Name); }); _InfomationNames = _InfomationClasses.Select(x => x.GetType().Name).ToArray(); } static Infomation TypeToInfomation(Type type) { return (Infomation)Activator.CreateInstance(type); } private void OnGUI() { using (var scope = new GUILayout.VerticalScope()) { _ShootPatturn = EditorGUILayout.Popup(_ShootPatturn, _InfomationNames); //ここでエラー発生、他クラスにてOnGUIのイベントを呼び出そうとしている _InfomationClasses[_ShootPatturn].Input(scope); if (GUILayout.Button("生成")) { string path = _SavePath + "/" + _ShootPatturn.ToString() + "/" + _InfomationClasses[_ShootPatturn].Name + ".asset"; var m = ObjectCreate<Infomation>(path); EditorUtility.SetDirty(m); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } } } T ObjectCreate<T>(string path) where T : ScriptableObject { if (!File.Exists(path)) { var i = ScriptableObject.CreateInstance<T>(); AssetDatabase.CreateAsset(i, path); return i; } else { return AssetDatabase.LoadAssetAtPath<T>(path); } } } public enum ShootPatturn { Gerobi, Diffusion, Colmn, }
using System; using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; [Serializable] public class ColmnShootInfomation : Infomation { const float _BeginShotPointLimit = -10f; const float _EndShotPointLimit = 10f; [SerializeField] float _ReloadTime; [SerializeField] bool _IsCharge; [SerializeField] float _ChargeTime; [SerializeField] float _BeginBulletPosition; [SerializeField] float _EndBulletPosition; [SerializeField] float _BulletDistance; public void Initialize(float reload, bool isCharge, float chargeT,float begin,float end,float distance) { _ReloadTime = reload; _IsCharge = isCharge; _ChargeTime = chargeT; _BeginBulletPosition = begin; _EndBulletPosition = end; _BulletDistance = distance; } public override void Initialize(Infomation inf) { var i = (ColmnShootInfomation)inf; _ReloadTime = i._ReloadTime; _IsCharge = i._IsCharge; _ChargeTime = i._ChargeTime; _BeginBulletPosition = i._BeginBulletPosition; _EndBulletPosition = i._EndBulletPosition; _BulletDistance = i._BulletDistance; } //ここで呼び出している public override void Input(GUI.Scope scope) { using (scope) { base.Name = EditorGUILayout.TextField("武装名", base.Name); _ReloadTime = EditorGUILayout.FloatField("リロードにかかる時間", _ReloadTime); _IsCharge = EditorGUILayout.Toggle("チャージがあるか", _IsCharge); if(_IsCharge)_ChargeTime = EditorGUILayout.FloatField("チャージ時間", _ChargeTime); _BeginBulletPosition = EditorGUILayout.Slider("開始位置",_BeginBulletPosition, _BeginShotPointLimit,0); _EndBulletPosition = EditorGUILayout.Slider("終了位置", _EndBulletPosition,0,_EndShotPointLimit); _BulletDistance = EditorGUILayout.Slider("弾の隙間", _BulletDistance, 0, Mathf.Abs(_EndBulletPosition - _BeginBulletPosition)); } } コード
タイトルの通り、他クラスのEditorGUILayoutをOnGUIより呼び出して動かすとクラッシュします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。