public void LoadResource <T>(string path, bool isSingle = true, bool _inBundle = false, System.Action <T> callback = null) where T : Object { ResourceObject resObject; ResourceCallback loadCallback = CreateCallback <T>(isSingle, callback); if (ResDict.TryGetValue(path, out resObject)) { if (resObject.isLoading) { //加载中 resObject.loadedCallback += loadCallback; } else { //已经加载了 resObject.loadedCallback = loadCallback; resObject.CallLoaded(); } } else if (ResourcePool.Instance.TryGetValue(path, out resObject)) { //从缓冲池中拿 ResourcePool.Instance.Remove(path); ResDict.Add(path, resObject); //回调 resObject.loadedCallback = loadCallback; resObject.CallLoaded(); } else { resObject = ResourceLoad.Instance.LoadResource(path, _inBundle, loadCallback); //放入字典 ResDict.Add(path, resObject); } }
public void PixelShader_should_take_texcoords_to_sample_cube_map() { // Arrange. var input = new VertexShaderOutput { TexCoords = new Vector3(1, 2, 3) }; var expectedColor = Vector4.One; var anyOtherColor = Vector4.Zero; ResourceCallback <Vector4> cubeSample = (u, v, w, i) => { var texCoords = new Vector3(u, v, w); return(texCoords.Equals(input.TexCoords) ? expectedColor : anyOtherColor); }; _pixelShader.SetResource("CubeSampler", cubeSample); //(u, v, w, i) => expectedColor);// ); // Act. var actual = _pixelShader.Execute <VertexShaderOutput, Vector4>(input); // Assert. Assert.That(actual, Is.EqualTo(expectedColor)); }
/// <summary> /// Sets a callback to be used whenever texture data is requested by a shader. /// The callback will be passed the u, v and w coordinates. /// </summary> /// <typeparam name="TColor">Color type, i.e. Vector4.</typeparam> /// <param name="name">Name of the resource.</param> /// <param name="callback">The callback will be executed once for each texture fetch, /// and will be passed the u, v and w coordinates.</param> public void SetResource <TColor>(string name, ResourceCallback <TColor> callback) where TColor : struct { // Validate. var resourceIndex = _resourceBindings.FindIndex(x => x.Name == name); if (resourceIndex == -1) { throw new ArgumentException("Could not find resource named '" + name + "'", "name"); } if (StructUtility.SizeOf <TColor>() != Number4.SizeInBytes) { throw new ArgumentException(string.Format("Expected color struct to be {0} bytes, but was {1}'", Number4.SizeInBytes, StructUtility.SizeOf <TColor>())); } // Set resource into virtual machine. We also set a default sampler state. var registerIndex = new RegisterIndex((ushort)resourceIndex); _virtualMachine.SetSampler(registerIndex, new SamplerState()); _virtualMachine.SetTexture(registerIndex, new FakeTexture((u, v, w, i) => { var bytes = StructUtility.ToBytes(callback(u, v, w, i)); return(Number4.FromByteArray(bytes, 0)); })); }
public ResourceObject(string path, bool _inBundle = false, ResourceCallback callback = null) { name = path; isLoading = true; resObject = null; inBundle = _inBundle; loadedCallback = callback; }
public object StartLoadResource(string path, ResourceCallback callback = null, object param = null) { TextAsset prefab = Resources.Load <TextAsset>(path); if (callback != null) { callback(prefab, param); } return(prefab); }
public ResourceObject LoadResource(string path, bool _inBundle = false, ResourceCallback callback = null) { //需要加载 ResourceObject resObject = new ResourceObject(path, _inBundle, callback); //加入load队列 LoadQueue.Enqueue(resObject); if (null == CoroutineHandle) { //协程还没启动 CoroutineHandle = _Load(); StartCoroutine(CoroutineHandle); } return(resObject); }
public FakeTextureMipMap(ResourceCallback<Number4> callback) { _callback = callback; }
public FakeTextureMipMap(ResourceCallback <Number4> callback) { _callback = callback; }