Beispiel #1
0
        public static void TryRegisterItems()
        {
            if (Consumables == null || ZNetScene.instance == null || ObjectDB.instance == null || ObjectDB.instance.m_items.Count == 0)
            {
                return;
            }

            PrefabCreator.Reset();
            var success = 0;
            var fail    = 0;

            foreach (var item in Consumables.items)
            {
                var newPrefab = PrefabCreator.CreatePrefab(item);
                if (newPrefab == null)
                {
                    fail++;
                }
                else
                {
                    success++;
                }
            }

            if (fail > 0)
            {
                Debug.LogError($"Failed to initialize {fail} prefabs!");
            }
            if (success > 0)
            {
                Debug.LogWarning($"Successfully initialized {success} prefabs in Jam.Update");
            }
        }
    void Start()
    {
        prefabCreator = GameObject.Find("PrefabCreator").GetComponent <PrefabCreator>();

        rbody2D     = GetComponent <Rigidbody2D>();
        audioSource = GetComponent <AudioSource>();
    }
Beispiel #3
0
    void Start()
    {
        mainManager   = GameObject.Find("MainManager").GetComponent <MainManager>();
        signalManager = GameObject.Find("SignalManager").GetComponent <SignalManager>();
        musicManager  = GameObject.Find("MusicManager").GetComponent <MusicManager>();
        prefabCreator = GameObject.Find("PrefabCreator").GetComponent <PrefabCreator>();
        ball          = GameObject.Find("TheBall").GetComponent <Ball>();

        audioSources = GetComponents <AudioSource>();

        body = gameObjectBody.GetComponent <SKL144SystemBody>();
        face = gameObjectFace.GetComponent <SKL144SystemFace>();

        motionTriggers[1] = motionTrigger1;
        motionTriggers[2] = motionTrigger2;
        motionTriggers[3] = motionTrigger3;

        durations[1] = duration1;
        durations[2] = duration2;
        durations[3] = duration3;

        isIdle = true;

        duration = duration1;
    }
Beispiel #4
0
    public Unit(string spritecode, Vector2 pos)
    {
        kinematics     = new Kinematics();
        kinematics.pos = pos;
        kinematics.g   = 1;
        TimeManager.Entities.Add(this);

        sprite      = Resources.Load <Sprite>(Filepaths.images[spritecode]);
        spriteOrder = 0;
        PrefabCreator.CreateSprite(this);

        colliderwidthcs  = 1.2f;
        colliderheightcs = 0.8f;
        PrefabCreator.CreateCollider(this);

        team   = Team.wildlifegeneric;
        health = 100;

        //initialize basic skill
        jump      = new Jump(this);
        walkleft  = new WalkLeft(this);
        walkright = new WalkRight(this);
        walkstop  = new WalkStop(this);
        attack    = new Shoot(this); // 2 s cooldown
    }
Beispiel #5
0
        // ---------------------------------------------------------------------------------------------------------------------------
        // Draw ProceduralTree inspector GUI
        // ---------------------------------------------------------------------------------------------------------------------------

        public override void OnInspectorGUI()
        {
            var building = (Building)target;

            /*var pt = PrefabUtility.GetPrefabType(building);
             * if (pt != PrefabType.None && pt != PrefabType.DisconnectedPrefabInstance) // Prefabs are not dynamic
             * {
             *  GUI.enabled = false;
             *  DrawDefaultInspector();
             *  return;
             * }*/

            DrawDefaultInspector();

            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Rand Building")) // Randomize all building parameters
                {
                    Undo.RecordObject(building, "Random building " + building.name);
                    building.RandomizeSettings();
                    building.Generate();
                }

                if (GUI.changed)
                {
                    building.Generate();
                }

                if (GUILayout.Button("Create Prefab"))
                {
                    PrefabCreator.CreatePrefab(building.gameObject);
                }
            }
            GUILayout.EndHorizontal();
        }
Beispiel #6
0
        private void CreatCurrentPrefab()
        {
            saveWeapon();
            var itemObject = PrefabCreator.CreateDropItem(currWeaponData);

            Tools.UpdatePrefab(itemObject, prefabPath + "/" + currWeaponData.id + ".prefab");
            DestroyImmediate(itemObject);
        }
Beispiel #7
0
 public static void SetupRecipes()
 {
     PrefabCreator.Reset();
     foreach (var recipe in Config.recipes)
     {
         PrefabCreator.AddNewRecipe(recipe.name, recipe.item, recipe);
     }
 }
Beispiel #8
0
    // Use this for initialization
    protected virtual void Start()
    {
        mainManager   = GameObject.Find("MainManager").GetComponent <MainManager>();
        signalManager = GameObject.Find("SignalManager").GetComponent <SignalManager>();
        prefabCreator = GameObject.Find("PrefabCreator").GetComponent <PrefabCreator>();
        aurora        = GameObject.Find("Aurora").GetComponent <Aurora>();

        aurora.SetActiveLevelUpAurora(isLevelUpFailZone);
    }
Beispiel #9
0
        public static void TryRegisterRecipes()
        {
            if (ObjectDB.instance == null || ObjectDB.instance.m_items.Count == 0)
            {
                return;
            }

            var fineWoodToWood = new RecipeConfig()
            {
                amount    = (int)FineWoodToWoodCount.Value.y,
                enabled   = true,
                resources = new List <RecipeRequirementConfig>
                {
                    new RecipeRequirementConfig()
                    {
                        item   = "FineWood",
                        amount = (int)FineWoodToWoodCount.Value.x
                    }
                }
            };

            PrefabCreator.AddNewRecipe("Recipe_FineWoodToWood", "Wood", fineWoodToWood);

            var coreWoodToWood = new RecipeConfig()
            {
                amount    = (int)CoreWoodToWoodCount.Value.y,
                enabled   = true,
                resources = new List <RecipeRequirementConfig>
                {
                    new RecipeRequirementConfig()
                    {
                        item   = "RoundLog",
                        amount = (int)CoreWoodToWoodCount.Value.x
                    }
                }
            };

            PrefabCreator.AddNewRecipe("Recipe_CoreWoodToWood", "Wood", coreWoodToWood);

            var ancientBarkToWood = new RecipeConfig()
            {
                amount    = (int)AncientBarkToWoodCount.Value.y,
                enabled   = true,
                resources = new List <RecipeRequirementConfig>
                {
                    new RecipeRequirementConfig()
                    {
                        item   = "ElderBark",
                        amount = (int)AncientBarkToWoodCount.Value.x
                    }
                }
            };

            PrefabCreator.AddNewRecipe("Recipe_AncientBarkWoodToWood", "Wood", ancientBarkToWood);
        }
Beispiel #10
0
 void CreatePrefabs()
 {
     // 生成预制体 add by TangJian 2017/11/16 17:42:05
     {
         foreach (var item in decorationDataDic)
         {
             var itemObject = PrefabCreator.CreateDropItem(item.Value);
             Tools.UpdatePrefab(itemObject, prefabPath + "/" + item.Value.id + ".prefab");
             DestroyImmediate(itemObject);
         }
     }
 }
Beispiel #11
0
        public static void TryRegisterRecipes()
        {
            if (ObjectDB.instance == null || ObjectDB.instance.m_items.Count == 0)
            {
                return;
            }

            PrefabCreator.Reset();
            foreach (var recipe in Recipes.recipes)
            {
                PrefabCreator.AddNewRecipe(recipe.name, recipe.item, recipe);
            }
        }
Beispiel #12
0
        public static void TryRegisterRecipes()
        {
            if (!IsObjectDBReady())
            {
                return;
            }

            PrefabCreator.Reset();
            foreach (var recipe in Recipes.recipes)
            {
                PrefabCreator.AddNewRecipe(recipe.name, recipe.item, recipe);
            }
        }
Beispiel #13
0
        private void LoadClasses()
        {
            var classesConfig = PrefabCreator.LoadJsonFile <ClassesConfig>("classes.json");

            foreach (var cskill in classesConfig.classes)
            {
                if (cskill.implemented)
                {
                    listofCSkills.Add(cskill);
                    SkillInjector.RegisterNewSkill(cskill.id, cskill.name, cskill.description, 1.0f, PrefabCreator.LoadCustomTexture(cskill.icon), Skills.SkillType.Unarmed);
                }
            }
        }
Beispiel #14
0
    void TileSelectGUI()
    {
        EditorGUILayout.LabelField("TileTool2D Tile", GUILayout.Width(100f));
        gTile = (GameObject)EditorGUILayout.ObjectField(gTile, typeof(GameObject), false, GUILayout.Width(175f));

        GUILayout.FlexibleSpace();

        if (GUILayout.Button("Create Tile", GUILayout.Width(120), GUILayout.Height(18)))
        {
            Tile2D oldTile;
            oldTile = PrefabCreator.CreateTile(null, false);
            String path = null;
            if (Directory.Exists("Assets/TileTool2D/Tiles/Wizard Tiles/"))
            {
                path = SaveFile("Assets/TileTool2D/Tiles/Wizard Tiles/", oldTile.transform.name + "", "prefab");
            }
            else
            {
                path = SaveFile("Assets/", oldTile.transform.name + "", "prefab");
            }

            if (path != null)
            {
                var asset = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject));
                if (asset)
                {
                    asset = PrefabUtility.ReplacePrefab(oldTile.gameObject, (GameObject)AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)));
                }
                else
                {
                    asset = PrefabUtility.CreatePrefab(path, oldTile.gameObject);
                }
                string spritePath = AssetDatabase.GetAssetPath(asset);
                gTile = (GameObject)AssetDatabase.LoadAssetAtPath(spritePath, typeof(GameObject));
            }
            DestroyImmediate(oldTile.gameObject);
        }



        if (gTile && GUI.changed)
        {
            tile = (Tile2D)gTile.GetComponent <Tile2D>();
        }
        else if (!gTile)
        {
            tile = null;
        }
        GUI.color = Color.white;
    }
