Exemple #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);
    }
Exemple #2
0
    static void SaveEnemyPrefab(AssetMetaData pEnemy, ref StringBuilder pResources)
    {
        if (pEnemy == null)
        {
            return;
        }
        Enemy  aEnemy         = AssetDatabase.LoadAssetAtPath <Enemy>(AssetDatabase.GUIDToAssetPath(pEnemy.mGUID));
        string aEnemyFilePath = "/Assets/Resources/Prefabs/" + aEnemy.mName + ".json";

        pEnemy.mAssetFilePath = ".." + aEnemyFilePath;
        if (aEnemy.mEnemyType == Enemy.Type.ProjectileThrower)
        {
            SaveProjectile(GetAssetFromGUID(aEnemy.mProjectileGUID, AssetMetaData.AssetType.PrefabAsset), ref pResources);
        }
        SaveAssetData(GetAssetFromGUID(aEnemy.mEnemyAnimations[0].mTextureAssetGUID, AssetMetaData.AssetType.TextureAsset), ref pResources);
        if (!IsAssetInResources(Application.dataPath + aEnemyFilePath))
        {
            GEnemy aEnemyComp = new GEnemy();
            aEnemyComp.mType      = aEnemy.mEnemyType;
            aEnemyComp.mSpeed     = aEnemy.mSpeed;
            aEnemyComp.mStopRange = aEnemy.mStopRange;
            if (aEnemyComp.mType == Enemy.Type.ProjectileThrower)
            {
                aEnemyComp.mProjectileGUID = aEnemy.mProjectileGUID;
            }
            GSprite aSprite = new GSprite(aEnemy.mDisplaySprite.rect, aEnemy.mEnemyAnimations[0].mTextureAssetGUID,
                                          aEnemy.mDisplaySprite.texture.height, (int)aEnemy.mRenderLayer);
            GRigidbody      aRigidBody   = new GRigidbody();
            GCircleCollider aCollider    = new GCircleCollider(32.00001f, false);
            StringBuilder   aEnemyObject = new StringBuilder("{\n");
            aEnemyObject.Append("\"name\" : \"" + aEnemy.mName + "\",\n");
            aEnemyObject.Append("\"Components\" : [\n");
            aEnemyObject.Append(aSprite.ToString() + ",\n");
            aEnemyObject.Append(aEnemyComp.ToString() + ",\n");
            aEnemyObject.Append(aCollider.ToString() + ",\n");
            aEnemyObject.Append(aRigidBody.ToString() + ",\n");
            aEnemyObject.Append("{\n\"class\" : \"Animator\",\n\"Name\" : \"" + aEnemy.mName + "\"\n},\n");
            foreach (AnimationData aData in aEnemy.mEnemyAnimations)
            {
                GAnimation aAnimation = new GAnimation(aData);
                aEnemyObject.Append(aAnimation.ToString() + ",\n");
            }
            aEnemyObject.Remove(aEnemyObject.Length - 2, 2);
            aEnemyObject.Append("]\n");
            aEnemyObject.Append("}\n");
            SaveToFile(aEnemyObject.ToString(), Application.dataPath + aEnemyFilePath);
            SaveToFile(pEnemy.ToString(), Application.dataPath + aEnemyFilePath + ".json");
        }
        if (!IsPathInResources(pResources, pEnemy.mAssetFilePath + ".json"))
        {
            pResources.Append("\"" + pEnemy.mAssetFilePath + ".json\",");
        }
    }
Exemple #3
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);
    }
Exemple #4
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() });
    }
Exemple #5
0
    static void SaveProjectile(AssetMetaData pProjectile, ref StringBuilder pResources)
    {
        if (pProjectile == null)
        {
            return;
        }
        Projectile aProjectile         = AssetDatabase.LoadAssetAtPath <Projectile>(AssetDatabase.GUIDToAssetPath(pProjectile.mGUID));
        string     aProjectileFilePath = "/Assets/Resources/Prefabs/" + aProjectile.mName + ".json";

        pProjectile.mAssetFilePath = ".." + aProjectileFilePath;
        SaveAssetData(GetAssetFromGUID(aProjectile.mProjectileAnimation[0].mTextureAssetGUID, AssetMetaData.AssetType.TextureAsset), ref pResources);
        if (!IsAssetInResources(Application.dataPath + aProjectileFilePath))
        {
            GProjectile aProj = new GProjectile();
            aProj.mPoolCount = aProjectile.mPoolCount;
            aProj.mSpeed     = aProjectile.mSpeed;
            GCircleCollider aCollider  = new GCircleCollider(32.00001f, true);
            GRigidbody      aRigidBody = new GRigidbody();
            GSprite         aSprite    = new GSprite(aProjectile.mDisplaySprite.rect, aProjectile.mProjectileAnimation[0].mTextureAssetGUID,
                                                     aProjectile.mDisplaySprite.texture.height, (int)aProjectile.mRenderLayer);
            StringBuilder aProjectileObject = new StringBuilder("{\n");
            aProjectileObject.Append("\"name\" : \"" + aProjectile.mName + "\",\n");
            aProjectileObject.Append("\"Components\" : [\n");
            aProjectileObject.Append(aSprite.ToString() + ",\n");
            aProjectileObject.Append(aProj.ToString() + ",\n");
            aProjectileObject.Append(aCollider.ToString() + ",\n");
            aProjectileObject.Append(aRigidBody.ToString() + ",\n");
            aProjectileObject.Append("{\n\"class\" : \"Animator\",\n\"Name\" : \"" + aProjectile.mName + "\"\n},\n");
            foreach (AnimationData aData in aProjectile.mProjectileAnimation)
            {
                GAnimation aAnimation = new GAnimation(aData);
                aProjectileObject.Append(aAnimation.ToString() + ",\n");
            }
            aProjectileObject.Remove(aProjectileObject.Length - 2, 2);
            aProjectileObject.Append("]\n");
            aProjectileObject.Append("}\n");
            SaveToFile(aProjectileObject.ToString(), Application.dataPath + aProjectileFilePath);
            SaveToFile(pProjectile.ToString(), Application.dataPath + aProjectileFilePath + ".json");
        }
        if (!IsPathInResources(pResources, pProjectile.mAssetFilePath + ".json"))
        {
            pResources.Append("\"" + pProjectile.mAssetFilePath + ".json\",");
        }
    }
Exemple #6
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);
    }