Пример #1
0
    /// <summary>
    /// Factory method which sets up and configures a new SnapshotCamera, then returns it.
    /// </summary>
    /// <param name="layer">The layer number of the layer on which to take snapshots.</param>
    /// <param name="name">The name that will be given to the new GameObject the SnapshotCamera will be attached to.</param>
    /// <returns>A new SnapshotCamera, ready for use.</returns>
    public static SnapshotCamera MakeSnapshotCamera(int layer = 5, string name = "Snapshot Camera")
    {
        //if (layer < 0 || layer > 31)
        //    throw new ArgumentOutOfRangeException("layer", "layer argument must specify a valid layer between 0 and 31");

        layer = 0;
        // Create a new GameObject to hold the camera
        GameObject snapshotCameraGO = new GameObject(name);
        // Add a Camera component to the GameObject
        Camera cam = snapshotCameraGO.AddComponent <Camera>();

        // Configure the Camera
        cam.cullingMask      = 1 << layer;
        cam.orthographic     = true;
        cam.orthographicSize = 1;
        cam.clearFlags       = CameraClearFlags.SolidColor;
        cam.backgroundColor  = Color.clear;
        cam.nearClipPlane    = 0.1f;
        cam.enabled          = false;

        // Add a SnapshotCamera component to the GameObject
        SnapshotCamera snapshotCamera = snapshotCameraGO.AddComponent <SnapshotCamera>();

        // Set the SnapshotCamera's cam and layer fields
        snapshotCamera.cam   = cam;
        snapshotCamera.layer = layer;

        // Return the SnapshotCamera
        return(snapshotCamera);
    }
Пример #2
0
 void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else
     {
         Destroy(this);
     }
 }
Пример #3
0
    void Update()
    {
        // Save a PNG of the snapshot when pressing space
        if (Input.GetKeyUp(KeyCode.Space))
        {
            UpdatePreview();
            System.IO.FileInfo fi = SnapshotCamera.SavePNG(texture);

            Debug.Log(string.Format("Snapshot {0} saved to {1}", fi.Name, fi.DirectoryName));
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        screenCapturePanel.gameObject.SetActive(false);

        snapCam = snapshotCam.GetComponent <SnapshotCamera>();
        snapCam = SnapshotCamera.MakeSnapshotCamera();

        BusinessCardButton.image.sprite = GetSpriteFromModel(businessCardPrefab, 6);
        BusinessCardButton.gameObject.SetActive(true);

        if (gameObject.GetComponent <AzureSpatialTest>().currentUser.communityId == -1)
        {
            CommunityButton.gameObject.SetActive(false);
            communityText.gameObject.SetActive(false);
        }
        else
        {
            CommunityButton.image.sprite = GetSpriteFromModelID("community", 0.3f);
        }
        //userCommunity = gameObject.GetComponent<AzureSpatialTest>().currentUser.community;


        saveButton.gameObject.SetActive(false);
        RotateLeftButton.gameObject.SetActive(false);
        RotateRightButton.gameObject.SetActive(false);
        OtherObjectsTMPDropdown.options.Clear();
        otherObjects = Resources.LoadAll <GameObject>("Prefabs/Models/Others");
        foreach (GameObject go in otherObjects)
        {
            Debug.Log(go.name);
            snapCam.defaultScale = new Vector3(18, 18, 18);
            var buttonImage = snapCam.TakePrefabSnapshot(go, new Color(0, 0.475f, 0.839f));
            var image       = Sprite.Create(buttonImage, new Rect(0, 0, 128, 128), new Vector2());

            OtherObjectsTMPDropdown.options.Add(new TMP_Dropdown.OptionData()
            {
                text = go.name, image = image
            });
        }

        OtherObjectsTMPDropdown.RefreshShownValue();
    }
Пример #5
0
    private void TakeAllSnapshots()
    {
        for (int i = 0; i < gameObjectToBuildingItems.Length; ++i)
        {
            gameObjectToBuildingItems[i].gameObject.SetActive(true);

            SnapshotCamera snapshotCamera =
                gameObjectToBuildingItems[i].gameObject.GetComponent <SnapshotCamera>();

            if (gameObjectToBuildingItems[i].gameObject.TryGetComponent(out PreparerTo3DSnapshot preparerTo3DSnapshot))
            {
                preparerTo3DSnapshot.Prepare();
            }

            if (!snapshotCamera)
            {
                Debug.LogError("SnapshotCamera didn't find");
            }
            else
            {
                snapshotCamera.TakeSnapshot(string.Format(
                                                "{0}/RenderedImages/{1}.png",
                                                Application.dataPath,
                                                buildingItemList.buildingItems[i].name));
            }

            if (preparerTo3DSnapshot)
            {
                preparerTo3DSnapshot.ResetToPrevious();
            }

            gameObjectToBuildingItems[i].gameObject.SetActive(false);
        }

        Debug.Log("Completed taking snapshots");
    }
    void Start()
    {
        snapshotCamera = SnapshotCamera.MakeSnapshotCamera(layerNum, "SnapshotLayer");

        UpdatePreview();
    }
Пример #7
0
    void OnGUI()
    {
        AssetPreview.SetPreviewTextureCacheSize(256);
        if (GUILayout.Button("Recreate Icon For Every Item"))
        {
            var snapshotCamera = SnapshotCamera.MakeSnapshotCamera(5, "Snapshot Camera");
            var guids = AssetDatabase.FindAssets("t:GameObject");
            foreach(var guid in guids)
            {
                var path = AssetDatabase.GUIDToAssetPath(guid);
                var obj = AssetDatabase.LoadAssetAtPath<GameObject>(path);
                var item = obj.GetComponent<Item>();
                if(item != null && item.type != Item.ItemType.Rod)
                {
                    var texture = snapshotCamera.TakePrefabSnapshot(obj, 512, 512);

                    string savePath = mainPath;

                    switch (item.type)
                    {
                        case Item.ItemType.Fish:
                            {
                                savePath += "Fishes/";
                            }
                            break;
                        case Item.ItemType.Hat:
                            {
                                savePath += "Hats/";
                            }
                            break;
                        case Item.ItemType.Shoe:
                            {
                                savePath += "Shoes/";
                            }
                            break;
                        case Item.ItemType.Tshirt:
                            {
                                savePath += "Tshirts/";
                            }
                            break;
                        case Item.ItemType.Pants:
                            {
                                savePath += "Pants/";
                            }
                            break;
                    }

                    AssetDatabase.CreateAsset(texture, savePath + item.name + "_iconTexture.asset");
                    var loadedTexture = AssetDatabase.LoadAssetAtPath<Texture2D>(savePath + item.name + "_iconTexture.asset");
                    var icon = Sprite.Create(loadedTexture, new Rect(0f, 0f, loadedTexture.width, loadedTexture.height), new Vector2(0.5f, 0.5f));
                    AssetDatabase.CreateAsset(icon, savePath + item.name + "_icon.asset");
                    var loadedIcon = AssetDatabase.LoadAssetAtPath<Sprite>(savePath + item.name + "_icon.asset");

                    item.SetIcon(loadedIcon);
                }
                EditorUtility.SetDirty(obj);
            }
            AssetDatabase.Refresh();
            DestroyImmediate(snapshotCamera);
        }
    }
Пример #8
0
 private void SaveImage()
 {
     Snapshotter.UpdatePreview();
     System.IO.FileInfo fi = SnapshotCamera.SavePNG(Snapshotter.texture);
     Debug.Log(string.Format("Snapshot {0} saved to {1}", "human.png", fi.DirectoryName));
 }