private ReflectionData ReflectionLoadSet(Control f, Assembly assembly) { ReflectionData rd = new ReflectionData(); rd.Assembly = assembly; PropertyInfo prop; Type iType = rd.Assembly.GetType("RandomTool.IRandomTool"); Type iRandomToolType = (from t in rd.Assembly.GetExportedTypes() where !t.IsInterface && !t.IsAbstract where iType.IsAssignableFrom(t) select t).FirstOrDefault(); rd.iRandomInstance = Activator.CreateInstance(iRandomToolType, new object[] { f }); rd.Methods = SetMethods(iRandomToolType); rd.Properties = SetOptions(rd.iRandomInstance); prop = rd.iRandomInstance.GetType().GetProperty("ToolProperties"); rd.ToolPropertiesObj = prop.GetValue(rd.iRandomInstance, null); ////rd.iRandomInstance.GetType().GetProperty("ToolProperties").GetValue(rd.iRandomInstance, null).GetType().GetProperty("TextToShow") rd.ToolProperties = SetToolProperties(rd.iRandomInstance); prop = rd.iRandomInstance.GetType().GetProperty("EntryList"); rd.EntryList = prop.GetValue(rd.iRandomInstance, null); rd.EntryType = rd.Assembly.GetType("RandomTool.Entry"); //-----------Actions---------- // Find parent Form from control var control = f; Form parent = control as Form; while (parent == null) { control = control.Parent; parent = control as Form; } EventInfo stopEventInfo = iRandomToolType.GetEvent("ToolStopCall"); Type eventType = rd.Assembly.GetType("RandomTool.ToolStopEventHandler"); Delegate eventHandler = Delegate.CreateDelegate(eventType, parent, "EventStopCall"); rd.ActionEvents.Add(stopEventInfo); rd.ActionDelegates.Add(eventHandler); stopEventInfo.AddEventHandler(rd.iRandomInstance, eventHandler); EventInfo actionEventInfo = iRandomToolType.GetEvent("ToolActionCall"); eventType = rd.Assembly.GetType("RandomTool.ToolActionEventHandler"); eventHandler = Delegate.CreateDelegate(eventType, parent, "EventActionCall"); rd.ActionEvents.Add(actionEventInfo); rd.ActionDelegates.Add(eventHandler); actionEventInfo.AddEventHandler(rd.iRandomInstance, eventHandler); //---------------------------- return(rd); }
public override object GetValue(NodePort port) { if (port.fieldName == nameof(ValueOut)) { ReflectionData reflectionData = GetInputValue <ReflectionData>(nameof(ValueIn)); return(reflectionData.Value == null); } return(null); }
public void GetMemberValueTest() { var d = new ReflectionData { Name = "fireasy", TypeName = "type" }; var type = d.GetType(); Console.WriteLine(type.GetMember("Name")[0].GetMemberValue(d)); Console.WriteLine(type.GetMember("TypeName")[0].GetMemberValue(d)); }
public override object GetValue(NodePort port) { if (port.fieldName == nameof(Output)) { ReflectionData reflectionData = GetInputValue <ReflectionData>(nameof(Data)); return(Application.isPlaying ? SelectedSerializableInfo.GetRuntimeValue(reflectionData.Value) : SelectedSerializableInfo.GetEditorValue()); } return(null); }
public override void OnCreateConnection(NodePort from, NodePort to) { base.OnCreateConnection(from, to); if (to.fieldName == nameof(Data) && to.node == this) { ReflectionData reflectionData = GetInputValue <ReflectionData>(nameof(Data)); SerializableInfos.AddRange(reflectionData.Type .GetMethods(SerializableInfo.DefaultBindingFlags) .Select(info => new SerializableInfo(info))); } }
public JObject SaveToJson() { // Creates a new instance of reflectionData that will hold the data to be saved var reflectionDataObject = new ReflectionData(); // This is just a simple method created to copy data from this object to the reflectionData instance. reflectionDataObject.FromMonoBehavior(this); // With JObject.Serialize(object o) we have now created a Json Object from this C# objects. var jObjectResult = JObject.Serialize(reflectionDataObject); return jObjectResult; }
private void UpdateReflectedData() { SerializableInfos.Clear(); ReflectionData reflectionData = GetInputValue <ReflectionData>(nameof(Data)); SerializableInfos.AddRange(reflectionData.Type .GetFields(SerializableInfo.DefaultBindingFlags) .Select(info => new SerializableInfo(info, reflectionData.FromIteration))); SerializableInfos.AddRange(reflectionData.Type .GetProperties(SerializableInfo.DefaultBindingFlags) .Select(info => new SerializableInfo(info, reflectionData.FromIteration))); }
public void GetMemberTypeTest() { var d = new ReflectionData { Name = "fireasy", TypeName = "type" }; var type = typeof(ReflectionData).GetType(); Console.WriteLine(type.GetMember("Name")[0].GetMemberType()); Console.WriteLine(type.GetMember("TypeName")[0].GetMemberType()); Console.WriteLine(type.GetMember("Change")[0].GetMemberType()); Console.WriteLine(type.GetMember("GetAge")[0].GetMemberType()); }
/// <summary> /// Gets the <see cref="MethodInfo"/> descriptor of a method that can be used for storing /// the information about the specified <paramref name="reflectionData"/>. /// </summary> /// <param name="reflectionData">The reflection data type of interest.</param> /// <returns>A <see cref="MethodInfo"/> descriptor of a method of this class.</returns> public static MethodInfo GetMethod(ReflectionData reflectionData) { string methodName; switch (reflectionData) { case ReflectionData.MethodInfo: methodName = nameof(StoreMethodInfo); break; case ReflectionData.MethodInfoMultiple: methodName = nameof(StoreMethodInfos); break; case ReflectionData.FieldInfo: methodName = nameof(StoreFieldInfo); break; case ReflectionData.FieldInfoMultiple: methodName = nameof(StoreFieldInfos); break; case ReflectionData.FieldInfoValueRead: methodName = nameof(StoreFieldInfoValueRead); break; case ReflectionData.FieldInfoValueWrite: methodName = nameof(StoreFieldInfoValueWrite); break; case ReflectionData.PropertyInfo: methodName = nameof(StorePropertyInfo); break; case ReflectionData.PropertyInfoMultiple: methodName = nameof(StorePropertyInfos); break; case ReflectionData.PropertyInfoValueRead: methodName = nameof(StorePropertyInfoValueRead); break; case ReflectionData.PropertyInfoValueWrite: methodName = nameof(StorePropertyInfoValueWrite); break; default: throw new ArgumentOutOfRangeException(nameof(reflectionData), "Unsupported reflection data type"); } return(typeof(Storage).GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic)); }
private void AssignDelegate(object target, ReflectionData reflectionData) { SceneEvents events; if (!_sceneEvents.TryGetValue(reflectionData.Attribute.Scene, out events)) { events = new SceneEvents(); _sceneEvents.Add(reflectionData.Attribute.Scene, events); } events.Add( reflectionData.Attribute.SceneEventType, (Action)Delegate.CreateDelegate(typeof(Action), target, reflectionData.MethodInfo)); }
public JObject SaveToJson() { // Creates a new instance of reflectionData that will hold the data to be saved var reflectionDataObject = new ReflectionData(); // This is just a simple method created to copy data from this object to the reflectionData instance. reflectionDataObject.FromMonoBehavior(this); // With JObject.Serialize(object o) we have now created a Json Object from this C# objects. var jObjectResult = JObject.Serialize(reflectionDataObject); return(jObjectResult); }
private void RemoveDelegate(object target, ReflectionData reflectionData) { SceneEvents sceneEvents; if (!_sceneEvents.TryGetValue(reflectionData.Attribute.Scene, out sceneEvents)) { return; } sceneEvents.Remove( reflectionData.Attribute.SceneEventType, (Action)Delegate.CreateDelegate(typeof(Action), target, reflectionData.MethodInfo)); }
public override void OnCreateConnection(NodePort from, NodePort to) { if (to.fieldName == nameof(Data) && to.node == this) { SerializableInfos.Clear(); ReflectionData reflectionData = GetInputValue <ReflectionData>(nameof(Data)); SerializableInfos.AddRange(reflectionData.Type .GetFields(SerializableInfo.DefaultBindingFlags) .Select(info => new SerializableInfo(info, reflectionData.FromIteration))); SerializableInfos.AddRange(reflectionData.Type .GetProperties(SerializableInfo.DefaultBindingFlags) .Select(info => new SerializableInfo(info, reflectionData.FromIteration))); } }
public override object GetValue(NodePort port) { if (port.fieldName == nameof(ValueOut)) { ReflectionData firstValue = GetInputValue <ReflectionData>(nameof(FirstValueIn)); ReflectionData secondValue = GetInputValue <ReflectionData>(nameof(SecondValueIn)); if (firstValue.Value != null && secondValue.Value != null) { return(Vector3.Distance((Vector3)firstValue.Value, (Vector3)secondValue.Value)); } return(null); } return(null); }
public void CameraPostRender(Camera cam) { if (_mReflections.ContainsKey(cam)) { ReflectionData reflectionData = _mReflections[cam]; if (reflectionData.texture[0] != null) { RenderTexture.ReleaseTemporary(reflectionData.texture[0]); reflectionData.texture[0] = null; } if (reflectionData.texture[1] != null) { RenderTexture.ReleaseTemporary(reflectionData.texture[1]); reflectionData.texture[1] = null; } } }
public override void OnCreateConnection(NodePort from, NodePort to) { base.OnCreateConnection(from, to); if (to.fieldName == nameof(Enumerable) && to.node == this) { ReflectionData reflectionData = GetInputValue <ReflectionData>(nameof(Enumerable)); if (reflectionData.Type.IsGenericType && reflectionData.Type.GetGenericTypeDefinition().GetInterface(typeof(IEnumerable <>).FullName) != null) { Type type = reflectionData.Type.GetGenericArguments()[0]; _typeArgumentName = type.AssemblyQualifiedName; AddDynamicOutput(type, ConnectionType.Multiple, TypeConstraint.Inherited, type.Name); } else { Debug.LogError("Enumerable need to be a generic type (List or Array for example)"); } } }
public override void OnCreateConnection(NodePort from, NodePort to) { if (to.fieldName == nameof(Enumerable) && to.node == this) { ClearDynamicPorts(); ReflectionData reflectionData = GetInputValue <ReflectionData>(nameof(Enumerable)); if (typeof(IEnumerable).IsAssignableFrom(reflectionData.Type)) { Type type = reflectionData.Type.GetGenericArguments()[0]; _argumentTypeName = type.AssemblyQualifiedName; AddDynamicOutput(type, ConnectionType.Multiple, TypeConstraint.Inherited, type.Name); } else { from.Disconnect(to); } } }
private ReflectionData GetReflectionData(Camera currentCamera) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown ReflectionData value = null; if (_mReflections == null) { _mReflections = new Dictionary <Camera, ReflectionData>(); } if (!_mReflections.TryGetValue(currentCamera, out value)) { ReflectionData reflectionData = new ReflectionData(); reflectionData.propertyBlock = new MaterialPropertyBlock(); value = reflectionData; _mReflections[currentCamera] = value; } int width; int height; if (mirrorResolution == Dimension.Auto) { GetAutoResolution(currentCamera, out width, out height); } else { width = (int)mirrorResolution; height = (int)mirrorResolution; } int antiAliasing = QualitySettings.get_antiAliasing(); antiAliasing = Mathf.Max(1, antiAliasing); for (int i = 0; i < 2 && (i <= 0 || currentCamera.get_stereoEnabled()); i++) { if (Object.op_Implicit(value.texture[i])) { RenderTexture.ReleaseTemporary(value.texture[i]); } value.texture[i] = RenderTexture.GetTemporary(width, height, 24, 2, 0, antiAliasing); value.propertyBlock.SetTexture(_texturePropertyId[i], value.texture[i]); } return(value); }
/// <inheritdoc/> public IEnumerable <MethodInfo> GetMethods(ReflectionData reflectionData) { switch (reflectionData) { case ReflectionData.MethodInfo: return(GetMethodsForMethodQuery()); case ReflectionData.MethodInfoMultiple: return(GetMethodsForMethodsQuery()); case ReflectionData.FieldInfo: return(GetMethodsForFieldQuery()); case ReflectionData.FieldInfoMultiple: return(GetMethodsForFieldsQuery()); case ReflectionData.FieldInfoValueRead: return(GetMethodsForFieldRead()); case ReflectionData.FieldInfoValueWrite: return(GetMethodsForFieldWrite()); case ReflectionData.PropertyInfo: return(GetMethodsForPropertyQuery()); case ReflectionData.PropertyInfoMultiple: return(GetMethodsForPropertiesQuery()); case ReflectionData.PropertyInfoValueRead: return(GetMethodsForPropertyRead()); case ReflectionData.PropertyInfoValueWrite: return(GetMethodsForPropertyWrite()); default: throw new ArgumentOutOfRangeException(nameof(reflectionData), "Unsupported reflection data type"); } }
public void FastSetPropertyValueTest() { var p = typeof(ReflectionData).GetProperty("Name"); var t = TimeWatcher.Watch(() => { var s = new ReflectionData(); for (var i = 0; i < 10000000; i++) { p.SetValue(s, "A"); } }); Console.WriteLine("反射:" + t); var ps = Reflection.ReflectionCache.GetAccessor(p); t = TimeWatcher.Watch(() => { var s = new ReflectionData(); for (var i = 0; i < 10000000; i++) { ps.SetValue(s, "A"); } }); Console.WriteLine("缓存:" + t); t = TimeWatcher.Watch(() => { var s = new ReflectionData(); for (var i = 0; i < 10000000; i++) { s.Name = "A"; } }); Console.WriteLine("直接:" + t); }
// On-demand create any objects we need private ReflectionData GetReflectionData(Camera currentCamera) { ReflectionData reflectionData = null; if (!m_Reflections.TryGetValue(currentCamera, out reflectionData)) { reflectionData = new ReflectionData(); reflectionData.propertyBlock = new MaterialPropertyBlock(); m_Reflections[currentCamera] = reflectionData; } int width = currentCamera.pixelWidth; int height = currentCamera.pixelHeight; int antiAliasing = Mathf.Min(QualitySettings.antiAliasing, maxAntiAliasing); // Apparently when anti-aliasing is turned off in the quality settings, the value is 0 rather than 1 as expected... :( antiAliasing = Mathf.Max(1, antiAliasing); // For stereo cameras, we are going to render into a double-wide texture if (currentCamera.stereoEnabled) { width *= 2; } if (!reflectionData.texture || reflectionData.texture.width != width || reflectionData.texture.height != height || reflectionData.texture.antiAliasing != antiAliasing) { if (reflectionData.texture) { DestroyImmediate(reflectionData.texture); } reflectionData.texture = new RenderTexture(width, height, 24); reflectionData.texture.antiAliasing = antiAliasing; reflectionData.texture.hideFlags = HideFlags.DontSave; reflectionData.propertyBlock.SetTexture(TexturePropertyID, reflectionData.texture); } return(reflectionData); }
private void InternalInitialize(int id) { windowID = id; if (rData == null) { rData = new ReflectionData(typeof(ExtendedControl)); } if (Position == Vector2.zero && Size == Vector2.zero) { WindowRect = new Rect(Vector2.zero, Editor.Size); } if (WindowSettings == null) { WindowSettings = new ExtendedWindowSettings(); } SceneView.onSceneGUIDelegate -= InternalSceneGUI; SceneView.onSceneGUIDelegate += InternalSceneGUI; OnInitialize(); }
static Reflector() { foreach (var type in //This is more correct but way slower //AppDomain.CurrentDomain.GetAssemblies() //.Where(a => !a.IsDynamic) //.Where(a => a.GetCustomAttributes(false).Any(c => c is ReflectAttribute)) ReflectableAssemblies .SelectMany(a => a.GetTypes())) { foreach (var ca in type.GetCustomAttributes()) { if (ca is ReflectAttribute ra) { ReflectionData.RecordPublic(type, ra.returnType); break; } } } InitializeEnumResolvers(); AllowMath <TEx <float> >(); AllowMath <TEx <bool> >(); //This will also allow stuff like (if + true false), which will error if you actually use it AllowMath <TEx <Vector2> >(); AllowMath <TEx <Vector3> >(); AllowMath <TEx <Vector4> >(); AllowMath <TEx <V2RV2> >(); void CreatePostAggregates(string method, string shortcut) { var mi = typeof(ExPostAggregators).GetMethod(method) ?? throw new Exception($"Couldn't find post-aggregator \"{method}\""); var attrs = Attribute.GetCustomAttributes(mi); var priority = 999; Type[]? types = null; foreach (var attr in attrs) { if (attr is PAPriorityAttribute pp) { priority = pp.priority; } else if (attr is PASourceTypesAttribute ps) { types = ps.types; } } void CreateAggregateMethod(MethodInfo gmi) { var prms = gmi.GetParameters(); if (prms.Length != 2) { throw new Exception($"Post-aggregator \"{method}\" doesn't have 2 arguments"); } var sourceType = prms[0].ParameterType; var searchType = prms[1].ParameterType; if (gmi.ReturnType != sourceType) { throw new Exception($"Post-aggregator \"{method}\" has a different return and first argument type"); } postAggregators.SetDefaultSet(sourceType, shortcut, new PostAggregate(priority, sourceType, searchType, gmi)); } if (types == null) { CreateAggregateMethod(mi); } else { //types = [ (float), (v2) ... ] foreach (var rt in types) { CreateAggregateMethod(mi.MakeGenericMethod(rt)); } } } CreatePostAggregates("PA_Add", "+"); CreatePostAggregates("PA_Mul", "*"); CreatePostAggregates("PA_Sub", "-"); CreatePostAggregates("PA_Div", "/"); CreatePostAggregates("PA_FDiv", "//"); CreatePostAggregates("PA_Pow", "^"); CreatePostAggregates("PA_And", "&"); CreatePostAggregates("PA_Or", "|"); void CreatePreAggregates(string method, string shortcut) { var mi = typeof(ExPreAggregators).GetMethod(method) ?? throw new Exception($"Couldn't find post-aggregator \"{method}\""); var attrs = Attribute.GetCustomAttributes(mi); var priority = 999; var types = new Type[0]; foreach (var attr in attrs) { if (attr is PAPriorityAttribute pp) { priority = pp.priority; } else if (attr is PASourceTypesAttribute ps) { types = ps.types; } } //types = [ (float), (v2) ... ] foreach (var rt in types) { var gmi = mi.MakeGenericMethod(rt); var prms = gmi.GetParameters(); if (prms.Length != 2) { throw new Exception($"Pre-aggregator \"{method}\" doesn't have 2 arguments"); } var resultType = gmi.ReturnType; var searchType1 = prms[0].ParameterType; var searchType2 = prms[1].ParameterType; if (preAggregators.TryGetValue(resultType, out var res)) { if (res.firstType != searchType1) { throw new Exception( $"Pre-aggregators currently support only one reducer type, " + $"but return type {resultType.RName()} is associated with " + $"{res.firstType.RName()} and {searchType1.RName()}."); } } else { res = new PreAggregate(searchType1); } res.AddResolver(new PreAggregateResolver(shortcut, searchType2, gmi, priority)); preAggregators[resultType] = res; } } CreatePreAggregates("PA_Mul", "*"); CreatePreAggregates("PA_GT", ">"); CreatePreAggregates("PA_LT", "<"); CreatePreAggregates("PA_GEQ", ">="); CreatePreAggregates("PA_LEQ", "<="); CreatePreAggregates("PA_EQ", "="); CreatePreAggregates("PA_NEQ", "=/="); foreach (var key in preAggregators.Keys.ToArray()) { var res = preAggregators[key]; res.SortResolvers(); preAggregators[key] = res; } }
public MyReflection(Control f, Assembly assembly) { Instance = ReflectionLoadSet(f, assembly); }
public void OnWillRenderObject() { //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) Renderer component = this.GetComponent <Renderer>(); if (this.get_enabled() && Object.op_Implicit(component) && component.get_enabled()) { Camera current = Camera.get_current(); if (Object.op_Implicit(current) && !(current == mirrorCamera) && !_sInsideRendering) { _sInsideRendering = true; ReflectionData reflectionData = GetReflectionData(current); int pixelLightCount = QualitySettings.get_pixelLightCount(); if (m_DisablePixelLights) { QualitySettings.set_pixelLightCount(0); } UpdateCameraModes(current); UpdateParentTransform(current); if (current.get_stereoEnabled()) { if (ShouldRenderLeftEye(current)) { Vector3 worldEyePos = GetWorldEyePos(current, 0); Quaternion worldEyeRot = GetWorldEyeRot(current, 0); Matrix4x4 eyeProjectionMatrix = GetEyeProjectionMatrix(current, 0); RenderMirror(reflectionData.texture[0], worldEyePos, worldEyeRot, eyeProjectionMatrix); } if (ShouldRenderRightEye(current)) { Vector3 worldEyePos2 = GetWorldEyePos(current, 1); Quaternion worldEyeRot2 = GetWorldEyeRot(current, 1); Matrix4x4 eyeProjectionMatrix2 = GetEyeProjectionMatrix(current, 1); RenderMirror(reflectionData.texture[1], worldEyePos2, worldEyeRot2, eyeProjectionMatrix2); } } else if (ShouldRenderMonoscopic(current)) { RenderMirror(reflectionData.texture[0], current.get_transform().get_position(), current.get_transform().get_rotation(), current.get_projectionMatrix()); } component.SetPropertyBlock(reflectionData.propertyBlock); if (m_DisablePixelLights) { QualitySettings.set_pixelLightCount(pixelLightCount); } _sInsideRendering = false; } } }
// This is called when it's known that this mirror will be rendered by some camera. We render reflections // and do other updates here. Because the script executes in edit mode, reflections for the scene view // camera will just work! public void OnWillRenderObject() { var rend = GetComponent <Renderer>(); if (!enabled || !rend || !rend.enabled) { return; } Camera cam = Camera.current; if (!cam || cam == mirrorCamera) { return; } // Safeguard from recursive reflections. if (s_InsideRendering) { return; } s_InsideRendering = true; ReflectionData reflectionData = GetReflectionData(cam); // Optionally disable pixel lights for reflection int oldPixelLightCount = QualitySettings.pixelLightCount; if (disablePixelLights) { QualitySettings.pixelLightCount = 0; } UpdateCameraModes(cam); // Sure would be nice if we could automatically do stereo instanced rendering to a split texture if (cam.stereoEnabled) { if (cam.stereoTargetEye == StereoTargetEyeMask.Both || cam.stereoTargetEye == StereoTargetEyeMask.Left) { Vector3 eyePos = cam.transform.TransformPoint(SteamVR.instance.eyes[0].pos); Quaternion eyeRot = cam.transform.rotation * SteamVR.instance.eyes[0].rot; Matrix4x4 projectionMatrix = GetSteamVRProjectionMatrix(cam, Valve.VR.EVREye.Eye_Left); RenderMirror(reflectionData.texture, eyePos, eyeRot, projectionMatrix, LeftEyeRect); } if (cam.stereoTargetEye == StereoTargetEyeMask.Both || cam.stereoTargetEye == StereoTargetEyeMask.Right) { Vector3 eyePos = cam.transform.TransformPoint(SteamVR.instance.eyes[1].pos); Quaternion eyeRot = cam.transform.rotation * SteamVR.instance.eyes[1].rot; Matrix4x4 projectionMatrix = GetSteamVRProjectionMatrix(cam, Valve.VR.EVREye.Eye_Right); RenderMirror(reflectionData.texture, eyePos, eyeRot, projectionMatrix, RightEyeRect); } } else { RenderMirror(reflectionData.texture, cam.transform.position, cam.transform.rotation, cam.projectionMatrix, DefaultRect); } // Apply the property block containing the appropriate reflection texture reference to this mirror's renderer rend.SetPropertyBlock(reflectionData.propertyBlock); // Restore pixel light count if (disablePixelLights) { QualitySettings.pixelLightCount = oldPixelLightCount; } s_InsideRendering = false; }
//Save the inputed event handler's methods that take in an event as it's only parameter to the list of event listeners //for that event //Very Reflection Heavy... public void registerEventListener(IListener eventHandler) { //Get the type of the type of the eventHandler Type handlerType = eventHandler.GetType(); //Iterate over all methods in the class foreach (MethodInfo methodInfo in handlerType.GetMethods()) { //Get any attributes associated with the method (attributes are the tags within the [] above the method definition) object[] attributes = methodInfo.GetCustomAttributes(false); //Initially we decide that most methods aren't event listeners, this covers us also if the method has no //attributes bool isEventListener = false; //Initialise the counting variable at 0 int i = 0; //Iterate over all the attributes on the method as long as we haven't reached the last one or encountered the desired //attribute while (!isEventListener && i < attributes.Length) { //Compare the current attribute to the desired attribute, if they are the same type, then this //method has been tagged as an event listener isEventListener = attributes[i].GetType() == typeof(EventListener); //increment the indexing variable i++; } //If the method was tagged with the EventListener attribute if (isEventListener) { //Get all parameters that the method take in ParameterInfo[] parameters = methodInfo.GetParameters(); //The method is assumed not to take in the correct amount and types of parameters initially bool isEventMethod = false; //The method can only be an event listener if it take in only 1 event as it's paramter if (parameters.Length == 1) { //Get the Reflection data type that refers to the parameter of the method ParameterInfo parameter = parameters[0]; //Get the type (the class) of the paramter Type parameterType = parameter.ParameterType; //The method is an event listener if it takes in an event as it's paramter, or any subclass of the //event class Type eventType = typeof(Event); isEventMethod = parameterType == eventType || parameterType.IsSubclassOf(eventType); } //If the method is an evetn listener, then we save a reference to it in the eventhandlers dictionary if (isEventMethod) { //Get the type of the event parameter of the method Type eventType = parameters[0].ParameterType; //Initialise an empty list of Reflection Data that is associated with the event parameter List <ReflectionData> handlerDataList = new List <ReflectionData>(); //If there already methods registered as event listeners for this event, then get the list of them from the dictionary if (eventHandlers.ContainsKey(eventType)) { handlerDataList = eventHandlers[eventType]; } //Create a ReflectionData object to store a reference to the event handler instance and the event listener //method ReflectionData handlerData = new ReflectionData(eventHandler, methodInfo); //Add this data to the existing list of event handlers for the event handlerDataList.Add(handlerData); //Save this updated list to the dictionary with the calling event as it's reference eventHandlers[eventType] = handlerDataList; } } } }
private IEnumerable <object> GetCollection() { ReflectionData reflectionData = GetInputValue <ReflectionData>(nameof(Enumerable)); return((IEnumerable <object>)reflectionData.Value); }
// On-demand create any objects we need private void CreateMirrorObjects(Camera currentCamera, out ReflectionData reflectionData) { if (!m_ReflectionCameras.TryGetValue(currentCamera, out reflectionData)) { reflectionData = new ReflectionData(); reflectionData.propertyBlock = new MaterialPropertyBlock(); m_ReflectionCameras[currentCamera] = reflectionData; } // Camera for reflection if (!reflectionData.camera) { GameObject go = new GameObject("Mirror Refl Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(), typeof(Camera), typeof(Skybox), typeof(FlareLayer)); reflectionData.camera = go.GetComponent <Camera>(); reflectionData.camera.enabled = false; go.hideFlags = HideFlags.HideAndDontSave; } if (m_UseSharedRenderTexture) { // Get rid of any per camera reflection textures if (reflectionData.left) { DestroyImmediate(reflectionData.left); reflectionData.left = null; } if (reflectionData.right) { DestroyImmediate(reflectionData.right); reflectionData.right = null; } // Create shared reflection textures of the desired size if (!m_SharedReflectionTextureLeft || m_SharedReflectionTextureLeft.width != m_SharedTextureSize) { if (m_SharedReflectionTextureLeft) { DestroyImmediate(m_SharedReflectionTextureLeft); } m_SharedReflectionTextureLeft = new RenderTexture(m_SharedTextureSize, m_SharedTextureSize, 24); m_SharedReflectionTextureLeft.name = "__MirrorReflectionLeft" + GetInstanceID(); m_SharedReflectionTextureLeft.hideFlags = HideFlags.DontSave; } if (!m_SharedReflectionTextureRight || m_SharedReflectionTextureRight.width != m_SharedTextureSize) { if (m_SharedReflectionTextureRight) { DestroyImmediate(m_SharedReflectionTextureRight); } m_SharedReflectionTextureRight = new RenderTexture(m_SharedTextureSize, m_SharedTextureSize, 24); m_SharedReflectionTextureRight.name = "__MirrorReflectionRight" + GetInstanceID(); m_SharedReflectionTextureRight.hideFlags = HideFlags.DontSave; } } else { // Get rid of any the shared reflection textures if (m_SharedReflectionTextureLeft) { DestroyImmediate(m_SharedReflectionTextureLeft); m_SharedReflectionTextureLeft = null; } if (m_SharedReflectionTextureRight) { DestroyImmediate(m_SharedReflectionTextureRight); m_SharedReflectionTextureRight = null; } // Reflection render texture if (!reflectionData.left || reflectionData.left.width != currentCamera.pixelWidth || reflectionData.left.height != currentCamera.pixelHeight) { if (reflectionData.left) { DestroyImmediate(reflectionData.left); } reflectionData.left = new RenderTexture(currentCamera.pixelWidth, currentCamera.pixelHeight, 24); reflectionData.left.name = "__MirrorReflectionLeft" + GetInstanceID() + " for " + currentCamera.GetInstanceID(); reflectionData.left.hideFlags = HideFlags.DontSave; reflectionData.propertyBlock.SetTexture(s_LeftTexturePropertyID, reflectionData.left); } // If stereo is enabled, create right reflection texture if (currentCamera.stereoEnabled) { if (!reflectionData.right || reflectionData.right.width != currentCamera.pixelWidth || reflectionData.right.height != currentCamera.pixelHeight) { if (reflectionData.right) { DestroyImmediate(reflectionData.right); } reflectionData.right = new RenderTexture(currentCamera.pixelWidth, currentCamera.pixelHeight, 24); reflectionData.right.name = "__MirrorReflectionRight" + GetInstanceID() + " for " + currentCamera.GetInstanceID(); reflectionData.right.hideFlags = HideFlags.DontSave; reflectionData.propertyBlock.SetTexture(s_RightTexturePropertyID, reflectionData.right); } } } }
public BinarySerializerContext(BitConverterHelper helper, Type type) { BitConverterHelper = helper; ReflectionData = new ReflectionData(type); }