Exemplo n.º 1
0
        /// <summary>
        /// Initialize animation clip.
        /// <para />First operation that has to be performed to work with GAF playback.
        /// <para />Creating serializable data e.g. game objects of animation children.
        /// </summary>
        /// <param name="_Asset">Animation asset file.</param>
        /// <param name="_TimelineID">ID of timeline.</param>
        public override void initialize(GAFAnimationAssetInternal _Asset, int _TimelineID)
        {
            if (!isInitialized)
            {
                settings.init(_Asset);

                isInitialized = true;

                m_AnimatorVersion = GAFSystem.AnimatorVersion;
                asset             = _Asset;
                timelineID        = _TimelineID;
                m_Animator        = GetComponent <Animator>();
                m_ObjectsManager  = GetComponent <ObjectsManagerType>();

#if UNITY_5
                m_Animator.cullingMode = AnimatorCullingMode.CullUpdateTransforms;
#else
                m_Animator.cullingMode = AnimatorCullingMode.BasedOnRenderers;
#endif
                //m_Animator.hideFlags = HideFlags.NotEditable;
                m_Animator.runtimeAnimatorController = _Asset.getAnimatorController(timelineID);

                m_ObjectsManager.initialize();
            }
        }
Exemplo n.º 2
0
        public override void createMecanimResources(GAFAnimationAssetInternal _Asset)
        {
            var serializedAsset = new SerializedObject(_Asset);
            var mecanimFolder   = serializedAsset.FindProperty("m_MecanimResourcesDirectory");

            var mecanimFolderPath = string.Empty;

            if (!string.IsNullOrEmpty(mecanimFolder.stringValue) &&
                System.IO.Directory.Exists(Application.dataPath + "/" + mecanimFolder.stringValue))
            {
                mecanimFolderPath = "Assets/" + mecanimFolder.stringValue;
            }
            else
            {
                var assetDirectoryPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(_Asset));
                mecanimFolderPath         = assetDirectoryPath + "/" + _Asset.name + "_animator/";
                mecanimFolder.stringValue = mecanimFolderPath.Substring("Assets/".Length, mecanimFolderPath.Length - "Assets/".Length);
                serializedAsset.ApplyModifiedProperties();

                if (!System.IO.Directory.Exists(Application.dataPath + "/" + mecanimFolderPath.Substring("Assets/".Length, mecanimFolderPath.Length - "Assets/".Length)))
                {
                    AssetDatabase.CreateFolder(assetDirectoryPath, _Asset.name + "_animator");
                }
            }

            List <RuntimeAnimatorController> controllersList = new List <RuntimeAnimatorController>();

            foreach (var timeline in _Asset.getTimelines())
            {
                var controllerPath     = mecanimFolderPath + "[" + _Asset.name + "]_Timeline_" + timeline.linkageName + ".controller";
                var animatorController = AssetDatabase.LoadAssetAtPath(controllerPath, typeof(AnimatorController)) as AnimatorController;
                if (animatorController == null)
                {
                    animatorController = AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
                }

                createAnimations(timeline, animatorController, mecanimFolderPath);

                controllersList.Add(animatorController);
            }

            var controllers = serializedAsset.FindProperty("m_AnimatorControllers");

            controllers.ClearArray();
            for (int i = 0; i < controllersList.Count; ++i)
            {
                controllers.InsertArrayElementAtIndex(0);
                var property = controllers.GetArrayElementAtIndex(0);
                property.objectReferenceValue = controllersList[i];
            }

            serializedAsset.ApplyModifiedProperties();

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
        }
