Esempio n. 1
0
    public void OnProcessScene(UnityEngine.SceneManagement.Scene scene)
    {
        string path                = EditorUserBuildSettings.GetBuildLocation(EditorUserBuildSettings.activeBuildTarget);
        int    last_slash          = path.LastIndexOf('/');
        string pointCloudDirectory = path.Substring(0, last_slash + 1);

        foreach (var gameObject in scene.GetRootGameObjects())
        {
            PlayableDirector director = gameObject.GetComponent <PlayableDirector>();
            if (director != null)
            {
                if (director.playableAsset != null)
                {
                    TimelineAsset timeline = (TimelineAsset)director.playableAsset;

                    foreach (var track in timeline.GetOutputTracks())
                    {
                        foreach (var clip in track.GetClips())
                        {
                            if (clip.asset.GetType() == typeof(PointCloudClip))
                            {
                                uint clip_start_frame        = (uint)clip.clipIn * 30;
                                uint clip_duration_in_frames = (uint)clip.duration * 30;
                                uint clip_end_frame          = clip_start_frame + clip_duration_in_frames;

                                string[]       files = new string[0];
                                PointCloudClip pcc   = (PointCloudClip)clip.asset;
                                if (Directory.Exists(pcc.template.PointCloudDirectory.Substring(1)))
                                {
                                    files = Directory.GetFiles(pcc.template.PointCloudDirectory.Substring(1));
                                }

                                foreach (var file in files)
                                {
                                    Directory.CreateDirectory(pointCloudDirectory + pcc.template.PointCloudDirectory);

                                    int  last_dot_in_filename   = file.LastIndexOf('.');
                                    int  last_slash_in_filename = file.LastIndexOf('\\');
                                    int  no_length = last_dot_in_filename - last_slash_in_filename - 1;
                                    uint file_no   = UInt32.Parse(file.Substring(last_slash_in_filename + 1, no_length));

                                    if (file_no >= clip_start_frame &&
                                        file_no <= clip_end_frame)
                                    {
                                        if (!File.Exists(pointCloudDirectory + '/' + file))
                                        {
                                            File.Copy(file, pointCloudDirectory + '/' + file);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Esempio n. 2
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        SerializedProperty PointCloudDirectoryProp = property.FindPropertyRelative("PointCloudDirectory");
        SerializedProperty translateProp           = property.FindPropertyRelative("translate");
        SerializedProperty scaleProp     = property.FindPropertyRelative("scale");
        SerializedProperty influenceProp = property.FindPropertyRelative("influence");

        Rect singleFieldRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

        singleFieldRect.width = position.width * 4 / 5;
        EditorGUI.PropertyField(singleFieldRect, PointCloudDirectoryProp);

        singleFieldRect.x    += singleFieldRect.width;
        singleFieldRect.width = position.width / 5;
        if (EditorGUI.DropdownButton(singleFieldRect, new GUIContent("ChooseDirectory"), FocusType.Keyboard))
        {
            string dataPath = Application.dataPath;
            dataPath = dataPath.Replace("/Assets", "");

            string path = EditorUtility.OpenFolderPanel("Choose Directory With Point Cloud Clips", dataPath + PointCloudDirectoryProp.stringValue, "");

            if (path != "")
            {
                if (path.StartsWith(dataPath))
                {
                    path = path.Substring(dataPath.Length);
                }

                PointCloudClip pcc = property.serializedObject.targetObject as PointCloudClip;
                pcc.template.PointCloudDirectory = path;

                PointCloudDirectoryProp.stringValue = path;
                PointCloudDirectoryProp.serializedObject.Update();
                PointCloudDirectoryProp.serializedObject.ApplyModifiedProperties();
            }
        }

        singleFieldRect.x     = position.x;
        singleFieldRect.width = position.width;
        singleFieldRect.y    += EditorGUIUtility.singleLineHeight;
        EditorGUI.PropertyField(singleFieldRect, translateProp);

        singleFieldRect.y += EditorGUIUtility.singleLineHeight;
        EditorGUI.PropertyField(singleFieldRect, scaleProp);

        singleFieldRect.y += EditorGUIUtility.singleLineHeight;
        EditorGUI.PropertyField(singleFieldRect, influenceProp);
    }