Beispiel #15
0
        public static void TryRegisterRecipes()
        {
            if (ObjectDB.instance == null || ObjectDB.instance.m_items.Count == 0)
            {
                Debug.LogWarning($"[Jam] Did not register recipes: ZNetScene.instance {ZNetScene.instance}, ObjectDB.instance {ObjectDB.instance}, item count {ObjectDB.instance.m_items.Count}");
                return;
            }

            PrefabCreator.Reset();
            foreach (var recipe in Recipes.recipes)
            {
                PrefabCreator.AddNewRecipe(recipe.name, recipe.item, recipe);
            }
        }
    // Use this for initialization
    void Start()
    {
        prefabCreator = GameObject.Find("PrefabCreator").GetComponent <PrefabCreator>();

        for (int i = 0; i < 15; i++)
        {
            spriteRenderersSignals[i] = gameObjectsSignals[i].GetComponent <SpriteRenderer>();
        }

        audioSource = GetComponent <AudioSource>();

        CreateLevelStage();
        StartCoroutine(Timer());
    }
Beispiel #17
0
    public Platform(Vector2 pos, float w, float h)
    {
        kinematics.pos   = pos;
        colliderwidthcs  = w;
        colliderheightcs = h;

        sprite      = Resources.Load <Sprite>(Filepaths.images["rblack"]);
        spriteOrder = 1;
        PrefabCreator.CreateSprite(this);

        colliderwidthcs  = w / 2;
        colliderheightcs = h / 2;
        PrefabCreator.CreateCollider(this);

        team = Team.environment;
    }
Beispiel #18
0
    public Projectile(Vector2 pos, Vector2 v)
    {
        kinematics.pos = pos;
        kinematics.v   = v;
        TimeManager.Entities.Add(this);

        sprite      = Resources.Load <Sprite>(Filepaths.images["Placeholder_circle"]);
        spriteOrder = -1;
        PrefabCreator.CreateSprite(this);

        colliderwidthcs  = 0.2f;
        colliderheightcs = 0.2f;
        PrefabCreator.CreateCollider(this);

        // TEMPORARY DEFAULTS: replace with proper functionality
        team   = Team.player;
        damage = 10;
    }
Beispiel #19
0
        private void LoadRunes()
        {
            for (var i = 1; i <= 5; i++)
            {
                runesConfig = PrefabCreator.LoadJsonFile <RunesConfig>("runes.json");
                var assetBundle = PrefabCreator.LoadAssetBundle("runeassets");

                if (runesConfig != null && assetBundle != null)
                {
                    foreach (var data in runesConfig.runes)
                    {
                        if (!data.implemented)
                        {
                            continue;
                        }
                        if (i > data.resources.Count)
                        {
                            continue;
                        }

                        if (assetBundle.Contains(data.recipe.item))
                        {
                            data.prefab = assetBundle.LoadAsset <GameObject>(data.recipe.item);
                            data.rank   = i;
                            data.core   = data.recipe.item;

                            data.name += " " + rank2rank[data.rank];
                            if (data.rank > 1)
                            {
                                data.prefab.name += data.rank;
                                data.recipe.name += data.rank;
                                data.recipe.item += data.rank;
                            }
                            runesData.Add(data);
                        }
                    }
                }

                assetBundle?.Unload(false);
            }

            _harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "fiote.mods.runicpower");
        }
Beispiel #20
0
        void saveSoul()
        {
            soulDataDic = soulDataList.ToDictionary(item => item.id, item => item);

            string jsonString = Tools.Obj2Json(soulDataDic, true);

            Debug.Log("jsonString = " + jsonString);
            Tools.WriteStringFromFile(Application.dataPath + "/" + soulDataFile, jsonString);

            // 生成预制体 add by TangJian 2017/11/16 17:42:05
            {
                foreach (var item in soulDataDic)
                {
                    var itemObject = PrefabCreator.CreateDropItem(item.Value);
                    Tools.UpdatePrefab(itemObject, prefabPath + "/" + item.Value.id + ".prefab");
                    DestroyImmediate(itemObject);
                }
            }
        }
        void saveConsumableData()
        {
            consumableDataDic = consumableDataList.ToDictionary(item => item.id, item => item);

            //string jsonString = Tools.Obj2Json(consumableDataDic, true);
            //Debug.Log("jsonString = " + jsonString);
            //Tools.WriteStringFromFile(Application.dataPath + "/" + consumableDataFile, jsonString);
            Tools.SaveOneData <ConsumableData>(consumableDataDic, Application.dataPath + "/" + "Resources_moved/Scripts/Consumable/ConsumableList");

            // 生成预制体 add by TangJian 2017/11/16 17:42:05
            {
                foreach (var item in consumableDataDic)
                {
                    var itemObject = PrefabCreator.CreateDropItem(item.Value);
                    Tools.UpdatePrefab(itemObject, prefabPath + "/" + item.Value.id + ".prefab");
                    DestroyImmediate(itemObject);
                }
            }
        }
Beispiel #22
0
        // ---------------------------------------------------------------------------------------------------------------------------
        // Draw ProceduralTree inspector GUI
        // ---------------------------------------------------------------------------------------------------------------------------

        public override void OnInspectorGUI()
        {
            var tree = (ProcTree)target;

            /*var pt = PrefabUtility.GetPrefabType(tree);
             * if (pt != PrefabType.None && pt != PrefabType.DisconnectedPrefabInstance) // Prefabs are not dynamic
             * {
             *  GUI.enabled = false;
             *  DrawDefaultInspector();
             *  return;
             * }*/

            DrawDefaultInspector();

            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Rand Tree")) // Randomize all tree parameters
                {
                    Undo.RecordObject(tree, "Random Tree " + tree.name);
                    tree.RandomizeSettings();
                    tree.Generate(Random.Range(0f, 1f) <= 0.5 ? true : false);
                }

                if (GUILayout.Button("Rand Seed")) // Generates a tree of the same type
                {
                    Undo.RecordObject(tree, "Random Tree " + tree.name);
                    //tree.RandomizeSettings();
                    tree.seed = Random.Range(0, 64000);
                    tree.Generate(tree.coneTree);
                }

                if (GUI.changed)
                {
                    tree.Generate(tree.coneTree);
                }

                if (GUILayout.Button("Create Prefab"))
                {
                    PrefabCreator.CreatePrefab(tree.gameObject);
                }
            }
            GUILayout.EndHorizontal();
        }
