private static void onCreatePrefab(string _AssetPath) { var assetName = Path.GetFileNameWithoutExtension(_AssetPath).Replace(" ", "_"); var assetDir = "Assets" + Path.GetDirectoryName(_AssetPath).Replace(Application.dataPath, "") + "/"; var asset = AssetDatabase.LoadAssetAtPath(assetDir + assetName + ".asset", typeof(GAFAnimationAsset)) as GAFAnimationAsset; if (!System.Object.Equals(asset, null)) { var selected = new List <Object>(Selection.gameObjects); var prefabPath = assetDir + assetName + ".prefab"; var existingPrefab = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; if (existingPrefab == null) { var movieClipObject = createMovieClip(asset); var prefab = PrefabUtility.CreateEmptyPrefab(assetDir + assetName + ".prefab"); prefab = PrefabUtility.ReplacePrefab(movieClipObject, prefab, ReplacePrefabOptions.ConnectToPrefab); GameObject.DestroyImmediate(movieClipObject); selected.Add(prefab); } else { selected.Add(existingPrefab); } Selection.objects = selected.ToArray(); } else { GAFUtils.Log("Cannot find asset with path - " + _AssetPath, ""); } }
private void initObjectsLists() { if (isLoaded) { m_IsObjectsCollected = true; m_BatchedObjects = new List <int>(); m_MaskedObjects = new List <int>(); m_ColoredObjects = new List <int>(); foreach (var timeline in m_SharedData.timelines.Values) { foreach (var obj in timeline.objects) { int type = 0; foreach (var frame in timeline.frames.Values) { if (frame.states.ContainsKey(obj.id)) { var state = frame.states[obj.id]; if ((state.alpha != 1f && state.alpha != 0f) || state.colorMatrix != null) { type |= 1; } if (state.maskID > 0) { type |= 2; } } } int id = (int)obj.id; switch (type) { case 0: m_BatchedObjects.Add(id); break; case 1: m_ColoredObjects.Add(id); break; case 2: m_MaskedObjects.Add(id); break; case 3: m_MaskedObjects.Add(id); m_ColoredObjects.Add(id); break; } } } if (m_BatchedObjects.Count > 0) { GAFUtils.Log("GAF! Your animation asset has batchable objects. Make sure that dynamic batching is enabled for you project."); } #if UNITY_EDITOR EditorUtility.SetDirty(this); #endif // UNITY_EDITOR } }
public void Load( byte [] _AssetData , ref GAFAnimationData _SharedData) { #if !UNITY_PRO_LICENSE && GAF_SUPPORT_COMPRESSED && UNITY_EDITOR if (PlayerSettings.apiCompatibilityLevel == ApiCompatibilityLevel.NET_2_0_Subset && Application.platform != RuntimePlatform.WindowsEditor && Application.platform != RuntimePlatform.WindowsPlayer) { GAFUtils.Warning("GAF! You are using compressed 'gaf' in free unity. Set API compatibility level as '.NET'!"); } #endif // !UNITY_PRO_LICENSE && GAF_SUPPORT_COMPRESSED && UNITY_EDITOR GAFHeader header = new GAFHeader(); MemoryStream fstream = new MemoryStream(_AssetData); using (BinaryReader freader = new BinaryReader(fstream)) { if (freader.BaseStream.Length > GAFHeader.headerDataOffset) { header.Read(freader); if (header.isValid) { _SharedData = new GAFAnimationData(); _SharedData.majorVersion = header.majorVersion; _SharedData.minorVersion = header.minorVersion; switch (header.compression) { case GAFHeader.CompressionType.CompressedNone: Read(freader, ref _SharedData); break; case GAFHeader.CompressionType.CompressedZip: #if GAF_SUPPORT_COMPRESSED using (ZlibStream zlibStream = new ZlibStream(fstream, CompressionMode.Decompress)) { byte [] uncompressedBuffer = new byte[header.fileLength]; zlibStream.Read(uncompressedBuffer, 0, uncompressedBuffer.Length); using (BinaryReader reader = new BinaryReader(new MemoryStream(uncompressedBuffer))) { Read(reader, ref _SharedData); } } break; #else GAFUtils.Assert(false, "GAF. Compressed gaf format is not supported in your plugin!"); break; #endif // GAF_SUPPORT_COMPRESSED } } } } }
public static void CheckTag(TagRecord _Record, BinaryReader _Reader) { if (_Reader.BaseStream.Position != _Record.expectedStreamPosition) { GAFUtils.Error( "GAFReader::CloseTag - " + "Tag " + _Record.type.ToString() + " " + "hasn't been correctly read, tag length is not respected. " + "Expected " + _Record.expectedStreamPosition + " " + "but actually " + _Reader.BaseStream.Position + " !"); } }
public void load() { lock (m_Locker) { #if UNITY_EDITOR if (m_AssetVersion < GAFSystem.AssetVersion && !EditorApplication.isPlayingOrWillChangePlaymode) { upgrade(); } #endif // UNITY_EDITOR if (m_AssetVersion == GAFSystem.AssetVersion) { if (!isLoaded && m_AssetData != null) { GAFReader reader = new GAFReader(); try { reader.Load(m_AssetData, ref m_SharedData); } catch (GAFException _Exception) { GAFUtils.Error(_Exception.Message); m_SharedData = null; } if (isLoaded && !m_IsExternalDataCollected) { collectExternalData(); #if UNITY_EDITOR if (!EditorApplication.isPlayingOrWillChangePlaymode) { EditorUtility.SetDirty(this); } #endif // UNITY_EDITOR } } } else { GAFUtils.Log("Asset \"" + name + "\" was not upgraged!", string.Empty); } } }
private static void onCreateClipPrefabPlusInstance(string _AssetPath, bool _IsBaked, bool _IsAnimator) { var assetName = Path.GetFileNameWithoutExtension(_AssetPath).Replace(" ", "_"); var assetDir = "Assets" + Path.GetDirectoryName(_AssetPath).Replace(Application.dataPath, "") + "/"; var asset = AssetDatabase.LoadAssetAtPath(assetDir + assetName + ".asset", typeof(GAFAnimationAsset)) as GAFAnimationAsset; if (!System.Object.Equals(asset, null)) { var selected = new List <Object>(Selection.gameObjects); var prefabPath = assetDir + assetName; if (_IsBaked) { prefabPath += "_baked"; } if (_IsAnimator) { prefabPath += "_animator"; } prefabPath += ".prefab"; var existingPrefab = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; if (existingPrefab == null) { var clipObject = createClip(asset, _IsBaked, _IsAnimator); var prefab = PrefabUtility.CreateEmptyPrefab(prefabPath); prefab = PrefabUtility.ReplacePrefab(clipObject, prefab, ReplacePrefabOptions.ConnectToPrefab); selected.Add(clipObject); selected.Add(prefab); } else { var instance = PrefabUtility.InstantiatePrefab(existingPrefab) as GameObject; selected.Add(existingPrefab); selected.Add(instance); } Selection.objects = selected.ToArray(); } else { GAFUtils.Log("Cannot find asset with path - " + _AssetPath, ""); } }
private static void onCreateMovieClip(string _AssetPath) { var assetName = Path.GetFileNameWithoutExtension(_AssetPath).Replace(" ", "_"); var assetDir = "Assets" + Path.GetDirectoryName(_AssetPath).Replace(Application.dataPath, "") + "/"; var asset = AssetDatabase.LoadAssetAtPath(assetDir + assetName + ".asset", typeof(GAFAnimationAsset)) as GAFAnimationAsset; if (!System.Object.Equals(asset, null)) { var movieClipObject = createMovieClip(asset); var selected = new List <Object>(Selection.gameObjects); selected.Add(movieClipObject); Selection.objects = selected.ToArray(); } else { GAFUtils.Log("Cannot find asset with path - " + _AssetPath, ""); } }
public void load() { lock (m_Locker) { #if UNITY_EDITOR m_GUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(this)); m_Version = GAFSystem.Version; #endif // UNITY_EDITOR if (!isLoaded) { if (m_AssetData != null) { GAFReader reader = new GAFReader(); try { reader.Load(m_AssetData, ref m_SharedData); } catch (GAFException _Exception) { GAFUtils.Error(_Exception.Message); m_SharedData = null; } } } if (isLoaded) { #if UNITY_EDITOR if (!m_IsObjectsCollected) { initObjectsLists(); } #endif // UNITY_EDITOR } } }