Esempio n. 1
0
        private void CopyAssetPropertyToClipboard(string msg, Func <APAsset, string> selector)
        {
            if (string.IsNullOrEmpty(msg))
            {
                return;
            }

            var decompressedMessage = Encoding.UTF8.GetString(CLZF2.Decompress(Convert.FromBase64String(msg)));
            var assets = decompressedMessage.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var names  = new List <string>();

            foreach (var assetId in assets)
            {
                var asset = APCache.GetValue(assetId);
                if (asset != null)
                {
                    names.Add(selector(asset));
                }
            }

            TextEditor textEditor = new TextEditor();

            textEditor.ReplaceSelection(string.Join("\n", names.ToArray()));
            textEditor.OnFocus();
            textEditor.Copy();
        }
Esempio n. 2
0
        private void OpenContainerFolder(string msg, object callback)
        {
            Utility.DebugLog(string.Format("OpenFolder Receive: {0}", msg));

            if (string.IsNullOrEmpty(msg))
            {
                return;
            }

            var decompressedMessage = Encoding.UTF8.GetString(CLZF2.Decompress(Convert.FromBase64String(msg)));
            var assets = decompressedMessage.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            HashSet <string> folders = new HashSet <string>();

            foreach (var item in assets)
            {
                var guid   = Utility.GetGuidFromAssetId(item);
                var path   = AssetDatabase.GUIDToAssetPath(guid);
                var folder = Utility.GetContainerFolder(path);

                Utility.DebugLog(string.Format("OpenFolder: {0}", folder));

                if (!string.IsNullOrEmpty(folder))
                {
                    folders.Add(folder);
                }
            }

            foreach (var folder in folders)
            {
                EditorUtility.RevealInFinder(folder);
            }
        }
Esempio n. 3
0
        private void GetIconCache(string message, object callback)
        {
            var json = APCache.GetIconCacheJSON();

            json = Convert.ToBase64String(CLZF2.Compress(Encoding.UTF8.GetBytes(json)));
            wrap = new CallbackWrapper(callback);
            wrap.Send(json);
        }
Esempio n. 4
0
        private static bool LoadFromLocal <T>(string filePath, ref T data) where T : class
        {
            System.Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");

            try
            {
                if (File.Exists(filePath))
                {
                    using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                    {
                        byte[] fileBytes = new byte[fileStream.Length];
                        fileStream.Read(fileBytes, 0, fileBytes.Length);
                        var realContentBytes = CLZF2.Decompress(fileBytes);
                        using (MemoryStream memoryStream = new MemoryStream(realContentBytes))
                        {
                            BinaryFormatter serializer = new BinaryFormatter();

                            try
                            {
                                data = serializer.Deserialize(memoryStream) as T;
                            }
                            catch
                            {
                                // Debug.LogError(e);
                                return(false);
                            }

                            if (AssetsCache == null)
                            {
                                return(false);
                            }

                            return(true);
                        }
                    }
                }
                return(false);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 5
0
        private void MultiSelect(string paths, object callback)
        {
            if (string.IsNullOrEmpty(paths))
            {
                return;
            }

            var decompressedIds = Encoding.UTF8.GetString(CLZF2.Decompress(Convert.FromBase64String(paths)));

            Utility.DebugLog(string.Format("MultiSelect: {0}", decompressedIds));

            var assetIds = decompressedIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var objects  = new UnityEngine.Object[assetIds.Length];

            for (int i = 0; i < assetIds.Length; i++)
            {
                string id = assetIds[i];
                if (Utility.IsSubAsset(id))
                {
                    Utility.DebugLog("MultiSelect: Is SubAsset");
                    var obj = GetAnimationObjectFromModel(id);
                    if (obj != null)
                    {
                        objects[i] = obj;
                    }
                }
                else
                {
                    Utility.DebugLog("MultiSelect: Is Not SubAsset");
                    objects[i] = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(id));
                }
            }

            if (objects.Length > 0)
            {
                Selection.objects = objects;
                if (Event.current != null)
                {
                    Event.current.Use();
                }
                ;
            }
        }
Esempio n. 6
0
        private static void SaveToLocal(string filePath, object data)
        {
            System.Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");
            using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    BinaryFormatter serializer = new BinaryFormatter();
                    serializer.Serialize(stream, data);

                    byte[] bytes = new byte[stream.Length];

                    // Have to reset the stream Position to 0 to ensure read real bytes
                    //
                    stream.Position = 0;
                    stream.Read(bytes, 0, bytes.Length);
                    var compressBytes = CLZF2.Compress(bytes);
                    fileStream.Write(compressBytes, 0, compressBytes.Length);
                }
            }
        }
Esempio n. 7
0
 private string CLZF2_Base64(string s)
 {
     return(Convert.ToBase64String(CLZF2.Compress(Encoding.UTF8.GetBytes(s))));
 }