{"id":1550,"date":"2019-11-20T15:55:13","date_gmt":"2019-11-20T15:55:13","guid":{"rendered":"https:\/\/docs.sisus.co\/power-inspector\/?p=1550"},"modified":"2019-11-20T15:55:13","modified_gmt":"2019-11-20T15:55:13","slug":"icomponentmodifiedcallbackreceiver","status":"publish","type":"post","link":"https:\/\/docs.sisus.co\/power-inspector\/attributes\/icomponentmodifiedcallbackreceiver\/","title":{"rendered":"IComponentModifiedCallbackReceiver"},"content":{"rendered":"<p>Interface for attributes that can be added to component classes to receive callbacks when components of a certain type are added or modified through the inspector.<\/p>\n<p>OnComponentAdded is called whenever a new component of type TComponent is added to the GameObject that contains the component with this attribute.<\/p>\n<p>OnComponentModified is called whenever an existing component of type TComponent is modified on the GameObject that contains the component with this attribute.<\/p>\n<h2>Interface Implementer<\/h2>\n<p>Attribute targeting a component class.<\/p>\n<h2>Example<\/h2>\n<pre>using System;\r\nusing UnityEngine;\r\n\r\n\/\/\/ &lt;summary&gt;\r\n\/\/\/ When added before a component class causes the transform component to be locked to default state for all GameObjects that contain the component with this attribute.\r\n\/\/\/ &lt;\/summary&gt;\r\n[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]\r\npublic sealed class LockTransformAttribute : Attribute, IComponentModifiedCallbackReceiver&lt;Transform&gt;\r\n{\r\n\t\/\/\/ &lt;inheritdoc\/&gt;\r\n\tpublic void OnComponentAdded(Component attributeHolder, Transform addedComponent)\r\n\t{\r\n\t\taddedComponent.hideFlags = HideFlags.NotEditable;\r\n\t\taddedComponent.localPosition = Vector3.zero;\r\n\t\taddedComponent.localEulerAngles = Vector3.zero;\r\n\t\taddedComponent.localScale = Vector3.one;\r\n\t}\r\n\r\n\t\/\/\/ &lt;inheritdoc\/&gt;\r\n\tpublic void OnComponentModified(Component attributeHolder, Transform modifiedComponent)\r\n\t{\r\n\t\tif(modifiedComponent.localPosition != Vector3.zero || modifiedComponent.localEulerAngles != Vector3.zero || modifiedComponent.localScale != Vector3.one)\r\n\t\t{\r\n\t\t\tDebug.LogWarning(attributeHolder.GetType().Name + \" requires that \" + modifiedComponent.GetType().Name + \" remains at default state.\");\r\n\r\n\t\t\tmodifiedComponent.localPosition = Vector3.zero;\r\n\t\t\tmodifiedComponent.localEulerAngles = Vector3.zero;\r\n\t\t\tmodifiedComponent.localScale = Vector3.one;\r\n\t\t}\r\n\t}\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Interface for attributes that can be added to component classes to receive callbacks when components of a certain type are added or modified through the inspector. OnComponentAdded is called whenever a new component of type TComponent is added to the GameObject that contains the component with this attribute. OnComponentModified is called whenever an existing component ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/docs.sisus.co\/power-inspector\/attributes\/icomponentmodifiedcallbackreceiver\/\" title=\"read more\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/1550"}],"collection":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/comments?post=1550"}],"version-history":[{"count":1,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/1550\/revisions"}],"predecessor-version":[{"id":1551,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/1550\/revisions\/1551"}],"wp:attachment":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/media?parent=1550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/categories?post=1550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/tags?post=1550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}