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() { 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, ""); } }