Search Unity

Package exportation: how can I add project settings, installed packages etc. to the package content?

Discussion in 'Package Manager' started by Deleted User, Apr 16, 2021.

  1. Deleted User

    Deleted User

    Guest

    Hi,

    The question is entirely in the title.

    Thanks for your help! :)
     
  2. Deleted User

    Deleted User

    Guest

    So, nobody knows how to do that?
     
  3. Deleted User

    Deleted User

    Guest

    Bump...

    @rustum, anyone at Unity Technologies who packed up projects and put them on the Asset Store: How did you add the project settings to the package?
     
  4. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    Hi @APSchmidt!

    I used the Asset Store Tools to submit the project to the Asset Store. One of the options when you do that is to include Project Settings. But this is only for submission to the Asset Store.

    You might also try the AssetDatabase.ExportPackage API. One of the options for the ExportPackageOptions flag is IncludeLibraryAssets which includes this description "The exported package will include all library assets, ie. the project settings located in the Library folder of the project."

    I haven't exported a package by script in a while, but please do let me know how this works for you.
     
    Deleted User likes this.
  5. Deleted User

    Deleted User

    Guest

    Thanks! I will try and tell you the results. :)
     
  6. Deleted User

    Deleted User

    Guest

    It didn't work out at all... I use the script in the doc; launching it creates an "Export Package" folder in temp that contains another folder with a string of figures as a name and that contains an "asset" file. I don't see any package anywhere and Unity freezes; I need to kill it in the task manager...

    Any idea?

    The "asset" file contains this:

    Code (CSharp):
    1. #pragma warning disable 0168 // variable declared but not used.
    2. #if ENABLE_ANIMATION_COLLECTION && ENABLE_ANIMATION_BURST
    3. #define ENABLE_SPRITESKIN_COMPOSITE
    4. #endif
    5.  
    6. using System;
    7. using System.Collections.Generic;
    8. using UnityEngine.Scripting;
    9. using UnityEngine.U2D.Common;
    10. using Unity.Collections;
    11. using UnityEngine.Rendering;
    12. using UnityEngine.Scripting.APIUpdating;
    13.  
    14. namespace UnityEngine.U2D.Animation
    15. {
    16.     public struct PositionVertex
    17.     {
    18.         public Vector3 position;
    19.     }
    20.  
    21.     public struct PositionTangentVertex
    22.     {
    23.         public Vector3 position;
    24.         public Vector4 tangent;
    25.     }
    26.  
    27.     struct DeformVerticesBuffer
    28.     {
    29.         public const int k_DefaultBufferSize = 2;
    30.         int m_BufferCount;
    31.         int m_CurrentBuffer;
    32.         NativeArray<byte>[] m_DeformedVertices;
    33.  
    34.         public DeformVerticesBuffer(int bufferCount)
    35.         {
    36.             m_BufferCount = bufferCount;
    37.             m_DeformedVertices = new NativeArray<byte>[m_BufferCount];
    38.             for (int i = 0; i < m_BufferCount; ++i)
    39.             {
    40.                 m_DeformedVertices[i] = new NativeArray<byte>(1, Allocator.Persistent);
    41.             }
    42.             m_CurrentBuffer = 0;
    43.         }
    44.  
    45.         public void Dispose()
    46.         {
    47.             for (int i = 0; i < m_BufferCount; ++i)
    48.             {
    49.                 if (m_DeformedVertices[i].IsCreated)
    50.                     m_DeformedVertices[i].Dispose();
    51.             }
    52.         }
    53.  
    54.         public ref NativeArray<byte> GetBuffer(int expectedSize)
    55.         {
    56.             m_CurrentBuffer = (m_CurrentBuffer + 1) % m_BufferCount;
    57.             if (m_DeformedVertices[m_CurrentBuffer].IsCreated && m_DeformedVertices[m_CurrentBuffer].Length != expectedSize)
    58.             {
    59.                 m_DeformedVertices[m_CurrentBuffer].Dispose();
    60.                 m_DeformedVertices[m_CurrentBuffer] = new NativeArray<byte>(expectedSize, Allocator.Persistent);
    61.             }
    62.             return ref m_DeformedVertices[m_CurrentBuffer];
    63.         }
    64.  
    65.         internal ref NativeArray<byte> GetCurrentBuffer()
    66.         {
    67.             return ref m_DeformedVertices[m_CurrentBuffer];
    68.         }
    69.     }
    70.  
    71.     /// <summary>
    72.     /// Deforms the Sprite that is currently assigned to the SpriteRenderer in the same GameObject
    73.     /// </summary>
    74.     [Preserve]
    75.     [ExecuteInEditMode]
    76.     [DefaultExecutionOrder(-1)]
    77.     [DisallowMultipleComponent]
    78.     [RequireComponent(typeof(SpriteRenderer))]
    79.     [AddComponentMenu("2D Animation/Sprite Skin")]
    80.     [MovedFrom("UnityEngine.U2D.Experimental.Animation")]
    81.     [HelpURL("https://docs.unity3d.com/Packages/com.unity.2d.animation@latest/index.html?subfolder=/manual/index.html%23sprite-skin-component")]
    82.     public sealed partial class SpriteSkin : MonoBehaviour, ISerializationCallbackReceiver
    83.     {
    84.         [SerializeField]
    85.         private Transform m_RootBone;
    86.         [SerializeField]
    87.         private Transform[] m_BoneTransforms = new Transform[0];
    88.         [SerializeField]
    89.         private Bounds m_Bounds;
    90.         [SerializeField]
    91.         private bool m_UseBatching = true;
    92.         [SerializeField]
    93.         private bool m_AlwaysUpdate = true;
    94.         [SerializeField]
    95.         private bool m_AutoRebind = false;
    96.  
    97.         // The deformed m_SpriteVertices stores all 'HOT' channels only in single-stream and essentially depends on Sprite  Asset data.
    98.         // The order of storage if present is POSITION, NORMALS, TANGENTS.
    99.         private DeformVerticesBuffer m_DeformedVertices;
    100.         private int m_CurrentDeformVerticesLength = 0;
    101.         private SpriteRenderer m_SpriteRenderer;
    102.         private int m_CurrentDeformSprite = 0;
    103.         private bool m_ForceSkinning;
    104.         private bool m_BatchSkinning = false;
    105.         bool m_IsValid = false;
    106.         int m_TransformsHash = 0;
    107.  
    108.         internal bool batchSkinning
    109.         {
    110.             get { return m_BatchSkinning; }
    111.             set { m_BatchSkinning = value; }
    112.         }
    113.  
    114.         internal bool autoRebind
    115.         {
    116.             get => m_AutoRebind;
    117.             set
    118.             {
    119.                 m_AutoRebind = value;
    120.                 CacheCurrentSprite(m_AutoRebind);
    121.             }
    122.        
    123.         }
    124.  
    125. #if UNITY_EDITOR
    126.         internal static Events.UnityEvent onDrawGizmos = new Events.UnityEvent();
    127.         private void OnDrawGizmos() { onDrawGizmos.Invoke(); }
    128.  
    129.         private bool m_IgnoreNextSpriteChange = true;
    130.         internal bool ignoreNextSpriteChange
    131.         {
    132.             get { return m_IgnoreNextSpriteChange; }
    133.             set { m_IgnoreNextSpriteChange = value; }
    134.         }
    135. #endif
    136.  
    137.         private int GetSpriteInstanceID()
    138.         {
    139.             return sprite != null ? sprite.GetInstanceID() : 0;
    140.         }
    141.  
    142.         internal void Awake()
    143.         {
    144.             m_SpriteRenderer = GetComponent<SpriteRenderer>();
    145.         }
    146.  
    147.         void OnEnable()
    148.         {
    149.             Awake();
    150.             m_TransformsHash = 0;
    151.             CacheCurrentSprite(false);
    152.             OnEnableBatch();
    153.             m_DeformedVertices = new DeformVerticesBuffer(DeformVerticesBuffer.k_DefaultBufferSize);
    154.         }
    155.  
    156.         internal void OnEditorEnable()
    157.         {
    158.             Awake();
    159.         }
    160.    
    161.         void CacheValidFlag()
    162.         {
    163.             m_IsValid = isValid;
    164.             if(!m_IsValid)
    165.                 DeactivateSkinning();
    166.         }
    167.  
    168.         void Reset()
    169.         {
    170.             Awake();
    171.             if (isActiveAndEnabled)
    172.             {
    173.                 CacheValidFlag();
    174.                 OnResetBatch();
    175.             }
    176.         }
    177.  
    178.         internal void UseBatching(bool value)
    179.         {
    180.             if (m_UseBatching != value)
    181.             {
    182.                 m_UseBatching = value;
    183.                 UseBatchingBatch();
    184.             }
    185.         }
    186.  
    187.         internal ref NativeArray<byte> GetDeformedVertices(int spriteVertexCount)
    188.         {
    189.             if (sprite != null)
    190.             {
    191.                 if (m_CurrentDeformVerticesLength != spriteVertexCount)
    192.                 {
    193.                     m_TransformsHash = 0;
    194.                     m_CurrentDeformVerticesLength = spriteVertexCount;
    195.                 }
    196.             }
    197.             else
    198.             {
    199.                 m_CurrentDeformVerticesLength = 0;
    200.             }
    201.             return ref m_DeformedVertices.GetBuffer(m_CurrentDeformVerticesLength);
    202.         }
    203.  
    204.         /// <summary>
    205.         /// Returns whether this SpriteSkin has currently deformed vertices.
    206.         /// </summary>
    207.         /// <returns>Returns true if this SpriteSkin has currently deformed vertices. Returns false otherwise.</returns>
    208.         public bool HasCurrentDeformedVertices()
    209.         {
    210.             if (!m_IsValid)
    211.                 return false;
    212.  
    213. #if ENABLE_SPRITESKIN_COMPOSITE
    214.             return m_DataIndex >= 0 && SpriteSkinComposite.instance.HasDeformableBufferForSprite(m_DataIndex);
    215. #else
    216.             return m_CurrentDeformVerticesLength > 0 && m_DeformedVertices.GetCurrentBuffer().IsCreated;
    217. #endif
    218.         }
    219.  
    220.         /// <summary>
    221.         /// Gets a byte array to the currently deformed vertices for this SpriteSkin.
    222.         /// </summary>
    223.         /// <returns>Returns a reference to the currently deformed vertices. This is valid only for this calling frame.</returns>
    224.         /// <exception cref="InvalidOperationException">Thrown when there are no currently deformed vertices</exception>
    225.         internal NativeArray<byte> GetCurrentDeformedVertices()
    226.         {
    227.             if (!m_IsValid)
    228.                 throw new InvalidOperationException("The SpriteSkin deformation is not valid.");
    229.  
    230. #if ENABLE_SPRITESKIN_COMPOSITE
    231.             if (m_DataIndex < 0)
    232.             {
    233.                 throw new InvalidOperationException("There are no currently deformed vertices.");
    234.             }
    235.             return SpriteSkinComposite.instance.GetDeformableBufferForSprite(m_DataIndex);
    236. #else
    237.             if (m_CurrentDeformVerticesLength <= 0)
    238.                 throw new InvalidOperationException("There are no currently deformed vertices.");
    239.             var buffer = m_DeformedVertices.GetCurrentBuffer();
    240.             if (!buffer.IsCreated)
    241.                 throw new InvalidOperationException("There are no currently deformed vertices.");
    242.             return buffer;
    243. #endif
    244.         }
    245.  
    246.         /// <summary>
    247.         /// Gets an array of currently deformed position vertices for this SpriteSkin.
    248.         /// </summary>
    249.         /// <returns>Returns a reference to the currently deformed vertices. This is valid only for this calling frame.</returns>
    250.         /// <exception cref="InvalidOperationException">
    251.         /// Thrown when there are no currently deformed vertices or if the deformed vertices does not contain only
    252.         /// position data.
    253.         /// </exception>
    254.         internal NativeSlice<PositionVertex> GetCurrentDeformedVertexPositions()
    255.         {
    256.             if (sprite.HasVertexAttribute(VertexAttribute.Tangent))
    257.                 throw new InvalidOperationException("This SpriteSkin has deformed tangents");
    258.             if (!sprite.HasVertexAttribute(VertexAttribute.Position))
    259.                 throw new InvalidOperationException("This SpriteSkin does not have deformed positions.");
    260.  
    261.             var deformedBuffer = GetCurrentDeformedVertices();
    262.             return deformedBuffer.Slice().SliceConvert<PositionVertex>();
    263.         }
    264.  
    265.         /// <summary>
    266.         /// Gets an array of currently deformed position and tangent vertices for this SpriteSkin.
    267.         /// </summary>
    268.         /// <returns>
    269.         /// Returns a reference to the currently deformed position and tangent vertices. This is valid only for this calling frame.
    270.         /// </returns>
    271.         /// <exception cref="InvalidOperationException">
    272.         /// Thrown when there are no currently deformed vertices or if the deformed vertices does not contain only
    273.         /// position and tangent data.
    274.         /// </exception>
    275.         internal NativeSlice<PositionTangentVertex> GetCurrentDeformedVertexPositionsAndTangents()
    276.         {
    277.             if (!sprite.HasVertexAttribute(VertexAttribute.Tangent))
    278.                 throw new InvalidOperationException("This SpriteSkin does not have deformed tangents");
    279.             if (!sprite.HasVertexAttribute(VertexAttribute.Position))
    280.                 throw new InvalidOperationException("This SpriteSkin does not have deformed positions.");
    281.  
    282.             var deformedBuffer = GetCurrentDeformedVertices();
    283.             return deformedBuffer.Slice().SliceConvert<PositionTangentVertex>();
    284.         }
    285.  
    286.         /// <summary>
    287.         /// Gets an enumerable to iterate through all deformed vertex positions of this SpriteSkin.
    288.         /// </summary>
    289.         /// <returns>Returns an IEnumerable to deformed vertex positions.</returns>
    290.         /// <exception cref="InvalidOperationException">Thrown when there is no vertex positions or deformed vertices.</exception>
    291.         public IEnumerable<Vector3> GetDeformedVertexPositionData()
    292.         {
    293.             bool hasPosition = sprite.HasVertexAttribute(Rendering.VertexAttribute.Position);
    294.             if (!hasPosition)
    295.                 throw new InvalidOperationException("Sprite does not have vertex position data.");
    296.  
    297.             var rawBuffer = GetCurrentDeformedVertices();
    298.             var rawSlice = rawBuffer.Slice(sprite.GetVertexStreamOffset(VertexAttribute.Position));
    299.             return new NativeCustomSliceEnumerator<Vector3>(rawSlice, sprite.GetVertexCount(), sprite.GetVertexStreamSize());
    300.         }
    301.  
    302.         /// <summary>
    303.         /// Gets an enumerable to iterate through all deformed vertex tangents of this SpriteSkin.
    304.         /// </summary>
    305.         /// <returns>Returns an IEnumerable to deformed vertex tangents.</returns>
    306.         /// <exception cref="InvalidOperationException">Thrown when there is no vertex tangents or deformed vertices.</exception>
    307.         public IEnumerable<Vector4> GetDeformedVertexTangentData()
    308.         {
    309.             bool hasTangent = sprite.HasVertexAttribute(Rendering.VertexAttribute.Tangent);
    310.             if (!hasTangent)
    311.                 throw new InvalidOperationException("Sprite does not have vertex tangent data.");
    312.  
    313.             var rawBuffer = GetCurrentDeformedVertices();
    314.             var rawSlice = rawBuffer.Slice(sprite.GetVertexStreamOffset(VertexAttribute.Tangent));
    315.             return new NativeCustomSliceEnumerator<Vector4>(rawSlice, sprite.GetVertexCount(), sprite.GetVertexStreamSize());
    316.         }
    317.  
    318.         void OnDisable()
    319.         {
    320.             DeactivateSkinning();
    321.             m_DeformedVertices.Dispose();
    322.             OnDisableBatch();
    323.         }
    324.  
    325. #if ENABLE_SPRITESKIN_COMPOSITE
    326.         internal void OnLateUpdate()
    327. #else
    328.         void LateUpdate()
    329. #endif
    330.         {
    331.             CacheCurrentSprite(m_AutoRebind);
    332.             if (isValid && !batchSkinning && this.enabled && (this.alwaysUpdate || this.spriteRenderer.isVisible))
    333.             {
    334.                 var transformHash = SpriteSkinUtility.CalculateTransformHash(this);
    335.                 var spriteVertexCount = sprite.GetVertexStreamSize() * sprite.GetVertexCount();
    336.                 if (spriteVertexCount > 0 && m_TransformsHash != transformHash)
    337.                 {
    338.                     var inputVertices = GetDeformedVertices(spriteVertexCount);
    339.                     SpriteSkinUtility.Deform(sprite, gameObject.transform.worldToLocalMatrix, boneTransforms, ref inputVertices);
    340.                     SpriteSkinUtility.UpdateBounds(this, inputVertices);
    341.                     InternalEngineBridge.SetDeformableBuffer(spriteRenderer, inputVertices);
    342.                     m_TransformsHash = transformHash;
    343.                     m_CurrentDeformSprite = GetSpriteInstanceID();
    344.                 }
    345.             }
    346.         }
    347.  
    348.         void CacheCurrentSprite(bool rebind)
    349.         {
    350.             if (m_CurrentDeformSprite != GetSpriteInstanceID())
    351.             {
    352.                 DeactivateSkinning();
    353.                 m_CurrentDeformSprite = GetSpriteInstanceID();
    354.                 if (rebind && m_CurrentDeformSprite > 0 && rootBone != null)
    355.                 {
    356.                     var spriteBones = sprite.GetBones();
    357.                     var transforms = new Transform[spriteBones.Length];
    358.                     if (GetSpriteBonesTransforms(spriteBones, rootBone, transforms))
    359.                         boneTransforms = transforms;
    360.                 }
    361.                 UpdateSpriteDeform();
    362.                 CacheValidFlag();
    363.                 m_TransformsHash = 0;
    364.             }
    365.         }
    366.  
    367.         internal Sprite sprite => spriteRenderer.sprite;
    368.  
    369.         internal SpriteRenderer spriteRenderer => m_SpriteRenderer;
    370.  
    371.         /// <summary>
    372.         /// Returns the Transform Components that is used for deformation
    373.         /// </summary>
    374.         /// <returns>An array of Transform Components</returns>
    375.         public Transform[] boneTransforms
    376.         {
    377.             get { return m_BoneTransforms; }
    378.             internal set
    379.             {
    380.                 m_BoneTransforms = value;
    381.                 CacheValidFlag();
    382.                 OnBoneTransformChanged();
    383.             }
    384.         }
    385.  
    386.         /// <summary>
    387.         /// Returns the Transform Component that represents the root bone for deformation
    388.         /// </summary>
    389.         /// <returns>A Transform Component</returns>
    390.         public Transform rootBone
    391.         {
    392.             get { return m_RootBone; }
    393.             internal set
    394.             {
    395.                 m_RootBone = value;
    396.                 CacheValidFlag();
    397.                 OnRootBoneTransformChanged();
    398.             }
    399.         }
    400.  
    401.         internal Bounds bounds
    402.         {
    403.             get { return m_Bounds; }
    404.             set { m_Bounds = value; }
    405.         }
    406.  
    407.         /// <summary>
    408.         /// Determines if the SpriteSkin executes even if the associated
    409.         /// SpriteRenderer has been culled from view.
    410.         /// </summary>
    411.         public bool alwaysUpdate
    412.         {
    413.             get => m_AlwaysUpdate;
    414.             set => m_AlwaysUpdate = value;
    415.         }
    416.    
    417.         internal static bool GetSpriteBonesTransforms(SpriteBone[] spriteBones, Transform rootBone, Transform[] outTransform)
    418.         {
    419.             if(rootBone == null)
    420.                 throw new ArgumentException("rootBone parameter cannot be null");
    421.             if(spriteBones == null)
    422.                 throw new ArgumentException("spritebone parameter cannot be null");
    423.             if(outTransform == null)
    424.                 throw new ArgumentException("outTransform parameter cannot be null");
    425.             if(spriteBones.Length != outTransform.Length)
    426.                 throw new ArgumentException("spritebone and outTransform array length must be the same");
    427.        
    428.             var boneObjects = rootBone.GetComponentsInChildren<Bone>();
    429.             if (boneObjects != null && boneObjects.Length >= spriteBones.Length)
    430.             {
    431.                 int i = 0;
    432.                 for (; i < spriteBones.Length; ++i)
    433.                 {
    434.                     var boneHash = spriteBones[i].guid;
    435.                     var boneTransform = Array.Find(boneObjects, x => (x.guid == boneHash));
    436.                     if (boneTransform == null)
    437.                         break;
    438.  
    439.                     outTransform[i] = boneTransform.transform;
    440.                 }
    441.                 if(i >= spriteBones.Length)
    442.                     return true;
    443.             }
    444.            
    445.             // If unable to successfuly map via guid, fall back to path
    446.             return GetSpriteBonesTranformFromPath(spriteBones, rootBone, outTransform);
    447.         }
    448.    
    449.    
    450.         static bool GetSpriteBonesTranformFromPath(SpriteBone[] spriteBones, Transform rootBone, Transform[] outNewBoneTransform)
    451.         {
    452.             var bonePath = new string[spriteBones.Length];
    453.             for (int i = 0; i < spriteBones.Length; ++i)
    454.             {
    455.                 if (bonePath[i] == null)
    456.                     CalculateBoneTransformsPath(i, spriteBones, bonePath);
    457.                 if (rootBone.name == spriteBones[i].name)
    458.                      outNewBoneTransform[i] = rootBone;
    459.                 else
    460.                 {
    461.                     var bone = rootBone.Find(bonePath[i]);
    462.                     if (bone == null)
    463.                         return false;
    464.                     outNewBoneTransform[i] = bone;
    465.                 }
    466.             }
    467.  
    468.             return true;
    469.         }
    470.    
    471.         private static void CalculateBoneTransformsPath(int index, SpriteBone[] spriteBones, string[] paths)
    472.         {
    473.             var spriteBone = spriteBones[index];
    474.             var parentId = spriteBone.parentId;
    475.             var bonePath = spriteBone.name;
    476.             if (parentId != -1 && spriteBones[parentId].parentId != -1)
    477.             {
    478.                 if (paths[parentId] == null)
    479.                     CalculateBoneTransformsPath(spriteBone.parentId, spriteBones, paths);
    480.                 paths[index] = string.Format("{0}/{1}", paths[parentId], bonePath);
    481.             }
    482.             else
    483.                 paths[index] = bonePath;
    484.         }
    485.    
    486.         internal bool isValid
    487.         {
    488.             get { return this.Validate() == SpriteSkinValidationResult.Ready; }
    489.         }
    490.  
    491.         void OnDestroy()
    492.         {
    493.             DeactivateSkinning();
    494.         }
    495.  
    496.         internal void DeactivateSkinning()
    497.         {
    498.             var sprite = spriteRenderer.sprite;
    499.             if (sprite != null)
    500.                 InternalEngineBridge.SetLocalAABB(spriteRenderer, sprite.bounds);
    501.  
    502.             SpriteRendererDataAccessExtensions.DeactivateDeformableBuffer(spriteRenderer);
    503.         }
    504.  
    505.         internal void ResetSprite()
    506.         {
    507.             m_CurrentDeformSprite = 0;
    508.             CacheValidFlag();
    509.         }
    510.  
    511.         public void OnBeforeSerialize()
    512.         {
    513.             OnBeforeSerializeBatch();
    514.         }
    515.  
    516.         public void OnAfterDeserialize()
    517.         {
    518.             OnAfterSerializeBatch();
    519.         }
    520.     }
    521. }
     
  7. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    Deleted User likes this.