赞
踩
using System;
using UnityEngine;
public class Test : MonoBehaviour
{
[Serializable]
public class PlayerSettings
{
public string playerName;
public int playerScore;
public float playerHealth;
}
public PlayerSettings playerSettings;
}
using System;
using UnityEngine;
public class Test : MonoBehaviour
{
// 这个字段将不被序列化
[NonSerialized]
public int myInt;
// 这个字段将被序列化
public float myFloat;
}
using UnityEngine;
[AddComponentMenu("Menu/CustomMenu")]
public class Test : MonoBehaviour
{
}
using UnityEngine;
[AddComponentMenu("test/CustomScript")]
public class test: MonoBehaviour
{
// 这是你的脚本的内容
}
using UnityEngine;
public class Test : MonoBehaviour
{
[ColorUsage(true, true)]
public Color myColor;
}
using UnityEngine;
public class Test : MonoBehaviour
{
[ContextMenu("Do Something")]
private void CustomMethod()
{
// 当在 Inspector 中的上下文菜单中选择 "Do Something" 时,将触发这个方法。
Debug.Log("Doing something...");
}
}
using UnityEngine;
public class Test : MonoBehaviour
{
[ContextMenuItem("Reset Score", "ResetScore")]
public int playerScore;
private void ResetScore()
{
playerScore = 0;
}
}
using UnityEngine;
using UnityEditor;
[CreateAssetMenu(fileName = "NewTest", menuName = "MyGame/Test")]
public class Test : ScriptableObject
{
}
using UnityEngine;
public class Test : MonoBehaviour
{
[Delayed]
public float delayedValue = 0.0f;
private void Update()
{
// 这里的 delayedValue 可能在多次更改后才会应用
Debug.Log("Delayed Value: " + delayedValue);
}
}
using UnityEngine;
[DisallowMultipleComponent]
public class Test : MonoBehaviour
{
}
using UnityEngine;
[ExecuteInEditMode] // 使用 ExecuteInEditMode 特性
public class Test : MonoBehaviour
{
public Vector3 somePosition;
private void Update()
{
// 这里的代码将在编辑器模式下执行
transform.position = somePosition;
}
}
using UnityEngine;
public class Test : MonoBehaviour
{
[GUITarget(0, 1)]
private void OnGUI()
{
GUI.Label(new Rect(10, 10, 300, 100), "Visible on TV and Wii U GamePad only");
}
}
using UnityEngine;
public class Test : MonoBehaviour
{
[Header("objectName")]
public string objectName;
[Header("objectScale")]
public float objectScale;
}
using UnityEngine;
[HelpURL("https://docs.unity3d.com/ScriptReference/Transform.html")]
public class Test : MonoBehaviour
{
}
using UnityEngine;
public class Test : MonoBehaviour
{
public int publicField; // 这个字段将显示在 Inspector 窗口中
[HideInInspector]
public int hiddenField; // 这个字段将被隐藏,不会在 Inspector 中显示
}
using UnityEngine;
public class Test : MonoBehaviour
{
[Multiline(4)] // 将该字段标记为多行文本输入,显示 4 行文本输入框
public string description;
}
using UnityEngine;
public class Test : MonoBehaviour
{
[Range(0.0f, 1.0f)]
public float rangeValue;
[Range(1, 10)]
public int rangeCount;
}
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class Test : MonoBehaviour
{
// 这个脚本需要一个 Rigidbody 组件
// 如果 GameObject 上没有 Rigidbody 组件,Unity 会自动添加一个
}
using UnityEngine;
public class Test
{
[RuntimeInitializeOnLoadMethod]
static void testInitializeOnLoad()
{
// 在游戏启动时执行的初始化逻辑
Debug.Log("Game is starting, performing initialization...");
}
}
using UnityEngine;
[SelectionBase] // 使用 SelectionBase 特性
public class Test : MonoBehaviour
{
}
using UnityEngine;
public class Test : MonoBehaviour
{
[SerializeField]
private int myField;
}
using UnityEngine;
public class Test : MonoBehaviour
{
public int field1;
[Space(10)] // 在此处添加一个 10 像素的间距
public float field2;
[Space(20)] // 在此处添加一个 20 像素的间距
public string field3;
}
using UnityEngine;
public class Test : MonoBehaviour
{
[TextArea(3, 6)] // 文本框显示 3-6 行文本
public string description;
}
using UnityEngine;
public class Test : MonoBehaviour
{
[Tooltip("This is the object's name.")]
public string objectName;
}
using UnityEditor;
[CustomEditor(typeof(MyComponent))]
[CanEditMultipleObjects]
public class TestComponentEditor : Editor
{
private TestComponent testComponent { get { return (TestComponent)target; } }
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
testComponent.age= EditorGUILayout.FloatField("年龄值", testComponent.age);
testComponent.myName = EditorGUILayout.TextField("名字", testComponent.myName);
}
}
using UnityEngine;
public class Test : MonoBehaviour
{
public float age;
public string myName;
}
using UnityEditor;
[CustomEditor(typeof(Test))]
public class TestEditor : Editor
{
private Test myTest { get { return (Test)target; } }
public override void OnInspectorGUI()
{
myTest.age = EditorGUILayout.FloatField("年龄", myTest.age);
myTest.myName = EditorGUILayout.TextField("名字", myTest.myName);
}
}
[CustomPreview(typeof(Texture))] // 将预览特性与 Texture 关联
public class TexturePreview : ObjectPreview
{
public override bool HasPreviewGUI()
{
return true;
}
public override GUIContent GetPreviewTitle()
{
return new GUIContent("Custom Texture Preview");
}
public override void OnPreviewGUI(Rect r, GUIStyle background)
{
if (target is Texture)
{
Texture texture = (Texture)target;
// 绘制纹理预览
GUI.DrawTexture(new Rect(r.width / 4, r.height / 4, r.width/2,r.height/2), texture);
// 在预览面板上绘制内容
GUI.Label(new Rect(r.width / 4, r.height / 2, r.width / 2, r.height / 2),
"Custom Preview Example", new GUIStyle {
fontSize = 40,
normal = { textColor=Color.white}
} );
}
}
using UnityEngine;
public class test: MonoBehaviour
{
}
using UnityEngine;
using UnityEditor;
public class testGizmoDrawer
{
[DrawGizmo(GizmoType.Selected | GizmoType.Active)]
static void DrawGizmoForMyScript(test scr, GizmoType gizmoType)
{
// 在选中或激活状态下绘制 Gizmo
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(scr.transform.position, 1.0f);
}
}
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public class testInitialization
{
static testInitialization()
{
// 在指定的时刻执行初始化代码
Debug.Log("Initialization has occurred.");
}
}
using UnityEditor;
public class testInitialization
{
[InitializeOnLoadMethod]
static void Initialize()
{
// 在指定的时刻执行初始化代码
Debug.Log("Initialization method has been called.");
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。