Esempio n. 1
0
    // once per frame, after physics update
    private void LateUpdate()
    {
        if (localPlayerFlow.isLocalPlayer)
        {
            List <CombatFlow> flowArray = CombatFlow.combatUnits;

            // Loop through all combatUnits
            for (int i = 0; i < CombatFlow.combatUnits.Count; i++)
            {
                if (flowArray[i] != null)
                {
                    // Current CombatFlow to attempt to see
                    CombatFlow currentFlow = flowArray[i];


                    if (currentFlow != null)
                    {
                        TgtHudIcon currentFlowHudIcon = currentFlow.myHudIconRef;

                        if (currentFlowHudIcon != null)
                        {
                            //  =====================  DISTANCE

                            // Distance between this gameobject and target
                            currentFlowHudIcon.currentDistance = Vector3.Distance(currentFlow.transform.position, transform.position);

                            // ======================== LINE OF SIGHT
                            int terrainLayer = 1 << 10; // line only collides with terrain layer
                            currentFlowHudIcon.hasLineOfSight = !Physics.Linecast(transform.position, currentFlow.transform.position, terrainLayer);


                            // ========================  IFF
                            currentFlowHudIcon.isFriendly = localPlayerFlow.team == currentFlow.team;

                            //{ // debug block

                            //    Weapon currentWeap = currentFlow.GetComponent<Weapon>();
                            //    if(currentWeap != null && currentFlow.localOwned)
                            //    {
                            //        Debug.LogWarning(currentFlow.gameObject.name + "'s team is: " + currentFlow.team + ", local player's is : "
                            //            + localPlayerFlow.team);
                            //    }

                            //}


                            // =====================  VISIBILITY

                            // Various conditions will attempt to make this true
                            bool isVisible = false;



                            // Show unit if this is NOT the local player
                            if (!currentFlow.isLocalPlayer && currentFlow.isActive)
                            {
                                if (currentFlow.team == localPlayerFlow.team)
                                {
                                    isVisible = true;
                                }
                                else
                                {
                                    isVisible = Vector3.Distance(currentFlow.transform.position, transform.position) < visibleRange &&
                                                currentFlow.myHudIconRef.hasLineOfSight;
                                    if (!isVisible)
                                    {
                                        isVisible = myRadar.tryDetect(currentFlow);
                                    }
                                }
                            }

                            // if nonfriendly
                            if (currentFlow.team != localPlayerFlow.team && currentFlow.type != CombatFlow.Type.PROJECTILE)
                            {
                                if (isVisible)
                                {
                                    currentFlow.tryAddSeenBy(localPlayerFlow.photonView.ViewID);
                                }
                                else
                                {
                                    currentFlow.tryRemoveSeenBy(localPlayerFlow.photonView.ViewID);
                                }

                                currentFlowHudIcon.dataLink = currentFlow.checkSeen(localPlayerFlow.photonView.ViewID);
                            }

                            //  Send visibility result
                            currentFlowHudIcon.isDetected = isVisible;

                            if (isVisible && prevTarget != null && currentFlow == prevTarget && currentTarget == null)
                            {
                                currentTarget = currentFlow;
                                TgtHudIcon newTargetHudIcon = currentTarget.myHudIconRef;
                                newTargetHudIcon.targetedState = TgtHudIcon.TargetedState.TARGETED;
                                hudControl.mainHud.GetComponent <hudControl>().mapManager.target = currentTarget.transform;
                            }

                            //canShowCurrentTarget = isVisible;

                            if (!isVisible && !currentFlowHudIcon.dataLink && currentTarget == currentFlow)
                            {
                                currentTarget.myHudIconRef.targetedState = TgtHudIcon.TargetedState.NONE;
                                currentTarget = null;
                                //canShowCurrentTarget = false;
                                hudControl.mainHud.GetComponent <hudControl>().mapManager.target = null;
                                playerInput.cam.lookAtObj = null;
                            }

                            // ========= TRY TO LOCK
                            tryLockTarget(currentFlow);
                        }
                    }
                }
            }
        }
    }