Beispiel #23
0
    static void GenrateGameObjectFromSprite()
    {
        Object[] objects = Selection.objects;
        string   label   = "GenerateSprites";

        try
        {
            for (int i = 0; i < objects.Length; i++)
            {
                Object obj      = objects[i];
                string fileName = AssetDatabase.GetAssetPath(obj);
                string path     = fileName.Substring(0, fileName.LastIndexOf('/'));

                Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>(fileName);

                EditorUtility.DisplayProgressBar("从Sprite生成GameObject", i + "/" + objects.Length, (float)i / objects.Length);

                if (sprite != null)
                {
                    path = path + "/" + label;

                    Tang.Tools.CreateFolder(Tang.Tools.AssetPathToSysPath(path));

                    path = path + "/" + sprite.name;

                    GameObject go = PrefabCreator.GenrateGameObjectFromSprite(sprite);
                    PrefabUtility.CreatePrefab(path + ".prefab", go);
                    GameObject.DestroyImmediate(go);
                    //AssetDatabase.CreateAsset(gameObject, path);
                }
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError(e);
        }
        finally
        {
            EditorUtility.ClearProgressBar();
        }
    }
Beispiel #24
0
    // Use this for initialization
    void Start()
    {
        mainManager   = GameObject.Find("MainManager").GetComponent <MainManager>();
        signalManager = GameObject.Find("SignalManager").GetComponent <SignalManager>();
        prefabCreator = GameObject.Find("PrefabCreator").GetComponent <PrefabCreator>();
        theBall       = GameObject.Find("TheBall").GetComponent <Ball>();

        for (int i = 0; i < 20; i++)
        {
            spriteRenderersSignals[i] = gameObjectsSignals[i].GetComponent <SpriteRenderer>();
        }
        for (int i = 0; i < 4; i++)
        {
            spriteRenderersNumbers[i] = gameObjectsNumbers[i].GetComponent <SpriteRenderer>();
        }
        spriteRendererBody = gameObjectBody.GetComponent <SpriteRenderer>();

        audioSources = GetComponents <AudioSource>();

        DecideBlocks();
    }
        void saveSceneDecoration()
        {
            SceneDecorationDic = SceneDecorationList.ToDictionary(item => item.id, item => item);

            string jsonString = Tools.Obj2Json(SceneDecorationDic, true);

            Debug.Log("jsonString = " + jsonString);
            Tools.WriteStringFromFile(Application.dataPath + "/" + SceneDecorationFile, jsonString);
            string scalejson = Tools.Obj2Json(imgsclae, true);

            Tools.WriteStringFromFile(Application.dataPath + "/Resources_moved/Scripts/SceneDecoration/scale.json", scalejson);

            // 生成预制体 add by TangJian 2017/11/16 17:42:05
            {
                foreach (var item in SceneDecorationDic)
                {
                    var itemObject = PrefabCreator.CreateSceneDecoration(item.Value, prefabPath, imgsclae);
                    Tools.UpdatePrefab(itemObject, prefabPath + "/" + item.Value.id + ".prefab");
                    DestroyImmediate(itemObject);
                }
            }
        }
Beispiel #26
0
        void saveArmor()
        {
            armorDataDic = armorDataList.ToDictionary(item => item.id, item => item);

            //string jsonString = Tools.Obj2Json(armorDataDic, true);

            //Debug.Log("jsonString = " + jsonString);
            //Tools.WriteStringFromFile(Application.dataPath + "/" + armorDataFile, jsonString);
            Tools.SaveOneData <ArmorData>(armorDataDic, Application.dataPath + "/" + "Resources_moved/Scripts/Armor/ArmorList");

            Tools.WriteStringFromFile(Application.dataPath + "/" + "Resources_moved/Scripts/Armor/ArmorskeletonDataAssetPath.json", skeletonDataAssetPath);

            // 生成预制体 add by TangJian 2017/11/16 17:42:05
            {
                foreach (var item in armorDataDic)
                {
                    var itemObject = PrefabCreator.CreateDropItem(item.Value);
                    Tools.UpdatePrefab(itemObject, prefabPath + "/" + item.Value.id + ".prefab");
                    DestroyImmediate(itemObject);
                }
            }
        }
Beispiel #27
0
    /// <summary>
    /// Generates all game objects (players, objectives/collectibles, etc).
    /// </summary>
    /// <param name="isPreview">If true, only creates objects useful for a preview of the world.</param>
    public void Generate(MatchStartData matchData, bool isPreview)
    {
        Generator    level  = matchData.GeneratedLevel;
        SpawnCreator spawns = matchData.Spawns;
        Dictionary <Color, List <byte> > playersOnTeams       = matchData.PlayersOnTeams;
        Dictionary <byte, byte>          localPlayersControls = matchData.PlayerControlSchemes;

        List <Camera> playerCameras = new List <Camera>();

        PrefabCreator prefCreator  = WorldConstants.Creator;
        LevelManager  levelManager = WorldConstants.MatchController.GetComponent <LevelManager>();

        #region Create players

        //Get the number of players on this machine.
        int localPlayers = 0;
        foreach (List <byte> bs in playersOnTeams.Values)
        {
            foreach (byte id in bs)
            {
                if (id <= 4)
                {
                    localPlayers++;
                }
            }
        }

        //Make sure there are a valid number of players in-game and on this machine.
        if (playersOnTeams.Keys.Count < 1 || playersOnTeams.Keys.Count > 8 ||
            localPlayersControls.Count < 1 || localPlayersControls.Count > 4)
        {
            throw new System.ArgumentOutOfRangeException();
        }

        //Spawn teams.
        int             spawnIndex = 0;
        List <Location> spawnAreas;
        Dictionary <Color, List <Location> > spawnsByTeam = new Dictionary <Color, List <Location> >();
        GameObject p;
        Location   spawnLoc;
        foreach (KeyValuePair <Color, List <byte> > team in playersOnTeams)
        {
            spawnAreas = spawns.TeamSpawns[spawnIndex++];
            spawnsByTeam.Add(team.Key, spawnAreas);

            int count = 0;
            foreach (byte id in team.Value)
            {
                spawnLoc = spawnAreas[count];
                bool cantSpawn = false;
                while (level.Map[spawnLoc.X, spawnLoc.Y])
                {
                    if (count >= spawnAreas.Count - 1)
                    {
                        cantSpawn = true;
                        break;
                    }
                    spawnLoc = spawnAreas[++count];
                }

                if (cantSpawn)
                {
                    throw new UnityException();
                }
                else if (!isPreview)
                {
                    p = prefCreator.CreatePlayer(ToWorldPos(spawnAreas[count++], matchData), id, localPlayersControls[id], team.Key);
                    playerCameras.Add(prefCreator.CreatePlayerCamera(p, localPlayers).camera);
                }
            }
        }

        #endregion

        #region Set up view data

        prefCreator.CreateMinimapCamera(new Location(Mathf.RoundToInt(WorldConstants.Size.x), Mathf.RoundToInt(WorldConstants.Size.y)), localPlayers);

        //Calculate the bounds covering all areas a camera could ever see.

        int       numbCams           = playerCameras.Count;
        Vector2[] viewExtentsInWorld = new Vector2[numbCams];
        Camera    ca;

        for (int i = 0; i < numbCams; ++i)
        {
            ca = playerCameras[i].camera;

            viewExtentsInWorld[i]  = ca.ViewportToWorldPoint(new Vector3(1.0f, 1.0f, 0.0f)) - ca.ViewportToWorldPoint(Vector3.zero);
            viewExtentsInWorld[i] *= 0.5f;
        }

        //Get the largest view sizes.
        Vector2 maxViewExtentsInWorld;
        float   maxX = System.Single.MinValue,
                maxY = System.Single.MinValue;
        for (int i = 0; i < viewExtentsInWorld.Length; ++i)
        {
            if (viewExtentsInWorld[i].x > maxX)
            {
                maxX = viewExtentsInWorld[i].x;
            }
            if (viewExtentsInWorld[i].y > maxY)
            {
                maxY = viewExtentsInWorld[i].y;
            }
        }
        maxViewExtentsInWorld = new Vector2(maxX, maxY);
        //Give the view rect a bit of leeway.
        maxViewExtentsInWorld += Vector2.one;

        //Get a boundary representing all the areas a player could ever view.
        WorldConstants.MaxViewBounds = new RecBounds(WorldConstants.LevelBounds.center,
                                                     WorldConstants.LevelBounds.size);
        WorldConstants.MaxViewBounds.size += maxViewExtentsInWorld * 2.0f;

        #endregion

        #region Create parallax objects

        if (!isPreview)
        {
            float starsChance    = WorldConstants.StarsChance;
            float specialsChance = WorldConstants.SpecialsChance;

            if (level.GenSettings.WrapX && level.GenSettings.WrapY)
            {
                starsChance /= 8;
            }
            else if (level.GenSettings.WrapX || level.GenSettings.WrapY)
            {
                starsChance /= 3;
            }

            starsChance /= localPlayers;

            for (int i = 0; i < level.Map.GetLength(0); ++i)
            {
                for (int j = 0; j < level.Map.GetLength(1); ++j)
                {
                    if (!level.Map[i, j])
                    {
                        if (Random.value <= starsChance)
                        {
                            prefCreator.CreateStars(new Vector2(i, j));
                        }
                        else if (Random.value <= specialsChance)
                        {
                            prefCreator.CreateSpecial(new Vector2(i, j));
                        }
                    }
                }
            }
        }

        #endregion

        #region Create flags/teams

        if (isPreview || levelManager.MatchRules.CTF != null)
        {
            foreach (Color c in playersOnTeams.Keys)
            {
                //Get a spot that has a floor underneath it.

                bool foundFloor = false;

                foreach (Location l in spawnsByTeam[c])
                {
                    //If a spot was found, put the flag there.
                    //Using "above" instead of "below" is intentional --
                    //   much of this framework was tested in XNA, which uses a flipped Y axis.
                    if (level.FillData.GetMapAt(l.Above) && !level.FillData.GetMapAt(l))
                    {
                        if (isPreview)
                        {
                            prefCreator.CreateMinimapIcon(ToWorldPos(l, matchData), Animations.MM_Team, c, prefCreator.MinimapIconScaling.Team, prefCreator.MinimapIconZPoses.Team);
                        }
                        else
                        {
                            prefCreator.CreateFlagAndFlagBase(ToWorldPos(l, matchData), c);
                        }
                        foundFloor = true;
                        break;
                    }
                }

                //If no spawn location has a floor under it, just put the flag in the air.
                if (!foundFloor)
                {
                    foreach (Location l in spawnsByTeam[c])
                    {
                        //If a spot is empty, put the flag there.
                        if (!level.FillData.GetMapAt(l))
                        {
                            if (isPreview)
                            {
                                prefCreator.CreateMinimapIcon(ToWorldPos(l, matchData), Animations.MM_Team, c, prefCreator.MinimapIconScaling.Team, prefCreator.MinimapIconZPoses.Team);
                            }
                            else
                            {
                                prefCreator.CreateFlagAndFlagBase(ToWorldPos(l, matchData), c);
                            }
                            break;
                        }
                    }
                }
            }
        }

        #endregion

        #region Create a waypoint

        //Get areas inside a wall.
        List <int> toRemove = new List <int>();
        Location   tempL;
        for (int i = 0; i < spawns.OtherSpawnsCreated[Spawns.Waypoint].Count; ++i)
        {
            tempL = spawns.OtherSpawnsCreated[Spawns.Waypoint][i];
            if (level.Map[tempL.X, tempL.Y])
            {
                Debug.Log("Found a spawn spot inside a wall!");
                toRemove.Add(i);
            }
        }

        //Remove areas that were inside the wall.
        //Start from the end so there's no issue with indices changing after an object is deleted.
        for (int i = toRemove.Count - 1; i >= 0; --i)
        {
            spawns.OtherSpawnsCreated[Spawns.Waypoint].RemoveAt(toRemove[i]);
        }

        //Generate a waypoint.
        if (!isPreview && levelManager.MatchRules.WaypointFight != null)
        {
            List <Location> waypointSpawns = spawns.OtherSpawnsCreated[Spawns.Waypoint];
            Location        l = waypointSpawns[Random.Range(0, waypointSpawns.Count - 1)];
            prefCreator.CreateWaypoint(ToWorldPos(l, matchData));
        }

        #endregion

        #region Create powerup spawns

        if (!isPreview)
        {
            PowerupSpawnLocations = spawns.OtherSpawnsCreated[Spawns.Powerup].ToList().ConvertAll <Vector2>(l => ToWorldPos(l, matchData));
        }

        #endregion
    }
Beispiel #28
0
        public override void OnInspectorGUI()
        {
            var undoStack = grid.undoStack;
            var redoStack = grid.redoStack;
            var current   = grid.current;

            GUILayout.BeginHorizontal();
            GUILayout.Label("Grid Width:");
            var oldWidth = grid.width;

            grid.width = EditorGUILayout.IntSlider(grid.width, 0, 100);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Grid height:");
            var oldHeight = grid.height;

            grid.height = EditorGUILayout.IntSlider(grid.height, 0, 100);
            GUILayout.EndHorizontal();

            if (grid.width != oldWidth || grid.height != oldHeight)
            {
                grid.GenerateMaps(false);
            }

            for (int i = 0; i < grid.streets.Count; i++)
            {
                if (grid.streets [grid.streets.Count - 1].Count > 1)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Street" + (i + 1) + ": ");

                    if (GUILayout.Button("Select"))
                    {
                        for (int j = 0; j < grid.selectedStreet.Count; j++)
                        {
                            grid.selectedStreet [j] = false;
                        }
                        grid.selectedStreet [i] = true;
                    }
                    if (GUILayout.Button("Deselect"))
                    {
                        grid.selectedStreet [i] = false;
                    }
                    if (GUILayout.Button("Delete"))
                    {
                        grid.streets.RemoveAt(i);
                        grid.selectedStreet.RemoveAt(i);
                        if (grid.selectedStreet.Count > i)
                        {
                            grid.selectedStreet [i] = false;
                        }
                    }
                    GUILayout.EndHorizontal();
                }
            }

            //select number of building types and add building prefabs
            showBuildingTypes = EditorGUILayout.Foldout(showBuildingTypes, "Show Building Types");

            if (showBuildingTypes)
            {
                GUILayout.BeginVertical("Box", GUILayout.ExpandWidth(true));

                EditorGUILayout.Space();
                AddTypesOfPrefabs("House Types", grid.housePrefab);

                EditorGUILayout.Space();
                AddTypesOfPrefabs("Skyscraper Types", grid.skyscraperPrefab);

                GUILayout.EndVertical();
            }

            EditorGUILayout.Space();
            //select number of building types and add building prefabs
            showTreeTypes = EditorGUILayout.Foldout(showTreeTypes, "Show Building Types");

            if (showTreeTypes)
            {
                GUILayout.BeginVertical("Box", GUILayout.ExpandWidth(true));

                AddTypesOfPrefabs("ConeTree Types", grid.conetreePrefab);

                EditorGUILayout.Space();
                AddTypesOfPrefabs("WoodTree Types", grid.woodtreePrefab);

                GUILayout.EndVertical();
            }



            DrawBasicEditTools();

            if (GUILayout.Button("Generate City", GUILayout.Height(30)))
            {
                grid.showGrid = false;
                if (grid.terrainData == null || grid.city == null)
                {
                    grid.city = GameObject.Find("MyProceduralCity");
                    if (grid.city)
                    {
                        grid.terrainData = grid.city.GetComponent <TerrainData> ();
                    }
                    else
                    {
                        // create new city GO
                        grid.terrainData             = new TerrainData();
                        grid.city                    = Terrain.CreateTerrainGameObject(grid.terrainData);
                        grid.city.name               = "MyProceduralCity";
                        grid.city.transform.position = Vector3.zero;
                        grid.city.AddComponent <CityPopulator> ();
                    }
                }
                grid.city.GetComponent <CityPopulator> ().Populate(grid);
            }

            if (GUILayout.Button("Reset Map", GUILayout.Height(30)))
            {
                grid.showGrid = true;
                redoStack     = new LinkedList <GridCreator.CellType[, ]> ();
                undoStack     = new LinkedList <GridCreator.CellType[, ]> ();
                grid.GenerateMaps(true);
                current = (GridCreator.CellType[, ])grid.worldMap.Clone();
                undoStack.AddLast(new LinkedListNode <GridCreator.CellType[, ]> (grid.worldMap));
            }

            if (GUILayout.Button("Save!", GUILayout.Height(30)))
            {
                var city = grid.city;

                if (city == null)
                {
                    Debug.Log("Please generate map first");
                }
                else
                {
                    city.GetComponent <CityPopulator> ().ClearFromScripts();
                    PrefabCreator.CreatePrefab(city.gameObject);
                }
            }
            GUI.enabled = true;


            SceneView.RepaintAll();

            if (GUI.changed)
            {
                grid.firstTimeBuild = true;
            }


            //base.OnInspectorGUI ();
        }
