Version: 2023.2
言語: 日本語
public Gradient gradientValue ;

説明

Gradient プロパティーの値

using System;
using UnityEditor;
using UnityEngine;

[CreateAssetMenu] public class SerializedPropertyGradientExample : ScriptableObject { public Gradient m_Gradient;

[Range(0, 1)] public float m_EvaluationTime;

public SerializedPropertyGradientExample() { // Establish a default gradient var colorKeys = new GradientColorKey[] { new GradientColorKey() { color = Color.red, time = 0.0f }, new GradientColorKey() { color = Color.green, time = 0.5f }, new GradientColorKey() { color = Color.blue, time = 1.0f } }; var alphaKeys = new GradientAlphaKey[] { new GradientAlphaKey() { alpha = 0.5f, time = 0.0f }, new GradientAlphaKey() { alpha = 1.0f, time = 1.0f } }; m_Gradient = new Gradient(); m_Gradient.SetKeys(colorKeys, alphaKeys); } }

// Override the default inspector behavior to add extra text line after the two properties [CustomEditor(typeof(SerializedPropertyGradientExample))] public class SerializedPropertyGradientExampleEditor : Editor { public override void OnInspectorGUI() { DrawDefaultInspector();

var gradient = serializedObject.FindProperty("m_Gradient").gradientValue; var evalPoint = serializedObject.FindProperty("m_EvaluationTime").floatValue; GUILayout.Label($"Gradiant at time {evalPoint}: {gradient.Evaluate(evalPoint)}"); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961