Example #1
0
        internal static NudgeSettings GetOrCreateSettings()
        {
            if (inst == null)
            {
                var found = AssetDatabase.FindAssets("t:NudgeSettings");
                if (found != null && found.Length > 0)
                {
                    if (found.Length > 1)
                    {
                        Debug.LogError("More than 1 NudgeSettings found in project, first found will be used.");
                    }

                    inst = AssetDatabase.LoadAssetAtPath <NudgeSettings>(AssetDatabase.GUIDToAssetPath(found[0]));
                }
                else
                {
                    var settings = ScriptableObject.CreateInstance <NudgeSettings>();
                    System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(DefaultNudgeSettingsPath));
                    AssetDatabase.CreateAsset(settings, DefaultNudgeSettingsPath);
                    AssetDatabase.SaveAssets();
                    inst = settings;
                }
            }

            return(inst);
        }
Example #2
0
        public static SettingsProvider CreateNudgeSettingsProvider()
        {
            var provider = new NudgeSettingsProvider("Project/Nudge Settings", SettingsScope.Project);

            provider.keywords = GetSearchKeywordsFromSerializedObject(NudgeSettings.GetSerializedSettings());
            return(provider);
        }
Example #3
0
 private void OnEnable()
 {
     nudgeSettings   = NudgeSettings.GetOrCreateSettings();
     titleContent    = new GUIContent("Tasks & Comments");
     sortingComparer = new CommentHolderDateCreatedSort();
     Recache();
 }
Example #4
0
        public static void CreateSceneComment()
        {
            var nudgeSettings = NudgeSettings.GetOrCreateSettings();
            //as per doco https://docs.unity3d.com/ScriptReference/Selection-transforms.html this gives only scene objects
            var selectedTrans = Selection.transforms;

            //should determine if this is in the scene or project?
            var newComment = new GameObject(nudgeSettings.defaultCommentName, typeof(CommentBeh)).GetComponent <CommentBeh>();

            if (selectedTrans != null && selectedTrans.Length > 0)
            {
                newComment.comment.SetSelectedItems(selectedTrans);
                newComment.gameObject.name = string.Format(nudgeSettings.defaultTargetedCommentFormat, selectedTrans[0].gameObject.name);
            }

            Undo.RegisterCreatedObjectUndo(newComment.gameObject, $"Created: {newComment.gameObject.name}");

            Selection.activeObject = newComment;
        }
Example #5
0
        public static void CreateAssetComment()
        {
            var nudgeSettings = NudgeSettings.GetOrCreateSettings();

            var newComment = ScriptableObject.CreateInstance <CommentSO>();

            newComment.name = nudgeSettings.defaultCommentName;

            var selectedAssets = Selection.GetFiltered <Object>(SelectionMode.Assets);

            if (selectedAssets != null && selectedAssets.Length > 0)
            {
                newComment.comment.SetSelectedItems(selectedAssets);
                newComment.name = string.Format(nudgeSettings.defaultTargetedCommentFormat, selectedAssets[0].name);
            }

            ProjectWindowUtil.CreateAsset(newComment, newComment.name + ".asset");
            ProjectWindowUtil.ShowCreatedAsset(newComment);

            //no undo for creating assets
        }
Example #6
0
        public static void DrawGizmoForCommentBeh(CommentBeh commentBeh, GizmoType gizmoType)
        {
            var nudgeSettings = NudgeSettings.GetOrCreateSettings();

            if (!nudgeSettings.showHidden && commentBeh.comment.Hidden && (gizmoType & GizmoType.Selected) == 0)
            {
                return;
            }

            Gizmos.DrawIcon(
                commentBeh.transform.position,
                commentBeh.comment.IsTask ? nudgeSettings.commentTaskGizmoPath : nudgeSettings.sceneCommentGizmoPath,
                true);

            if ((gizmoType & GizmoType.Selected) != 0 || nudgeSettings.drawLinkedConnection)
            {
                AttemptToDrawLine(commentBeh.transform, commentBeh.comment.PrimaryLinkedObject, commentBeh.comment, nudgeSettings);

                foreach (var item in commentBeh.comment.AdditionalLinkedObjects)
                {
                    AttemptToDrawLine(commentBeh.transform, item, commentBeh.comment, nudgeSettings);
                }
            }
        }
Example #7
0
 public override void OnActivate(string searchContext, VisualElement rootElement)
 {
     // This function is called when the user clicks on the MyCustom element in the Settings window.
     nudgeSettingsSerializedObject = NudgeSettings.GetSerializedSettings();
 }
Example #8
0
        private static void AttemptToDrawLine(Transform from, UnityEngine.Object targetObj, Comment comment, NudgeSettings nudgeSettings)
        {
            if (targetObj != null)
            {
                Transform linkedTransform = null;
                if (targetObj is GameObject)
                {
                    linkedTransform = (targetObj as GameObject).transform;
                }
                else if (targetObj is Component)
                {
                    linkedTransform = (targetObj as Component).transform;
                }

                if (linkedTransform != null)
                {
                    Gizmos.DrawIcon(
                        linkedTransform.position,
                        comment.IsTask ? nudgeSettings.commentTaskLinkedGizmoPath : nudgeSettings.commentLinkedGizmoPath,
                        true);

                    var prevCol = Gizmos.color;
                    Gizmos.color = prevCol * nudgeSettings.linkedTint;
                    Gizmos.DrawLine(from.position, linkedTransform.position);
                    Gizmos.color = prevCol;
                }
            }
        }