コード例 #1
0
        private void CreateSavedComMarker()
        {
            // Do not try to create the marker if it already exisits
            if (null != SavedCoMMarker)
            {
                return;
            }
            // First try to find the camera that will be used to display the marker - it needs a special camera to make it "float"
            Camera markerCam = InFlightMarkerCam.GetMarkerCam();

            // Did we find the camera? If we did then set up the marker object, and idsplkay it via tha camera we found
            if (null == markerCam)
            {
                return;
            }
            // Try to create a game object using our marker mesh
            SavedCoMMarker = Instantiate(GameDatabase.Instance.GetModel("PWBFuelBalancer/Assets/PWBTargetComMarker"));

            // Make it a bit smaller - we need to fix the model for this
            SavedCoMMarker.transform.localScale = Vector3.one * 0.5f;

            // Add a behaviour to it to allow us to control it and link it to the part that is marks the saved CoM position for
            SavedCoMMarker.AddComponent <SavedCoMMarker>();
            // Tell the marker which instance of the PWBFueldBalancingModule it is displaying the set CoM location for (we could have more than one per vessel)
            SavedCoMMarker.GetComponent <SavedCoMMarker>().LinkPart(this);

            // Start the marker visible if it has been set to be visible, or hidden if it is set to be hidden
            SavedCoMMarker.SetActive(MarkerVisible);
            markerCam.enabled = MarkerVisible;

            int layer = (int)(Math.Log(markerCam.cullingMask) / Math.Log(2));

            // print("MarkerCam has cullingMask: " + markerCam.cullingMask + " setting marker to be in layer: " + layer);
            SavedCoMMarker.layer = layer;


            // Do it all again to create a marker for the actual centre of mass (rather than the target) TODO find a way of refactoring this
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            // Try to create a game object using our marker mesh
            ActualCoMMarker = Instantiate(GameDatabase.Instance.GetModel("PWBFuelBalancer/Assets/PWBComMarker"));

            // Make it a bit smaller - we need to fix the model for this
            ActualCoMMarker.transform.localScale = Vector3.one * 0.45f;
            ActualCoMMarker.GetComponent <Renderer>().material.color = Color.yellow;

            // Add a behaviour to it to allow us to control it and link it to the part that is marks the saved CoM position for
            ActualCoMMarker.AddComponent <PwbcoMMarker>();
            // Tell the marker which instance of the PWBFueldBalancingModule it is displaying the set CoM location for (we could have more than one per vessel)
            ActualCoMMarker.GetComponent <PwbcoMMarker>().LinkPart(this);

            // Start the marker visible if it has been set to be visible, or hidden if it is set to be hidden
            ActualCoMMarker.SetActive(MarkerVisible);

            //print("MarkerCam has cullingMask: " + markerCam.cullingMask + " setting marker to be in layer: " + layer);
            ActualCoMMarker.layer = layer;
        }
