Ejemplo n.º 1
0
        public void GameSettings_FilePathAttribute_ShouldMatch()
        {
            GameSettings      settings = new GameSettings();
            FilePathAttribute attr     = (FilePathAttribute)settings.GetType().GetCustomAttribute(typeof(FilePathAttribute));

            Assert.AreEqual(attr.FilePath, "./Settings/Game.settings");
        }
Ejemplo n.º 2
0
        public void FilePathAttribute_OnInstantiate_ShouldSetFilePath()
        {
            string            filePath = "this is a fake file path";
            FilePathAttribute attr     = new FilePathAttribute(filePath);

            Assert.AreEqual(attr.FilePath, filePath);
        }
    // Draw the property inside the given rect
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        // First get the attribute since it contains the range for the slider
        FilePathAttribute attr = (FilePathAttribute)attribute;

        EditorGUI.BeginProperty(position, label, property);

        var padding = 10;

        //EditorGUILayout.BeginHorizontal();
        var btnWidth = position.height * 3;

        Rect rect = position;

        rect.width          -= btnWidth + padding;
        property.stringValue = EditorGUI.TextField(rect, property.name, property.stringValue);

        Rect r2 = new Rect(rect.width + padding * 2, rect.y, btnWidth, rect.height);

        if (GUI.Button(r2, "find"))
        {
            var fullPath = EditorUtility.OpenFilePanel(property.name, "", attr.Ext);
            if (string.IsNullOrEmpty(fullPath) == false)
            {
                var uriA         = new Uri(Application.dataPath);
                var uriB         = new Uri(fullPath);
                var relativePath = uriA.MakeRelativeUri(uriB);
                property.stringValue = relativePath.ToString();
                property.serializedObject.ApplyModifiedProperties();
            }
        }

        EditorGUI.EndProperty();
    }
Ejemplo n.º 4
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.propertyType != SerializedPropertyType.String)
        {
            EditorGUI.HelpBox(position, "This attribute is a string only.", MessageType.Error);
            return;
        }

        EditorGUI.BeginProperty(position, label, property);

        Rect buttonPosition = new Rect(position.x + position.width - 30, position.y, 30, position.height);
        Rect textPosition   = new Rect(position.x, position.y, position.width - buttonPosition.width - 5, position.height);

        EditorGUI.TextField(textPosition, label, property.stringValue);

        if (GUI.Button(buttonPosition, "..."))
        {
            string dirpath = "";
            // ファイルが存在していたら、そのディレクトリを開く
            if (System.IO.File.Exists(property.stringValue))
            {
                dirpath = System.IO.Path.GetDirectoryName(property.stringValue);
            }

            FilePathAttribute filepath = (FilePathAttribute)attribute;
            string            path     = EditorUtility.OpenFilePanel("select file", dirpath, filepath.extensionFilter);
            if (false == string.IsNullOrEmpty(path))
            {
                // ファイルが選択されていたらそれを反映させる
                property.stringValue = path;
            }
        }

        EditorGUI.EndProperty();
    }
Ejemplo n.º 5
0
    // Draw the property inside the given rect
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        // First get the attribute since it contains the range for the slider
        FilePathAttribute attr = (FilePathAttribute)attribute;

        EditorGUI.BeginProperty(position, label, property);

        var padding = 10;

        //EditorGUILayout.BeginHorizontal();
        var btnWidth = position.height * 3;

        Rect rect = position;

        rect.width          -= btnWidth + padding;
        property.stringValue = EditorGUI.TextField(rect, property.name, property.stringValue);

        Rect r2 = new Rect(rect.width + padding * 2, rect.y, btnWidth, rect.height);

        if (GUI.Button(r2, "find"))
        {
            property.stringValue = EditorUtility.OpenFilePanel(property.name, "", attr.Ext);
            property.serializedObject.ApplyModifiedProperties();
        }

        EditorGUI.EndProperty();
    }
        /// <summary>
        /// Returns File Path from a type.
        /// </summary>
        /// <param name="type">Type to search</param>
        /// <returns></returns>
        public static string GetFilePath(this Type type)
        {
            FilePathAttribute attribute = type.GetCustomAttributes(typeof(FilePathAttribute), false).FirstOrDefault() as FilePathAttribute;

            if (attribute != null)
            {
                return(attribute.Path);
            }
            return(string.Empty);
        }
