版本: Unity 6 (6000.0)
语言英语
  • C#

RequiredMemberAttribute

UnityEngine.Scripting 中的类

/

实现于:UnityEngine.CoreModule

建议修改

成功!

感谢您帮助我们改进 Unity 文档的质量。虽然我们无法接受所有提交,但我们确实阅读了用户提出的每个建议的更改,并在适用的情况下进行更新。

关闭

提交失败

由于某种原因,您的建议更改无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们改进 Unity 文档的质量。

关闭

取消

描述

当一个类型被标记时,其所有带有 [RequiredMember] 的成员都会被标记。

using System;
using UnityEngine;
using UnityEngine.Scripting;

public class NewBehaviourScript : MonoBehaviour { void Start() { new UsedFoo(); } }

class UsedFoo { // Will survive managed code stripping because UsedFoo is used [RequiredMember] public int Field;

// Will survive managed code stripping because UsedFoo is used [RequiredMember] public void Method() { }

// The property, property getter method, and property setter method will survive managed code stripping because UsedFoo is used [RequiredMember] public int Property1 { get; set; }

// The property and property getter method will survive managed code stripping because UsedFoo is used public int Property2 { [RequiredMember] get; set; }

// The property and property setter method will survive managed code stripping because UsedFoo is used public int Property3 { get; [RequiredMember] set; }

// The event, the add method, and the remove method will survive managed code stripping because UsedFoo is used [RequiredMember] public event EventHandler Event; }

class UnusedFoo { // Will not survive stripping because UnusedFoo is not used [RequiredMember] public int Field;

// Will not survive stripping because UnusedFoo is not used [RequiredMember] public void Method() { }

// Will not survive stripping because UnusedFoo is not used [RequiredMember] public int Property { get; set; }

// Will not survive stripping because UnusedFoo is not used [RequiredMember] public event EventHandler Event; }