コード例 #2
0
        internal void CreateMarkers(string msg)
        {
            // Do not try to create the marker if it already exisits
            if (SavedCoMMarker != null)
            {
                return;
            }
            Log.Info("CreateMarkers, msg: " + msg + ", MarkerVisible: " + MarkerVisible);

            // First try to find the camera that will be used to display the marker - it needs a special camera to make it "float"
            Camera markerCam = InFlightMarkerCam.GetMarkerCam();

            if (markerCam == null)
            {
                Log.Error("markerCam is null");
                return;
            }

            // Camera found, now set up the marker object, and display it via tha camera we found

            if (HighLogic.LoadedScene == GameScenes.FLIGHT)
            {
                markerCam.enabled = MarkerVisible;
            }

            int layer = (int)(Math.Log(markerCam.cullingMask) / Math.Log(2));

            // Log.Info("MarkerCam has cullingMask: " + markerCam.cullingMask + " setting marker to be in layer: " + layer);

            ////////////// VVVVV Create Saved CoMMarker VVVVV ///////////////////////////////////////////////////////

            // Try to create a game object using our marker mesh
            SavedCoMMarker = Instantiate(GameDatabase.Instance.GetModel("PWBFuelBalancerRestored/Assets/PWBTargetComMarker"));

            // Make it a bit smaller - we need to fix the model for this
            SavedCoMMarker.transform.localScale = Vector3.one * 0.45f;

            // Add a behaviour to it to allow us to control it and link it to the part that is marks the saved CoM position for
            SavedCoMMarker savedCoMMarkerComponent = SavedCoMMarker.AddComponent <SavedCoMMarker>();

            // Tell the marker which instance of the PWBFueldBalancingModule it is displaying the set CoM location for (we could have more than one per vessel)
            savedCoMMarkerComponent.LinkPart = this;

            // Start the marker visible if it has been set to be visible, or hidden if it is set to be hidden
            SavedCoMMarker.SetActive(MarkerVisible);
            SavedCoMMarker.layer = layer;

            ////////////// ^^^^^ Create Saved CoMMarker ^^^^^ ///////////////////////////////////////////////////////

            ////////////// VVVVV Create Actual CoMMarker VVVVV ///////////////////////////////////////////////////////

            // Do it all again to create a marker for the actual centre of mass (rather than the target) TODO find a way of refactoring this
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            // Try to create a game object using our marker mesh
            ActualCoMMarker = Instantiate(GameDatabase.Instance.GetModel("PWBFuelBalancerRestored/Assets/PWBComMarker"));

            // Make it a bit smaller - we need to fix the model for this
            ActualCoMMarker.transform.localScale = Vector3.one * 0.45f;
            ActualCoMMarker.GetComponent <Renderer>().material.color = Color.yellow;

            // Add a behaviour to it to allow us to control it and link it to the part that is marks the saved CoM position for
            PwbCoMMarker actualCoMMarkerComponent = ActualCoMMarker.AddComponent <PwbCoMMarker>();

            // Tell the marker which instance of the PWBFueldBalancingModule it is displaying the set CoM location for (we could have more than one per vessel)
            actualCoMMarkerComponent.LinkPart = this;

            // Start the marker visible if it has been set to be visible, or hidden if it is set to be hidden
            ActualCoMMarker.SetActive(MarkerVisible);

            //Log.Info("MarkerCam has cullingMask: " + markerCam.cullingMask + " setting marker to be in layer: " + layer);
            ActualCoMMarker.layer = layer;

            ////////////// ^^^^^ Create Actual CoMMarker ^^^^^ ///////////////////////////////////////////////////////

            ////////////// VVVVV Create Actual CoLMarker VVVVV ///////////////////////////////////////////////////////

            // Do it all again to create a marker for the centre of lift  TODO find a way of refactoring this
            // Try to create a game object using our marker mesh
            ActualCoLMarker = Instantiate(GameDatabase.Instance.GetModel("PWBFuelBalancerRestored/Assets/blue/PWBCoLMarker"));

            // Make it a bit smaller - we need to fix the model for this
            ActualCoLMarker.transform.localScale = Vector3.one * 0.45f;
            ActualCoLMarker.GetComponent <Renderer>().material.color = Color.blue;

            // Add a behaviour to it to allow us to control it and link it to the part that is marks the saved CoM position for
            PwbCoLMarker actualCoLMarkerComponent = ActualCoLMarker.AddComponent <PwbCoLMarker>();

            // Tell the marker which instance of the PWBFueldBalancingModule it is displaying the set CoM location for (we could have more than one per vessel)
            actualCoLMarkerComponent.LinkPart = this;

            // Start the marker visible if it has been set to be visible, or hidden if it is set to be hidden
            ActualCoLMarker.SetActive(MarkerVisible);

            //Log.Info("MarkerCam has cullingMask: " + markerCam.cullingMask + " setting marker to be in layer: " + layer);
            ActualCoLMarker.layer = layer;
            ////////////// ^^^^^ Create Actual CoLMarker VVVVV ///////////////////////////////////////////////////////
        }