Esempio n. 1
0
    public static WorldObject CreateWorldObject(WorldObjectData data, Transform parent = null)
    {
        GameObject gameObject = Instantiate(ResourceManager.GetWorldObject(data.ID));
        //gameObject.layer = 8;
        WorldObject obj = gameObject.AddComponent <WorldObject>();


        if (parent != null)
        {
            gameObject.transform.parent = parent;
        }
        if (data.HasMetaData())
        {
            if (data.GetMetaData().Direction != null)
            {
                float angle = Vector2.SignedAngle(new Vector2(0, 1), data.GetMetaData().Direction.AsVector2());
                obj.transform.rotation = Quaternion.Euler(0, angle, 0);
            }
        }


        gameObject.transform.localPosition = new Vector3(data.WorldPosition.x % World.ChunkSize, 0, data.WorldPosition.z % World.ChunkSize) + data.ObjectDeltaPosition;
        if (data.Size != null)
        {
            float height = 1;
            if (data.HasMetaData())
            {
                height = data.GetMetaData().Height;
            }
            if (!(data is IMultiTileObject))
            {
                gameObject.transform.localScale = new Vector3(data.Size.x, height, data.Size.z);
            }
        }
        obj.Data = data;
        data.OnObjectLoad(obj);
        return(obj);
    }
Esempio n. 2
0
    public static WorldObject CreateWorldObject(WorldObjectData data, Transform parent = null, float heightOffset = 0)
    {
        if (GROUND_LAYER_MASK == -1)
        {
            GROUND_LAYER_MASK = LayerMask.GetMask("Ground");
        }

        GameObject gameObject = Instantiate(data.ObjectPrefab);
        //gameObject.layer = 8;
        WorldObject obj = gameObject.GetComponent <WorldObject>();

        if (parent != null)
        {
            gameObject.transform.parent = parent;
        }
        gameObject.transform.RotateAround(data.Position + data.Size / 2, Vector3.up, data.Rotation);
        gameObject.transform.localPosition = data.Position.Mod(World.ChunkSize);
        gameObject.transform.localScale    = data.Scale;
        obj.Data = data;
        obj.Data.LoadedObject = obj;
        data.OnObjectLoad(obj);
        obj.CoroutineAdjust();
        return(obj);
    }