// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) VRMADA, All rights reserved. // // -------------------------------------------------------------------------------------------------------------------- using UnityEditor; using UnityEngine; namespace UltimateXR.Editor { /// /// Used by to send information about the component that needs to be processed. /// /// Component type public class UxrComponentInfo where T : Component { #region Public Types & Data /// /// Gets the target component that needs to be processed. /// public T TargetComponent { get; } /// /// Gets, if is located inside a prefab, its root GameObject. /// It is null if is in a GameObject in a scene. /// public GameObject TargetPrefab { get; } /// /// Gets whether the component is the original source of data or it exists in a parent prefab instead. /// This can be used to process components only once and have the source value come from the original source component. /// /// For prefabs, it is true in the original prefab and false in prefab variants /// /// For GameObjects in the scene, it is true if they are not instantiated prefabs and false if they are the /// result of instantiating a prefab in the scene /// /// /// When processing components, this enables setting values only when is true, /// and setting the to false for non-original components. /// /// /// This property doesn't check if the data is actually overriden or not, it just tells whether the component /// comes from a source prefab or not. /// public bool IsOriginalSource { get; } /// /// /// Similar to but when working with specific project paths. /// If is true, will always be true. /// If is false, it will be true if the parent prefab is not located in a valid /// project path. This means that the instance or the prefab in question is the last element in the chain that /// is still in a valid project path. /// /// /// Here are some examples when might be false but /// is true: /// /// /// You want to apply changes to prefabs or instances in an application (for example the /// /Assets/Application folder) but not in the root prefabs that lie in a framework folder in /// /Assets/Framework /// /// /// You want to apply changes in prefab variants where the original prefab is in UltimateXR, for example /// avatars. This will ensure that your modifications are applied to your prefabs but not to UltimateXR /// /// /// /// /// The main use of is to help component processors that target only /// the innermost prefab. Usually these component processors' goal is to add or modify a component on the innermost /// prefab, letting all child prefabs inherit these changes. Sometimes the innermost prefab or the prefab instance /// is located outside the target path, but it is still desired to modify the one that is still inside the target /// path so that all child prefabs that are also inside can inherit the changes. In the case of a prefab instance /// it allows the prefab instance to have the changes. /// /// public bool IsInnermostInValidChain { get; } #endregion #region Constructors & Finalizer /// /// Constructor. /// /// Component to process public UxrComponentInfo(T component) { TargetComponent = component; T componentInParent = PrefabUtility.GetCorrespondingObjectFromSource(component); if (componentInParent != null) { TargetPrefab = componentInParent.transform.root.gameObject; } IsOriginalSource = componentInParent == null; IsInnermostInValidChain = false; } /// /// Constructor. /// /// Component to process /// /// Root GameObject of the prefab to process if is located inside a prefab. /// It is null if the being processed is in a scene. /// /// /// If is the original source of data (true) or it is instantiated from a parent prefab /// (false) /// /// See public UxrComponentInfo(T component, GameObject prefab, bool isOriginalSource, bool isInnermostInValidChain) { TargetComponent = component; TargetPrefab = prefab; IsOriginalSource = isOriginalSource; IsInnermostInValidChain = isInnermostInValidChain; } #endregion } }