Beispiel #1
0
        /// <summary>Creates a Button that adds a child object with a Rail component to the game object</summary>
        /// <param name="railManager">The RailManager component selected in the Inspector</param>
        private void AddNewRailButton(RailManager railManager)
        {
            // Disallows rails being added when Editor in Play Mode
            if (EditorApplication.isPlaying)
            {
                GUI.enabled = false;
            }

            // Button to add a rail
            _content = new GUIContent("Add New Rail", "");
            if (GUILayout.Button(_content, GUILayout.Height(24f)))
            {
                // Checks for next available index to append to rail object name
                var railNames = new List <string>();
                for (int i = 0; i < _rails.Count; i++)
                {
                    railNames.Add(_rails[i].gameObject.name);
                }
                var newRailIndex = GUIUtilities.GetUniqueChildObjectIndex(railNames, "Rail ");

                // Adds the rail object
                GUIUtilities.AddRailObjectAsChild(railManager.gameObject, newRailIndex);
                _repaintScene = true;
            }

            if (EditorApplication.isPlaying)
            {
                GUI.enabled = true;
            }
        }
Beispiel #2
0
        /// <summary>Creates a Button that adds a child object with a Trigger component to the game object</summary>
        /// <param name="triggerManager">The TriggerManager component selected in the Inspector</param>
        private void AddNewTriggerButton(TriggerManager triggerManager)
        {
            // Disallows triggers being added when Editor in Play Mode
            if (EditorApplication.isPlaying)
            {
                GUI.enabled = false;
            }

            // Button to add a trigger
            _content = new GUIContent("Add New Trigger", "");
            if (GUILayout.Button(_content, GUILayout.Height(24f)))
            {
                // Checks for next available index to append to trigger object name
                var triggerNames = new List <string>();
                for (int i = 0; i < _triggers.Count; i++)
                {
                    triggerNames.Add(_triggers[i].gameObject.name);
                }
                var newTriggerIndex = GUIUtilities.GetUniqueChildObjectIndex(triggerNames, "Trigger ");

                // Adds the trigger object
                GUIUtilities.AddTriggerObjectAsChild(triggerManager.gameObject, newTriggerIndex);
                _repaintScene = true;
            }

            if (EditorApplication.isPlaying)
            {
                GUI.enabled = true;
            }
        }