Ejemplo n.º 1
0
        private void DrawCurrAssetWindow(int windowID)
        {
            GUI.Box(new Rect(10, 30, 580, 290), ""); // Background

            _currAssetScrollPos = GUI.BeginScrollView(new Rect(10, 30, 580, 290), _currAssetScrollPos,
                                                      new Rect(0, 0, 560, _instancedList.Values.Sum(list => list.Count) * 28 + 5));

            int i = 0;

            foreach (string objectList in _instancedList.Keys)
            {
                foreach (StaticObject sObject in _instancedList[objectList])
                {
                    bool itemMatches = sObject.ObjectID == _currentObjectID;
                    GUI.backgroundColor = new Color(0.3f, itemMatches ? 1f : 0.3f, 0.3f);

                    if (GUI.Button(new Rect(5, (i * 28) + 5, 550, 25),
                                   string.Format("{0} (ID: {1})", sObject.ModelUrl, sObject.ObjectID)))
                    {
                        // Clear text fields.
                        //_visRange = _xScale = _yScale = _zScale = _xPosition = _rPosition = _yPosition = _zPosition = "";
                        _visRange = _xPosition = _rPosition = _yPosition = _zPosition = "";

                        if (itemMatches)
                        {
                            // Deselect
                            if (_currentSelectedObject != null)
                            {
                                _currentSelectedObject.Manipulate(false);
                            }

                            _currentObjectID       = "";
                            _currentSelectedObject = null;
                            _lsNameVisible         = false;
                        }
                        else
                        {
                            // Select
                            if (_currentSelectedObject != null)
                            {
                                _currentSelectedObject.Manipulate(false);
                            }

                            _currentObjectID       = sObject.ObjectID;
                            _currentSelectedObject = sObject;
                            _currentSelectedObject.Manipulate(true);
                        }
                    }
                    i++;
                }
            }
            GUI.EndScrollView();

            GUI.backgroundColor = new Color(0.5f, 0.5f, 0.5f);
            if (GUI.Button(new Rect(120, 335, 60, 25), "Close"))
            {
                _currAssetsVisible = false;
            }

            GUI.backgroundColor = new Color(_currentSelectedObject != null ? 1 : 0, 0, 0);
            if (GUI.Button(new Rect(10, 330, 100, 30), "Delete"))
            {
                if (_currentSelectedObject != null)
                {
                    KtCamera.RestoreCameraParent();
                    //Destroy(_currentSelectedObject.StaticGameObject);
                    DestroySoInstance(_currentSelectedObject);
                    //RemoveCurrentStaticObject(_currentSelectedObject.ModelUrl);
                    _instancedList[_currentSelectedObject.ModelUrl].Remove(_currentSelectedObject);
                }

                _currentObjectID       = "";
                _currentSelectedObject = null;
            }

            GUI.backgroundColor = new Color(0, 0, _currentSelectedObject != null ? 1 : 0);
            if (GUI.Button(new Rect(490, 330, 100, 30), "Initialize"))
            {
                if (_currentSelectedObject != null)
                {
                    InvokeSetup(_currentSelectedObject);
                }
            }

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
Ejemplo n.º 2
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
        }