public TypeSafeDataUnit GetTypeSafeDataUnit()
        {
            TSLog.Log(LogCategory.Scanner, "Beginning Sorting Layer Scan");

            var layerNames = InternalEditorUtilityWrapper.sortingLayerNames;
            var layerIds   = InternalEditorUtilityWrapper.sortingLayerUniqueIDs;

            if (layerNames.Length != layerIds.Length)
            {
                throw new Exception("Sorting layer name and id array lengths do not match.");
            }

            var data = new List <TypeSafeDataEntry>();

            for (var i = 0; i < layerNames.Length; i++)
            {
                var name = layerNames[i];
                var id   = layerIds[i];

                TSLog.Log(LogCategory.Scanner, string.Format("Sorting Layer {0}: name={1}, unique_id={2}", i, name, id));

                data.Add(new TypeSafeDataEntry(name, new object[] { name, id }));
            }

            TSLog.Log(LogCategory.Scanner, "Sorting Layer Scan Completed");

            return(new TypeSafeDataUnit(TypeSafeUtil.GetFinalClassName(Strings.SortingLayersTypeName),
                                        typeof(SortingLayer), data, true, "SortingLayers"));
        }
Esempio n. 2
0
        public TypeSafeDataUnit GetTypeSafeDataUnit()
        {
            var data = new List <TypeSafeDataEntry>();

            data.Add(new TypeSafeDataEntry("All", new object[] { int.MaxValue }, true));
            data.Add(new TypeSafeDataEntry("None", new object[] { 0 }, true));

            var layers = InternalEditorUtility.layers;

            foreach (var layer in layers)
            {
                var ignore = string.IsNullOrEmpty(layer) || layer.Trim().Length == 0;
                var num    = LayerMask.NameToLayer(layer);

                TSLog.Log(LogCategory.Scanner, string.Format("Layer: {0}, (index: {1},ignore={2})", layer, num, ignore));

                if (!ignore)
                {
                    data.Add(new TypeSafeDataEntry(layer, new object[] { 1 << num }));
                }
            }

            return(new TypeSafeDataUnit(TypeSafeUtil.GetFinalClassName(Strings.LayerMaskTypeName), typeof(int), data,
                                        false, "LayerMask"));
        }
        static ProgressIndicationController()
        {
            if (!TypeSafeUtil.IsEnabled())
            {
                return;
            }

            EditorApplication.update += OnEditorUpdate;
        }
Esempio n. 4
0
        private void Apply()
        {
            TSLog.Log(LogCategory.Info, "Clearing current output directory.");
            TypeSafeUtil.Clean();

            Settings.Instance.OutputDirectory = _newPath;
            Settings.Instance.Save();

            TSLog.Log(LogCategory.Info, "Queuing scan.");
            TypeSafeApi.QueueRefresh();
        }
        public TypeSafeDataUnit GetTypeSafeDataUnit()
        {
            var data = new List <TypeSafeDataEntry>();

            TSLog.Log(LogCategory.Scanner, "Beginning Scene Scan");

            var i = 0;

            var scenes = new List <string>();

            foreach (var scene in EditorBuildSettings.scenes)
            {
                if (!Settings.Instance.IncludeNonActiveScenes && !scene.enabled)
                {
                    continue;
                }

                if (scenes.Any(p => p == scene.path))
                {
                    TSLog.Log(LogCategory.Scanner, string.Format("Duplicate Scene: {0}, {1}", i, scene.path));
                    continue;
                }

                var name = Path.GetFileNameWithoutExtension(scene.path);

                TSLog.Log(LogCategory.Scanner, string.Format("Scene: {0} (name={1}, isEnabled: {2})", scene.path, name, scene.enabled));

                if (string.IsNullOrEmpty(name))
                {
                    TSLog.LogWarning(LogCategory.Scanner, "Scene name is empty, skipping.");
                    continue;
                }

                scenes.Add(scene.path);

                var warning = scene.enabled ? null : Strings.Warning_NonActiveScene;

                data.Add(new TypeSafeDataEntry(name, new object[] { name, scene.enabled ? i : -1 },
                                               obsoleteWarning: warning));

                if (scene.enabled)
                {
                    i++;
                }
            }

            TSLog.Log(LogCategory.Scanner, "Scene Scan Complete");

            return(new TypeSafeDataUnit(TypeSafeUtil.GetFinalClassName(Strings.ScenesTypeName), typeof(Scene), data,
                                        true,
                                        "Scenes"));
        }
