Пример #1
0
        private static void CreateTerrain(MenuCommand menuCommand)
        {
            TerrainData asset = new TerrainData {
                heightmapResolution = 0x401,
                size = new Vector3(1000f, 600f, 1000f),
                heightmapResolution = 0x200,
                baseMapResolution   = 0x400
            };

            asset.SetDetailResolution(0x400, asset.detailResolutionPerPatch);
            AssetDatabase.CreateAsset(asset, AssetDatabase.GenerateUniqueAssetPath("Assets/New Terrain.asset"));
            GameObject context = menuCommand.context as GameObject;
            string     uniqueNameForSibling = GameObjectUtility.GetUniqueNameForSibling(context?.transform, "Terrain");
            GameObject child = Terrain.CreateTerrainGameObject(asset);

            child.name = uniqueNameForSibling;
            GameObjectUtility.SetParentAndAlign(child, context);
            Selection.activeObject = child;
            Undo.RegisterCreatedObjectUndo(child, "Create terrain");
        }
Пример #2
0
        static void CreateTerrain(MenuCommand menuCommand)
        {
            // Create the storage for the terrain in the project
            // (So we can reuse it in multiple scenes)
            TerrainData terrainData = new TerrainData();

            terrainData.heightmapResolution = 513;
            terrainData.size = new Vector3(1000, 600, 1000);
            terrainData.baseMapResolution = 1024;
            terrainData.SetDetailResolution(1024, terrainData.detailResolutionPerPatch);

            AssetDatabase.CreateAsset(terrainData, AssetDatabase.GenerateUniqueAssetPath("Assets/New Terrain.asset"));
            var        parent  = menuCommand.context as GameObject;
            GameObject terrain = Terrain.CreateTerrainGameObject(terrainData);

            terrain.name = "Terrain";

            GameObjectUtility.SetParentAndAlign(terrain, parent);
            StageUtility.PlaceGameObjectInCurrentStage(terrain);
            GameObjectUtility.EnsureUniqueNameForSibling(terrain);
            Selection.activeObject = terrain;
            Undo.RegisterCreatedObjectUndo(terrain, "Create terrain");
        }
Пример #3
0
        private static void CreateSpriteMaskGameObject()
        {
            GameObject gameObject = ObjectFactory.CreateGameObject("", new Type[]
            {
                typeof(SpriteMask)
            });

            if (Selection.activeObject is Sprite)
            {
                gameObject.GetComponent <SpriteMask>().sprite = (Sprite)Selection.activeObject;
            }
            else if (Selection.activeObject is Texture2D)
            {
                string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
                if (!string.IsNullOrEmpty(assetPath))
                {
                    Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>(assetPath);
                    if (sprite != null)
                    {
                        gameObject.GetComponent <SpriteMask>().sprite = sprite;
                    }
                }
            }
            else if (Selection.activeObject is GameObject)
            {
                GameObject gameObject2 = (GameObject)Selection.activeObject;
                PrefabType prefabType  = PrefabUtility.GetPrefabType(gameObject2);
                if (prefabType != PrefabType.Prefab && prefabType != PrefabType.ModelPrefab)
                {
                    GameObjectUtility.SetParentAndAlign(gameObject, gameObject2);
                }
            }
            gameObject.name = GameObjectUtility.GetUniqueNameForSibling(gameObject.transform.parent, SpriteMaskEditor.Contents.newSpriteMaskName.text);
            Undo.SetCurrentGroupName(SpriteMaskEditor.Contents.createSpriteMaskUndoString.text);
            Selection.activeGameObject = gameObject;
        }