Ejemplo n.º 1
0
        public static VFWSettings GetInstance()
        {
            if (instance == null || !AssetDatabase.Contains(instance))
            {
                var dirs = Directory.GetDirectories("Assets", "Vexe", SearchOption.AllDirectories);
                var editorDir = dirs.FirstOrDefault(x => Directory.GetParent(x).Name == "Editor");
                var prefsDir = Path.Combine(editorDir, "ScriptableAssets");
                if (editorDir == null || !Directory.Exists(prefsDir))
                {
                    Debug.LogError("Unable to create Vfw settings asset at Editor/Vexe/ScriptableAssets (couldn't find folder). Please make sure that path exists 'somewhere' in your project");
                    return instance != null ? instance : instance = CreateInstance<VFWSettings>();
                }

                var path = Path.Combine(prefsDir, "VFWSettings.asset");
                instance = (VFWSettings)AssetDatabase.LoadAssetAtPath(path, typeof(VFWSettings));
                if (instance == null)
                {
                    instance = ScriptableObject.CreateInstance<VFWSettings>();
                    AssetDatabase.CreateAsset(instance, path);
                    AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
                    AssetDatabase.Refresh();
                }
            }
            return instance;
        }
Ejemplo n.º 2
0
        public static VFWSettings GetInstance()
        {
            if (instance == null || !AssetDatabase.Contains(instance))
            {
                var dirs      = Directory.GetDirectories("Assets", "Vexe", SearchOption.AllDirectories);
                var editorDir = dirs.FirstOrDefault(x => Directory.GetParent(x).Name == "Editor");
                var prefsDir  = Path.Combine(editorDir, "ScriptableAssets");
                if (editorDir == null || !Directory.Exists(prefsDir))
                {
                    Debug.LogError("Unable to create Vfw settings asset at Editor/Vexe/ScriptableAssets (couldn't find folder). Please make sure that path exists 'somewhere' in your project");
                    return(instance != null ? instance : instance = CreateInstance <VFWSettings>());
                }

                var path = Path.Combine(prefsDir, "VFWSettings.asset");
                instance = AssetDatabase.LoadAssetAtPath <VFWSettings>(path);
                if (instance == null)
                {
                    instance = ScriptableObject.CreateInstance <VFWSettings>();
                    AssetDatabase.CreateAsset(instance, path);
                    AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
                    AssetDatabase.Refresh();
                }
            }
            return(instance);
        }
Ejemplo n.º 3
0
        private EditorMember(MemberInfo memberInfo, Type memberType, string memberName,
                             object rawTarget, UnityObject unityTarget, int targetId, Attribute[] attributes)
        {
            Info         = memberInfo;
            Type         = memberType;
            RawTarget    = rawTarget;
            Name         = memberName;
            TypeNiceName = memberType.GetNiceName();
            UnityTarget  = unityTarget;
            Attributes   = attributes ?? Empty;

            string displayFormat = null;

            var formatAttr = Attributes.GetAttribute <DisplayAttribute>();

            if (formatAttr != null && !string.IsNullOrEmpty(formatAttr.FormatLabel))
            {
                displayFormat = formatAttr.FormatLabel;
            }

            var settings = VFWSettings.GetInstance();

            if (displayFormat == null)
            {
                if (Type.IsImplementerOfRawGeneric(typeof(IDictionary <,>)))
                {
                    displayFormat = settings.DefaultDictionaryFormat;
                }
                else if (Type.IsImplementerOfRawGeneric(typeof(IList <>)))
                {
                    displayFormat = settings.DefaultSequenceFormat;
                }
                else
                {
                    displayFormat = settings.DefaultMemberFormat;
                }
            }

            var iter = Formatters.GetEnumerator();

            while (iter.MoveNext())
            {
                var pair    = iter.Current;
                var pattern = pair.Key;
                var result  = pair.Value(this);
                displayFormat = Regex.Replace(displayFormat, pattern, result, RegexOptions.IgnoreCase);
            }

            DisplayText = displayFormat;

            Id = RuntimeHelper.CombineHashCodes(targetId, TypeNiceName, DisplayText);
        }
Ejemplo n.º 4
0
 public static VFWSettings GetInstance()
 {
     if (_instance == null)
     {
         _instance = AssetDatabase.LoadAssetAtPath(SettingsPath, typeof(VFWSettings)) as VFWSettings;
         if (_instance == null)
         {
             _instance = CreateInstance <VFWSettings>();
             AssetDatabase.CreateAsset(_instance, SettingsPath);
             AssetDatabase.ImportAsset(SettingsPath, ImportAssetOptions.ForceUpdate);
         }
     }
     return(_instance);
 }
Ejemplo n.º 5
0
 public static VFWSettings GetInstance()
 {
     if (instance == null)
     {
         instance = AssetDatabase.LoadAssetAtPath(SettingsPath, typeof(VFWSettings)) as VFWSettings;
         if (instance == null)
         {
             instance = CreateInstance<VFWSettings>();
             AssetDatabase.CreateAsset(instance, SettingsPath);
             AssetDatabase.ImportAsset(SettingsPath, ImportAssetOptions.ForceUpdate);
         }
     }
     return instance;
 }
