11using UnityEngine ;
2+ #if UNITY_EDITOR
3+ using UnityEditor ;
4+ #endif
25
36namespace OC . Communication
47{
58 public static class LinkExtension
69 {
10+ /// <summary>
11+ /// Retrieves the name of the GameObject associated with the given <see cref="Link"/>.
12+ /// If the name is not a valid variable name according to <see cref="ClientVariableExtension"/>,
13+ /// it will be corrected on the GameObject and a warning will be logged in the Unity Editor.
14+ /// </summary>
15+ /// <param name="link">The <see cref="Link"/> whose GameObject name is being retrieved and validated.</param>
16+ /// <returns>The (original) name of the GameObject. Note that the GameObject’s name is modified in-editor if it was invalid.</returns>
717 public static string GetName ( this Link link )
818 {
919 var name = link . Component . gameObject . name ;
20+
21+ if ( ! ClientVariableExtension . IsVariableNameValid ( name ) )
22+ {
23+ var oldName = name ;
24+ name = ClientVariableExtension . CorrectVariableName ( name ) ;
25+ #if UNITY_EDITOR
26+ Debug . LogWarning ( $ "Link component name { oldName } is invalid! The name is modified to { name } ", link . Component ) ;
27+ link . Component . gameObject . name = name ;
28+ EditorUtility . SetDirty ( link . Component ) ;
29+ #endif
30+ }
31+
32+ return name ;
33+ }
34+
35+ /// <summary>
36+ /// Constructs the full hierarchical name for the GameObject associated with the given <see cref="Link"/>.
37+ /// Starting from the GameObject’s own name, it traverses upward through its parent transforms.
38+ /// For each parent that has a <see cref="Hierarchy"/> component marked as a sampler (<see cref="Hierarchy.IsNameSampler"/>),
39+ /// its <see cref="Hierarchy.Name"/> is prepended (followed by an underscore) to the current name.
40+ /// The process stops when there are no more sampler hierarchies in the chain.
41+ /// </summary>
42+ /// <param name="link">The <see cref="Link"/> whose GameObject full name is being assembled.</param>
43+ /// <returns>
44+ /// A string representing the combined sampler names and the original GameObject name,
45+ /// separated by underscores (e.g. "RootSampler_SubSampler_ObjectName").
46+ /// </returns>
47+ public static string GetHierarchyName ( this Link link )
48+ {
49+ var name = link . GetName ( ) ;
1050 var parent = link . Parent != null ? link . Parent . transform : link . Component . transform . parent ;
1151
1252 while ( parent != null )
@@ -31,10 +71,29 @@ public static string GetName(this Link link)
3171
3272 return name ;
3373 }
34-
35- public static string GetPath ( this Link link , bool original = false )
74+
75+ /// <summary>
76+ /// Builds a dot-separated path representing the link’s position in the client/hierarchy structure.
77+ /// Starts with the link’s own name (validated via <see cref="GetName"/>), then walks up through
78+ /// parent transforms. If a <see cref="Client"/> is encountered, its <see cref="Client.RootName"/>
79+ /// is prepended and the traversal ends. Otherwise, for each <see cref="Hierarchy"/> parent, its
80+ /// <see cref="Hierarchy.Name"/> is prepended using “.” or “_” if <see cref="Hierarchy.IsNameSampler"/>
81+ /// is true. If <paramref name="original"/> is false and the link has a <see cref="Link.Parent"/>,
82+ /// the traversal uses that chain; otherwise it uses the GameObject’s raw transform hierarchy.
83+ /// </summary>
84+ /// <param name="link">The <see cref="Link"/> whose hierarchy path is being constructed.</param>
85+ /// <param name="original">
86+ /// If false and <paramref name="link"/> has a non-null <see cref="Link.Parent"/>, use the parent link’s
87+ /// transform chain; otherwise use the GameObject’s direct transform parents.
88+ /// </param>
89+ /// <returns>
90+ /// A string combining client root and hierarchy names, separated by “.” (or “_” for samplers),
91+ /// e.g. “RootClient.ParentName.ChildName” or “Sampler1_Sampler2_ObjectName”.
92+ /// </returns>
93+ public static string GetHierarchyPath ( this Link link , bool original = false )
3694 {
37- var path = link . Component . gameObject . name ;
95+ var path = link . GetName ( ) ;
96+
3897 Transform parent ;
3998
4099 if ( ! original && link . Parent != null )
0 commit comments