Ejemplo n.º 7
0
        protected override void OpenDialog(SerializedProperty property, GUIContent label)
        {
            // Open a file panel
            FilePathAttribute path        = (FilePathAttribute)attribute;
            string            browsedFile = EditorUtility.OpenFilePanel(label.text, path.DefaultPath, path.FileExtension);

            // Check if a folder was found
            if (string.IsNullOrEmpty(browsedFile) == false)
            {
                property.stringValue = browsedFile;
            }
        }
Ejemplo n.º 8
0
        static void InitData(FilePathAttribute attribute)
        {
            listPath.Clear();

            foreach (string path in attribute.arrPath)
            {
                DirectoryInfo dirInfo = new DirectoryInfo(Application.dataPath + "/" + path);
                foreach (string ext in attribute.arrExt)
                {
                    _loadFiles(dirInfo, path, ext, ref listPath);
                }
            }
        }
        private string GetFilePath()
        {
            Type type = base.GetType();

            object[] customAttributes = type.GetCustomAttributes(true);
            object[] array            = customAttributes;
            string   result;

            for (int i = 0; i < array.Length; i++)
            {
                object obj = array[i];
                if (obj is FilePathAttribute)
                {
                    FilePathAttribute filePathAttribute = obj as FilePathAttribute;
                    result = filePathAttribute.get_filepath();
                    return(result);
                }
            }
            result = "Library";
            return(result);
        }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (service != null)
         {
             string            title  = null;
             string            filter = null;
             FilePathAttribute fa     = null;
             if (context.PropertyDescriptor.Attributes != null)
             {
                 foreach (Attribute a in context.PropertyDescriptor.Attributes)
                 {
                     fa = a as FilePathAttribute;
                     if (fa != null)
                     {
                         title  = fa.Title;
                         filter = fa.Pattern;
                         break;
                     }
                 }
             }
             if (string.IsNullOrEmpty(title))
             {
                 title  = "Select web file";
                 filter = "All files|*.*";
             }
             ParameterValue pv = context.Instance as ParameterValue;
             if (pv != null)
             {
                 OpenFileDialog dlg = new OpenFileDialog();
                 if (value != null)
                 {
                     dlg.FileName = value.ToString();
                 }
                 dlg.Title  = title;
                 dlg.Filter = filter;
                 if (dlg.ShowDialog() == DialogResult.OK)
                 {
                     value = dlg.FileName;
                 }
             }
             else
             {
                 HtmlElement_Base heb = context.Instance as HtmlElement_Base;
                 if (heb != null)
                 {
                     try
                     {
                         //the dialog will copy the selected file to web folder
                         DialogHtmlFile dlg = new DialogHtmlFile();
                         dlg.LoadData(heb.WebPhysicalFolder, value as string, title, filter);
                         if (service.ShowDialog(dlg) == DialogResult.OK)
                         {
                             HtmlElement_object hob = heb as HtmlElement_object;
                             if (hob != null && string.CompareOrdinal(context.PropertyDescriptor.Name, "archive") == 0)
                             {
                                 hob.AppendArchiveFile(hob.id, dlg.WebFile);
                             }
                             else
                             {
                                 heb.SetWebProperty(context.PropertyDescriptor.Name, dlg.WebFile);
                                 value = dlg.WebFile;
                             }
                         }
                     }
                     catch (Exception err)
                     {
                         MessageBox.Show(err.Message);
                     }
                 }
             }
         }
     }
     return(value);
 }
Ejemplo n.º 11
0
 public FilePathDrawer(InspectorAttribute attribute) : base(attribute)
 {
     FAttribute = attribute as FilePathAttribute;
     OpenGC     = EditorGUIUtility.IconContent("Folder Icon");
 }
Ejemplo n.º 12
0
 public static string Description(this FilePathAttribute filePath)
 {
     return("This is a file path.");
 }