Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

ProceduralMaterial.GetProceduralPropertyDescriptions

フィードバック

ありがとうございます

この度はドキュメントの品質向上のためにご意見・ご要望をお寄せいただき、誠にありがとうございます。頂いた内容をドキュメントチームで確認し、必要に応じて修正を致します。

閉じる

送信に失敗しました

なんらかのエラーが発生したため送信が出来ませんでした。しばらく経ってから<a>もう一度送信</a>してください。ドキュメントの品質向上のために時間を割いて頂き誠にありがとうございます。

閉じる

キャンセル

マニュアルに切り替える
public function GetProceduralPropertyDescriptions(): ProceduralPropertyDescription[];
public ProceduralPropertyDescription[] GetProceduralPropertyDescriptions();

説明

この ProceduralMaterial が持っているすべての ProceduralProperties の記述の配列を取得します。

そのプロパティーを事前に知らなくても ProceduralMaterial のプロパティーを編集するために使用することで汎用的な GUI の構築に使用できます。

var scrolling : Vector2;
var rend: Renderer;

function Start() { rend = GetComponent.<Renderer>(); }

function OnGUI () { if (rend.sharedMaterial as ProceduralMaterial) { // Show substance properties inside window var windowRect = new Rect (Screen.width-250, 30, 220, Screen.height-60); GUI.Window (0, windowRect, ProceduralPropertiesGUI, "Procedural Properties"); } }

function ProceduralPropertiesGUI (windowId : int) { scrolling = GUILayout.BeginScrollView (scrolling); var substance = rend.sharedMaterial as ProceduralMaterial; // Get a list of all the Procedural properties var inputs = substance.GetProceduralPropertyDescriptions (); // Iterate through all the properties for (var i : int = 0; i < inputs.Length; i++) { var input = inputs[i]; // Handle the different types of properties var type = input.type; // Show a boolean as a toggle if (type == ProceduralPropertyType.Boolean) { var inputBool = substance.GetProceduralBoolean (input.name); var oldInputBool = inputBool; inputBool = GUILayout.Toggle (inputBool, input.name); if (inputBool != oldInputBool) substance.SetProceduralBoolean (input.name, inputBool); } // Show a float as a slider else if (type == ProceduralPropertyType.Float) { // Only show GUI for numbers with a defined range if (input.hasRange) { GUILayout.Label (input.name); var inputFloat = substance.GetProceduralFloat (input.name); var oldInputFloat = inputFloat; inputFloat = GUILayout.HorizontalSlider (inputFloat, input.minimum, input.maximum); if (inputFloat != oldInputFloat) substance.SetProceduralFloat (input.name, inputFloat); } } // Show a vector as multiple sliders else if (type == ProceduralPropertyType.Vector2 || type == ProceduralPropertyType.Vector3 || type == ProceduralPropertyType.Vector4 ) { // Only show GUI for numbers with a defined range if (input.hasRange) { GUILayout.Label (input.name); // How many components are in this vector? var vectorComponentAmount = 4; if (type == ProceduralPropertyType.Vector2) vectorComponentAmount = 2; if (type == ProceduralPropertyType.Vector3) vectorComponentAmount = 3; var inputVector = substance.GetProceduralVector (input.name); var oldInputVector = inputVector; // Loop through the vector component and show a slider for each for (var c : int = 0; c < vectorComponentAmount; c++) inputVector[c] = GUILayout.HorizontalSlider ( inputVector[c], input.minimum, input.maximum); if (inputVector != oldInputVector) substance.SetProceduralVector (input.name, inputVector); } } // Show a color as multiple sliders else if (type == ProceduralPropertyType.Color3 || type == ProceduralPropertyType.Color4) { GUILayout.Label (input.name); // How many numbers are in this color? var colorComponentAmount = (type == ProceduralPropertyType.Color3 ? 3 : 4); var colorInput = substance.GetProceduralColor (input.name); var oldColorInput = colorInput; // Loop through the vector numbers and show a slider for each for (var d : int = 0; d < colorComponentAmount; d++) colorInput[d] = GUILayout.HorizontalSlider (colorInput[d], 0, 1); if (colorInput != oldColorInput) substance.SetProceduralColor (input.name, colorInput); } // Show an enum as a selection grid else if (type == ProceduralPropertyType.Enum) { GUILayout.Label (input.name); var enumInput = substance.GetProceduralEnum (input.name); var oldEnumInput = enumInput; var enumOptions = input.enumOptions; enumInput = GUILayout.SelectionGrid (enumInput, enumOptions, 1); if (enumInput != oldEnumInput) substance.SetProceduralEnum (input.name, enumInput); } } // Rebuild the textures to show the changes substance.RebuildTextures(); GUILayout.EndScrollView(); }
using UnityEngine;
using System.Collections;

public class ExampleClass2 : MonoBehaviour {

public Vector2 scrolling; public Renderer rend; void Start() { rend = GetComponent<Renderer>(); } void OnGUI() { if (rend.sharedMaterial as ProceduralMaterial) { Rect windowRect = new Rect(Screen.width - 250, 30, 220, Screen.height - 60); GUI.Window(0, windowRect, ProceduralPropertiesGUI, "Procedural Properties"); } } void ProceduralPropertiesGUI(int windowId) { scrolling = GUILayout.BeginScrollView(scrolling); ProceduralMaterial substance = rend.sharedMaterial as ProceduralMaterial; ProceduralPropertyDescription[] inputs = substance.GetProceduralPropertyDescriptions(); // Iterate through all the properties int i = 0; while (i < inputs.Length) { ProceduralPropertyDescription input = inputs[i]; ProceduralPropertyType type = input.type; // Show a boolean as a toggle if (type == ProceduralPropertyType.Boolean) { bool inputBool = substance.GetProceduralBoolean(input.name); bool oldInputBool = inputBool; inputBool = GUILayout.Toggle(inputBool, input.name); if (inputBool != oldInputBool) substance.SetProceduralBoolean(input.name, inputBool); } // Show a float as a slider else if (type == ProceduralPropertyType.Float) { if (input.hasRange) { GUILayout.Label(input.name); float inputFloat = substance.GetProceduralFloat(input.name); float oldInputFloat = inputFloat; inputFloat = GUILayout.HorizontalSlider(inputFloat, input.minimum, input.maximum); if (inputFloat != oldInputFloat) substance.SetProceduralFloat(input.name, inputFloat); } } // Show a vector as multiple sliders else if (type == ProceduralPropertyType.Vector2 || type == ProceduralPropertyType.Vector3 || type == ProceduralPropertyType.Vector4) // Only show GUI for numbers with a defined range if (input.hasRange) { GUILayout.Label(input.name); int vectorComponentAmount = 4; if (type == ProceduralPropertyType.Vector2) vectorComponentAmount = 2; if (type == ProceduralPropertyType.Vector3) vectorComponentAmount = 3; Vector4 inputVector = substance.GetProceduralVector(input.name); Vector4 oldInputVector = inputVector; int c = 0; while (c < vectorComponentAmount) { inputVector[c] = GUILayout.HorizontalSlider(inputVector[c], input.minimum, input.maximum); c++; } if (inputVector != oldInputVector) substance.SetProceduralVector(input.name, inputVector); } else if (type == ProceduralPropertyType.Color3 || type == ProceduralPropertyType.Color4) { GUILayout.Label(input.name); int colorComponentAmount = ((type == ProceduralPropertyType.Color3) ? 3 : 4); Color colorInput = substance.GetProceduralColor(input.name); Color oldColorInput = colorInput; int d = 0; while (d < colorComponentAmount) { colorInput[d] = GUILayout.HorizontalSlider(colorInput[d], 0, 1); d++; } if (colorInput != oldColorInput) substance.SetProceduralColor(input.name, colorInput); } // Show an enum as a selection grid else if (type == ProceduralPropertyType.Enum) { GUILayout.Label(input.name); int enumInput = substance.GetProceduralEnum(input.name); int oldEnumInput = enumInput; string[] enumOptions = input.enumOptions; enumInput = GUILayout.SelectionGrid(enumInput, enumOptions, 1); if (enumInput != oldEnumInput) substance.SetProceduralEnum(input.name, enumInput); } i++; }

// Rebuild the textures to show the changes substance.RebuildTextures(); GUILayout.EndScrollView(); } }