1+ // Copyright 2019-2022 Robotec.ai.
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
15+ #if UNITY_EDITOR
16+ using System . IO ;
17+ using UnityEngine ;
18+ using UnityEditor ;
19+ using UnityEditor . Build ;
20+ using UnityEditor . Build . Reporting ;
21+
22+ namespace ROS2
23+ {
24+
25+ /// <summary>
26+ /// An internal class responsible for installing ros2-for-unity metadata files
27+ /// </summary>
28+ internal class PostInstall : IPostprocessBuildWithReport
29+ {
30+ public int callbackOrder { get { return 0 ; } }
31+ public void OnPostprocessBuild ( BuildReport report )
32+ {
33+ var r2fuMetadataName = "metadata_ros2_for_unity.xml" ;
34+ var r2csMetadataName = "metadata_ros2cs.xml" ;
35+
36+ // FileUtil.CopyFileOrDirectory: All file separators should be forward ones "/".
37+ var r2fuMeta = ROS2ForUnity . GetRos2ForUnityPath ( ) + "/" + r2fuMetadataName ;
38+ var r2csMeta = ROS2ForUnity . GetPluginPath ( ) + "/" + r2csMetadataName ;
39+ var outputDir = Directory . GetParent ( report . summary . outputPath ) ;
40+ var execFilename = Path . GetFileNameWithoutExtension ( report . summary . outputPath ) ;
41+ FileUtil . CopyFileOrDirectory (
42+ r2fuMeta , outputDir + "/" + execFilename + "_Data/" + r2fuMetadataName ) ;
43+ FileUtil . CopyFileOrDirectory (
44+ r2csMeta , outputDir + "/" + execFilename + "_Data/Plugins/" + r2csMetadataName ) ;
45+ }
46+
47+ }
48+
49+ }
50+ #endif
0 commit comments