示例#1
0
        static string GetWarnings(GameObject gameobject)
        {
            var isSubScene = EditorEntityScenes.IsEntitySubScene(gameobject.scene);

            gameobject.GetComponentsInParent(true, s_ConvertToEntityBuffer);
            var convertToEntity = s_ConvertToEntityBuffer.Count > 0;

            s_ConvertToEntityBuffer.Clear();

            var willBeConverted = convertToEntity | isSubScene;

            if (!willBeConverted)
            {
                Type convertType = null;
                foreach (var behaviour in gameobject.GetComponents <MonoBehaviour>())
                {
                    if (behaviour != null && behaviour.GetType().GetCustomAttribute <RequiresEntityConversionAttribute>(true) != null)
                    {
                        convertType = behaviour.GetType();
                        break;
                    }
                }

                if (convertType != null)
                {
                    return($"The {convertType.Name} component on '{gameobject.name}' is meant for entity conversion, but it is not part of a SubScene or ConvertToEntity component.\nPlease move the game object to a SubScene or add the ConvertToEntity component.");
                }
            }

            if (isSubScene && convertToEntity)
            {
                return($"'{gameobject.name}' will be converted due to being in a SubScene. ConvertToEntity will have no effect.\nPlease remove the ConvertToEntity component.");
            }

            if (isSubScene && gameobject.GetComponent <GameObjectEntity>() != null)
            {
                return($"'{gameobject.name}' will be converted due to being in a SubScene. GameObjectEntity will have no effect the game object will not be loaded.\nPlease remove the GameObjectEntity component");
            }

            if (convertToEntity && gameobject.GetComponent <GameObjectEntity>() != null)
            {
                return($"'{gameobject.name}' will be converted due to being in a ConvertToEntity hierarchy. GameObjectEntity will have no effect.\nPlease remove the GameObjectEntity component.");
            }

            return(null);
        }
        static string GetWarning(GameObject gameObject)
        {
            // only care about scene objects
            if (gameObject == null)
            {
                return(null);
            }

            // assets have no scene context
            if (gameObject.IsPrefab())
            {
                return(null);
            }

            // editing in a preview scene (like a prefab in isolation mode) also has no context
            if (EditorSceneManager.IsPreviewSceneObject(gameObject))
            {
                return(null);
            }

            var isSubScene = EditorEntityScenes.IsEntitySubScene(gameObject.scene);

            gameObject.GetComponentsInParent(true, s_ConvertToEntityBuffer);
            var convertToEntity = s_ConvertToEntityBuffer.Count > 0;

            s_ConvertToEntityBuffer.Clear();

            var willBeConverted = convertToEntity | isSubScene;

            if (!willBeConverted)
            {
                Type convertType = null;
                foreach (var behaviour in gameObject.GetComponents <MonoBehaviour>())
                {
                    if (behaviour != null && behaviour.GetType().GetCustomAttribute <RequiresEntityConversionAttribute>(true) != null)
                    {
                        convertType = behaviour.GetType();
                        break;
                    }
                }

                if (convertType != null)
                {
                    return
                        ($"The {convertType.Name} component on '{gameObject.name}' is meant for entity conversion, " +
                         $"but it is not part of a {nameof(SubScene)} or {nameof(ConvertToEntity)} component.\n" +
                         $"Please move the {nameof(GameObject)} to a {nameof(SubScene)} or add the {nameof(ConvertToEntity)} component.");
                }
            }

            if (isSubScene && convertToEntity)
            {
                return
                    ($"'{gameObject.name}' will be converted due to being in a {nameof(SubScene)}. {nameof(ConvertToEntity)} " +
                     $"will have no effect. Please remove the {nameof(ConvertToEntity)} component.");
            }

            if (isSubScene && gameObject.GetComponent <GameObjectEntity>() != null)
            {
                return
                    ($"'{gameObject.name}' will be converted due to being in a {nameof(SubScene)}. {nameof(GameObjectEntity)} " +
                     $"will have no effect the {nameof(GameObject)} will not be loaded.\nPlease remove the {nameof(GameObjectEntity)} component");
            }

            if (convertToEntity && gameObject.GetComponent <GameObjectEntity>() != null)
            {
                return
                    ($"'{gameObject.name}' will be converted due to being in a {nameof(ConvertToEntity)} hierarchy. " +
                     $"{nameof(GameObjectEntity)} will have no effect.\nPlease remove the {nameof(GameObjectEntity)} component.");
            }

            return(null);
        }