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;
        }
        private static GameObject createMovieClip(GAFAnimationAsset _Asset)
        {
            var clipObject = new GameObject(_Asset.name);

            var clip = clipObject.AddComponent<GAFMovieClip>();
            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);
            }
        }
Esempio n. 4
0
        public void initialize(GAFAnimationAsset _Asset, List <string> _Names, float _Scale, float _CSF, string _DataPath)
        {
            m_Asset         = _Asset;
            m_Scale         = _Scale;
            m_CSF           = _CSF;
            currentDataPath = _DataPath;

            foreach (var name in _Names)
            {
                m_Data.Add(new GAFResourceData(name));
            }
        }
        private void createPrefabPlusInstance(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);
            }
            else
            {
                PrefabUtility.InstantiatePrefab(existingPrefab);
            }
        }
 private void addToScene(GAFAnimationAsset _Asset)
 {
     createClip(_Asset);
 }
 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);
 }
Esempio n. 10
0
 protected override void initResource(GAFAnimationAsset _Asset)
 {
     resource = _Asset.getResource(settings.scale, settings.csf);
 }
 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();
     }
 }
        protected virtual void drawBuildResources(GAFAnimationAsset _Asset)
        {
            GUILayout.Space(3f);

            if (GUILayout.Button("Build resources"))
            {
                GAFResourceManager.createResources(_Asset);

                foreach (var _target in targets)
                    _target.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();
 }
		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();
						}
					}
				}
			}
		}
 public void init(GAFAnimationAsset _Asset)
 {
     scale = _Asset.scales[0];
     csf = _Asset.csfs[0];
 }
        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);
                }
            }
        }
Esempio n. 17
0
        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);
            }
        }
Esempio n. 18
0
        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;
        }
        public void initialize(GAFAnimationAsset _Asset, List<string> _Names, float _Scale, float _CSF, string _DataPath)
        {
            m_Asset			= _Asset;
            m_Scale			= _Scale;
            m_CSF			= _CSF;
            currentDataPath	= _DataPath;

            foreach (var name in _Names)
                m_Data.Add(new GAFResourceData(name));
        }
        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);
            }
        }