<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: tsjost</title>
    <description>The latest articles on DEV Community by tsjost (@tsjost).</description>
    <link>https://dev.to/tsjost</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F271175%2F92a3278f-097b-41a4-aeed-1a29e99cc9a8.jpg</url>
      <title>DEV Community: tsjost</title>
      <link>https://dev.to/tsjost</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tsjost"/>
    <language>en</language>
    <item>
      <title>Extracting content from Unity packages in terminal</title>
      <dc:creator>tsjost</dc:creator>
      <pubDate>Wed, 13 Nov 2019 18:52:29 +0000</pubDate>
      <link>https://dev.to/tsjost/extracting-content-from-unity-packages-in-terminal-301d</link>
      <guid>https://dev.to/tsjost/extracting-content-from-unity-packages-in-terminal-301d</guid>
      <description>&lt;p&gt;While I was researching some physics mathsy stuff, the only actual source code implementation I could find was buried inside a Unity asset thing. I don't use Unity, but as far as I know you can only download Unity packages through the Unity editor, not through the Unity asset store website, and it still won't seem to let you browse through the asset's source.&lt;/p&gt;

&lt;p&gt;Regardless, here's a method to extract Unity &lt;code&gt;unitypackage&lt;/code&gt; files properly and not just the GUID names with hexadecimal directories.&lt;/p&gt;

&lt;p&gt;For example the Standard Assets package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;file Standard&lt;span class="se"&gt;\ &lt;/span&gt;Assets.unitypackage
Standard Assets.unitypackage: &lt;span class="nb"&gt;gzip &lt;/span&gt;compressed data, extra field,
last modified: Mon Mar  5 16:28:50 2018, max compression,
from Unix, original size 250911232
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not only is the file gzipped, but underneath it's also a tar archive, so we can extract everything like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;tar &lt;/span&gt;zxfv Standard&lt;span class="se"&gt;\ &lt;/span&gt;Assets.unitypackage &lt;span class="nt"&gt;--one-top-level&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Standard&lt;span class="se"&gt;\ &lt;/span&gt;Assets
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All the package content has now been extracted into the &lt;code&gt;Standard Assets&lt;/code&gt; directory, but it's not very usable as there are tons of directories with meaningless hexchar GUID names; but they all contain a &lt;code&gt;pathname&lt;/code&gt; file that we can process and use to organise the data with this simple oneliner:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;find &lt;span class="nt"&gt;-name&lt;/span&gt; asset &lt;span class="nt"&gt;-exec&lt;/span&gt; bash &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s1"&gt;'\
    filename="`dirname "$(dirname "{}")"`/`cat "$(dirname "{}")/pathname" \
        | cut -d$'&lt;/span&gt;&lt;span class="s2"&gt;"'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;'"&lt;/span&gt;&lt;span class="s1"&gt;' -f1 \
        | tr -d "\n"`"; \
    filedir=`dirname "$filename"`; \
    mkdir -p "$filedir"; \
    echo "Extracting \"$filename\"..."; \
    cp "{}" "$filename"'&lt;/span&gt; &lt;span class="se"&gt;\;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Having done that the intermediate directories can be cleaned up:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;find &lt;span class="nt"&gt;-type&lt;/span&gt; d &lt;span class="nt"&gt;-regextype&lt;/span&gt; &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-regex&lt;/span&gt; &lt;span class="s1"&gt;'.*[0-9a-f]\{32\}'&lt;/span&gt; | xargs &lt;span class="nt"&gt;-I&lt;/span&gt;&lt;span class="o"&gt;{}&lt;/span&gt; &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; &lt;span class="s2"&gt;"{}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All the files should now be extracted properly and you can poke around with them! Hooray!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls &lt;/span&gt;Standard&lt;span class="se"&gt;\ &lt;/span&gt;Assets/Assets/Standard&lt;span class="se"&gt;\ &lt;/span&gt;Assets/
2D  Cameras  Characters  CrossPlatformInput  Editor  Effects  Environment
Fonts  ParticleSystems  PhysicsMaterials  Prototyping  Utility  Vehicles
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can untar multiple unitypackages before running the oneliner and it will extract all of them at once!&lt;/p&gt;

</description>
      <category>unity3d</category>
      <category>gamedev</category>
      <category>bash</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
