Ejemplo n.º 1
0
    static StringBuilder GetEndPositionJson(Level.GamePositions pEndPosition, ref StringBuilder pResources)
    {
        StringBuilder aEndPositionGobj = new StringBuilder("{");

        aEndPositionGobj.Append("\"name\" : \"End Position\",\n");
        aEndPositionGobj.Append("\"enabled\" : false,\n");
        aEndPositionGobj.Append("\"Components\" : [\n");
        GTransform aTransform = new GTransform();

        aTransform.Position = new position(pEndPosition.mWorldPosition.x * 64.00001f, pEndPosition.mWorldPosition.y * 64.00001f);
        aEndPositionGobj.Append(aTransform.ToString());
        aEndPositionGobj.Append(",\n");
        string  aSpGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(pEndPosition.mDisplaySprite));
        GSprite aSprite = new GSprite(pEndPosition.mDisplaySprite.rect, aSpGUID,
                                      pEndPosition.mDisplaySprite.texture.height, (int)Level.LayerTypes.Players);

        SaveAssetData(GetAssetFromGUID(aSpGUID, AssetMetaData.AssetType.TextureAsset), ref pResources);
        aEndPositionGobj.Append(aSprite.ToString() + ",\n");
        GPolygonCollider aPolygonCollider = new GPolygonCollider(true);

        aEndPositionGobj.Append(aPolygonCollider.ToString() + ",\n");
        Teleporter aTeleporter = new Teleporter();

        aEndPositionGobj.Append(aTeleporter.ToString());
        aEndPositionGobj.Append("]\n");
        aEndPositionGobj.Append("}");
        return(aEndPositionGobj);
    }
Ejemplo n.º 2
0
    static StringBuilder GetSpawnFactoryJson(SpawnFactory pFactory, ref StringBuilder pResources)
    {
        StringBuilder aFactoryComponents = new StringBuilder();
        GSprite       aSprite            = new GSprite(pFactory.mDisplaySprite.rect, pFactory.mTextureGUID,
                                                       pFactory.mDisplaySprite.texture.height, (int)pFactory.mRenderLayer);

        SaveAssetData(GetAssetFromGUID(pFactory.mTextureGUID, AssetMetaData.AssetType.TextureAsset), ref pResources);
        aFactoryComponents.Append(aSprite.ToString() + ",\n");
        GPolygonCollider aCollider = new GPolygonCollider(pFactory.mIsTrigger);

        aFactoryComponents.Append(aCollider.ToString() + ",\n");
        SFactory aFactory = new SFactory(pFactory.mEnemyGUID, pFactory.mPoolCount, pFactory.mSpawnTime);

        SaveEnemyPrefab(GetAssetFromGUID(pFactory.mEnemyGUID, AssetMetaData.AssetType.PrefabAsset), ref pResources);
        aFactoryComponents.Append(aFactory.ToString());
        return(aFactoryComponents);
    }
Ejemplo n.º 3
0
    static string[] SaveItemPrefabs()
    {
        StringBuilder aItemsSB   = new StringBuilder("\"resources\" : [\n");
        StringBuilder aItemGUIDs = new StringBuilder("\"mItemGUIDs\" : [\n");

        foreach (AssetMetaData aAsset in mCurrentAssets[AssetMetaData.AssetType.PrefabAsset])
        {
            string aAssetPath = AssetDatabase.GUIDToAssetPath(aAsset.mGUID);
            if (AssetDatabase.GetMainAssetTypeAtPath(aAssetPath) != typeof(Item))
            {
                continue;
            }
            StringBuilder aItemJSON     = new StringBuilder("{\n");
            Item          aItem         = AssetDatabase.LoadAssetAtPath <Item>(aAssetPath);
            string        aItemFilePath = "/Assets/Resources/Prefabs/" + aItem.mName + ".json";
            aAsset.mAssetFilePath = ".." + aItemFilePath;
            if (!IsAssetInResources(Application.dataPath + aItemFilePath))
            {
                aItemJSON.Append("\"name\" : \"" + aItem.mName + "\",\n");
                Pickable aPickable = new Pickable();
                aPickable.mType = aItem.mItemType;
                GPolygonCollider aCollider = new GPolygonCollider(true);
                GSprite          aSprite   = new GSprite(aItem.mDisplaySprite.rect, aItem.mTextureGUID,
                                                         aItem.mDisplaySprite.texture.height, (int)aItem.mRenderLayer);
                SaveAssetData(GetAssetFromGUID(aItem.mTextureGUID, AssetMetaData.AssetType.TextureAsset), ref aItemsSB);
                aItemJSON.Append("\"Components\" : [\n");
                aItemJSON.Append(aSprite.ToString() + ",\n");
                aItemJSON.Append(aPickable.ToString() + ",\n");
                aItemJSON.Append(aCollider.ToString() + "\n");
                aItemJSON.Append("]\n");
                aItemJSON.Append("}\n");
                SaveToFile(aItemJSON.ToString(), Application.dataPath + aItemFilePath);
                SaveToFile(aAsset.ToString(), Application.dataPath + aItemFilePath + ".json");
            }
            if (!IsPathInResources(aItemsSB, aAsset.mAssetFilePath + ".json"))
            {
                aItemsSB.Append("\"" + aAsset.mAssetFilePath + ".json\",");
                aItemGUIDs.Append("\"" + aAsset.mGUID + "\",");
            }
        }
        aItemsSB.Remove(aItemsSB.Length - 1, 1);
        aItemsSB.Append("]\n");
        aItemGUIDs.Remove(aItemGUIDs.Length - 1, 1);
        aItemGUIDs.Append("]\n");
        return(new[] { aItemsSB.ToString(), aItemGUIDs.ToString() });
    }
Ejemplo n.º 4
0
    static StringBuilder GetStaticObjectJson(StaticObject pObject, ref StringBuilder pResources)
    {
        StringBuilder aObjectComponents = new StringBuilder();
        GSprite       aSprite           = new GSprite(pObject.mDisplaySprite.rect, pObject.mTextureGUID,
                                                      pObject.mDisplaySprite.texture.height, (int)pObject.mRenderLayer);

        SaveAssetData(GetAssetFromGUID(pObject.mTextureGUID, AssetMetaData.AssetType.TextureAsset), ref pResources);
        aObjectComponents.Append(aSprite.ToString());
        if (pObject.mColliderType == GameScriptable.ColliderType.Box)
        {
            GPolygonCollider aCollider = new GPolygonCollider(pObject.mIsTrigger);
            aObjectComponents.Append(",\n" + aCollider.ToString());
        }
        else if (pObject.mColliderType == GameScriptable.ColliderType.Circle)
        {
            GCircleCollider aCollider = new GCircleCollider(32.00001f, pObject.mIsTrigger);
            aObjectComponents.Append(",\n" + aCollider.ToString());
        }
        return(aObjectComponents);
    }