Beispiel #29
0
        void SaveRole()
        {
            List <tian.PlacementData> listpl = new List <tian.PlacementData>();

            _placementConfigDic = _placementConfigList.ToDictionary(item => item.id, item => item);

            //string jsonString = Tools.Obj2Json(_placementConfigDic, true);
            //Debug.Log("jsonString = " + jsonString);
            //Tools.WriteStringFromFile(Application.dataPath + "/" + _roleDataFile, jsonString);
            Tools.SaveOneData <PlacementConfig>(_placementConfigDic, Application.dataPath + "/" + "Resources_moved/Scripts/box/InteractionComponentsList");

            string scalejson = Tools.Obj2Json(_scalefloat, true);

            Tools.WriteStringFromFile(Application.dataPath + "/Resources_moved/Scripts/box/scale.json", scalejson);
            string tagjsonstring = Tools.Obj2Json(taglist, true);

            Tools.WriteStringFromFile(Application.dataPath + "/Resources_moved/Scripts/box/Taglist.json", tagjsonstring);
            // 生成预制体 add by TangJian 2017/11/16 17:42:05

            // 创建目录 add by TangJian 2018/06/12 17:12:19
            Tools.CreateFolder(Application.dataPath.Substring(0, Application.dataPath.IndexOf("/Assets")) + "/" + _prefabPath);
            Tools.CreateFolder(Application.dataPath.Substring(0, Application.dataPath.IndexOf("/Assets")) + "/" + _prefabPath + "/Mats");
            Tools.CreateFolder(Application.dataPath.Substring(0, Application.dataPath.IndexOf("/Assets")) + "/" + _prefabPath + "/Render");
            Tools.CreateFolder(Application.dataPath.Substring(0, Application.dataPath.IndexOf("/Assets")) + "/" + _prefabPath + "/Render/Anim");
            Tools.CreateFolder(Application.dataPath.Substring(0, Application.dataPath.IndexOf("/Assets")) + "/" + _prefabPath + "/Render/Image");



            //try
            //{
            int currIndex = 0;

            //// 移除老的预制体 add by TangJian 2018/11/20 22:46
            //var files = Tools.GetFilesInFolder(Application.dataPath.Substring(0, Application.dataPath.IndexOf("/Assets")) + "/" + prefabPath + "/Render");
            //foreach (var item in files)
            //{
            //    EditorUtility.DisplayProgressBar("移除老的预制体", item, (float)currIndex++ / files.Count);

            //    Debug.Log("删除文件: " + item);
            //    AssetDatabase.DeleteAsset(item.Substring(item.IndexOf("Assets/")));
            //}

            // 生成新的预制体 add by TangJian 2018/11/20 22:46
            currIndex = 0;
            foreach (var item in _placementConfigDic)
            {
                EditorUtility.DisplayProgressBar("生成新的预制体", item.Value.id, (float)currIndex++ / _placementConfigDic.Count);

                listpl.Add(item.Value.placementData);
                // dataConfigDic.Add(item.Value.placementData.id,item.Value.placementData);
                var itemObject = PrefabCreator.CreatePlacement(item.Value, _prefabPath, _scalefloat);
                DestroyImmediate(itemObject);
            }
            //}
            //catch (System.Exception e)
            //{
            //    Debug.LogError(e);
            //}
            //finally
            //{
            EditorUtility.ClearProgressBar();
            //}

//            _dataConfigDic = listpl.ToDictionary(item => item.id, item => item);
//            string tostr = Tools.Obj2Json(_dataConfigDic, true);
//            Tools.WriteStringFromFile(Application.dataPath + "/" + _dataFile, tostr);
        }
Beispiel #30
0
        void Createprefab()
        {
            var itemObject = PrefabCreator.CreatePlacement(_currPlacementConfig, _prefabPath, _scalefloat);

            DestroyImmediate(itemObject);
        }