Example #1
0
 // Unique functions
 /// <summary>
 /// 全ての子オブジェクトに対して処理を実行します。
 /// </summary>
 public static void ForeachChild(this UnityEngine.GameObject obj, Action<UnityEngine.GameObject> func)
 {
     for (int i = 0; i < obj.GetChildCount(); ++i)
     {
         func(obj.GetChild(i));
     }
 }
Example #2
0
 /// <summary>
 /// 子オブジェクトの内<T>がアタッチされている全てオブジェクトに対して処理を実行します。
 /// </summary>
 public static void ForeachChild<T>(this UnityEngine.GameObject obj, Action<T> func)
 {
     for (int i = 0; i < obj.GetChildCount(); ++i)
     {
         T ty = obj.GetChild(i).GetComponent<T>();
         if (ty != null)
         {
             func(ty);
         }
     }
 }
 static int GetChild(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.GameObject obj = (UnityEngine.GameObject)ToLua.CheckObject(L, 1, typeof(UnityEngine.GameObject));
         int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         UnityEngine.GameObject o = obj.GetChild(arg0);
         ToLua.PushSealed(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="prefab"></param>
        public PropertySlider(WingProperty propRef, Color foreColour, Action<float> onChange)
        {
            propertyInstance = UnityEngine.Object.Instantiate(StaticWingGlobals.UI_PropertyPrefab);

            inputSlider = propertyInstance.GetChild("InputSlider").GetComponent<Slider>();
            inputSlider.fillRect.GetComponent<Image>().color = foreColour;

            propertyLabel = inputSlider.gameObject.GetChild("PropertyLabel").GetComponent<Text>();
            propertyLabel.text = propRef.name;
            input = inputSlider.gameObject.GetChild("UserInput").GetComponent<InputField>();

            Refresh(propRef);

            input.onValueChange.AddListener(TextValueChanged);
            inputSlider.onValueChanged.AddListener(SliderValueChanged);
            onValueChanged += onChange;
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public EditorWindow()
        {
            // get references to all useful components
            canvas = UnityEngine.Object.Instantiate(StaticWingGlobals.UI_WindowPrefab.GetComponent<Canvas>());
            canvas.enabled = false;

            mainPanel = canvas.gameObject.GetChild("MainPanel");
            windowPosition = mainPanel.GetComponent<RectTransform>();
            GameObject headerPanel = mainPanel.GetChild("HeaderPanel");
            wingType = headerPanel.GetChild("WingType").GetComponent<Text>();
            lastModifiedProperty = headerPanel.GetChild("LastModifiedProperty").GetComponent<Text>();
            lastModifiedPropertyTooltip = headerPanel.GetChild("LastModifiedPropertyToolTip").GetComponent<Text>();
            closeButton = headerPanel.GetChild("CloseButton").GetComponent<Button>();

            // window position drag event
            EventTrigger.Entry entry = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.Drag;
            entry.callback = new EventTrigger.TriggerEvent();
            entry.callback.AddListener((x) => windowDrag(x));
            mainPanel.GetComponent<EventTrigger>().triggers.Add(entry);

            // close button click hides the window
            closeButton.onClick.AddListener(closeWindow);
        }
        public void Start()
        {
            LoggingUtil.LogVerbose(this, "Start");

            // Don't run if not in career
            if (HighLogic.CurrentGame.Mode != Game.Modes.CAREER)
            {
                LoggingUtil.LogDebug(this, "Destroying TrackingStationUI - not in career mode.");
                Destroy(this);
                return;
            }

            // Get the last button in the list to use as a copy
            MapViewFiltering.FilterButton lastButton = MapViewFiltering.Instance.FilterButtons.Last();

            // Create our copies
            activeWaypointButton = UnityEngine.Object.Instantiate(lastButton.button.gameObject);
            activeWaypointButton.name = "Button Active Waypoints";
            offeredWaypointButton = UnityEngine.Object.Instantiate(lastButton.button.gameObject);
            offeredWaypointButton.name = "Button Offered Waypoints";
            activeOrbitButton = UnityEngine.Object.Instantiate(lastButton.button.gameObject);
            activeOrbitButton.name = "Button Active Orbits";
            offeredOrbitButton = UnityEngine.Object.Instantiate(lastButton.button.gameObject);
            offeredOrbitButton.name = "Button Offered Orbits";

            // Fix z coordinates
            activeWaypointButton.GetComponent<RectTransform>().SetLocalPositionZ(750);
            offeredWaypointButton.GetComponent<RectTransform>().SetLocalPositionZ(750);
            activeOrbitButton.GetComponent<RectTransform>().SetLocalPositionZ(750);
            offeredOrbitButton.GetComponent<RectTransform>().SetLocalPositionZ(750);

            // Set up the tool-tips
            activeWaypointButton.GetComponent<TooltipController_Text>().textString = "Toggle Active Waypoints";
            offeredWaypointButton.GetComponent<TooltipController_Text>().textString = "Toggle Offered Waypoints";
            activeOrbitButton.GetComponent<TooltipController_Text>().textString = "Toggle Active Orbits";
            offeredOrbitButton.GetComponent<TooltipController_Text>().textString = "Toggle Offered Orbits";

            // Setup the button
            TrackingStationObjectButton activeWaypointTSButton = activeWaypointButton.GetComponent<TrackingStationObjectButton>();
            TrackingStationObjectButton offeredWaypointTSButton = offeredWaypointButton.GetComponent<TrackingStationObjectButton>();
            TrackingStationObjectButton activeOrbitTSButton = activeOrbitButton.GetComponent<TrackingStationObjectButton>();
            TrackingStationObjectButton offeredOrbitTSButton = offeredOrbitButton.GetComponent<TrackingStationObjectButton>();

            // Setup handlers
            activeWaypointTSButton.OnClickLeft.AddListener(new UnityAction(ActiveWaypointButtonClick));
            activeWaypointTSButton.OnClickRight.AddListener(new UnityAction(ActiveWaypointButtonClick));
            offeredWaypointTSButton.OnClickLeft.AddListener(new UnityAction(OfferedWaypointButtonClick));
            offeredWaypointTSButton.OnClickRight.AddListener(new UnityAction(OfferedWaypointButtonClick));
            activeOrbitTSButton.OnClickLeft.AddListener(new UnityAction(ActiveOrbitButtonClick));
            activeOrbitTSButton.OnClickRight.AddListener(new UnityAction(ActiveOrbitButtonClick));
            offeredOrbitTSButton.OnClickLeft.AddListener(new UnityAction(OfferedOrbitButtonClick));
            offeredOrbitTSButton.OnClickRight.AddListener(new UnityAction(OfferedOrbitButtonClick));

            // Setup sprites
            activeWaypointTSButton.spriteTrue = activeWaypointEnabledSprite;
            activeWaypointTSButton.spriteFalse = activeWaypointDisabledSprite;
            offeredWaypointTSButton.spriteTrue = offeredWaypointEnabledSprite;
            offeredWaypointTSButton.spriteFalse = offeredWaypointDisabledSprite;
            activeOrbitTSButton.spriteTrue = activeOrbitEnabledSprite;
            activeOrbitTSButton.spriteFalse = activeOrbitDisabledSprite;
            offeredOrbitTSButton.spriteTrue = offeredOrbitEnabledSprite;
            offeredOrbitTSButton.spriteFalse = offeredOrbitDisabledSprite;

            // Set defaults
            ContractConfiguratorParameters parms = HighLogic.CurrentGame.Parameters.CustomParams<ContractConfiguratorParameters>();
            activeWaypointButton.GetComponent<TrackingStationObjectButton>().SetState(parms.DisplayActiveWaypoints);
            offeredWaypointButton.GetComponent<TrackingStationObjectButton>().SetState(parms.DisplayOfferedWaypoints);
            activeOrbitButton.GetComponent<TrackingStationObjectButton>().SetState(parms.DisplayActiveOrbits);
            offeredOrbitButton.GetComponent<TrackingStationObjectButton>().SetState(parms.DisplayOfferedOrbits);

            // Disable counts
            activeWaypointButton.GetChild("Count").SetActive(false);
            offeredWaypointButton.GetChild("Count").SetActive(false);
            activeOrbitButton.GetChild("Count").SetActive(false);
            offeredOrbitButton.GetChild("Count").SetActive(false);

            // Re-parent
            GameObject trackingFilters = lastButton.button.transform.parent.gameObject;
            RectTransform trackingFiltersRect = trackingFilters.GetComponent<RectTransform>();
            trackingFiltersRect.sizeDelta = new Vector2(trackingFiltersRect.sizeDelta.x + 44 * 2, trackingFiltersRect.sizeDelta.y);
            activeWaypointButton.transform.SetParent(trackingFilters.transform);
            offeredWaypointButton.transform.SetParent(trackingFilters.transform);
            activeOrbitButton.transform.SetParent(trackingFilters.transform);
            offeredOrbitButton.transform.SetParent(trackingFilters.transform);
            activeWaypointButton.SetActive(true);
            offeredWaypointButton.SetActive(true);
            activeOrbitButton.SetActive(true);
            offeredOrbitButton.SetActive(true);

            // Move the commNet button
            GameObject commNet = trackingFilters.transform.parent.gameObject.GetChild("CommNetVisualisation");
            if (commNet != null)
            {
                RectTransform r = commNet.GetComponent<RectTransform>();
                r.localPosition = new Vector3(r.localPosition.x + 132, r.localPosition.y);
            }

            LoggingUtil.LogVerbose(this, "Finished setup");
        }
Example #7
0
        /// <summary>
        /// Constructor
        /// </summary>
        public EditorWindow(string title)
        {
            // get references to all useful components
            go = Object.Instantiate(StaticWingGlobals.UI_WindowPrefab);
            go.transform.SetParent(KSP.UI.UIMasterController.Instance.appCanvas.transform, false);
            canvas = go.GetComponent<Canvas>();

            mainPanel = canvas.gameObject.GetChild("MainPanel");
            windowPosition = mainPanel.GetComponent<RectTransform>();
            GameObject headerPanel = mainPanel.GetChild("HeaderPanel");
            wingType = headerPanel.GetChild("WingType").GetComponent<Text>();
            lastModifiedProperty = headerPanel.GetChild("LastModifiedProperty").GetComponent<Text>();
            lastModifiedPropertyTooltip = headerPanel.GetChild("LastModifiedPropertyToolTip").GetComponent<Text>();
            closeButton = headerPanel.GetChild("CloseButton").GetComponent<Button>();

            // window position drag event
            EventTrigger.Entry dragEntry = new EventTrigger.Entry();
            dragEntry.eventID = EventTriggerType.Drag;
            dragEntry.callback = new EventTrigger.TriggerEvent();
            dragEntry.callback.AddListener((x) => windowDrag(x));
            mainPanel.GetComponent<EventTrigger>().triggers.Add(dragEntry);

            // close button click hides the window
            closeButton.onClick.AddListener(closeWindow);
            Visible = false;

            WindowTitle = title;
        }