Esempio n. 6
0
        private bool ValidateNaming()
        {
            var typeNames = TypeSafeUtil.GetTypeSafeClassNames();

            string errorMessage;

            for (var i = 0; i < typeNames.Count; i++)
            {
                if (
                    !TypeSafeUtil.ValidateTypeName(typeNames[i], _newNamespace, _newPrefix, _newSuffix, out errorMessage))
                {
                    return(false);
                }
            }

            return(true);
        }
        public TypeSafeDataUnit GetTypeSafeDataUnit()
        {
            var rootUnit = new TypeSafeDataUnit(TypeSafeUtil.GetFinalClassName(Strings.AudioMixersName)
                                                , typeof(float), new List <TypeSafeDataEntry>(), false, "AudioMixers");

            var mixers = Settings.Instance.AudioMixers;

            foreach (var guid in mixers)
            {
                var assetPath = AssetDatabase.GUIDToAssetPath(guid);
                var asset     = AssetDatabase.LoadAssetAtPath <AudioMixer>(assetPath);

                TSLog.Log(LogCategory.Trace, string.Format("AudioMixer: {0}", assetPath), asset);
                rootUnit.NestedUnits.Add(CreateMixerDataUnit(new AudioMixerControllerWrapper(asset)));
            }

            return(rootUnit);
        }
        public TypeSafeDataUnit GetTypeSafeDataUnit()
        {
            var unit = new TypeSafeDataUnit(TypeSafeUtil.GetFinalClassName(Strings.TagsTypeName), typeof(string));
            var tags = InternalEditorUtility.tags;

            foreach (var tag in tags)
            {
                var ignore = string.IsNullOrEmpty(tag) || tag.Trim().Length == 0;

                TSLog.Log(LogCategory.Scanner, string.Format("Tag: {0}, (ignore={1})", tag, ignore));

                if (!ignore)
                {
                    unit.Data.Add(new TypeSafeDataEntry(tag, new object[] { tag }));
                }
            }

            unit.EnableAllProperty = true;
            unit.FileName          = "Tags";

            return(unit);
        }
Esempio n. 9
0
        private void DrawNamingPreview(string className, int index, ref bool validationFailed)
        {
            var style = index % 2 == 0 ? Styles.NamingPreviewRowOdd : Styles.NamingPreviewRowEven;

            EditorGUILayout.BeginHorizontal(style);

            GUILayout.Label(_newNamespace, Styles.NamingPreviewNamespaceLabel);

            if (!string.IsNullOrEmpty(_newNamespace))
            {
                GUILayout.Label(".", Styles.NamingPreviewSeperatorLabel);
            }

            if (!string.IsNullOrEmpty(_newPrefix))
            {
                GUILayout.Label(_newPrefix, Styles.NamingPreviewPrefixLabel);
            }

            GUILayout.Label(className, Styles.NamingPreviewClassNameLabel);

            if (!string.IsNullOrEmpty(_newSuffix))
            {
                GUILayout.Label(_newSuffix, Styles.NamingPreviewSuffixLabel);
            }

            string errorMessage;

            if (!TypeSafeUtil.ValidateTypeName(className, _newNamespace, _newPrefix, _newSuffix, out errorMessage))
            {
                GUILayout.FlexibleSpace();

                GUILayout.Label(TypeSafeUtil.GetShortErrorMessage(errorMessage), _errorLabelStyle);
                GUILayout.Label(new GUIContent(_errorIcon, errorMessage), GUILayout.Height(ErrorIconHeight));
                validationFailed = true;
            }

            EditorGUILayout.EndHorizontal();
        }
        public TypeSafeDataUnit GetTypeSafeDataUnit()
        {
            var data = new List <TypeSafeDataEntry>();

            var inputManager =
                new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]);

            var axesArray = inputManager.FindProperty("m_Axes");

            TSLog.Log(LogCategory.Scanner, string.Format("Axes Array: {0}, count: {1}", axesArray, axesArray.arraySize));

            for (var i = 0; i < axesArray.arraySize; i++)
            {
                var entry = axesArray.GetArrayElementAtIndex(i);

                var name = entry.FindPropertyRelative("m_Name").stringValue;

                var hasPositive = !string.IsNullOrEmpty(entry.FindPropertyRelative("positiveButton").stringValue) ||
                                  !string.IsNullOrEmpty(entry.FindPropertyRelative("altPositiveButton").stringValue);

                var hasNegative = !string.IsNullOrEmpty(entry.FindPropertyRelative("negativeButton").stringValue) ||
                                  !string.IsNullOrEmpty(entry.FindPropertyRelative("altNegativeButton").stringValue);

                var isButton = (hasPositive && !hasNegative) || (!hasPositive && hasNegative);

                TSLog.Log(LogCategory.Scanner,
                          string.Format("Input Axis: {0}, hasPositive: {1}, hasNegative: {2}, isButton: {3}", name, hasPositive, hasNegative, isButton));

                if (!data.Any(p => p.PropertyName == name))
                {
                    data.Add(new TypeSafeDataEntry(name, new object[] { name }));
                }
            }

            return(new TypeSafeDataUnit(TypeSafeUtil.GetFinalClassName(Strings.InputTypeName), typeof(InputAxis), data,
                                        false, "Input"));
        }
