Search Unity

|= (Pipe Equals) ?

Discussion in 'Scripting' started by Jessy, Apr 26, 2009.

  1. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    What is that? It's used in this script that Joachim Ante wrote.

    Code (csharp):
    1. // Storage for all active visibility culling areas
    2. static var areas = ArrayList();
    3. var alwaysEnabledLayers : LayerMask = 1;
    4. function OnPreCull () {
    5.     // Calculate the culling mask
    6.     // Go through all areas and take the union of all visible layers
    7.     var layerMask = 0;
    8.     var cameraPos = transform.position;
    9.     for (var area : VisibilityCullingArea in areas)
    10.     {
    11.         var areaTransform : Transform = area.transform;
    12.         var relative = areaTransform.InverseTransformPoint(cameraPos);
    13.         var bounds = new Bounds (Vector3.zero, transform.localScale);
    14.         if (bounds.Contains(relative))
    15.         {
    16.             layerMask |= area.visibleLayers.value;
    17.         }
    18.     }
    19.    
    20.     // If we are not in a visibility area. We render everything
    21.     layerMask |= alwaysEnabledLayers.value;
    22.  
    23.     camera.cullingMask = layerMask;
    24. }
     
  2. Charles Hinshaw

    Charles Hinshaw

    Joined:
    Feb 6, 2008
    Posts:
    1,070
    I believe it is a binary operator. The | operator computes the bitwise or logical OR of its operands depending on if the types are integral or boolean.

    Bitwise OR is:

    Code (csharp):
    1.  
    2.    0101
    3. OR 0011
    4. =  0111
    5.  
    In this case, it makes a lot of sense for the masks.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    is also useful (distinct from ).

    Code (csharp):
    1.     0101
    2. AND 0011
    3. =   0001
    --Eric
     
  4. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I took a class in discrete logic about 8 years ago, and remember a smattering of what I learned there, so I understand what is going on in your equations. Thanks for the info. However, the class didn't actually involve computers, just logic theory, so I don't know when I might find these operators useful.
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    if you want to store 8 binary states in a single byte for example to be used in a network viewed environment.