Exemplo n.º 3
0
		protected override void relocateAssetResources(GAFAnimationAssetInternal _Asset, string _NewPath)
		{
			for (int i = 0; i < _Asset.animatorControllers.Count; ++i)
			{
				var controllerOldPath = AssetDatabase.GetAssetPath(_Asset.animatorControllers[i]);
				var animatorController = _Asset.animatorControllers[i] as AnimatorController;
				var controllerNewPath = "Assets/" + _NewPath + System.IO.Path.GetFileName(controllerOldPath);
				var existingController = AssetDatabase.LoadAssetAtPath(controllerNewPath, typeof(AnimatorController)) as AnimatorController;
				if (existingController != null)
					AssetDatabase.DeleteAsset(controllerNewPath);

				AssetDatabase.MoveAsset(controllerOldPath, controllerNewPath);

#if !UNITY_5
				for (int j = 0; j < animatorController.layerCount; ++j)
				{
					var layerStateMachine = animatorController.GetLayer(j).stateMachine;
					for (int k = 0; k < layerStateMachine.stateCount; ++k)
					{
						var state = layerStateMachine.GetState(k);
						var clip = state.GetMotion() as AnimationClip;
						var clipOldPath = AssetDatabase.GetAssetPath(clip);
						var clipNewPath = "Assets/" + _NewPath + System.IO.Path.GetFileName(clipOldPath);
						var existingClip = AssetDatabase.LoadAssetAtPath(controllerNewPath, typeof(AnimationClip)) as AnimationClip;
						if (existingClip != null)
							AssetDatabase.DeleteAsset(clipNewPath);

						AssetDatabase.MoveAsset(clipOldPath, clipNewPath);
					}
				}
#else
				for (int j = 0; j < animatorController.layers.Length; ++j)
				{
					var layerStateMachine = animatorController.layers[j].stateMachine;
					for (int k = 0; k < layerStateMachine.states.Length; ++k)
					{
						var state = layerStateMachine.states[k].state;
						var clip = state.motion as AnimationClip;
						var clipOldPath = AssetDatabase.GetAssetPath(clip);
						var clipNewPath = "Assets/" + _NewPath + System.IO.Path.GetFileName(clipOldPath);
						var existingClip = AssetDatabase.LoadAssetAtPath(controllerNewPath, typeof(AnimationClip)) as AnimationClip;
						if (existingClip != null)
							AssetDatabase.DeleteAsset(clipNewPath);

						AssetDatabase.MoveAsset(clipOldPath, clipNewPath);
					}
				}
#endif // !UNITY_5
			}
		}
Exemplo n.º 4
0
		public override void createMecanimResources(GAFAnimationAssetInternal _Asset)
		{
			var serializedAsset = new SerializedObject(_Asset);
			var mecanimFolder = serializedAsset.FindProperty("m_MecanimResourcesDirectory");

			var mecanimFolderPath = string.Empty;
			if (!string.IsNullOrEmpty(mecanimFolder.stringValue) &&
				System.IO.Directory.Exists(Application.dataPath + "/" + mecanimFolder.stringValue))
			{
				mecanimFolderPath = "Assets/" + mecanimFolder.stringValue;
			}
			else
			{
				var assetDirectoryPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(_Asset));
				mecanimFolderPath = assetDirectoryPath + "/" + _Asset.name + "_animator/";
				mecanimFolder.stringValue = mecanimFolderPath.Substring("Assets/".Length, mecanimFolderPath.Length - "Assets/".Length);
				serializedAsset.ApplyModifiedProperties();

				if (!System.IO.Directory.Exists(Application.dataPath + "/" + mecanimFolderPath.Substring("Assets/".Length, mecanimFolderPath.Length - "Assets/".Length)))
					AssetDatabase.CreateFolder(assetDirectoryPath, _Asset.name + "_animator");
			}

			List<RuntimeAnimatorController> controllersList = new List<RuntimeAnimatorController>();
			foreach (var timeline in _Asset.getTimelines())
			{
				var controllerPath = mecanimFolderPath + "[" + _Asset.name + "]_Timeline_" + timeline.linkageName + ".controller";
				var animatorController = AssetDatabase.LoadAssetAtPath(controllerPath, typeof(AnimatorController)) as AnimatorController;
				if (animatorController == null)
					animatorController = AnimatorController.CreateAnimatorControllerAtPath(controllerPath);

				createAnimations(timeline, animatorController, mecanimFolderPath);

				controllersList.Add(animatorController);
			}

			var controllers = serializedAsset.FindProperty("m_AnimatorControllers");
			controllers.ClearArray();
			for (int i = 0; i < controllersList.Count; ++i)
			{
				controllers.InsertArrayElementAtIndex(0);
				var property = controllers.GetArrayElementAtIndex(0);
				property.objectReferenceValue = controllersList[i];
			}

			serializedAsset.ApplyModifiedProperties();

			AssetDatabase.SaveAssets();
			AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
		}
Exemplo n.º 5
0
        /// <summary>
        /// Initialize animation clip.
        /// <para />First operation that has to be performed to work with GAF playback.
        /// <para />Creating serializable data e.g. game objects of animation children.
        /// </summary>
        /// <param name="_Asset">Animation asset file.</param>
        /// <param name="_TimelineID">ID of timeline.</param>
        public override void initialize(GAFAnimationAssetInternal _Asset, int _TimelineID)
        {
            if (!isInitialized)
            {
                settings.init(_Asset);

                isInitialized = true;

                m_ClipVersion    = GAFSystem.MovieClipVersion;
                asset            = _Asset;
                timelineID       = _TimelineID;
                m_ObjectsManager = GetComponent <ObjectsManagerType>();

                m_SequenceIndex = asset.getSequences(_TimelineID).Count - 1;

                m_ObjectsManager.initialize();

                cacheAllStates();

                defineFramesEvents(stop, play, setSequence, gotoAndStop, gotoAndPlay);
            }
        }