//Runs on Worker Thread:
    public void UpdateSightSourceFov()
    {
        nearbyShroudsInWorkerThread = nextShrouds;

        List <Vector2> inFieldOFVision = new List <Vector2>();

        // Returns all shroud nodes in field of vision
        for (int i = nearbyShroudsInWorkerThread.Count; i-- > 0;)
        {
            ShroudAction sA = new ShroudAction {
                key = nearbyShroudsInWorkerThread[i], enabled = true
            };
            shroudStatusQueue.Enqueue(sA);
            // Light close behind and around
            if (Vector2.Distance(sourcePosCache, nearbyShroudsInWorkerThread[i]) < InnatePreyVision)
            {
                inFieldOFVision.Add(nearbyShroudsInWorkerThread[i]);
                continue;
            }

            // In front cone
            if (Vector3.Angle(
                    new Vector3(nearbyShroudsInWorkerThread[i].x, nearbyShroudsInWorkerThread[i].y, 0f) -
                    sourcePosCache, GetSightSourceDirection()) < FieldOfVision)
            {
                if (i < nearbyShroudsInWorkerThread.Count)
                {
                    inFieldOFVision.Add(nearbyShroudsInWorkerThread[i]);
                }
            }
        }

        // Loop through all tiles that are nearby and are in field of vision
        for (int i = inFieldOFVision.Count; i-- > 0;)
        {
            // There is a slight issue with linecast where objects directly diagonal to you are not hit by the cast
            // and since we are standing next to the tile we should always be able to view it, lets always deactive the shroud
            if (Vector2.Distance(inFieldOFVision[i], sourcePosCache) < 2)
            {
                ShroudAction lA = new ShroudAction {
                    key = inFieldOFVision[i], enabled = false
                };
                shroudStatusQueue.Enqueue(lA);
                continue;
            }
            // Everything else:
            // Perform a linecast to see if a wall is blocking vision of the target tile
            Vector2      offsetPos = ShroudCornerOffset(Angle(((Vector2)sourcePosCache - inFieldOFVision[i]).normalized));
            ShroudAction rA        = new ShroudAction
            {
                isRayCastAction = true,
                endPos          = inFieldOFVision[i] += offsetPos,
                offset          = offsetPos
            };
            shroudStatusQueue.Enqueue(rA);
        }

        inFieldOFVision = null;
    }
示例#2
0
 // This function handles every queued action on the main thread, set by the WT
 private void SetShroudStatus(ShroudAction shroudAction)
 {
     if (shroudAction.isRayCastAction)
     {
         RayCastQueue(shroudAction.endPos, shroudAction.offset);
     }
     else if (shroudTiles.ContainsKey(shroudAction.key))
     {
         shroudTiles[shroudAction.key].SendMessage("SetShroudStatus", shroudAction.enabled, SendMessageOptions.DontRequireReceiver);
     }
 }