Ejemplo n.º 1
0
        public void Manipulate(bool objectInactive, Color highlightColor)
        {
            if (StaticGameObject == null)
            {
                Extensions.LogWarning(NameID + " has no GameObject attached.");
                return;
            }

            #region Colliders

            if (_colliderComponents == null || _colliderComponents.Count == 0)
            {
                Collider[] colliderList = StaticGameObject.GetComponentsInChildren <Collider>();

                if (colliderList.Length > 0)
                {
                    _colliderComponents = new List <Collider>(colliderList);
                }
                else
                {
                    Extensions.LogWarning(NameID + " has no collider components.");
                }
            }

            if (_colliderComponents != null && _colliderComponents.Count > 0)
            {
                foreach (Collider collider in _colliderComponents)
                {
                    collider.enabled = !objectInactive;
                }
            }

            #endregion

            #region Highlight

            if ((_rendererComponents == null || _rendererComponents.Count == 0))
            {
                Renderer[] rendererList = StaticGameObject.GetComponentsInChildren <Renderer>();
                if (rendererList.Length == 0)
                {
                    Extensions.PostScreenMessage("[KerbTown] Active Vessel not within visibility range.");
                    Extensions.LogWarning(NameID + " has no renderer components.");
                    return;
                }
                _rendererComponents = new List <Renderer>(rendererList);
            }

            if (!objectInactive) // Deactivate.
            {
                highlightColor = new Color(0, 0, 0, 0);

                KtCamera.RestoreCameraParent();
            }
            else // Activate
            {
                if (
                    Vector3.Distance(PQSCityComponent.sphere.transform.position, PQSCityComponent.transform.position) >=
                    PQSCityComponent.lod[0].visibleRange)
                {
                    KtCamera.SetCameraParent(StaticGameObject.transform);
                }
                else
                {
                    Extensions.PostScreenMessage(
                        "[KerbTown] Ignoring camera switch. Static object is not within the visible range of your active vessel.");
                }
            }

            foreach (Renderer renderer in _rendererComponents)
            {
                renderer.material.SetFloat("_RimFalloff", 1.8f);
                renderer.material.SetColor("_RimColor", highlightColor);
            }

            #endregion
        }