-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to use "normal" object properties like Width and Height with prefab replacements #267
Comments
Hey @markus1978. I was trying to do the same thing with rects and I wasn't able to find a built in way to do this. But I did find a way of hacking it in myself that might help you until the feature is added. There's a function in TmxAssetImporter.cs called |
@M0Z1NG0 Thanks alot for the suggestion. I opted to pull this into a custom importer. Since the replaced prefabs are inaccessible from the custom importer, I did the custom prefab replacement in the custom importer: using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.AssetImporters;
using SuperTiled2Unity;
using SuperTiled2Unity.Editor;
[AutoCustomTmxImporter()]
public class MyTmxCustomImporter : CustomTmxImporter
{
private GameObject cloudPrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Prefabs/Cloud.prefab");
public override void TmxAssetImported(TmxAssetImportedArgs args)
{
var map = args.ImportedSuperMap;
foreach (var so in map.GetComponentsInChildren<SuperObject>())
{
if (so.m_Type == "Cloud")
{
var width = so.m_Width / 16;
var height = so.m_Height / 16;
var instance = PrefabUtility.InstantiatePrefab(cloudPrefab) as GameObject;
instance.transform.SetParent(so.transform.parent);
instance.transform.position = so.transform.position + cloudPrefab.transform.localPosition + new Vector3(width * 0.5f, -height * 0.5f, 0);
instance.transform.rotation = so.transform.rotation;
instance.transform.localScale = new Vector3(width, height, 1);
instance.name = so.gameObject.name;
UnityEngine.Object.DestroyImmediate(so.gameObject);
}
}
}
} This is basically the same lines that the normal importer does in It would be nicer, if I could use the standard prefab replacement and customize this in the custom importer. But i really could not find a way to access the instantiated prefabs from the custom importer. In principle the instances would be accessible via |
Thanks for the great tool. Maybe it can even help me with this problem.
I know that we can use custom properties and assign them to public fields or setters on a script in a prefab replacement. But is it also possible somehow get the "normal" build-id tiled object properties like
Width
,Height
,X
,Y
etc. transferred.May particular use case is importing ellipses or rects. Here i want to assign the
Width
andHeight
to the transform scale and correct the transform position to the middle of the object. By default, SuperTiled2Unity does not seem to override the transform scale from the prefab and takes the top-left of the object (I guess this is what the X, Y in tiled refers to) and assigns it to the transform position.The text was updated successfully, but these errors were encountered: