Example #1
0
        public override void OnUpdate()
        {
            // Check if we are near a surface feature
            Boolean isNearObject = false;

            Physics.OverlapSphereNonAlloc(FlightGlobals.ship_position, distance, _colliders);
            for (Int32 i = 0; i < _colliders.Length; i++)
            {
                if (_colliders[i] == null)
                {
                    continue;
                }

                if (!_colliders[i].gameObject.activeSelf)
                {
                    continue;
                }

                KopernicusSurfaceObject surfaceObject = _colliders[i].GetComponent <KopernicusSurfaceObject>();
                if (!surfaceObject || !objects.Contains(surfaceObject.objectName))
                {
                    continue;
                }

                isNearObject = true;
                break;
            }

            // Has the value changed?
            if (isNearObject != _isNearObject)
            {
                _targetModule.SendMessage(isNearObject ? "OnObjectInRange" : "OnObjectOutOfRange");
            }

            _isNearObject = isNearObject;

            if (toggles == null)
            {
                return;
            }

            for (Int32 i = 0; i < toggles.Count; i++)
            {
                if (_targetModule.Events[toggles[i]] != null)
                {
                    _targetModule.Events[toggles[i]].guiActive = _isNearObject;
                }
                if (_targetModule.Actions[toggles[i]] != null)
                {
                    _targetModule.Actions[toggles[i]].active = _isNearObject;
                }
                if (_targetModule.Fields[toggles[i]] != null)
                {
                    _targetModule.Fields[toggles[i]].guiActive = _isNearObject;
                }
            }
        }
        public override void OnUpdate()
        {
            // Check if we are near one
            Boolean isNearObject = false;

            Physics.OverlapSphereNonAlloc(FlightGlobals.ship_position, distance, _colliders);
            for (Int32 i = 0; i < _colliders.Length; i++)
            {
                if (_colliders[i] == null)
                {
                    continue;
                }

                if (!_colliders[i].gameObject.activeSelf)
                {
                    continue;
                }

                KopernicusSurfaceObject surfaceObject = _colliders[i].GetComponent <KopernicusSurfaceObject>();
                if (!surfaceObject || surfaceObject.objectName != objectName)
                {
                    continue;
                }

                isNearObject = true;
                break;
            }

            // Has the value changed?
            if (isNearObject != _isNearObject)
            {
                _targetModule.SendMessage(isNearObject ? "OnObjectInRange" : "OnObjectOutOfRange", objectName);
            }

            _isNearObject = isNearObject;

            if (_toggle == null)
            {
                return;
            }

            for (Int32 i = 0; i < _toggle.Count; i++)         //iterate through all the toggless
            {
                if (_targetModule.Events[_toggle[i]] != null) //if it is an event, enable the gui if we are near the scatter
                {
                    _targetModule.Events[_toggle[i]].guiActive = _isNearObject;
                }
                if (_targetModule.Actions[_toggle[i]] != null) //if it is an action, activate it if we are near the scatter
                {
                    _targetModule.Actions[_toggle[i]].active = _isNearObject;
                }
                if (_targetModule.Fields[_toggle[i]] != null) //if it is a field, show it if we are near the scatter
                {
                    _targetModule.Fields[_toggle[i]].guiActive = _isNearObject;
                }
            }
        }
        public override void OnUpdate()
        {
            // Find all active surface objects
            KopernicusSurfaceObject surfaceObject =
                FlightGlobals.currentMainBody.pqsController.GetComponentsInChildren <KopernicusSurfaceObject>(false)
                .First(m => m.objectName == objectName);

            // Check if we are near one
            Boolean isNearObject = false;

            Physics.OverlapSphereNonAlloc(FlightGlobals.ship_position, distance, _colliders);
            for (Int32 i = 0; i < _colliders.Length; i++)
            {
                if (_colliders[i] == null)
                {
                    continue;
                }

                if (!_colliders[i].gameObject.activeSelf)
                {
                    continue;
                }

                if (_colliders[i].transform.parent != surfaceObject.transform)
                {
                    continue;
                }

                isNearObject = true;
                break;
            }

            // Has the value changed?
            if (isNearObject != _isNearObject)
            {
                if (isNearObject)
                {
                    _targetModule.SendMessage("OnObjectInRange", surfaceObject);
                }
                else
                {
                    _targetModule.SendMessage("OnObjectOutOfRange", objectName);
                }
            }

            _isNearObject = isNearObject;

            if (_toggle == null)
            {
                return;
            }

            for (Int32 i = 0; i < _toggle.Count; i++)
            {
                if (_targetModule.Events[_toggle[i]] != null)
                {
                    _targetModule.Events[_toggle[i]].guiActive = _isNearObject;
                }
                if (_targetModule.Actions[_toggle[i]] != null)
                {
                    _targetModule.Actions[_toggle[i]].active = _isNearObject;
                }
                if (_targetModule.Fields[_toggle[i]] != null)
                {
                    _targetModule.Fields[_toggle[i]].guiActive = _isNearObject;
                }
            }
        }