Ejemplo n.º 6
0
        public static VFWSettings GetInstance()
        {
            if (instance == null)
            {
                // First attempt is to find the pref instance anywhere in the AssetDatabase
                var prefPath = AssetDatabase.FindAssets("t:VFWSettings").Select(x => AssetDatabase.GUIDToAssetPath(x)).FirstOrDefault();
                if (prefPath != null)
                {
                    instance = AssetDatabase.LoadAssetAtPath <VFWSettings>(prefPath);
                }
                else
                {
                    // Otherwise create one on the spot
                    instance = CreateInstance <VFWSettings>();
                }
            }

            if (AssetDatabase.Contains(instance))
            {
                return(instance);
            }

            const string root      = "Assets";
            var          dirs      = Directory.GetDirectories(root, "Vexe", SearchOption.AllDirectories);
            var          editorDir = dirs.FirstOrDefault(x => Directory.GetParent(x).Name == "Editor") ?? string.Empty;

            var prefsDir = Path.Combine(editorDir, "ScriptableAssets");

            if (editorDir.IsNullOrEmpty() || !Directory.Exists(prefsDir))
            {
                Debug.LogError("Unable to create editor prefs asset at Editor/Vexe/ScriptableAssets (couldn't find folder). Creating in project root instead...");
                prefsDir = root;
            }

            var path = Path.Combine(prefsDir, "VFWSettings.asset");

            AssetDatabase.CreateAsset(instance, path);
            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
            AssetDatabase.Refresh();
            return(instance);
        }
Ejemplo n.º 7
0
        public static VFWSettings GetInstance()
        {
            if (instance == null)
            {
                // First attempt is to find the pref instance anywhere in the AssetDatabase
                var prefPath = AssetDatabase.FindAssets("t:VFWSettings").Select(x => AssetDatabase.GUIDToAssetPath(x)).FirstOrDefault();
                if (prefPath != null)
                {
                    instance = AssetDatabase.LoadAssetAtPath<VFWSettings>(prefPath);
                }
                else
                {
                    // Otherwise create one on the spot
                    instance = CreateInstance<VFWSettings>();
                }
            }

            if (AssetDatabase.Contains(instance))
                return instance;

            const string root = "Assets";
            var dirs = Directory.GetDirectories(root, "Vexe", SearchOption.AllDirectories);
            var editorDir = dirs.FirstOrDefault(x => Directory.GetParent(x).Name == "Editor") ?? string.Empty;

            var prefsDir = Path.Combine(editorDir, "ScriptableAssets");
            if (editorDir.IsNullOrEmpty() || !Directory.Exists(prefsDir))
            {
                Debug.LogError("Unable to create editor prefs asset at Editor/Vexe/ScriptableAssets (couldn't find folder). Creating in project root instead...");
                prefsDir = root;
            }

            var path = Path.Combine(prefsDir, "VFWSettings.asset");
            AssetDatabase.CreateAsset(instance, path);
            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
            AssetDatabase.Refresh();
            return instance;
        }
Ejemplo n.º 8
0
 public static void SelectSettings()
 {
     Selection.activeObject = VFWSettings.GetInstance();
 }
Ejemplo n.º 9
0
        private EditorMember(MemberInfo memberInfo, Type memberType, string memberName,
                             object rawTarget, UnityObject unityTarget, int targetId, Attribute[] attributes)
        {
            if (attributes == null)
            {
                attributes = Empty;
            }
            else
            {
                ResolveUsing(ref attributes);
            }

            Info         = memberInfo;
            Type         = memberType;
            RawTarget    = rawTarget;
            TypeNiceName = memberType.GetNiceName();
            Name         = memberName;
            NiceName     = Formatters[@"\$nicename"].Invoke(this);
            UnityTarget  = unityTarget;
            Attributes   = attributes;

            string displayFormat = null;

            var displayAttr = attributes.GetAttribute <DisplayAttribute>();

            if (displayAttr != null && MemberDrawersHandler.IsApplicableAttribute(memberType, displayAttr, attributes))
            {
                displayFormat = displayAttr.FormatLabel;
            }

            var settings = VFWSettings.GetInstance();

            if (displayFormat == null)
            {
                if (Type.IsImplementerOfRawGeneric(typeof(IDictionary <,>)))
                {
                    displayFormat = settings.DictionaryFormat;
                }
                else if (Type.IsImplementerOfRawGeneric(typeof(IList <>)))
                {
                    displayFormat = settings.SequenceFormat;
                }
                else
                {
                    displayFormat = settings.MemberFormat;
                }
            }

            var iter = Formatters.GetEnumerator();

            while (iter.MoveNext())
            {
                var pair    = iter.Current;
                var pattern = pair.Key;
                var result  = pair.Value(this);
                displayFormat = Regex.Replace(displayFormat, pattern, result, RegexOptions.IgnoreCase);
            }

            DisplayText = displayFormat;

            Id = RuntimeHelper.CombineHashCodes(targetId, TypeNiceName, DisplayText);
        }