Esempio n. 11
0
        public void OnGUI()
        {
            GUILayout.Label("Naming Scheme", EditorStyles.boldLabel);

            GUILayout.Label(
                "The naming scheme of the generated code can be adjusted here. Edit the namespace, prefix and suffix settings then press Apply to save and trigger a regeneration.",
                Styles.ParagraphLabel);

            var validationFailed = false;

            var width = (Screen.width - 8) / 3;

            EditorGUILayout.BeginHorizontal(Styles.NamingPreviewHeaderGroupStyle);

            string errorMessage;

            EditorGUILayout.BeginHorizontal(GUILayout.Width(width));
            GUILayout.Label("Namespace", Styles.NamingHeaderNamespaceLabel);

            if (!string.IsNullOrEmpty(_newNamespace) &&
                !TypeSafeUtil.ValidateNamespaceName(_newNamespace, out errorMessage))
            {
                GUILayout.Label(new GUIContent(_errorIcon, errorMessage), GUILayout.Height(ErrorIconHeight));
                validationFailed = true;
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal(GUILayout.Width(width));

            GUILayout.Label("Prefix", Styles.NamingHeaderPrefixLabel);

            if (!string.IsNullOrEmpty(_newPrefix) && !TypeSafeUtil.ValidateTypeName(_newPrefix, out errorMessage))
            {
                GUILayout.Label(new GUIContent(_errorIcon, errorMessage), GUILayout.Height(ErrorIconHeight));
                validationFailed = true;
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal(GUILayout.Width(width));

            GUILayout.Label("Suffix", Styles.NamingHeaderSuffixLabel);

            if (!string.IsNullOrEmpty(_newSuffix) && !TypeSafeUtil.ValidateTypeName(_newSuffix, out errorMessage))
            {
                GUILayout.Label(new GUIContent(_errorIcon, errorMessage), GUILayout.Height(ErrorIconHeight));
                validationFailed = true;
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal(Styles.NamingPreviewGroupStyle);

            _newNamespace = EditorGUILayout.TextField(_newNamespace, Styles.NamingHeaderTextBox);
            _newPrefix    = EditorGUILayout.TextField(_newPrefix, Styles.NamingHeaderTextBox);
            _newSuffix    = EditorGUILayout.TextField(_newSuffix, Styles.NamingHeaderTextBox);

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginVertical(Styles.NamingPreviewTable);

            var typeNames = TypeSafeUtil.GetTypeSafeClassNames();

            for (var i = 0; i < typeNames.Count; i++)
            {
                DrawNamingPreview(typeNames[i], i, ref validationFailed);
            }

            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginDisabledGroup(!HasChangedNaming() || validationFailed);

            if (GUILayout.Button("Apply"))
            {
                Apply();
            }

            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginDisabledGroup(!HasChangedNaming());

            if (GUILayout.Button("Reset", GUILayout.ExpandWidth(false)))
            {
                Reset();
            }

            EditorGUI.EndDisabledGroup();

            EditorGUILayout.EndHorizontal();
            GUILayout.FlexibleSpace();
        }
Esempio n. 12
0
        public void OnGUI()
        {
            GUILayout.Label("Audio Mixers", EditorStyles.boldLabel);

            GUILayout.Label(
                string.Format("Audio mixers in this list will be added to the {0} class.", TypeSafeUtil.GetFinalClassName(Strings.AudioMixersName)),
                Styles.ParagraphLabel);

            _mixerTable.Draw(Settings.Instance.AudioMixers);

            GUILayout.Label("Drag-and-drop an audio mixer asset into the box above.", EditorStyles.miniLabel);

            EditorGUILayout.Space();

            GUILayout.Label("Animators", EditorStyles.boldLabel);

            GUILayout.Label(
                string.Format("Animators in this list will be added to the {0} class.", TypeSafeUtil.GetFinalClassName(Strings.AnimatorsName)),
                Styles.ParagraphLabel);

            _animatorTable.Draw(Settings.Instance.Animators);

            GUILayout.Label("Drag-and-drop an animator asset into the box above.", EditorStyles.miniLabel);

            GUILayout.FlexibleSpace();
        }
 public static void Clean()
 {
     TypeSafeUtil.Clean();
 }
Esempio n. 14
0
        public void OnGUI()
        {
            //EditorGUILayout.BeginVertical(Styles.WelcomeTextBox);

            _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);

            GUILayout.BeginVertical();

            GUILayout.Label("Welcome", Styles.HeaderLabel);

            GUILayout.Label(
                "Thank you for purchasing TypeSafe! By using TypeSafe throughout your project you will significantly improve the robustness of your codebase. Errors in your code introduced by changes via the Unity Editor will be a thing of the past.",
                Styles.ParagraphLabel);

            GUILayout.Label("Quick Start", Styles.HeaderLabel);

            GUILayout.Label(
                "TypeSafe allows you to replace any \"raw-strings\" in your code-base with strong-typed references to generated classes. " +
                "This way, if you change the location of a resource or modify layer names, you will discover errors that result from this instantly.",
                Styles.ParagraphLabel);

            GUILayout.Label(
                "TypeSafe watches for changes to your project and automatically regenerates the classes if changes occur.",
                Styles.ParagraphLabel);
            GUILayout.Label(
                "If you have just installed TypeSafe, you might want to trigger a scan manually from the <i>Assets/TypeSafe Refresh</i> menu item.",
                Styles.ParagraphLabel);

            if (!TypeSafeUtil.HasGeneratedBefore())
            {
                GUILayout.BeginHorizontal("CN EntryInfo");

                GUILayout.Label("Looks like you haven't run a scan yet, would you like to do it now?",
                                Styles.ParagraphLabel);

                GUI.enabled = TypeSafeController.Instance.State == States.Idle;

                if (GUILayout.Button("Start Scan", GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
                {
                    TypeSafeController.Instance.Queue(true);
                }

                GUI.enabled = true;

                GUILayout.EndHorizontal();
            }

            TypeSafeGUI.DrawScreenshot(Embedded.ResourcesDemo);

            GUILayout.Label(
                string.Format(
                    "Once the scan is complete, your resources will be available in the <b>{0}</b> class. You can use Intellisense to navigate this class from your code editor.",
                    TypeSafeUtil.GetFinalClassName(Strings.ResourcesTypeName)), Styles.ParagraphLabel);

            GUILayout.Label(
                string.Format(
                    "Similarly, your scenes (as listed in the build window), layers and tags will be available in <b>{0}</b>, <b>{1}</b> and <b>{2}</b> respectively.",
                    TypeSafeUtil.GetFinalClassName(Strings.ScenesTypeName),
                    TypeSafeUtil.GetFinalClassName(Strings.LayersTypeName),
                    TypeSafeUtil.GetFinalClassName(Strings.TagsTypeName)), Styles.ParagraphLabel);

            GUILayout.Label(
                "The naming scheme can be customized from the settings window. This can be accessed from <i>Window/TypeSafe/Open Settings</i> menu.",
                Styles.ParagraphLabel);

            TypeSafeGUI.DrawScreenshot(Embedded.UsageDemo);

            if (TypeSafeGUI.ClickableLabel(
                    string.Format("For more detailed information, <color={0}>click here</color> to visit the online documentation.", Strings.LinkColour),
                    Styles.ParagraphLabel))
            {
                Application.OpenURL(Strings.DocumentationUrl);
            }

            GUILayout.Label("Thanks again for purchasing, and we hope you find TypeSafe useful!", Styles.ParagraphLabel);

            GUILayout.FlexibleSpace();
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label("Version " + Strings.Version, EditorStyles.miniLabel);
            EditorGUILayout.EndHorizontal();

            GUILayout.EndVertical();

            EditorGUILayout.EndScrollView();

            //EditorGUILayout.EndVertical();
        }
Esempio n. 15
0
 public AdvancedTab()
 {
     _dataSources = TypeSafeUtil.GetCustomDataSourcesTypes().ToList();
 }
        private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets,
                                                   string[] movedFromAssetPaths)
        {
            // Short-circuit if all the paths are related to TypeSafe. Helps to reduce crashes when updating the DLLs
            if (importedAssets.All(PathUtility.IsTypeSafePath) && deletedAssets.All(PathUtility.IsTypeSafePath) &&
                movedAssets.All(PathUtility.IsTypeSafePath))
            {
                return;
            }

            TSLog.Log(LogCategory.Trace, "TypeSafeAssetPostProcessor.OnPostprocessAllAssets");

            if (!TypeSafeUtil.IsEnabled())
            {
                TSLog.Log(LogCategory.Trace, "OnPostProcessAllAssets, aborting. !IsEnabled()");
                return;
            }

            if (Settings.Instance == null)
            {
                TSLog.Log(LogCategory.Trace, "OnPostProcessAllAssets, aborting. Settings = null, likely AssetDatabase isn't ready yet.");
                return;
            }

            TSLog.Log(LogCategory.Trace, string.Format("Settings: AutoRebuild: {0}, ", Settings.Instance.AutoRebuild) +
                      string.Format("TriggerOnResourceChange={0}, ", Settings.Instance.TriggerOnResourceChange) +
                      string.Format("TriggerOnLayerChange={0}, ", Settings.Instance.TriggerOnLayerChange) +
                      string.Format("TriggerOnInputChange={0}, ", Settings.Instance.TriggerOnInputChange) +
                      string.Format("TriggerOnSceneChange={0}, ", Settings.Instance.TriggerOnSceneChange) +
                      string.Format("TriggerOnAssetChange={0})", Settings.Instance.TriggerOnAssetChange));

            // Check for changes that require deleting entries in the asset type cache
            var changes = 0;

            for (var i = 0; i < importedAssets.Length; i++)
            {
                if (AssetTypeCache.ClearAssetType(importedAssets[i]))
                {
                    changes++;
                }
            }

            for (var i = 0; i < deletedAssets.Length; i++)
            {
                if (AssetTypeCache.ClearAssetType(deletedAssets[i]))
                {
                    changes++;
                }
            }

            for (var i = 0; i < movedFromAssetPaths.Length; i++)
            {
                if (AssetTypeCache.ClearAssetType(movedFromAssetPaths[i]))
                {
                    changes++;
                }
            }

            if (changes > 0)
            {
                TSLog.Log(LogCategory.Trace, string.Format("OnPostProcessAllAssets: Items removed from AssetTypeCache: {0}", changes));
                AssetTypeCache.SaveCache();
            }

            if (!Settings.Instance.AutoRebuild)
            {
                return;
            }

            if (deletedAssets.Length > 0)
            {
                if (TypeSafeUtil.ContainsTypeSafeTrackedAsset(deletedAssets) && Settings.Instance.TriggerOnAssetChange)
                {
                    TSLog.Log(LogCategory.Trace, "Queuing refresh due to asset removal.");
                    TypeSafeController.Instance.Refresh();
                    return;
                }
            }

            if (Settings.Instance.TriggerOnAssetChange && importedAssets.Select(AssetDatabase.AssetPathToGUID).Any(
                    p => Settings.Instance.AudioMixers.Contains(p) ||
                    Settings.Instance.Animators.Contains(p)))
            {
                TSLog.Log(LogCategory.Trace, "Queuing refresh due to asset change.");
                TypeSafeController.Instance.Refresh();
                return;
            }

            if (Settings.Instance.TriggerOnResourceChange &&
                importedAssets.Concat(deletedAssets)
                .Concat(movedAssets)
                .Concat(movedFromAssetPaths)
                .Where(p => !PathUtility.IsInBlacklist(p) && (!Settings.Instance.EnableWhitelist || PathUtility.IsInWhitelist(p)))
                .Any(PathUtility.IsAssetResource))
            {
                TSLog.Log(LogCategory.Trace, "Queuing refresh due to resources change.");
                TypeSafeController.Instance.Refresh();
                return;
            }

            var isSceneChange = importedAssets.Contains("ProjectSettings/EditorBuildSettings.asset");
            var isLayerChange = importedAssets.Contains("ProjectSettings/TagManager.asset");
            var isInputChange = importedAssets.Contains("ProjectSettings/InputManager.asset");

            TSLog.Log(LogCategory.Trace, string.Format("IsLayerChange: {0}, ", isLayerChange) +
                      string.Format("IsSceneChange: {0}, ", isSceneChange) +
                      string.Format("IsInputChange: {0}", isInputChange));

            if (isSceneChange && Settings.Instance.TriggerOnSceneChange)
            {
                TSLog.Log(LogCategory.Trace, "Queuing refresh due to scene change.");
                TypeSafeController.Instance.Refresh();
                return;
            }

            if (isLayerChange && Settings.Instance.TriggerOnLayerChange)
            {
                TSLog.Log(LogCategory.Trace, "Queuing refresh due to layer change.");
                TypeSafeController.Instance.Refresh();
                return;
            }

            if (isInputChange && Settings.Instance.TriggerOnInputChange)
            {
                TSLog.Log(LogCategory.Trace, "Queuing refresh due to input change.");
                TypeSafeController.Instance.Refresh();
            }
        }