本文整理汇总了C#中UnityEditor.SerializedObject.GetArrayElementAtIndex方法的典型用法代码示例。如果您正苦于以下问题:C# SerializedObject.GetArrayElementAtIndex方法的具体用法?C# SerializedObject.GetArrayElementAtIndex怎么用?C# SerializedObject.GetArrayElementAtIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEditor.SerializedObject
的用法示例。
在下文中一共展示了SerializedObject.GetArrayElementAtIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
static void Build()
{
var layerNames = new List<string>();
var objs = Resources.FindObjectsOfTypeAll<Object>();
var sortingLayers = new List<string>();
var inputNames = new List<string>();
var navMeshLayers = new List<string>();
foreach (var obj in objs)
{
switch (obj.name)
{
case "InputManager":
{
var axesProperty = new SerializedObject(obj).FindProperty("m_Axes");
for (var j = 0; j < axesProperty.arraySize; j++)
{
inputNames.Add(axesProperty.GetArrayElementAtIndex(j).FindPropertyRelative("m_Name").stringValue);
}
}
break;
case "TagManager":
{
var sortinglayersProperty = new SerializedObject(obj).FindProperty("m_SortingLayers");
for (var j = 0; j < sortinglayersProperty.arraySize; j++)
{
sortingLayers.Add(sortinglayersProperty.GetArrayElementAtIndex(j).FindPropertyRelative("name").stringValue);
}
}
break;
case "NavMeshLayers":
{
var navMeshlayersObject = new SerializedObject(obj);
for (var j = 0; j < 3; j++)
{
navMeshLayers.Add(navMeshlayersObject.FindProperty("Built-in Layer " + j).FindPropertyRelative("name").stringValue);
}
for (var j = 0; j < 28; j++)
{
navMeshLayers.Add(navMeshlayersObject.FindProperty("User Layer " + j).FindPropertyRelative("name").stringValue);
}
}
break;
}
}
for (var i = 0; i < 32; i++)
{
layerNames.Add(LayerMask.LayerToName(i));
}
AssetDatabase.StartAssetEditing();
{
Build("Tag", InternalEditorUtility.tags);
Build("Layer", layerNames.ToArray());
Build("SortingLayer", sortingLayers.ToArray());
Build("NavMeshLayer", navMeshLayers.ToArray());
Build("Input", inputNames.ToArray());
Build("Scene", EditorBuildSettings.scenes.Where(scene => scene.enabled).Select<EditorBuildSettingsScene, string>(scene => Path.GetFileNameWithoutExtension(scene.path)).ToArray());
}
AssetDatabase.StopAssetEditing();
EditorUtility.UnloadUnusedAssetsImmediate();
AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);
}
示例2: GenerateFields
static string GenerateFields(string indent, Options options)
{
var lines = new List<string> (128);
var uniquesList = new HashSet<string> ();
// layers, layer masks
if ((int) (options & Options.Layers) != 0) {
foreach (var layerName in InternalEditorUtility.layers) {
lines.Add (string.Format (LayerName, indent, CleanupName (layerName), CleanupValue (layerName)));
lines.Add (string.Format (LayerMask, indent, CleanupName (layerName)));
}
}
// tags
if ((int) (options & Options.Tags) != 0) {
foreach (var tagName in InternalEditorUtility.tags) {
lines.Add (string.Format (TagName, indent, CleanupName (tagName), CleanupValue (tagName)));
}
}
// scenes
if ((int) (options & Options.Scenes) != 0) {
foreach (var scene in EditorBuildSettings.scenes) {
var sceneName = Path.GetFileNameWithoutExtension (scene.path);
lines.Add (string.Format (SceneName, indent, CleanupName (sceneName), CleanupValue (sceneName)));
}
}
// animators
if ((int) (options & Options.Animators) != 0) {
foreach (var guid in AssetDatabase.FindAssets ("t:animatorcontroller")) {
var assetPath = AssetDatabase.GUIDToAssetPath (guid);
var ac = AssetDatabase.LoadAssetAtPath<UnityEditor.Animations.AnimatorController> (assetPath);
for (int i = 0, iMax = ac.parameters.Length; i < iMax; i++) {
var name = ac.parameters[i].name;
if (!uniquesList.Contains (name)) {
lines.Add (string.Format (AnimatorName, indent, CleanupName (name), CleanupValue (name)));
uniquesList.Add (name);
}
}
}
uniquesList.Clear ();
}
// axes
if ((int) (options & Options.Axes) != 0) {
var inputManager = AssetDatabase.LoadAllAssetsAtPath ("ProjectSettings/InputManager.asset")[0];
var axes = new SerializedObject (inputManager).FindProperty ("m_Axes");
for (int i = 0, iMax = axes.arraySize; i < iMax; i++) {
var axis = axes.GetArrayElementAtIndex (i).FindPropertyRelative ("m_Name").stringValue;
if (!uniquesList.Contains (axis)) {
lines.Add (string.Format (AxisName, indent, CleanupName (axis), CleanupValue (axis)));
uniquesList.Add (axis);
}
}
uniquesList.Clear ();
}
// shaders
if ((int) (options & Options.Shaders) != 0) {
foreach (var guid in AssetDatabase.FindAssets ("t:shader")) {
var assetPath = AssetDatabase.GUIDToAssetPath (guid);
var shader = AssetDatabase.LoadAssetAtPath<Shader> (assetPath);
if (shader.name.IndexOf ("Hidden") != 0) {
for (int i = 0, iMax = ShaderUtil.GetPropertyCount (shader); i < iMax; i++) {
if (!ShaderUtil.IsShaderPropertyHidden (shader, i)) {
var name = ShaderUtil.GetPropertyName (shader, i);
if (!uniquesList.Contains (name)) {
lines.Add (string.Format (ShaderName, indent, CleanupName (name), CleanupValue (name)));
uniquesList.Add (name);
}
}
}
}
}
uniquesList.Clear ();
}
lines.Sort ();
return string.Join ("\n\n", lines.ToArray ());
}