public void OverrideAnimationClip(string path) { if (_animationPath == path) { return; } _animationPath = path; if (_animationClipProxy != null) { _animationClipProxy.UnloadProxy(); } _animationClipProxy = ResourceMgr.singleton.LoadAssetAsync(path); _animationClipProxy.AddLoadFinishCallBack(() => { var clip = _animationClipProxy.GetUnityAsset <AnimationClip>(); if (Machine.AnimatorOverrideController && clip) { Machine.AnimatorOverrideController[StateName] = clip; Machine.Animator.runtimeAnimatorController = Machine.AnimatorOverrideController; //_animator.Rebind(); _animationClip = clip; } }); }
/// <summary> /// 同步从AssetBundle加载资源; /// </summary> /// <param name="path"></param> /// <param name="isUsePool"></param> /// <returns></returns> private AssetBundleAssetProxy LoadAssetSync(string path, bool isUsePool) { AssetBundleAssetProxy proxy = PoolMgr.Instance.GetCsharpObject <AssetBundleAssetProxy>(); proxy.Initialize(path, isUsePool); Object asset = null; AssetBundle assetBundle = AssetBundleMgr.Instance.LoadFromFile(path); if (assetBundle != null) { var name = Path.GetFileNameWithoutExtension(path); asset = assetBundle.LoadAsset(name); } if (asset == null) { AssetBundleMgr.Instance.UnloadAsset(path, null); LogHelper.PrintError(string.Format("[ResourceMgr]LoadSyncAssetProxy load asset:{0} failure.", path)); } else { AssetBundleMgr.Instance.AddAssetRef(path, asset); } proxy.OnFinish(asset); return(proxy); }
protected override void InitializeEx() { base.InitializeEx(); _partDataDict = new Dictionary <ModelPart, string> { [ModelPart.ModelHead] = ModelConfig.HeadArray[0], [ModelPart.ModelBody] = ModelConfig.BodyArray[0], [ModelPart.ModelHand] = ModelConfig.HandArray[0], [ModelPart.ModelFeet] = ModelConfig.FeetArray[0], [ModelPart.ModelWeapon] = ModelConfig.WeaponArray[0] }; _skeletonProxy = ResourceMgr.singleton.LoadAssetAsync(_skeletonPath); _skeletonProxy.AddLoadFinishCallBack(() => { _skeleton = _skeletonProxy.GetInstantiateObject <GameObject>(); OnLoaded(); }); _partProxyDict = new Dictionary <ModelPart, AssetBundleAssetProxy>(); _tempPartProxyDict = new Dictionary <ModelPart, AssetBundleAssetProxy>(); foreach (var temp in _partDataDict) { var part = temp.Key; var name = temp.Value; var proxy = ResourceMgr.singleton.LoadAssetAsync(name); _partProxyDict[part] = proxy; proxy.AddLoadFinishCallBack(OnLoaded); } }
/// <summary> /// 异步从AssetBundle加载资源; /// </summary> /// <param name="path"></param> /// <param name="progress"></param> /// <param name="isUsePool"></param> /// <returns></returns> public AssetBundleAssetProxy LoadAssetAsync(string path, Action <float> progress, bool isUsePool) { AssetBundleAssetProxy proxy = PoolMgr.Instance.GetCsharpObject <AssetBundleAssetProxy>(); proxy.Initialize(path, isUsePool); CoroutineMgr.Instance.RunCoroutine(LoadFromFileAsync(path, proxy, progress)); return(proxy); }
protected override void InitializeEx() { base.InitializeEx(); _skeletonProxy = ResourceMgr.singleton.LoadAssetAsync(_skeletonPath); _skeletonProxy.AddLoadFinishCallBack(() => { _skeleton = _skeletonProxy.GetInstantiateObject <GameObject>(); OnLoadFinish(); }); }
/// <summary> /// 异步从AssetBundle加载资源; /// </summary> /// <param name="path"></param> /// <param name="progress"></param> /// <param name="isUsePool"></param> /// <returns></returns> public AssetBundleAssetProxy LoadAssetAsync(string path, Action <float> progress, bool isUsePool) { path = $"Assets/Bundles/{path}"; AssetBundleAssetProxy proxy = PoolMgr.singleton.GetCsharpObject <AssetBundleAssetProxy>(); proxy.Initialize(path, isUsePool); CoroutineMgr.singleton.RunCoroutine(AssetLoader.LoadAssetAsync(path, proxy, progress)); return(proxy); }
public void OnUninitialize() { _objectRefDict.Clear(); _spriteDict.Clear(); _texture = null; _proxy.UnloadProxy(); _proxy = null; AtlasPath = null; RefCount = 0; Deprecated = false; }
public void OnInitialize(string atlasPath) { _objectRefDict.Clear(); _spriteDict.Clear(); _atlasPrefab = null; _proxy = null; AtlasPath = atlasPath; RefCount = 0; Deprecated = false; LoadAtlas(); }
/// Asset async load from AssetBundle; private IEnumerator <float> LoadFromFileAsync(string path, AssetBundleAssetProxy proxy , Action <float> progress) { AssetBundle assetBundle = null; //此处加载占0.8; IEnumerator itor = AssetBundleMgr.Instance.LoadFromFileAsync(path, bundle => { assetBundle = bundle; }, progress); while (itor.MoveNext()) { yield return(Timing.WaitForOneFrame); } var name = Path.GetFileNameWithoutExtension(path); AssetBundleRequest request = assetBundle.LoadAssetAsync(name); //此处加载占0.2; while (request.progress < 0.99f) { if (progress != null) { progress(LOAD_BUNDLE_PRECENT + LOAD_ASSET_PRECENT * request.progress); } yield return(Timing.WaitForOneFrame); } while (!request.isDone) { yield return(Timing.WaitForOneFrame); } if (null == request.asset) { AssetBundleMgr.Instance.UnloadAsset(path, null); LogHelper.PrintError(string.Format("[ResourceMgr]LoadFromFileAsync load asset:{0} failure.", path)); } else { AssetBundleMgr.Instance.AddAssetRef(path, request.asset); } //先等一帧; yield return(Timing.WaitForOneFrame); if (proxy != null) { proxy.OnFinish(request.asset); } else { LogHelper.PrintError(string.Format("[ResourceMgr]LoadFromFileAsync proxy is null:{0}.", path)); } }
public void Init(AbsEntity entity, string path, bool isAsync = true) { Entity = entity; ResPath = path; IsLoadFinish = false; proxy = ResourceMgr.singleton.LoadAssetAsync(ResPath); proxy.AddLoadFinishCallBack(() => { gameObject = proxy.GetInstantiateObject <GameObject>(); gameObject.name = entity.UID.ToString(); IsLoadFinish = true; Trans = gameObject.transform; _loadFinishHandler?.Invoke(this); }); }
public void Init(Animator animator, string path) { _animator = animator; _runtimeAnimatorProxy = ResourceMgr.Instance.LoadAssetAsync(path); _runtimeAnimatorProxy.AddLoadFinishCallBack(() => { RuntimeAnimatorController ctrl = _runtimeAnimatorProxy.GetUnityAsset <RuntimeAnimatorController>(); if (ctrl) { _animator.runtimeAnimatorController = ctrl; _animatorOverrideController = ctrl as AnimatorOverrideController; _animator.Rebind(); } }); }
public void Initialize(Animator animator, string path) { _animator = animator; _runtimeAnimatorProxy = ResourceMgr.singleton.LoadAssetAsync(path); _runtimeAnimatorProxy.AddLoadFinishCallBack(() => { var ctrl = _runtimeAnimatorProxy.GetUnityAsset <RuntimeAnimatorController>(); if (ctrl) { _animator.runtimeAnimatorController = ctrl; _animatorOverrideController = new AnimatorOverrideController(ctrl); _animator.Rebind(); } }); }
public void Initialize() { if (null == Entity) { return; } Animator = Entity.Animator; _runtimeAnimatorProxy = ResourceMgr.singleton.LoadAssetAsync(AssetPath); _runtimeAnimatorProxy.AddLoadFinishCallBack(() => { var ctrl = _runtimeAnimatorProxy.GetUnityAsset <RuntimeAnimatorController>(); if (ctrl) { AnimatorOverrideController = new AnimatorOverrideController(ctrl); Animator.runtimeAnimatorController = AnimatorOverrideController; Animator.Rebind(); Enable = true; TransToDefault(); //TODO foreach (var state in StateList) { var str = string.Empty; if (state.StateName == StateNameEnum.Idle.ToString()) { str = "Animation/Skeleton/Idle.anim"; } if (state.StateName == StateNameEnum.Move.ToString()) { str = "Animation/Skeleton/Run.anim"; } if (state.StateName == StateNameEnum.Skill.ToString()) { str = "Animation/Skeleton/Attack.anim"; } if (state.StateName == StateNameEnum.Special.ToString()) { str = "Animation/Skeleton/Damage.anim"; } if (state.StateName == StateNameEnum.Dead.ToString()) { str = "Animation/Skeleton/Death.anim"; } state.Initialize(str); } } }); }
public void OnUninitialize() { if (_atlasPrefab != null) { ResourceMgr.singleton.DestroyInstantiateObject(_atlasPrefab); } _objectRefDict.Clear(); _spriteDict.Clear(); _atlasPrefab = null; _proxy.UnloadProxy(); _proxy = null; AtlasPath = null; RefCount = 0; Deprecated = false; }
static int LoadAssetAsync(IntPtr L) { #if UNITY_EDITOR ToluaProfiler.AddCallRecord("Framework.ResourceMgr.Register"); #endif try { int count = LuaDLL.lua_gettop(L); if (count == 2) { Framework.ResourceMgr obj = (Framework.ResourceMgr)ToLua.CheckObject <Framework.ResourceMgr>(L, 1); string arg0 = ToLua.CheckString(L, 2); Framework.AssetBundleAssetProxy o = obj.LoadAssetAsync(arg0); ToLua.PushObject(L, o); return(1); } else if (count == 3) { Framework.ResourceMgr obj = (Framework.ResourceMgr)ToLua.CheckObject <Framework.ResourceMgr>(L, 1); string arg0 = ToLua.CheckString(L, 2); bool arg1 = LuaDLL.luaL_checkboolean(L, 3); Framework.AssetBundleAssetProxy o = obj.LoadAssetAsync(arg0, arg1); ToLua.PushObject(L, o); return(1); } else if (count == 4) { Framework.ResourceMgr obj = (Framework.ResourceMgr)ToLua.CheckObject <Framework.ResourceMgr>(L, 1); string arg0 = ToLua.CheckString(L, 2); System.Action <float> arg1 = (System.Action <float>)ToLua.CheckDelegate <System.Action <float> >(L, 3); bool arg2 = LuaDLL.luaL_checkboolean(L, 4); Framework.AssetBundleAssetProxy o = obj.LoadAssetAsync(arg0, arg1, arg2); ToLua.PushObject(L, o); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: Framework.ResourceMgr.LoadAssetAsync")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public IEnumerator <float> LoadAssetAsync(string path, AssetBundleAssetProxy proxy, Action <float> progress) { UnityObject asset = null; #if UNITY_EDITOR asset = UnityEditor.AssetDatabase.LoadAssetAtPath <UnityObject>(path); #endif //先等一帧; yield return(Timing.WaitForOneFrame); if (proxy != null) { proxy.OnFinish(asset); } else { LogHelper.PrintError($"[ResourceMgr]LoadFromFileAsync proxy is null:{path}."); } }
public void OverrideAnimationClip(string name, string path, bool autoPlay = true) { _animationClipProxy = ResourceMgr.Instance.LoadAssetAsync(path); _animationClipProxy.AddLoadFinishCallBack(() => { AnimationClip clip = _animationClipProxy.GetUnityAsset <AnimationClip>(); if (_animatorOverrideController && clip) { _animatorOverrideController[name] = clip; _animator.runtimeAnimatorController = _animatorOverrideController; _AnimationInfo.Data[name] = clip; _animator.Rebind(); if (autoPlay) { _animator.Play(name); } } }); }
public void Initialize() { if (null == Entity) { return; } Animator = Entity.Animator; _runtimeAnimatorProxy = ResourceMgr.singleton.LoadAssetAsync(AssetPath); _runtimeAnimatorProxy.AddLoadFinishCallBack(() => { RuntimeAnimatorController ctrl = _runtimeAnimatorProxy.GetUnityAsset <RuntimeAnimatorController>(); if (ctrl) { Animator.runtimeAnimatorController = ctrl; AnimatorOverrideController = new AnimatorOverrideController(ctrl); Animator.Rebind(); Enable = true; TransToDefault(); } }); }
protected override void OnInitialize() { base.OnInitialize(); uiRootProxy = ResourceMgr.singleton.LoadAssetAsync(_uiRoot); uiRootProxy.AddLoadFinishCallBack(() => { var go = uiRootProxy.GetInstantiateObject <GameObject>(); go.transform.localPosition = Vector3.zero; MainUICamera = go.transform.Find("MainUICamera").GetComponent <Camera>(); DontDestroyOnLoad(go); OnInitFinish(); }); mainCameraProxy = ResourceMgr.singleton.LoadAssetAsync(_mainCamera); mainCameraProxy.AddLoadFinishCallBack(() => { var go = mainCameraProxy.GetInstantiateObject <GameObject>(); go.transform.localPosition = Vector3.zero; MainCamera = go.transform.GetComponent <Camera>(); DontDestroyOnLoad(go); OnInitFinish(); }); }
private void LoadAtlas() { _proxy = ResourceMgr.singleton.LoadAssetAsync(AtlasPath); _proxy.AddLoadFinishCallBack(OnLoadFinish); }