public MovableSkeletalMeshEntity(string modelPath, string texturePath, string normalMapPath, string specularMapPath, float Speed, Vector3 translation, Vector3 rotation, Vector3 scale) : base(modelPath, texturePath, normalMapPath, specularMapPath, translation, rotation, scale) { TryLoadAnimation(modelPath); m_animationHolder = new AnimationHolder(m_animations); m_animationHolder.SetAnimationByNameNoBlend(m_animations[0].GetName()); }
/// <summary> /// /// </summary> /// <param name="res">ResHelper.</param> protected override void onBaseResLoadCompleteSyncCall() { if (bundle != null) { asset = bundle.LoadAsset <GameObject>(modelName); if (asset == null) { return; } #if UNITY_EDITOR EditorHelper.SetEditorShader(asset); #endif var refholder = asset.AddComponent <InastanceAssetRefHolder>(); refholder.resType = ResourceType.Model; refholder.assetName = modelName; //加载模型贴图资源 matHolder = asset.GetComponent <PrefabMaterialHolder>(); if (matHolder != null) { matHolder.SyncLoadMatsTex(); } //加载动作clip资源 clipHolder = asset.GetComponent <AnimationHolder>(); if (clipHolder != null) { clipHolder.SyncLoadClips(); } } }
public static void LoadAssets() { PlayerHolder.Initialize(); EnemyHolder.Initialize(); WeaponHolder.Initialize(); AmmunitionDropHolder.Initialize(); ProjectileHolder.Initialize(); SoundHolder.Initialize(); VisualEffectHolder.Initialize(); AnimationHolder.Initialize(); MapHolder.Initialize(); OnLoadingStatus += PlayerHolder.CurrentLoadingPercentage; OnLoadingStatus += EnemyHolder.CurrentLoadingPercentage; OnLoadingStatus += WeaponHolder.CurrentLoadingPercentage; OnLoadingStatus += ProjectileHolder.CurrentLoadingPercentage; OnLoadingStatus += SoundHolder.CurrentLoadingPercentage; OnLoadingStatus += VisualEffectHolder.CurrentLoadingPercentage; OnLoadingStatus += AnimationHolder.CurrentLoadingPercentage; OnLoadingStatus += AmmunitionDropHolder.CurrentLoadingPercentage; OnLoadingStatus += MapHolder.CurrentLoadingPercentage; PlayerHolder.LoadAssets(); EnemyHolder.LoadAssets(); WeaponHolder.LoadAssets(); ProjectileHolder.LoadAssets(); SoundHolder.LoadAssets(); VisualEffectHolder.LoadAssets(); AnimationHolder.LoadAssets(); AmmunitionDropHolder.LoadAssets(); MapHolder.LoadAssets(); }
// Start is called before the first frame update void Start() { anim = GetComponent <Animation>(); clip = new AnimationClip(); clip.legacy = true; holder = new AnimationHolder(); start_btn.onClick.AddListener(Start_Record); fin_btn.onClick.AddListener(Stop_Record); }
private void SendAnimationInfo(GameClient client, WorldObject obj) { if (obj != null) { AnimationHolder animations = obj.GetAnimations(); if (animations != null) { client.ChannelSend(new AnimatorUpdate(obj.GetObjectId(), animations.GetVelocityX(), animations.GetVelocityZ(), animations.IsTriggerJump(), animations.IsInWater(), animations.IsGrounded())); } } }
public SkeletonDummy(string pathToAnimatedMesh) { m_skeletonShader = PoolProxy.GetResource <ObtainShaderPool, ShaderAllocationPolicy <SkeletonShader>, string, SkeletonShader> (String.Format("{0}{1},{0}{2},{0}{3}", ProjectFolders.ShadersPath, "skeletonVS.glsl", "skeletonFS.glsl")); m_skeletonVAO = new VertexArrayObject(); InitBonesVAO(); m_animations = PoolProxy.GetResource <ObtainAnimationPool, AnimationAllocationPolicy, string, List <AnimationSequence> >(pathToAnimatedMesh); m_animationHolder = new AnimationHolder(m_animations); m_animationHolder.SetAnimationByNameNoBlend(m_animations[0].GetName()); }
public void ChangeAnimation(AnimationHolder animationHolder) { AnimationType type = animationHolder.animationType; if (!spriteMeshes.ContainsKey(type)) { Debug.Log("Animation type change not implemented:" + type.ToString()); return; } animationHolders[animationHolder.animationType] = animationHolder; spriteMeshes[animationHolder.animationType].spriteMesh = animationHolder.front; }
public static void Initialize() { EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager; if (Player.Entity != Entity.Null) { entityManager.DestroyEntity(Player.Entity); } Assert.IsNotNull(entityManager); //Create player entity Entity player = entityManager.Instantiate(PlayerHolder.PlayerPrefabDict[PlayerType.Player]); //Give player an animation batch entityManager.AddSharedComponentData(player, new AnimationBatch { BatchId = AnimationHolder.AddAnimatedObject() }); entityManager.SetComponentData(player, new Translation { Value = new float3(3, -1f, 20) }); entityManager.AddBuffer <DynamicAnimator>(player); var buff = entityManager.GetBuffer <DynamicAnimator>(player); buff.Add(new DynamicAnimator() { State = State.Running }); buff.Add(new DynamicAnimator() { State = State.Idle }); buff.Add(new DynamicAnimator() { State = State.Dashing }); buff.Add(new DynamicAnimator() { State = State.Dying }); /* * entityManager.SetComponentData(player, new Rotation * { * Value = quaternion.identity //TODO SET SPAWN ROTATION * });*/ Player.Entity = player; Player.CurrentWeaponHeld = WeaponType.Pistol; }
private void listBox_anims_SelectedIndexChanged(object sender, EventArgs e) { button_playAnim.Enabled = button_playbackAnim.Enabled = trackBar_anim.Enabled = listBox_anims.SelectedIndex >= 0; _curAnim = null; if (listBox_anims.SelectedIndex >= 0) { _curAnim = _anims[listBox_anims.SelectedIndex]; UpdateAnim(); NewRender(); } }
private void AddAnimationHolder(GameObject go) { if (go == null) { return; } AnimationHolder holder = go.GetComponent <AnimationHolder>(); if (holder == null) { return; } animationHolders.Add(holder.animationType, holder); }
void Awake() { if (Carrier == null) { Carrier = this; } else { WriteToLog("An instance of Log already exists with name: " + Carrier.gameObject.name); } if (!animationHolder) { animationHolder = GetComponentInChildren <AnimationHolder>(); } }
/// <summary> /// /// </summary> /// <param name="res">ResHelper.</param> protected override void onBaseResLoadCompleteSyncCall() { if (bundle != null) { asset = bundle.LoadAsset <GameObject>(modelName); bundle.Unload(false); bundle = null; if (asset == null) { return; } #if UNITY_EDITOR EditorHelper.SetEditorShader(asset); #endif var refholder = asset.GetOrAddComponent <InstanceAssetRefHolder>(); refholder.resType = ResourceType.Model; refholder.assetName = modelName; //加载模型贴图资源 var matHolder = asset.GetComponent <PrefabRenderHolder>(); if (matHolder != null) { texResRefs.Clear(); meshResRefs.Clear(); //GameObject.DestroyImmediate(matHolder, true); SyncLoadMatsTex(matHolder.rendersMatTexInfo, texResRefs); SyncLoadPrefabMesh(matHolder.rendersMeshInfo, meshResRefs); matHolder.rendersMatTexInfo = null; matHolder.rendersMeshInfo = null; } //加载动作clip资源 clipHolder = asset.GetComponent <AnimationHolder>(); if (clipHolder != null) { clipHolder.SyncLoadClips(); depAnimList = clipHolder.depAnimList; GameObject.DestroyImmediate(clipHolder, true); } } }
private void createEntity(int i, int j) { Entity e = em.Instantiate(en); em.SetComponentData(e, new Translation { Value = new float3(Random.Range(1, 100), 0, Random.Range(1, 100)) }); em.AddComponentData(e, new PathFollowComponent { pathIndex = -1, EnemyState = EnemyState.Wondering }); em.AddSharedComponentData(e, new BatchFilter { Value = batch++ }); em.AddSharedComponentData(e, new AnimationBatch { BatchId = AnimationHolder.AddAnimatedObject() }); batch %= 8; }
public void SetAnimations(AnimationHolder animations) { this.animations = animations; }
/// <summary> /// 真正异步加载部分重写 /// </summary> /// <returns></returns> protected override IEnumerator asyncLoadReal() { if (state == ResLoadingState.LOADSTATE_UNLOADED) { state = ResLoadingState.LOADSTATE_LOADING; var req = asyncLoadAb(name); if (req == null) { if (onCmp != null) { onCmp.Clear(); } UnityEngine.Debug.LogError("async load bundle error:" + name); state = ResLoadingState.LOADSTATE_UNLOADED; yield break; } yield return(req); bundle = req.assetBundle; refCount = 0; #region 异步加载贴图等资源,设置模型参数 if (bundle != null) { //异步加载bundle里的资源 var assetReq = bundle.LoadAssetAsync <GameObject>(modelName); yield return(assetReq); bundle.Unload(false); bundle = null; asset = assetReq.asset as GameObject; if (asset == null) { state = ResLoadingState.LOADSTATE_UNLOADED; yield break; } state = ResLoadingState.LOADSTATE_LOADING; #if UNITY_EDITOR EditorHelper.SetEditorShader(asset); #endif //异步加载模型贴图资源 var refholder = asset.GetOrAddComponent <InstanceAssetRefHolder>(); refholder.resType = ResourceType.Model; refholder.assetName = modelName; var matHolder = asset.GetComponent <PrefabRenderHolder>(); if (matHolder != null) { texResRefs.Clear(); meshResRefs.Clear(); //GameObject.DestroyImmediate(matHolder, true); //DestroyImmediate有问题 if (matHolder.rendersMatTexInfo != null && matHolder.rendersMatTexInfo.Count > 0) { yield return(AsyncLoadMatsTex(matHolder.rendersMatTexInfo, texResRefs)); } if (matHolder.rendersMeshInfo != null && matHolder.rendersMeshInfo.Count > 0) { yield return(AsyncLoadPrefabMesh(matHolder.rendersMeshInfo, meshResRefs)); } matHolder.rendersMeshInfo = null; matHolder.rendersMatTexInfo = null; } //异步加载动作clip资源 clipHolder = asset.GetComponent <AnimationHolder>(); if (clipHolder != null) { yield return(clipHolder.AsyncLoadClips()); depAnimList = clipHolder.depAnimList; GameObject.DestroyImmediate(clipHolder, true); } #endregion if (onCmp != null) { onCmp.Call(this); } state = ResLoadingState.LOADSTATE_LOADED; } else { if (onCmp != null) { onCmp.Clear(); } UnityEngine.Debug.LogError("async load bundle error:" + name); state = ResLoadingState.LOADSTATE_UNLOADED; } } else { if (onCmp != null) { onCmp.Call(this); } } }
/// <summary> /// 真正异步加载部分重写 /// </summary> /// <returns></returns> protected override IEnumerator asyncLoadReal() { if (state == ResLoadingState.LOADSTATE_UNLOADED) { state = ResLoadingState.LOADSTATE_LOADING; var req = asyncLoadAb(name); if (req == null) { if (onCmp != null) { onCmp.Clear(); } Logger.err("async load bundle error:" + name); state = ResLoadingState.LOADSTATE_UNLOADED; yield break; } yield return(req); bundle = req.assetBundle; refCount = 0; #region 异步加载贴图等资源,设置模型参数 if (bundle != null) { //异步加载bundle里的资源 var assetReq = bundle.LoadAssetAsync <GameObject>(modelName); yield return(assetReq); asset = assetReq.asset as GameObject; if (asset == null) { state = ResLoadingState.LOADSTATE_UNLOADED; yield break; } state = ResLoadingState.LOADSTATE_LOADING; #if UNITY_EDITOR EditorHelper.SetEditorShader(asset); #endif //异步加载模型贴图资源 var refholder = asset.AddComponent <InastanceAssetRefHolder>(); refholder.resType = ResourceType.Model; refholder.assetName = modelName; matHolder = asset.GetComponent <PrefabMaterialHolder>(); if (matHolder != null) { yield return(matHolder.AsyncLoadMatsTex()); } //异步加载动作clip资源 clipHolder = asset.GetComponent <AnimationHolder>(); if (clipHolder != null) { yield return(clipHolder.AsyncLoadClips()); } #endregion if (onCmp != null) { onCmp.Call(this); } state = ResLoadingState.LOADSTATE_LOADED; } else { if (onCmp != null) { onCmp.Clear(); } Logger.err("async load bundle error:" + name); state = ResLoadingState.LOADSTATE_UNLOADED; } } else { if (onCmp != null) { onCmp.Call(this); } } }
/// <summary> /// /// </summary> /// <param name="obj">Object.</param> public static new void Build(Object obj) { string assetPath = AssetDatabase.GetAssetPath(obj); if (!assetPath.EndsWith(".prefab")) { return; } //创建临时预制体 string temp_main_path = "Assets/temp/" + Path.GetFileName(assetPath); AssetDatabase.DeleteAsset(temp_main_path); var tempPrefab = GameObject.Instantiate(obj as GameObject); var texsDeps = GetDepTexs(tempPrefab); /* //记录需要打包的动画控制器 animator * Dictionary<RuntimeAnimatorController, string> aniCtrs = new Dictionary<RuntimeAnimatorController, string>(); * * //去掉动画控制器 * List<Animator> anis = new List<Animator>(); * tempPrefab.GetComponentsInChildren<Animator>(anis); * var mah = tempPrefab.AddComponent<ModelAnimatorHolder>(); * int count = 0; * foreach (var v in anis) * { * if (v.runtimeAnimatorController == null) * continue; * count++; * //得到文件目录名字 * string abName = AssetDatabase.GetAssetPath(v.runtimeAnimatorController); * * abName = abName.Replace( Path.GetFileName(abName),""); * abName.Replace("\\","/"); * string [] strs = abName.Split(new char[]{'/'}); * if (strs.Length < 3) * abName = v.runtimeAnimatorController.name + BuildConfig.abSuffix; * else * { * abName = strs[strs.Length - 3] + "_" + strs[strs.Length - 2] + "_"+v.runtimeAnimatorController.name + BuildConfig.abSuffix; * } * * abName = abName.Replace(" ", ""); * abName = abName.ToLower(); * abName = "ac_" + abName; * * if (!aniCtrs.ContainsKey(v.runtimeAnimatorController)) * { * aniCtrs[v.runtimeAnimatorController] = abName; * } * * if (mah.animatorCtrs == null) * mah.animatorCtrs = new List<ModelAnimatorHolder.AnimatorControllerPair>(); * mah.animatorCtrs.Add(new ModelAnimatorHolder.AnimatorControllerPair { animator = v,controllerABName = abName}); * * v.runtimeAnimatorController = null; * } * if (count == 0) * { * GameObject.DestroyImmediate(mah, true); * } * else * { * //打包动画控制器资源 * foreach (var v in aniCtrs) * { * AssetBundleBuild[] buildMap = new AssetBundleBuild[1]; * buildMap[0].assetBundleName = v.Value; * buildMap[0].assetNames = new string[] { AssetDatabase.GetAssetPath(v.Key) }; * BuildPipeline.BuildAssetBundles(BuildConfig.abOutputPath, buildMap, BuildConfig.options, EditorUserBuildSettings.activeBuildTarget); * } * } * */ //animation //看是否存在animation组件 var animation = tempPrefab.GetComponent <Animation>(); Dictionary <string, string> clipAssets = new Dictionary <string, string>(); //单独记录一个clip列表,以免存在重复添加clip的情况 List <AnimationClip> clips = new List <AnimationClip>(); AnimationHolder aniHolder = null; if (animation != null) { aniHolder = tempPrefab.AddComponent <AnimationHolder>(); aniHolder.ani = animation; aniHolder.depAnimList = new List <string>(); foreach (AnimationState state in animation) { string fbxPath = AssetDatabase.GetAssetPath(state.clip); clips.Add(state.clip); string fbxName = null; if (fbxPath.EndsWith("fbx")) { string[] arr = fbxPath.Split('/'); fbxName = arr[arr.Length - 1].ToLower(); fbxName = fbxName.Split('@')[0]; fbxName = fbxName.Split('.')[0]; } else { string[] arr = fbxPath.Split('/'); fbxName = arr[arr.Length - 2].ToLower(); } string clipAbName = "c_" + fbxName + "_" + state.clip.name.ToLower() + BuildConfig.abSuffix; //保存默认clip信息 if (animation.clip == state.clip) { aniHolder.defaultAnim = clipAbName; animation.clip = null; } //将动作资源单独保存一个临时的...因为我实在不知道怎么打包fbx里的动作资源... string temp_clip_path = "Assets/temp/" + state.clip.name + ".asset"; AssetDatabase.CreateAsset(Object.Instantiate(state.clip), temp_clip_path); clipAssets[clipAbName] = temp_clip_path; } //移除prefab所有clip foreach (var clip in clips) { animation.RemoveClip(clip); } foreach (var clipInfo in clipAssets) { //保存依赖的动作资源信息 aniHolder.depAnimList.Add(clipInfo.Key); } } //保存临时修改 PrefabUtility.CreatePrefab(temp_main_path, tempPrefab); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); //打包公共依赖 AssetBundleBuild[] buildMap1 = new AssetBundleBuild[2 + clipAssets.Count + texsDeps.Count]; buildMap1[0] = BuildCommand.getCommonDep(); int i = 0; for (i = 0; i < texsDeps.Count; i++) { buildMap1[i + 1] = texsDeps[i]; } i = 1 + texsDeps.Count; //打包动作文件 foreach (var clipInfo in clipAssets) { buildMap1[i].assetBundleName = clipInfo.Key; buildMap1[i].assetNames = new string[] { clipInfo.Value }; i++; } //打包临时prefab本身 buildMap1[buildMap1.Length - 1].assetBundleName = "m_" + obj.name.ToLower() + BuildConfig.abSuffix; buildMap1[buildMap1.Length - 1].assetNames = new string[] { temp_main_path }; BuildPipeline.BuildAssetBundles(BuildConfig.abOutputPath, buildMap1, BuildConfig.options, EditorUserBuildSettings.activeBuildTarget); //delete tmp obj GameObject.DestroyImmediate(tempPrefab); //删除临时资源 AssetDatabase.DeleteAsset(temp_main_path); foreach (var clipInfo in clipAssets) { AssetDatabase.DeleteAsset(clipInfo.Value); } AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { #if UNITY_EDITOR dstManager.SetName(entity, "Interactable Object"); #endif dstManager.AddComponentData(entity, new InteractableComponent { Type = Type, ObjectType = ObjectType }); //Add to Map portals if (ObjectType == InteractableObjectType.Portal) { //Create MapInfo for this MapType if (!MapHolder.MapsInfo.ContainsKey(CurrentMapType)) { MapHolder.MapsInfo.Add(CurrentMapType, new MapInfo()); } if (ReferenceEquals(PlayerTeleportPosition, null)) { PlayerTeleportPosition = transform; } //Add info MapHolder.MapsInfo[CurrentMapType].Portals.Add(PortalId, new MapInfo.Portal { Id = PortalId, Position = PlayerTeleportPosition.position, Rotation = PlayerTeleportPosition.rotation, MapTypeLeadingTo = MapTypeLeadingTo, PortalIdLeadingTo = PortalIdLeadingTo }); //Add Component to Entity dstManager.AddComponentData(entity, new PortalData { Value = PortalId }); } if (ObjectType == InteractableObjectType.Door) { //If Type Door -> Make sure theres a door linked to it lol Assert.IsNotNull(DoorToOpen); dstManager.AddComponentData(entity, new InteractableComponent { Type = Type, ObjectType = ObjectType, DoorToOpen = conversionSystem.GetPrimaryEntity(DoorToOpen) }); dstManager.AddSharedComponentData(entity, new AnimationBatch { BatchId = AnimationHolder.AddAnimatedObject() }); dstManager.AddComponent <AnimationData>(entity); } if (ObjectType == InteractableObjectType.Weapon) { dstManager.AddComponentData(entity, new InteractableComponent { Type = Type, ObjectType = ObjectType, WeaponType = WeaponType }); } if (ObjectType == InteractableObjectType.DoorClosing) { Entity door = conversionSystem.GetPrimaryEntity(DoorToOpen); dstManager.SetEnabled(door, false); dstManager.AddComponentData(entity, new InteractableComponent { Type = Type, ObjectType = ObjectType, DoorToOpen = door }); } }
public static T ManuallyInitialize <T>(this T ani) where T : IAnimation { AnimationHolder.EnsureInitialization(ani); return(ani); }