BattlehubCode / RTE_Docs

This is a repository for Runtime Editor documentation, discussion and tracking features and issues.
https://assetstore.unity.com/packages/tools/modeling/runtime-editor-64806
11 stars 0 forks source link

How to get the Transform value when dragging and dropping a Prefab into a Scene. #44

Closed BattlehubCode closed 2 years ago

BattlehubCode commented 2 years ago

You'll need to override SceneViewModel and use PrefabInstance property. Here is the example:

using Battlehub.RTEditor.ViewModels;
using UnityEngine;

public class SceneViewModelOverride : SceneViewModel
{
    public override void OnExternalObjectEnter()
    {
        base.OnExternalObjectEnter();
    }

    public override void OnExternalObjectLeave()
    {
        base.OnExternalObjectLeave();
    }

    public override void OnExternalObjectDrag()
    {
        base.OnExternalObjectDrag();

        if(PrefabInstance != null)
        {
            Debug.Log(PrefabInstance.transform.position);
        }
    }

    public override void OnExternalObjectDrop()
    {
        base.OnExternalObjectDrop();
    }
}

using Battlehub.RTCommon;
using Battlehub.RTEditor;
using Battlehub.RTEditor.ViewModels;

public class ExtendSceneWindowExample : RuntimeWindowExtension
{
    public override string WindowTypeName => BuiltInWindowNames.Scene;

    protected override void Extend(RuntimeWindow window)
    {
        ViewModelBase.ReplaceWith<SceneViewModelOverride>(window);
    }
}