public static void OnPostprocessAllAssets( string[] importedAssets , string[] deletedAssets , string[] movedAssets , string[] movedFromAssetPaths) { foreach (string assetName in importedAssets) { if (assetName.EndsWith(".gaf")) { byte [] fileBytes = null; using (BinaryReader freader = new BinaryReader(File.OpenRead(assetName))) { fileBytes = freader.ReadBytes((int)freader.BaseStream.Length); } if (fileBytes.Length > sizeof(int)) { int header = System.BitConverter.ToInt32(fileBytes.Take(4).ToArray(), 0); if (GAFHeader.isCorrectHeader((GAFHeader.CompressionType)header)) { GAFAnimationAsset animationAsset = ScriptableObject.CreateInstance <GAFAnimationAsset>(); animationAsset = GAFAssetUtils.saveAsset(animationAsset, Path.GetDirectoryName(assetName) + "/" + Path.GetFileNameWithoutExtension(assetName) + ".asset"); animationAsset.init(fileBytes); GAFTracking.sendAssetCreatedRequest(assetName); } } } } }
public Material getMaterial(GAFAnimationAsset _Asset, uint _ObjectID, string _TextureName) { if (!System.Object.Equals(_Asset, null)) { if (_Asset.maskedObjects.Contains((int)_ObjectID)) { Material material = new Material(Shader.Find(m_sMaskedObjectShaderPath)); material.color = new Color(1f, 1f, 1f, 1f); material.mainTexture = getTexture(_TextureName); return(material); } else if (_Asset.coloredObjects.Contains((int)_ObjectID)) { Material material = new Material(Shader.Find(m_sColorizedObjectShaderPath)); material.color = new Color(1f, 1f, 1f, 1f); material.mainTexture = getTexture(_TextureName); return(material); } else if (_Asset.batchableObjects.Contains((int)_ObjectID)) { #if UNITY_EDITOR if (!GAFAssetUtils.checkAssets(ref m_SharedMaterials) || m_SharedMaterials.Find(material => material.name == _TextureName) == null) { createSharedData(); AssetDatabase.SaveAssets(); } #endif // UNITY_EDITOR return(m_SharedMaterials.Find(material => material.name == _TextureName)); } } return(null); }
protected virtual void drawChooseTimeline(GAFAnimationAsset _Asset) { if (_Asset.getTimelines().Count > 1) { GUILayout.Space(6f); EditorGUILayout.BeginVertical(EditorStyles.textField); { EditorGUILayout.LabelField("Choose timeline ID:"); EditorGUILayout.BeginHorizontal(); { var timelineIDs = _Asset.getTimelines().ConvertAll(timeline => timeline.id.ToString() + (timeline.linkageName.Length > 0 ? " - " + timeline.linkageName : "")).ToArray(); var index = GUILayout.SelectionGrid(m_TimelineIndex, timelineIDs, timelineIDs.Length < 4 ? timelineIDs.Length : 4); if (index != m_TimelineIndex) { m_TimelineIndex = index; var timeline = timelineIDs[index]; m_TimelineID = timeline.IndexOf(" - ") > 0 ? int.Parse(timeline.Split('-')[0]) : int.Parse(timeline); } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); } else { GUILayout.Space(6f); EditorGUILayout.BeginVertical(EditorStyles.textField); { EditorGUILayout.LabelField("Timeline ID: 0 - rootTimeline"); m_TimelineID = 0; m_TimelineIndex = 0; } EditorGUILayout.EndVertical(); } }
private static GameObject createClip(GAFAnimationAsset _Asset, bool _IsBaked, bool _IsAnimator) { var clipObject = new GameObject(_Asset.name); GAFInternal.Core.GAFBaseClip clip = null; if (_IsBaked) { if (!_IsAnimator) { clip = clipObject.AddComponent <GAFBakedMovieClip>(); } else { clip = clipObject.AddComponent <GAFBakedAnimator>(); } } else { if (!_IsAnimator) { clip = clipObject.AddComponent <GAFMovieClip>(); } else { clip = clipObject.AddComponent <GAFAnimator>(); } } clip.initialize(_Asset); clip.reload(); return(clipObject); }
public static void createResources(GAFAnimationAsset _Asset) { var assetPath = AssetDatabase.GetAssetPath(_Asset); if (!string.IsNullOrEmpty(assetPath)) { GAFSystemEditor.getCachePath(); var assetGUID = AssetDatabase.AssetPathToGUID(assetPath); var resourceTexturesNames = new Dictionary <KeyValuePair <float, float>, List <string> >(); _Asset.resetGUID(assetGUID); foreach (var timeline in _Asset.getTimelines()) { foreach (var atlas in timeline.atlases) { foreach (var data in atlas.texturesData.Values) { foreach (var textureInfo in data.files) { string textureName = Path.GetFileNameWithoutExtension(textureInfo.Value); var key = new KeyValuePair <float, float>(atlas.scale, textureInfo.Key); if (!resourceTexturesNames.ContainsKey(key)) { resourceTexturesNames[key] = new List <string>(); } resourceTexturesNames[key].Add(textureName); } } } } m_Resources.RemoveAll(resource => resource == null || !resource.isValid); foreach (var pair in resourceTexturesNames) { var name = _Asset.getResourceName(pair.Key.Key, pair.Key.Value) + ".asset"; var path = GAFSystemEditor.getCachePath() + name; var initialResDir = Path.GetDirectoryName(assetPath).Replace('\\', '/') + "/"; var resource = ScriptableObject.CreateInstance <GAFTexturesResource>(); resource = GAFAssetUtils.saveAsset(resource, path); resource.initialize(_Asset, pair.Value.Distinct().ToList(), pair.Key.Key, pair.Key.Value, initialResDir); EditorUtility.SetDirty(resource); findResourceTextures(resource, true); if (!resource.isReady) { m_Resources.Add(resource); } } EditorUtility.SetDirty(_Asset); } }
private void drawReloadAsset(GAFAnimationAsset _Asset) { GUILayout.Space(3f); if (GUILayout.Button("Reload asset")) { _Asset.reload(); } }
protected virtual void drawAssetIsNotLoaded(GAFAnimationAsset _Asset) { GUILayout.Space(3f); EditorGUILayout.BeginVertical(EditorStyles.textField); { EditorGUILayout.LabelField("Asset '" + _Asset.name + "' is not loaded properly! Try to reimport .GAF file!"); } EditorGUILayout.EndVertical(); }
private void drawResourcesMissing(GAFAnimationAsset _Asset) { GUILayout.Space(3f); EditorGUILayout.BeginVertical(EditorStyles.textField); { EditorGUILayout.LabelField("Asset '" + _Asset.name + "' missing resources! Try to reload asset!"); } EditorGUILayout.EndVertical(); }
private void drawAssetIsNotLoaded(GAFAnimationAsset _Asset) { GUILayout.Space(3f); EditorGUILayout.BeginVertical(EditorStyles.textField); { EditorGUILayout.LabelField("Asset '" + _Asset.name + "' is not loaded properly! Try to reload asset!"); } EditorGUILayout.EndVertical(); }
private static GameObject createMovieClip(GAFAnimationAsset _Asset) { var clipObject = new GameObject(_Asset.name); var clip = clipObject.AddComponent <GAFMovieClip>(); clip.initialize(_Asset); clip.reload(); return(clipObject); }
private static GameObject createMovieClip(GAFAnimationAsset _Asset) { var movieClipObject = new GameObject(_Asset.name); var movieClip = movieClipObject.AddComponent <GAFMovieClip>(); movieClip.settings.init(_Asset); movieClip.init(_Asset, 0); movieClip.reload(); return(movieClipObject); }
protected virtual void drawInitMovieClipButton(GAFAnimationAsset _Asset) { GUILayout.Space(3f); if (GUILayout.Button("Create GAF movie clip")) { foreach (var target in targets) { target.initialize(_Asset, m_TimelineID); target.reload(); GAFTracking.sendMovieClipCreatedRequest(_Asset.name); } } }
protected virtual void drawBuildResources(GAFAnimationAsset _Asset) { GUILayout.Space(3f); if (GUILayout.Button("Build resources")) { GAFResourceManager.createResources(_Asset); foreach (var _target in targets) { _target.reload(); } } }
public void init(GAFAnimationAsset _Asset, int _TimelineID) { if (!isInitialized) { m_IsInitialized = true; m_GAFAsset = _Asset; m_TimelineID = _TimelineID; m_Version = GAFSystem.Version; createMaskElements(); createAnimationObjects(); } }
public override void initialize(GAFAnimationAsset _Asset, int _TimelineID, bool _BakeObjects) { if (!isInitialized) { settings.init(_Asset); m_IsInitialized = true; m_MovieClipVersion = GAFSystem.MovieClipVersion; m_GAFAsset = _Asset; m_TimelineID = _TimelineID; manager.initialize(this, _BakeObjects); } }
public static void deleteResources(GAFAnimationAsset _Asset) { var assetPath = AssetDatabase.GetAssetPath(_Asset); if (!string.IsNullOrEmpty(assetPath)) { var resourcePaths = _Asset.resourcesPaths; foreach (var path in resourcePaths) { AssetDatabase.DeleteAsset(path); } _Asset.resetGUID(AssetDatabase.AssetPathToGUID(assetPath)); EditorUtility.SetDirty(_Asset); } }
private void createPrefab(GAFAnimationAsset _Asset) { var path = AssetDatabase.GetAssetPath(target); path = path.Substring(0, path.Length - name.Length - ".asset".Length); var prefabPath = path + name + ".prefab"; var existingPrefab = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; if (existingPrefab == null) { var clipObject = createClip(_Asset); var prefab = PrefabUtility.CreateEmptyPrefab(prefabPath); prefab = PrefabUtility.ReplacePrefab(clipObject, prefab, ReplacePrefabOptions.ConnectToPrefab); GameObject.DestroyImmediate(clipObject); } }
public void init(GAFAnimationAsset _Asset, List <string> _Names, float _Scale, float _CSF) { if (this != null && !string.IsNullOrEmpty(AssetDatabase.GetAssetPath(this))) { string path = AssetDatabase.GetAssetPath(_Asset); if (!string.IsNullOrEmpty(path)) { m_Asset = _Asset; m_TexturesNames = _Names; m_Scale = _Scale; m_CSF = _CSF; processTextures(); } } }
private void upgrade() { GAFAnimationAsset _asset = asset; int _timelineID = timelineID; GAFAnimationPlayerSettings _settings = settings; int _sequenceIndex = m_SequenceIndex; int _currentFrameNumber = m_CurrentFrameNumber; bool destroyChildren = m_Version == 0; clear(destroyChildren); m_Settings = _settings; m_SequenceIndex = _sequenceIndex; m_CurrentFrameNumber = _currentFrameNumber; init(_asset, _timelineID); }
public virtual void clear(bool destroyChildren) { if (m_ObjectsManager != null) { m_ObjectsManager.clear(destroyChildren); } if (cachedFilter.sharedMesh != null) { cachedFilter.sharedMesh.Clear(); } cachedRenderer.sharedMaterials = new Material[0]; m_GAFAsset = null; resource = null; m_Settings = new GAFAnimationPlayerSettings(); m_SequenceIndex = 0; m_CurrentFrameNumber = 1; m_IsInitialized = false; }
protected virtual void initResource(GAFAnimationAsset _Asset) { resource = _Asset.getResource(settings.scale, settings.csf); }
public abstract void initialize(GAFAnimationAsset _Asset, int _TimelineID, bool _BakeObjects);
public virtual void initialize(GAFAnimationAsset _Asset, int _TimelineID) { initialize(_Asset, _TimelineID, true); }
public virtual void initialize(GAFAnimationAsset _Asset) { initialize(_Asset, 0, true); }
public void init(GAFAnimationAsset _Asset) { scale = _Asset.scales[0]; csf = _Asset.csfs[0]; }
private void addToScene(GAFAnimationAsset _Asset) { createClip(_Asset); }
public static void OnPostprocessAllAssets( string[] importedAssets , string[] deletedAssets , string[] movedAssets , string[] movedFromAssetPaths) { foreach (string assetName in importedAssets) { if (assetName.EndsWith(".gaf")) { byte[] fileBytes = null; using (BinaryReader freader = new BinaryReader(File.OpenRead(assetName))) { fileBytes = freader.ReadBytes((int)freader.BaseStream.Length); } if (fileBytes.Length > sizeof(int)) { int header = System.BitConverter.ToInt32(fileBytes.Take(4).ToArray(), 0); if (GAFHeader.isCorrectHeader((GAFHeader.CompressionType)header)) { var path = Path.GetDirectoryName(assetName) + "/" + Path.GetFileNameWithoutExtension(assetName) + ".asset"; asset = AssetDatabase.LoadAssetAtPath(path, typeof(GAFAnimationAsset)) as GAFAnimationAsset; if (asset == null) { asset = ScriptableObject.CreateInstance <GAFAnimationAsset>(); AssetDatabase.CreateAsset(asset, path); asset = AssetDatabase.LoadAssetAtPath(path, typeof(GAFAnimationAsset)) as GAFAnimationAsset; findAsset = false; } var assetDir = Path.GetDirectoryName(path); assetDir = assetDir == "Assets" ? string.Empty : assetDir.Substring("Assets/".Length, assetDir.Length - "Assets/".Length); asset.name = Path.GetFileNameWithoutExtension(assetName); asset.initialize(fileBytes, AssetDatabase.AssetPathToGUID(path), assetDir == string.Empty ? assetDir : assetDir + "/"); EditorUtility.SetDirty(asset); AssetDatabase.SaveAssets(); GAFResourceManagerInternal.initInstance <GAFResourceManager>(); GAFResourceManagerInternal.instance.createResources <GAFTexturesResource>(asset); GAFResourceManagerInternal.instance.createMecanimResources(asset); GAFResourceManagerInternal.instance.defineAudioResources(asset); EditorUtility.SetDirty(asset); AssetDatabase.SaveAssets(); } } } else if (assetName.EndsWith(".asset")) { if (findAsset) { #if UNITY_5 asset = AssetDatabase.LoadAssetAtPath <GAFAnimationAsset>(assetName); #else asset = AssetDatabase.LoadAssetAtPath(assetName, typeof(GAFAnimationAsset)) as GAFAnimationAsset; #endif if (asset != null) { findAsset = false; } if (asset != null && ((asset.resourcesPaths == null || asset.resourcesPaths.Count == 0) || (asset.audioResources.Count == 0 && asset.sharedData.audioClips.Count > 0))) { GAFResourceManagerInternal.initInstance <GAFResourceManager>(); GAFResourceManagerInternal.instance.createResources <GAFTexturesResource>(asset); GAFResourceManagerInternal.instance.createMecanimResources(asset); GAFResourceManagerInternal.instance.defineAudioResources(asset); EditorUtility.SetDirty(asset); AssetDatabase.SaveAssets(); } } } } }