Beispiel #1
0
        void comButtonClick()
        {
            if (RCSBuildAid.Enabled)
            {
                /* plugin enabled, CoM button is for toggle marker visibility */
                bool visible = !CoM.GetComponent <MarkerVisibility> ().GeneralToggle;
                CoM.GetComponent <MarkerVisibility> ().GeneralToggle  = visible;
                DCoM.GetComponent <MarkerVisibility> ().GeneralToggle = visible;
                ACoM.GetComponent <MarkerVisibility> ().GeneralToggle = visible;

                /* we need the CoM to remain active, but we can't stop the editor from
                 * deactivating it when the CoM toggle button is used, so we toggle it now so is
                 * toggled again by the editor. That way it will remain active. */

                Log.Info("comButtonClick, setting to: " + !CoM.activeInHierarchy);
                CoM.SetActive(!CoM.activeInHierarchy);
            }

            if (!RCSBuildAid.Enabled)
            {
                /* restore CoM visibility, so the regular CoM toggle button works. */
                var markerVisibility = CoM.GetComponent <MarkerVisibility> ();
                if (markerVisibility != null)
                {
                    markerVisibility.Show();
                }
            }
        }
        void comButtonClick()
        {
            bool markerEnabled = !CoM.activeInHierarchy; /* toggle com */

            if (userEnable)
            {
                bool visible = !CoM.GetComponent <MarkerVisibility> ().GeneralToggle;
                CoM.GetComponent <MarkerVisibility> ().GeneralToggle  = visible;
                DCoM.GetComponent <MarkerVisibility> ().GeneralToggle = visible;
                ACoM.GetComponent <MarkerVisibility> ().GeneralToggle = visible;

                /* we need the CoM to remain active, but we can't stop the editor from
                 * deactivating it when the CoM toggle button is used, so we toggle it now so is
                 * toggled again by the editor. That way it will remain active. */
                CoM.SetActive(markerEnabled);
            }

            if (!userEnable && markerEnabled)
            {
                /* restore CoM visibility, so the regular CoM toggle button works. */
                var markerVisibility = CoM.GetComponent <MarkerVisibility> ();
                if (markerVisibility != null)
                {
                    markerVisibility.Show();
                }
            }
        }
        void setupMarker()
        {
            /* get CoM */
            if (vesselOverlays.CoMmarker == null)
            {
                gameObject.SetActive(false);
                throw new Exception("CoM marker is null, this shouldn't happen.");
            }
            CoM = vesselOverlays.CoMmarker.gameObject;

            /* init DCoM */
            DCoM = (GameObject)UnityEngine.Object.Instantiate(CoM);
            Destroy(DCoM.GetComponent <EditorMarker_CoM> ());           /* we don't need this */
            DCoM.name = "DCoM Marker";
            if (DCoM.transform.childCount > 0)
            {
                /* Stock CoM doesn't have any attached objects, if there's some it means
                 * there's a plugin doing the same thing as us. We don't want extra
                 * objects */
                for (int i = 0; i < DCoM.transform.childCount; i++)
                {
                    Destroy(DCoM.transform.GetChild(i).gameObject);
                }
            }

            /* init ACoM */
            ACoM      = (GameObject)UnityEngine.Object.Instantiate(DCoM);
            ACoM.name = "ACoM Marker";

            /* init CoD */
            CoD = (GameObject)UnityEngine.Object.Instantiate(DCoM);

            referenceDict[MarkerType.CoM]  = CoM;
            referenceDict[MarkerType.DCoM] = DCoM;
            referenceDict[MarkerType.ACoM] = ACoM;

            /* CoM setup, replace stock component with our own */
            CoMMarker comMarker = CoM.AddComponent <CoMMarker> ();

            comMarker.posMarkerObject = vesselOverlays.CoMmarker.posMarkerObject;
            Destroy(vesselOverlays.CoMmarker);
            vesselOverlays.CoMmarker = comMarker;

            /* setup DCoM */
            DCoMMarker dcomMarker = DCoM.AddComponent <DCoMMarker> (); /* we do need this    */

            dcomMarker.posMarkerObject = DCoM;

            /* setup ACoM */
            var acomMarker = ACoM.AddComponent <AverageMarker> ();

            acomMarker.posMarkerObject = ACoM;
            acomMarker.CoM1            = comMarker;
            acomMarker.CoM2            = dcomMarker;

            /* setup CoD */
            var codMarker = CoD.AddComponent <CoDMarker> ();

            codMarker.posMarkerObject = CoD;
            CoD.SetActive(false);

            var obj = new GameObject("Vessel Forces Object");

            obj.layer    = CoM.layer;
            vesselForces = obj.AddComponent <MarkerForces> ();
            SetReferenceMarker(ReferenceType);

            /* scaling for CoL and CoT markers */
            vesselOverlays.CoLmarker.gameObject.AddComponent <MarkerScaler> ();
            vesselOverlays.CoTmarker.gameObject.AddComponent <MarkerScaler> ();

            /* attach our method to the CoM toggle button */
            vesselOverlays.toggleCoMbtn.AddValueChangedDelegate(delegate { comButtonClick(); });
        }