当前位置: 首页>>代码示例>>C#>>正文


C# SerializedObject.GetArrayElementAtIndex方法代码示例

本文整理汇总了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);
    }
开发者ID:uxtuno,项目名称:SilverShip,代码行数:71,代码来源:NameCreator.cs

示例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 ());
        }
开发者ID:Leopotam,项目名称:LeopotamGroupLibraryUnity,代码行数:81,代码来源:UnityIdentsGenerator.cs


注:本文中的UnityEditor.SerializedObject.GetArrayElementAtIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。