예제 #1
0
        /// <summary>
        /// Checks if a file or folder at the specified path exists in the library, and if it does generates a new unique
        /// name for the file or folder.
        /// </summary>
        /// <param name="path">Path to the file or folder to generate a unique name.</param>
        /// <returns>New path with the unique name. This will be unchanged from input path if the input path doesn't
        ///          already exist.</returns>
        public static string GetUniquePath(string path)
        {
            string extension = Path.GetExtension(path);
            string pathClean = path;

            if (!String.IsNullOrEmpty(extension))
            {
                pathClean = path.Remove(path.Length - extension.Length);
            }

            int idx          = 0;
            int separatorIdx = pathClean.LastIndexOf('_');

            if (separatorIdx != -1)
            {
                string numberString = pathClean.Substring(separatorIdx + 1, pathClean.Length - (separatorIdx + 1));
                if (int.TryParse(numberString, out idx))
                {
                    pathClean = pathClean.Substring(0, separatorIdx);
                    idx++;
                }
            }

            string destination = path;

            while (ProjectLibrary.Exists(destination))
            {
                destination = pathClean + "_" + idx + extension;
                idx++;
            }

            return(destination);
        }
예제 #2
0
        /// <summary>
        /// Sets a resource whose GUI is to be displayed in the inspector. Clears any previous contents of the window.
        /// </summary>
        /// <param name="resourcePath">Resource path relative to the project of the resource to inspect.</param>
        private void SetObjectToInspect(String resourcePath)
        {
            activeResourcePath = resourcePath;
            if (!ProjectLibrary.Exists(resourcePath))
            {
                return;
            }

            ResourceMeta meta         = ProjectLibrary.GetMeta(resourcePath);
            Type         resourceType = meta.Type;

            currentType = InspectorType.Resource;

            inspectorScrollArea = new GUIScrollArea();
            GUI.AddElement(inspectorScrollArea);
            inspectorLayout = inspectorScrollArea.Layout;

            GUIPanel titlePanel = inspectorLayout.AddPanel();

            titlePanel.SetHeight(RESOURCE_TITLE_HEIGHT);

            GUILayoutY titleLayout = titlePanel.AddLayoutY();

            titleLayout.SetPosition(PADDING, PADDING);

            string name = Path.GetFileNameWithoutExtension(resourcePath);
            string type = resourceType.Name;

            LocString title      = new LocEdString(name + " (" + type + ")");
            GUILabel  titleLabel = new GUILabel(title);

            titleLayout.AddFlexibleSpace();
            GUILayoutX titleLabelLayout = titleLayout.AddLayoutX();

            titleLabelLayout.AddElement(titleLabel);
            titleLayout.AddFlexibleSpace();

            GUIPanel titleBgPanel = titlePanel.AddPanel(1);

            GUITexture titleBg = new GUITexture(null, EditorStylesInternal.InspectorTitleBg);

            titleBgPanel.AddElement(titleBg);

            inspectorLayout.AddSpace(COMPONENT_SPACING);

            inspectorResource       = new InspectorResource();
            inspectorResource.panel = inspectorLayout.AddPanel();

            var persistentProperties = persistentData.GetProperties(meta.UUID.ToString());

            inspectorResource.inspector = InspectorUtility.GetInspector(resourceType);
            inspectorResource.inspector.Initialize(inspectorResource.panel, activeResourcePath, persistentProperties);

            inspectorLayout.AddFlexibleSpace();
        }