public class UVBaseTool : ScriptableObject, IPropertiesChanged
{
private BaseToolProperties properties_;
private ScriptableObject propertiesNoValidate_;
// Some code ...
protected void SetProperties(System.Type propertiesType, System.Type properties1Type)
{
properties_ = propertiesType == null ? null : CreateInstance(propertiesType) as BaseToolProperties;
if (properties_ != null)
{
properties_.tool = (this);
}
propertiesNoValidate_ = properties1Type == null ? null : CreateInstance(properties1Type);
}
public T Properties<T>()
{
return properties_;
}
public T PropertiesNoValidate<T>()
{
return propertiesNoValidate_;
}
}
任何人都可以帮我解决这个问题,因为我无法解决这些错误:
Rocket.Archi.BaseToolProperties' to
T'UnityEngine.ScriptableObject' to
T'我尝试遍历CS0029的在线上下文,但仍然无法通过IConvertable进行转换。请让我知道是否有解决方案。
这是我打电话给
的方式[SerializeField]
private BaseToolProperties properties_;
[SerializeField]
private ScriptableObject propertiesNoValidate_;
public virtual void Start()
{
EditorUtil.HideGlobalGizmo();
ArchiEx.selectedElements.ClearVertexBoxes();
ArchiEx.currentCamera = (Camera) null;
GizmoHandler.Destroy();
if (properties_ != null)
EditorUtil.LoadObject(properties_, null);
if (propertiesNoValidate_ != null)
EditorUtil.LoadObject(propertiesNoValidate_, null);
Ruler.Add(this, RulerType.Local);
ArchiSettings.GatherArchi();
}
这是baseTool;
using System;
using UnityEngine;
namespace Rocket.Archi
{
[Serializable]
public class BaseToolProperties : ScriptableObject
{
[NonSerialized]
public IPropertiesChanged tool;
public virtual void OnValidate()
{
if (tool == null)
return;
tool.OnPropertiesChanged();
}
}
}
如果我这样写,错误消失了,但是现在我又遇到了另一个错误,该错误是针对IConvertable的。每当我尝试在场景视图中制作对象时,都会出现此重复错误。见下文;
public T Properties<T>()
{
return (T)Convert.ChangeType(properties_, typeof(T));
}
public T PropertiesNoValidate<T>()
{
return (T)Convert.ChangeType(propertiesNoValidate_, typeof(T));
}
InvalidCastException:对象必须实现IConvertible。 System.Convert.ChangeType(System.Object值,System.Type conversionType,System.IFormatProvider提供程序)(位于:0) System.Convert.ChangeType(System.Object值,System.Type conversionType)(位于:0) RocketMod.Archi.BaseTool.Properties [T]()(在Assets / Rocket-建模工具/Archi/Scripts/Editor/BaseTool.cs:224处) RocketMod.Archi.PropertiesGUI.HasContents()(在Assets / Rocket-建模工具/Archi/Scripts/Editor/PropertiesGUI.cs:54) RocketMod.Archi.PropertiesGUI.OnGUI()(在Assets / Rocket-建模工具/Archi/Scripts/Editor/PropertiesGUI.cs:17) RocketMod.Archi.ToolSelectionGUI.OnGUI()(在Assets / Rocket-建模工具/Archi/Scripts/Editor/ToolSelectionGUI.cs:164处) RocketMod.Archi.ArchiEditor.OnInspectorGUI()(在Assets / Rocket-建模工具/Archi/Scripts/Editor/ArchiEditor.cs:299处) UnityEditor.InspectorWindow.DrawEditor(UnityEditor.Editor []编辑器,System.Int32编辑器索引,System.Boolean rebuildOptimizedGUIBlock,System.Boolean&showImportedObjectBarNext,UnityEngine.Rect&importedObjectBarRect)(在C:/ buildslave / unity / build / Editor / Mono / Inspector / InspectorWindow.cs:1253) UnityEngine.GUIUtility:ProcessEvent(Int32,IntPtr)
如果要解决这个问题,我会在下面写下所有内容停止工作;
public T Properties<T>() where T : IConvertible
{
return (T)Convert.ChangeType(properties_, typeof(T));
}
public T PropertiesNoValidate<T>() where T : IConvertible
{
return (T)Convert.ChangeType(propertiesNoValidate_, typeof(T));
}
任何帮助的人都将被接纳!!!
答案 0 :(得分:0)
您在返回特定类型属性的方法中使用了通用类型<T>
。
通过以下内容替换方法的签名:
// v----------------v--------------The type of properties_
public BaseToolProperties Properties()
{ // ^----------------the <T> was removed
return properties_;
}
// v--------------v----------------The type of propertiesNoValidate_
public ScriptableObject PropertiesNoValidate()
{ // ^--------the <T> was removed
return propertiesNoValidate_;
}