コード例 #1
0
    public override void OnInspectorGUI()
    {
        if (!head)
        {
            return;
        }
        FieldOfViewVisualizer tgt = target as FieldOfViewVisualizer;

        if (tgt == null)
        {
            return;
        }
        EditorGUIUtility.labelWidth = 250.0f;
        EditorGUILayout.BeginVertical();
        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        DrawBox(Color.white, head);
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();

        // Camera check
        if (tgt.GetComponent <Camera>() == null)
        {
            EditorGUILayout.HelpBox("This component must be used on a camera only.", MessageType.Error);
            EditorGUILayout.EndVertical();
            return;
        }
        // Material
        material = EditorGUILayout.ObjectField(new GUIContent("Material", "The override material for the field of view visualizer"), tgt.material, typeof(Material), false) as Material;
        if (tgt.material != material || init)
        {
            tgt.material = material;
            if (tgt.material == null)
            {
                material = tgt.default_material;
            }
                        #if UNITY_EDITOR
            ((MeshRenderer)tgt.fov.GetComponent <MeshRenderer>()).sharedMaterial = material;
                        #else
            ((MeshRenderer)tgt.fov.GetComponent <MeshRenderer>()).material = material;
                        #endif

            init = true;
        }


        EditorGUILayout.EndVertical();
        Repaint();
    }
コード例 #2
0
 void Start()
 {
     visualizer = GetComponent <FieldOfViewVisualizer> ();
 }
    public override void OnInspectorGUI()
    {
        if (!head)
        {
            return;
        }
        FieldOfViewVisualizer tgt = target as FieldOfViewVisualizer;

        if (tgt == null)
        {
            return;
        }
        EditorGUIUtility.labelWidth = 250.0f;
        EditorGUILayout.BeginVertical();
        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        DrawBox(Color.white, head);
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();

        // Camera check
        if (tgt.GetComponent <Camera>() == null)
        {
            EditorGUILayout.HelpBox("This component must be used on a camera only.", MessageType.Error);
            EditorGUILayout.EndVertical();
            return;
        }

        // Get layer for the FOV visualizer
        layerNameForFov = LayerMask.LayerToName(EditorGUILayout.LayerField("Layer ", LayerMask.NameToLayer(tgt.layerNameForFov)));
        if (tgt.layerNameForFov != layerNameForFov || init)
        {
            tgt.layerNameForFov = layerNameForFov;
            tgt.fov.layer       = LayerMask.NameToLayer(layerNameForFov);
            // Set the camera cullingmask to avoid seeing the visualizer through the camera.
            if (layerNameForFov != "Default")
            {
                tgt.GetComponent <Camera>().cullingMask &= ~(1 << LayerMask.NameToLayer(layerNameForFov));
            }
            if (tgt.layerNameForFov == "")
            {
                tgt.layerNameForFov = LayerMask.LayerToName(0);
            }
        }

        // Material
        material = EditorGUILayout.ObjectField(new GUIContent("Material", "The override material for the field of view visualizer"), tgt.material, typeof(Material), false) as Material;
        if (tgt.material != material || init)
        {
            tgt.material = material;
            if (tgt.material == null)
            {
                material = tgt.default_material;
            }
                        #if UNITY_EDITOR
            ((MeshRenderer)tgt.fov.GetComponent <MeshRenderer>()).sharedMaterial = material;
                        #else
            ((MeshRenderer)tgt.fov.GetComponent <MeshRenderer>()).material = material;
                        #endif

            init = true;
        }


        EditorGUILayout.EndVertical();
        Repaint();
    }