using System; using System.IO; using UnityEditor; using UnityEngine; namespace WeChatWASM.MDV { public class HandlerNavigate { public History History; public string CurrentPath; public Action ScrollTo; public Func FindBlock; //------------------------------------------------------------------------------ public void SelectPage( string url ) { if( string.IsNullOrEmpty( url ) ) { return; } // internal link if( url.StartsWith( "#" ) ) { var block = FindBlock( url.ToLower() ); if( block != null ) { ScrollTo( block.Rect.y ); } else { Debug.LogWarning( string.Format( "Unable to find section header {0}", url ) ); } return; } // relative or absolute link ... var newPath = string.Empty; if( url.StartsWith( "/" ) ) { newPath = url.Substring( 1 ); } else { newPath = Utils.PathCombine( Path.GetDirectoryName( CurrentPath ), url ); } // load file var asset = AssetDatabase.LoadAssetAtPath( newPath ); if( asset != null ) { History.Add( newPath ); Selection.activeObject = asset; } else { Debug.LogError( string.Format( "Could not find asset {0}", newPath ) ); } } } }