简体   繁体   English

无法从 Unity 上的检查员分配游戏 Object

[英]Can't Assign Game Object from inspector on Unity

I'm working on a unity project and have added the Assembly definition to my project to keep things more organized.我正在开发一个统一项目,并将程序集定义添加到我的项目中,以使事情更有条理。 But now that I have added the Assembly Definition I can't assign any object at all from the inspector (no matter if it's a public or serialized field)但是现在我已经添加了程序集定义,我无法从检查员那里分配任何 object (无论它是公共字段还是序列化字段)

I have tried:我努力了:

  • To make the fields serialized使字段序列化
  • Changed the file namespace更改了文件命名空间
    1. Removed the namespace删除了命名空间
    2. Changed that to the Root directory将其更改为根目录
  • I also tried moving the file to another directory (directly under assets)我还尝试将文件移动到另一个目录(直接在资产下)

I also have added the Root namespaces at project settings>>editor.我还在项目设置>>编辑器中添加了根命名空间。

And all the Assembly definitions have the same Root namespaces并且所有程序集定义都具有相同的Root 命名空间

Any suggestion would mean a lot to me, Thanks!任何建议对我来说都意义重大,谢谢!

Inspector in normal state检查器正常 state

在此处输入图像描述

Here is the inspector under Debug这是Debug下的检查器

在此处输入图像描述

The scripts are all under the Scripts folder脚本都在 Scripts 文件夹下

在此处输入图像描述

here is my class.这是我的 class。


    using IndritVaka.Assets.Script.Core;
    using IndritVaka.Assets.Script.Model;
    using TMPro;
    using UnityEngine;
    namespace IndritVaka.Assets.Script.IO
    {
        public class OutputManager: MonoBehaviour
        {
            public TextMeshProUGUI Date { get; set; }
            public TextMeshProUGUI Imsak { get; set; }
            public TextMeshProUGUI Fajr { get; set; }
            public TextMeshProUGUI Sunrise { get; set; }
            public TextMeshProUGUI Dhuhr { get; set; }
            public TextMeshProUGUI Asr { get; set; }
            public TextMeshProUGUI Sunset { get; set; }
            public TextMeshProUGUI Isha { get; set; }
    
            private void Awake()
            {
                TimingUtility.UPDATE_TIMINGS_UI += UpdateUi;
            }
    
            private void UpdateUi(Timings timings)
            {
                Date.text = timings.Date?.ToShortDateString();
                Imsak.text = timings.Imsak?.ToShortTimeString();
                Fajr.text = timings.Fajr?.ToShortTimeString();
                Sunrise.text = timings.Sunrise?.ToShortTimeString();
                Dhuhr.text = timings.Dhuhr?.ToShortTimeString();
                Asr.text = timings.Asr?.ToShortTimeString();
                Sunset.text = timings.Sunset?.ToShortTimeString();
                Isha.text = timings.Isha?.ToShortTimeString();
            }
            private void OnDestroy()
            {
                TimingUtility.UPDATE_TIMINGS_UI -= UpdateUi;
            }
        }
    }

If you want to use auto properties and still want to expose them in the inspector, you can add the SerializeFieldAttribute , like you always would, but add a field: in front of it.如果你想使用自动属性并且仍然想在检查器中公开它们,你可以像往常一样添加SerializeFieldAttribute ,但在它前面添加一个field: This will add the attribute to the auto-generated backing field, resulting in it being serialized like it would if you wrote a full property.这会将属性添加到自动生成的支持字段中,从而像编写完整属性一样对其进行序列化。

[field: SerializeField]
public GameObject StuffToAssign { get; }

The problem doesn't have to do at all with assembly.问题与组装完全无关。 The problem was at get and set Removing them fixed the problem.问题在于获取和设置删除它们解决了问题。

public TextMeshProUGUI Date { get; set; } 

to

public TextMeshProUGUI Date;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM