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


C# Operator.SetValue方法代码示例

本文整理汇总了C#中Operator.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Operator.SetValue方法的具体用法?C# Operator.SetValue怎么用?C# Operator.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Operator的用法示例。


在下文中一共展示了Operator.SetValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawNodeInspector

        public static void DrawNodeInspector(Operator op)
        {
            if (_TitleStyle == null) {
                _TitleStyle = new GUIStyle();
                _TitleStyle.fontSize = 16;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(op.Title, _TitleStyle, GUILayout.Width(GraphEditor.SidebarWidth/2-20f));
            if (op.IsGeometryOutput) {
                EditorGUILayout.LabelField("(output)", GUILayout.Width(GraphEditor.SidebarWidth/2-20f));
            } else {
                if (GUILayout.Button("Output")) {
                    foreach (var kvp in GraphEditor.Template.Operators) {
                        kvp.Value.IsGeometryOutput = kvp.Value.GUID == op.GUID;
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            if (op.IsGeometryOutput) {
                EditorGUILayout.LabelField("[Geometry Output]");
            }

            foreach (IOOutlet input in op.Inputs) {

                // Value comes from outlet connection
                foreach (IOConnection conn in GraphEditor.Template.Connections) {
                    if (op.GUID == conn.To.GUID && input.Name == conn.Input.Name) {
                        var valueFrom = System.String.Format("{0}.{1}", conn.From.Title, conn.Output.Name);
                        EditorGUILayout.LabelField(input.Name, valueFrom);
                        continue;
                    }
                }

                // Float input
                if (input.DataType == typeof(System.Single)) {
                    float newValue = EditorGUILayout.FloatField(input.Name, op.GetValue<float>(input));
                    op.SetValue<float>(input, newValue);
                }

                // Integer field
                else if (input.DataType == typeof(System.Int32)) {
                    int newValue = EditorGUILayout.IntField(input.Name, op.GetValue<int>(input));
                    op.SetValue<int>(input, newValue);
                }

                // Boolean input
                else if (input.DataType == typeof(System.Boolean)) {
                    bool newValue = EditorGUILayout.Toggle(input.Name, op.GetValue<bool>(input));
                    op.SetValue<bool>(input, newValue);
                }

                // Enum input
                else if (input.DataType.IsEnum) {
                    if (input.Member is System.Reflection.FieldInfo) {
                        object objValue = ((System.Reflection.FieldInfo) input.Member).GetValue(op);
                        string[] enumNames = System.Enum.GetNames(input.DataType);
                        System.Array enumValues = System.Enum.GetValues(input.DataType);
                        int selectedIndex = System.Array.IndexOf(enumValues, objValue);

                        selectedIndex = EditorGUILayout.Popup(input.Name, selectedIndex, enumNames);

                        ((System.Reflection.FieldInfo) input.Member).SetValue(op, enumValues.GetValue(selectedIndex));
                    } else {
                        Debug.LogFormat("Enum {0} is not a field", input.Name);
                    }
                }

                // Vector2
                else if (input.DataType == typeof(Vector2)) {
                    Vector2 newValue = EditorGUILayout.Vector2Field(input.Name, op.GetValue<Vector2>(input));
                    op.SetValue<Vector2>(input, newValue);
                }

                // Vector3
                else if (input.DataType == typeof(Vector3)) {
                    Vector3 newValue = EditorGUILayout.Vector3Field(input.Name, op.GetValue<Vector3>(input));
                    op.SetValue<Vector3>(input, newValue);
                }

                // Unsupported
                else {
                    EditorGUILayout.LabelField(input.Name, input.DataType.ToString());
                }
            }

            if (GUILayout.Button("Delete Selection")) {
                foreach (var node in GraphEditor.Selection.Nodes) {
                    GraphEditor.Template.RemoveOperator(node.Operator);
                }
                GraphEditor.Selection.Clear();
            }
        }
开发者ID:BrettRToomey,项目名称:forge,代码行数:96,代码来源:OperatorInspector.cs


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