Пример #1
0
        public SearchTarget(Object target, FindModeEnum findMode, string sceneOrStagePath = null)
        {
            Asr.IsNotNull(target, "Asset you're trying to search is corrupted");

            Target = target;

            var path = sceneOrStagePath ?? AssetDatabase.GetAssetPath(Target);

            PrefabProperties properties = null;

            if (target.GetType() == typeof(GameObject))
            {
                properties = PrefabUtilities.GetPrefabProperties(target as GameObject);
            }

            if (string.IsNullOrEmpty(sceneOrStagePath) && AssetDatabase.IsSubAsset(Target))
            {
                Root   = AssetDatabase.LoadMainAssetAtPath(path);
                Nested = AufUtils.LoadAllAssetsAtPath(path);
                //Nested = new[] { Target };
            }
            else if (!string.IsNullOrEmpty(sceneOrStagePath) && Target is GameObject && findMode == FindModeEnum.Stage)
            {
                // object in Stage
                var gg = (GameObject)Target;
                Nested = gg.GetComponents <Component>().OfType <Object>().ToArray();
                Stage  = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
            }
            else if (properties != null && (properties.IsRootOfAnyPrefab || properties.IsAssetRoot))
            {
                Root   = AssetDatabase.LoadMainAssetAtPath(path);
                Nested = AufUtils.LoadAllAssetsAtPath(path);
            }
            else if (properties != null && (properties.IsPartOfAnyPrefab || properties.IsPartOfPrefabAsset))
            {
                if (target is GameObject go)
                {
                    Nested = new[] { Target, }
                }
Пример #2
0
        static void FileMenu(MenuCommand command)
        {
            InitCache();

            var continueFinding = DoYouWantToSaveScene();

            if (!continueFinding)
            {
                return;
            }

            var pickupMessage = $"Please pick up a file from the project!";

            var selected = Selection.activeObject;
            var type     = selected.GetType();

            if (selected == null ||
                type == typeof(DefaultAsset) ||
                type == typeof(SceneAsset))
            {
                EditorUtility.DisplayDialog($"{_version}", $"{pickupMessage}", "Ok");
                return;
            }

            if (type == typeof(GameObject))
            {
                var prefabProperties = PrefabUtilities.GetPrefabProperties(Selection.activeObject as GameObject);
                if (prefabProperties.IsPartOfStage || prefabProperties.IsSceneObject)
                {
                    EditorUtility.DisplayDialog($"{_version}", $"{pickupMessage}", "Ok");
                    return;
                }
            }

            EditorApplication.ExecuteMenuItem("File/Save Project");
            OpenFileWindow(selected);
            return;
        }
Пример #3
0
        public static void SceneOrStageMenu(MenuCommand data)
        {
            InitCache();

            var message = $"Please pick up an object from the scene && stage!";

            var selected = Selection.activeObject;

            if (selected == null || !(selected is GameObject))
            {
                EditorUtility.DisplayDialog($"{_version}", $"{message}", "Ok");
                return;
            }

            var continueFinding = DoYouWantToSaveScene();

            if (!continueFinding)
            {
                return;
            }

            var prefabProperties = PrefabUtilities.GetPrefabProperties(Selection.activeObject as GameObject);

            if (prefabProperties.IsPartOfStage)
            {
                OpenStageWindow(selected, prefabProperties.Path);
            }
            else if (prefabProperties.IsSceneObject)
            {
                OpenSceneWindow(selected, SceneManager.GetActiveScene().path);
            }
            else
            {
                EditorUtility.DisplayDialog($"{_version}", $"{message}", "Ok");
                return;
            }
        }