public override void CreatePreview()
        {
            m_PreviewUtility = new PreviewRenderUtility(true);
            m_PreviewUtility.camera.orthographic       = true;
            m_PreviewUtility.camera.orthographicSize   = 2;
            m_PreviewUtility.camera.transform.position = new Vector3(0, 0, -10);

            var previewInstance = new GameObject();

            m_PreviewGrid = previewInstance.AddComponent <Grid>();
            m_PreviewUtility.AddSingleGO(previewInstance);

            m_PreviewTilemaps         = new List <Tilemap>();
            m_PreviewTilemapRenderers = new List <TilemapRenderer>();

            for (int i = 0; i < 2; i++)
            {
                var previewTilemapGo = new GameObject();
                m_PreviewTilemaps.Add(previewTilemapGo.AddComponent <Tilemap>());
                m_PreviewTilemapRenderers.Add(previewTilemapGo.AddComponent <TilemapRenderer>());

                previewTilemapGo.transform.SetParent(previewInstance.transform, false);
            }

            UpdatePreviews();
        }
Exemplo n.º 2
0
    //previewの用意
    private void previewSetup()
    {
        previewObject = expansion.GetBuiltObject((StageGenerator.Built)previewNumber);

        //previewObject.hideFlags = HideFlags.HideAndDontSave;
        previewObject.SetActive(true);
        var flags        = BindingFlags.Static | BindingFlags.NonPublic;
        var propInfo     = typeof(Camera).GetProperty("PreviewCullingLayer", flags);
        int previewLayer = (int)propInfo.GetValue(null, new object[0]);

        previewRenderUtility = new PreviewRenderUtility(true);
        previewRenderUtility.AddSingleGO(previewObject);
        //FieldOfView を 30 にするとちょうどいい見た目になる
        previewRenderUtility.cameraFieldOfView = 30f;
        //必要に応じて nearClipPlane と farClipPlane を設定
        previewRenderUtility.camera.nearClipPlane = 0.3f;
        previewRenderUtility.camera.farClipPlane  = 1000;
        //previewLayer のみ表示する
        previewRenderUtility.camera.cullingMask = 1 << previewLayer;

        var previewCamera = previewRenderUtility.camera;

        previewCamera.transform.position = previewObject.transform.position + new Vector3(2.5f, 2.5f, -5);
        previewCamera.transform.LookAt(previewObject.transform);
        previewCamera.clearFlags      = CameraClearFlags.Skybox;
        previewCamera.backgroundColor = new Color(0.9f, 0.9f, 0.9f);

        previewObject.layer = previewLayer;
        foreach (Transform transform in previewObject.transform)
        {
            transform.gameObject.layer = previewLayer;
        }
    }
Exemplo n.º 3
0
        void CreatePreviewInstances()
        {
            this.DestroyPreviewInstances();

            var skeletonDataAsset = (SkeletonDataAsset)target;

            if (skeletonDataAsset.GetSkeletonData(false) == null)
            {
                return;
            }

            if (this.m_previewInstance == null)
            {
                string skinName = EditorPrefs.GetString(m_skeletonDataAssetGUID + "_lastSkin", "");
                m_previewInstance = SpineEditorUtilities.InstantiateSkeletonAnimation(skeletonDataAsset, skinName).gameObject;

                if (m_previewInstance != null)
                {
                    m_previewInstance.hideFlags         = HideFlags.HideAndDontSave;
                    m_previewInstance.layer             = 0x1f;
                    m_skeletonAnimation                 = m_previewInstance.GetComponent <SkeletonAnimation>();
                    m_skeletonAnimation.initialSkinName = skinName;
                    m_skeletonAnimation.LateUpdate();
                    m_skeletonData = m_skeletonAnimation.skeletonDataAsset.GetSkeletonData(true);
                    m_previewInstance.GetComponent <Renderer>().enabled = false;
                    m_initialized = true;

                                        #if SPINE_UNITY_2018_PREVIEW_API
                    m_previewUtility.AddSingleGO(m_previewInstance);
                                        #endif
                }

                AdjustCameraGoals(true);
            }
        }
        public override void CreatePreview()
        {
            m_PreviewUtility = new PreviewRenderUtility(true);
            m_PreviewUtility.camera.orthographic       = true;
            m_PreviewUtility.camera.orthographicSize   = 0.5f;
            m_PreviewUtility.camera.transform.position = new Vector3(0, 0.5f, -10);

            var previewInstance = new GameObject();

            m_PreviewGrid = previewInstance.AddComponent <Grid>();
            m_PreviewUtility.AddSingleGO(previewInstance);

            m_PreviewTilemaps         = new List <Tilemap>();
            m_PreviewTilemapRenderers = new List <TilemapRenderer>();

            for (int i = 0; i < 2; i++)
            {
                var previewTilemapGo = new GameObject();
                m_PreviewTilemaps.Add(previewTilemapGo.AddComponent <Tilemap>());
                m_PreviewTilemapRenderers.Add(previewTilemapGo.AddComponent <TilemapRenderer>());

                previewTilemapGo.transform.SetParent(previewInstance.transform, false);
            }

            m_PreviewTilemaps[0].SetTile(new Vector3Int(-1, 0, 0), tile);
            m_PreviewTilemaps[1].SetTile(new Vector3Int(0, 0, 0), tile);

            doorTile.SetOpen(new Vector3Int(-1, 0, 0), m_PreviewTilemaps[0].gameObject.AddComponent <GridInformation>(), false);
            doorTile.SetOpen(new Vector3Int(0, 0, 0), m_PreviewTilemaps[1].gameObject.AddComponent <GridInformation>(), true);
        }
Exemplo n.º 5
0
    /// <summary>
    /// Handle the display of the material preview
    /// </summary>
    /// <param name="materialEditor">Current Material Editor</param>
    /// <param name="r">Fullsized rect for the interactive preview</param>
    /// <param name="background">Background data for the interactive preview</param>
    public override void OnMaterialInteractivePreviewGUI(MaterialEditor materialEditor, Rect r, GUIStyle background)
    {
        if (!ShaderUtil.hardwareSupportsRectRenderTexture)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40f), "Material preview \nnot available");
        }
        else
        {
            if (targetMesh == null)
            {
                base.OnMaterialInteractivePreviewGUI(materialEditor, r, background);
                return;
            }

            Material mat = materialEditor.target as Material;

            if (m_previewRenderUtility == null)
            {
                m_previewRenderUtility = new PreviewRenderUtility();
                m_previewRenderUtility.AddSingleGO(GameObject.CreatePrimitive(PrimitiveType.Plane));

#if UNITY_2017_1_OR_NEWER
                fov = m_previewRenderUtility.cameraFieldOfView = 30f;
#else
                fov = m_previewRenderUtility.m_CameraFieldOfView = 30f;
#endif
            }

            if (m_previewGUIType == null)
            {
                m_previewGUIType = Type.GetType(GUISrc);

                m_dragMethod = m_previewGUIType.GetMethod("Drag2D", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            }

            if (m_modelInspectorType == null)
            {
                m_modelInspectorType = Type.GetType("UnityEditor.ModelInspector, UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
                m_renderMeshMethod   = m_modelInspectorType.GetMethod("RenderMeshPreview", BindingFlags.Static | BindingFlags.NonPublic);
            }

            m_previewDir = (Vector2)m_dragMethod.Invoke(m_previewGUIType, new object[] { m_previewDir, r });

            if (Event.current.type == EventType.Repaint)
            {
                m_previewRenderUtility.BeginPreview(r, background);
                m_renderMeshMethod.Invoke(m_modelInspectorType, new object[] { targetMesh, m_previewRenderUtility, mat, null, m_previewDir, -1 });
                m_previewRenderUtility.EndAndDrawPreview(r);
            }
        }
    }
        public void Initialize(SkeletonDataAsset skeletonDataAsset, string skinName = "")
        {
            if (skeletonDataAsset == null)
            {
                return;
            }
            if (skeletonDataAsset.GetSkeletonData(false) == null)
            {
                return;
            }

            this.skeletonDataAsset = skeletonDataAsset;
            this.skeletonData      = skeletonDataAsset.GetSkeletonData(false);

            if (previewRenderUtility == null)
            {
                previewRenderUtility = new PreviewRenderUtility(true);
                animationLastTime    = Time.realtimeSinceStartup;

                const int PreviewLayer             = 31;
                const int PreviewCameraCullingMask = 1 << PreviewLayer;

                {
                    var c = this.PreviewUtilityCamera;
                    c.orthographic     = true;
                    c.orthographicSize = 1;
                    c.cullingMask      = PreviewCameraCullingMask;
                    c.nearClipPlane    = 0.01f;
                    c.farClipPlane     = 1000f;
                }

                DestroyPreviewGameObject();

                if (previewGameObject == null)
                {
                    try {
                        previewGameObject = SpineEditorUtilities.InstantiateSkeletonAnimation(skeletonDataAsset, skinName).gameObject;

                        if (previewGameObject != null)
                        {
                            previewGameObject.hideFlags       = HideFlags.HideAndDontSave;
                            previewGameObject.layer           = PreviewLayer;
                            skeletonAnimation                 = previewGameObject.GetComponent <SkeletonAnimation>();
                            skeletonAnimation.initialSkinName = skinName;
                            skeletonAnimation.LateUpdate();
                            previewGameObject.GetComponent <Renderer>().enabled = false;
                            previewRenderUtility.AddSingleGO(previewGameObject);
                        }

                        AdjustCameraGoals(true);
                    } catch {
                        DestroyPreviewGameObject();
                    }
                }
            }
        }
Exemplo n.º 7
0
        public static byte[] GeneratePrefabThumbnail(GameObject prefab)
        {
            var prefabInstance = UnityObject.Instantiate(prefab);

            var renderUtility         = new PreviewRenderUtility();
            var renderCamera          = renderUtility.camera;
            var renderCameraTransform = renderCamera.transform;

            renderCamera.fieldOfView = k_FieldOfView;

            renderUtility.AddSingleGO(prefabInstance);
            renderCamera.backgroundColor = k_BackgroundColor;

            var prefabList = new List <GameObject>();

            prefabList.Add(prefabInstance);

            var bounds   = BoundsUtils.GetBounds(prefabList);
            var halfSize = Mathf.Max(bounds.extents.magnitude, 0.0001f);
            var distance = halfSize * k_CameraDistanceRatio;

            var pos = bounds.center - k_PreviewRotation * (Vector3.forward * distance);

            renderCameraTransform.position = pos;
            renderCameraTransform.rotation = k_PreviewRotation;
            renderCamera.nearClipPlane     = distance - halfSize * k_Padding;
            renderCamera.farClipPlane      = distance + halfSize * k_Padding;

            renderUtility.lights[0].intensity          = k_LightIntensity;
            renderUtility.lights[0].transform.rotation = k_FirstLightRotation;
            renderUtility.lights[1].intensity          = k_LightIntensity;
            renderUtility.lights[1].transform.rotation = k_SecondLightRotation;

            renderUtility.ambientColor = k_AmbientLightColor;

            renderUtility.BeginPreview(k_TextureRect, null);
            renderUtility.Render(true);

            var renderTexture = renderUtility.EndPreview() as RenderTexture;
            var temporary     = RenderTexture.GetTemporary((int)k_TextureRect.width, (int)k_TextureRect.height, 0, GraphicsFormat.R8G8B8A8_UNorm);

            Graphics.Blit(renderTexture, temporary);
            RenderTexture.active = temporary;
            var texture = new Texture2D((int)k_TextureRect.width, (int)k_TextureRect.height, TextureFormat.RGBA32, false, false);

            texture.ReadPixels(new Rect(0.0f, 0.0f, k_TextureRect.width, k_TextureRect.height), 0, 0);
            texture.Apply();
            var thumbnail = texture.EncodeToPNG();

            RenderTexture.ReleaseTemporary(temporary);
            renderUtility.Cleanup();
            UnityObject.DestroyImmediate(texture);

            return(thumbnail);
        }
Exemplo n.º 8
0
 public IFPreview(GameObject go, MeshFilter[] filters, Renderer[] renderers)
 {
     this.go        = GameObject.Instantiate(go);
     this.filters   = filters;
     this.renderers = renderers;
     for (int i = 0; i < renderers.Length; i++)
     {
         dic.Add(renderers[i], renderers[i].sharedMaterials);
     }
     preview = new PreviewRenderUtility(false);
     preview.AddSingleGO(this.go);
     GameObject.DestroyImmediate(this.go);
 }
        private void OnEnable()
        {
            if (!HasPreviewGUI())
            {
                return;
            }
            m_CameraDirection                   = Vector3.Normalize(new Vector3(0f, 3f, 15f));
            m_Preview                           = new PreviewRenderUtility();
            m_Preview.camera.fieldOfView        = 30.0f;
            m_Preview.camera.nearClipPlane      = 0.3f;
            m_Preview.camera.farClipPlane       = 1000;
            m_Preview.camera.transform.position = m_CameraDirection * m_CameraDistance;

            m_PreviewTarget = GameObject.Instantiate(((Component)target).gameObject).GetComponent <GPUAnimationController>();
            m_Preview.AddSingleGO(m_PreviewTarget.gameObject);
            m_PreviewMeshRenderer = m_PreviewTarget.GetComponent <MeshRenderer>();
            m_TargetBlock         = new MaterialPropertyBlock();
            m_PreviewTarget.transform.position = Vector3.zero;
            m_PreviewTarget.Init();
            m_PreviewTarget.SetAnimation(0);

            Material transparentMaterial = new Material(Shader.Find("Unlit/Transparent"));

            transparentMaterial.SetColor("_Color", new Color(1, 1, 1, .3f));

            m_BoundsViewer = GameObject.CreatePrimitive(PrimitiveType.Cube);
            m_BoundsViewer.GetComponent <MeshRenderer>().material = transparentMaterial;

            m_Preview.AddSingleGO(m_BoundsViewer.gameObject);
            m_BoundsViewer.transform.SetParent(m_PreviewTarget.transform);
            m_BoundsViewer.transform.localRotation = Quaternion.identity;
            m_BoundsViewer.transform.localScale    = m_PreviewTarget.m_MeshFilter.sharedMesh.bounds.size;
            m_BoundsViewer.transform.localPosition = m_PreviewTarget.m_MeshFilter.sharedMesh.bounds.center;
            m_BoundsViewer.SetActive(false);

            EditorApplication.update += Update;
        }
Exemplo n.º 10
0
        private void CreatePreview()
        {
            previewRenderUtility = new PreviewRenderUtility(true);
            previewRenderUtility.camera.orthographic       = true;
            previewRenderUtility.camera.orthographicSize   = 2;
            previewRenderUtility.camera.transform.position = new Vector3(0, 0, -10);

            GameObject previewGameObject = new GameObject();

            previewGrid = previewGameObject.AddComponent <Grid>();
            previewRenderUtility.AddSingleGO(previewGameObject);
            previewTilemaps         = new List <Tilemap>();
            previewTilemapRenderers = new List <TilemapRenderer>();

            for (int tileIndex = 0; tileIndex < 4; tileIndex++)
            {
                GameObject previewTilemapGameObject = new GameObject();
                previewTilemaps.Add(previewTilemapGameObject.AddComponent <Tilemap>());
                previewTilemapRenderers.Add(previewTilemapGameObject.AddComponent <TilemapRenderer>());

                previewTilemapGameObject.transform.SetParent(previewGameObject.transform, false);
            }

            for (int x = -2; x <= 0; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    previewTilemaps[0].SetTile(new Vector3Int(x, y, 0), scriptedTile);
                }
            }

            for (int y = -1; y <= 1; y++)
            {
                previewTilemaps[1].SetTile(new Vector3Int(1, y, 0), scriptedTile);
            }

            for (int x = -2; x <= 0; x++)
            {
                previewTilemaps[2].SetTile(new Vector3Int(x, -2, 0), scriptedTile);
            }

            previewTilemaps[3].SetTile(new Vector3Int(1, -2, 0), scriptedTile);
        }
Exemplo n.º 11
0
    private void OnEnable()
    {
        groundMapProperty = serializedObject.FindProperty("groundMap");
        treeMapProperty   = serializedObject.FindProperty("treeMap");
        caveMapProperty   = serializedObject.FindProperty("caveMap");

        GenerateGroundTexture();
        GenerateTreeTexture();

        renderTexture            = new RenderTexture(300, 300, 16);
        renderTexture.filterMode = FilterMode.Point;

        renderUtils    = new PreviewRenderUtility();
        noise3DPreview = CreateNoise3DPreview();
        UpdateNoise3DPreview();
        renderUtils.AddSingleGO(noise3DPreview);

        renderUtils.camera.transform.position = new Vector3(0, 0, -10);
        renderUtils.camera.farClipPlane       = 20;
        renderUtils.camera.targetTexture      = renderTexture;
    }
Exemplo n.º 12
0
    //添加GO 到预览窗体
    virtual public GameObject AddGameObject(GameObject go, bool cloneInstance = true)
    {
        AssertInit();

        if (go == null)
        {
            return(null);
        }

        if (m_MapObjects.ContainsKey(go.GetInstanceID()))
        {
            Debug.LogError(string.Format("GameObject[{0}] target is Exit in PreviewWindow", go.GetInstanceID()));
            return(go);
        }

        GameObject target = null;

        if (cloneInstance)
        {
            target = PreviewHelper.InstantiateGameObject(go);
        }
        else
        {
            PreviewHelper.FormatGameObject(go);
            target = go;
        }

        target.transform.position = Vector3.zero;

        //加入到目标列表
        m_MapObjects.Add(target.GetInstanceID(), target);

        SetEnabledRecursive(false);

#if UNITY_2017_1_OR_NEWER
        m_Preview.AddSingleGO(target);
#endif
        return(target);
    }
Exemplo n.º 13
0
    //---- Enable/Disable/Destroy
    //---------------------------
    private void OnEnable()
    {
        _renderUtils = new PreviewRenderUtility();

        // Create hex tile
        _hexTile = Instantiate <HexTile>(_hexTilePreferences.Prefab);
        _renderUtils.AddSingleGO(_hexTile.gameObject);
        _renderUtils.camera.farClipPlane       = 100;
        _renderUtils.camera.transform.position = new Vector3(0, 0, -10);
        _renderUtils.camera.transform.LookAt(_hexTile.transform, Vector3.up);

        // Get texture contents
        GetTexturesContent();
        _textureIndex = 0;

        // Updates
        UpdateRotation();
        UpdateScale();
        UpdateJsonOptions();
        _hexTile.View.SetMaterial(_hexTilePreferences.Materials["default"]);
        UpdateTexture(_textureContent[_textureIndex].text);
        _filename = "Hex_Temp";
    }
Exemplo n.º 14
0
    private void AddSingleGO(GameObject go)
    {
#if UNITY_2017_1_OR_NEWER
        m_PreviewUtility.AddSingleGO(go);
#endif
    }
    void DrawPreview(bool save = false)
    {
        float   iconPreviewBrightness = mIconPreviewBrightness.floatValue;
        Vector3 iconPreviewOffset     = mIconPreviewOffset.vector3Value;
        Vector3 iconPreviewAngles     = mIconPreviewAngles.vector3Value;
        Vector3 iconPreviewPosition   = mIconPreviewPosition.vector3Value;
        Vector3 iconPreviewRotation   = mIconPreviewRotation.vector3Value;
        Vector3 iconPreviewScale      = mIconPreviewScale.vector3Value;

        if (mShouldRefresh ||
            mCurrentPreviewBrightness != iconPreviewBrightness ||
            mCurrentPreviewOffset != iconPreviewOffset ||
            mCurrentPreviewAngles != iconPreviewAngles ||
            mCurrentPreviewPosition != iconPreviewPosition ||
            mCurrentPreviewRotation != iconPreviewRotation ||
            mCurrentPreviewScale != iconPreviewScale ||
            save ||
            ShouldRefreshPreviewObject())
        {
            DestroyPreview();

            mShouldRefresh            = false;
            mCurrentPreviewBrightness = iconPreviewBrightness;
            mCurrentPreviewOffset     = iconPreviewOffset;
            mCurrentPreviewAngles     = iconPreviewAngles;
            mCurrentPreviewPosition   = iconPreviewPosition;
            mCurrentPreviewRotation   = iconPreviewRotation;
            mCurrentPreviewScale      = iconPreviewScale;

            mPreviewGameObject = CreatePreviewObject();
            if (mPreviewGameObject != null)
            {
                mPreviewGameObject.hideFlags = HideFlags.HideAndDontSave;
            }
        }

        if (mPreviewGameObject == null && !save)
        {
            return;
        }

        if (mPreviewRenderUtility == null)
        {
            mPreviewRenderUtility = new PreviewRenderUtility();
            mPreviewRenderUtility.camera.fieldOfView              = 30.0f;
            mPreviewRenderUtility.camera.allowHDR                 = false;
            mPreviewRenderUtility.camera.allowMSAA                = false;
            mPreviewRenderUtility.ambientColor                    = new Color(1.0f, 1.0f, 1.0f, 0.0f);
            mPreviewRenderUtility.lights[0].intensity             = iconPreviewBrightness;
            mPreviewRenderUtility.lights[0].transform.position    = iconPreviewOffset;
            mPreviewRenderUtility.lights[0].transform.eulerAngles = iconPreviewAngles;
            mPreviewRenderUtility.lights[1].intensity             = iconPreviewBrightness;
            mPreviewRenderUtility.camera.transform.position       = iconPreviewOffset;
            mPreviewRenderUtility.camera.transform.eulerAngles    = iconPreviewAngles;
            mPreviewRenderUtility.camera.nearClipPlane            = 0.1f;
            mPreviewRenderUtility.camera.farClipPlane             = 10.0f;
            mPreviewRenderUtility.AddSingleGO(mPreviewGameObject);
        }

        mPreviewGameObject.transform.position    = iconPreviewPosition;
        mPreviewGameObject.transform.eulerAngles = iconPreviewRotation;
        mPreviewGameObject.transform.localScale  = iconPreviewScale;

        Rect previewRect = EditorGUILayout.GetControlRect(false, 200.0f);
        int  previewID   = GUIUtility.GetControlID(PreviewControlID, FocusType.Passive, previewRect);

        Event     e         = Event.current;
        EventType eventType = e.GetTypeForControl(previewID);
        bool      repaint   = eventType == EventType.Repaint;

        if (repaint || save)
        {
            Texture texture = null;
            mPreviewRenderUtility.BeginPreview(new Rect(0, 0, IconSize, IconSize), mGUIStyle);
            try {
                mPreviewRenderUtility.Render(false);
            } finally {
                texture = mPreviewRenderUtility.EndPreview();
            }

            if (save)
            {
                UnityEngine.Object obj  = serializedObject.targetObject;
                string             path = $"Sprites/Inventory/{Category}/{obj.name}.png";

                var rt     = (RenderTexture)texture;
                int width  = rt.width;
                int height = rt.height;

                RenderTexture.active = rt;
                try {
                    var tex2D = new Texture2D(width, height, TextureFormat.RGB24, false);
                    try {
                        tex2D.ReadPixels(new Rect(0, 0, width, height), 0, 0);
                        File.WriteAllBytes($"{Application.dataPath}/{path}", tex2D.EncodeToPNG());
                    } finally {
                        DestroyImmediate(tex2D);
                    }
                } finally {
                    RenderTexture.active = null;
                }

                AssetDatabase.Refresh();

                path = $"Assets/{path}";
                TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter;
                importer.textureType         = TextureImporterType.Sprite;
                importer.sRGBTexture         = false;
                importer.alphaIsTransparency = true;
                importer.alphaSource         = TextureImporterAlphaSource.None;
                importer.spritePixelsPerUnit = 100.0f;
                importer.mipmapEnabled       = false;
                importer.maxTextureSize      = IconSize;
                EditorUtility.SetDirty(importer);
                importer.SaveAndReimport();

                mIcon.objectReferenceValue = AssetDatabase.LoadAssetAtPath(path, typeof(Sprite));
            }

            if (repaint)
            {
                GUI.DrawTexture(previewRect, texture, ScaleMode.ScaleToFit, false);
            }
        }
    }
Exemplo n.º 16
0
        public override int OnGUI(PreviewRenderUtility context, BaseParam[] param)
        {
            int refreshCount = 0;

            OnPUI("Mesh", false, () =>
            {
                var meshTypeValue = (MeshType)EditorGUILayout.EnumPopup("Type", meshType);
                if (meshType.Equals(meshTypeValue) == false)
                {
                    Record("Change Mesh Type");

                    if (param[(int)PreParamType.kAnimation] is AnimationParam animationParam)
                    {
                        animationParam.Dispose();
                    }
                    if (gameObject != null)
                    {
                        GameObject.DestroyImmediate(gameObject);
                        gameObject = null;
                    }
                    if (boundsObject != null)
                    {
                        GameObject.DestroyImmediate(boundsObject);
                        boundsObject = null;
                    }
                    meshType = meshTypeValue;
                }
                if (meshType == MeshType.kAssets)
                {
                    var assetMeshValue = EditorGUILayout.ObjectField("Mesh", assetMesh, typeof(Mesh), false) as Mesh;
                    if (assetMesh != assetMeshValue)
                    {
                        Record("Change Mesh Assets");
                        assetMesh = assetMeshValue;
                    }
                }
                else if (meshType == MeshType.kDynamic)
                {
                    Color vertexColorValue = EditorGUILayout.ColorField("Vertex Color", vertexColor);
                    if (vertexColor.Equals(vertexColorValue) == false)
                    {
                        Record("Change Vertex Color");
                        dynamicMesh.colors = new Color[]
                        {
                            vertexColorValue,
                            vertexColorValue,
                            vertexColorValue,
                            vertexColorValue
                        };
                        vertexColor = vertexColorValue;
                    }
                    List <Vector4> texcoord;
                    Vector4 uv;

                    Vector2 texcoordZW = new Vector2(texcoords0.z, texcoords0.w);
                    Vector2 uvZW       = EditorGUILayout.Vector2Field("TexCoord0.zw", texcoordZW);
                    if (texcoordZW.Equals(uvZW) == false)
                    {
                        Record("Change TexCoord0");
                        texcoord = new List <Vector4>();
                        texcoord.Add(new Vector4(0, 0, uvZW.x, uvZW.y));
                        texcoord.Add(new Vector4(0, 1, uvZW.x, uvZW.y));
                        texcoord.Add(new Vector4(1, 0, uvZW.x, uvZW.y));
                        texcoord.Add(new Vector4(1, 1, uvZW.x, uvZW.y));
                        dynamicMesh.SetUVs(0, texcoord);
                        texcoords0 = new Vector4(0, 0, uvZW.x, uvZW.y);
                    }
                    uv = EditorGUILayout.Vector4Field("TexCoord1", texcoords1);
                    if (texcoords1.Equals(uv) == false)
                    {
                        Record("Change TexCoord1");
                        texcoord = new List <Vector4>();
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        dynamicMesh.SetUVs(1, texcoord);
                        texcoords1 = uv;
                    }
                    uv = EditorGUILayout.Vector4Field("TexCoord2", texcoords2);
                    if (texcoords2.Equals(uv) == false)
                    {
                        Record("Change TexCoord2");
                        texcoord = new List <Vector4>();
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        dynamicMesh.SetUVs(2, texcoord);
                        texcoords2 = uv;
                    }
                    uv = EditorGUILayout.Vector4Field("TexCoord3", texcoords3);
                    if (texcoords3.Equals(uv) == false)
                    {
                        Record("Change TexCoord3");
                        texcoord = new List <Vector4>();
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        dynamicMesh.SetUVs(3, texcoord);
                        texcoords3 = uv;
                    }
                    uv = EditorGUILayout.Vector4Field("TexCoord4", texcoords4);
                    if (texcoords4.Equals(uv) == false)
                    {
                        Record("Change TexCoord4");
                        texcoord = new List <Vector4>();
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        dynamicMesh.SetUVs(4, texcoord);
                        texcoords4 = uv;
                    }
                    uv = EditorGUILayout.Vector4Field("TexCoord5", texcoords5);
                    if (texcoords5.Equals(uv) == false)
                    {
                        Record("Change TexCoord5");
                        texcoord = new List <Vector4>();
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        dynamicMesh.SetUVs(5, texcoord);
                        texcoords5 = uv;
                    }
                    uv = EditorGUILayout.Vector4Field("TexCoord6", texcoords6);
                    if (texcoords6.Equals(uv) == false)
                    {
                        Record("Change TexCoord6");
                        texcoord = new List <Vector4>();
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        dynamicMesh.SetUVs(6, texcoord);
                        texcoords6 = uv;
                    }
                    uv = EditorGUILayout.Vector4Field("TexCoord7", texcoords7);
                    if (texcoords7.Equals(uv) == false)
                    {
                        Record("Change TexCoord7");
                        texcoord = new List <Vector4>();
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        texcoord.Add(uv);
                        dynamicMesh.SetUVs(7, texcoord);
                        texcoords7 = uv;
                    }
                }
                else if (meshType == MeshType.kPrefab)
                {
                    var prefabValue = EditorGUILayout.ObjectField("Prefab", prefab, typeof(GameObject), false) as GameObject;
                    if (requestPrefab != null)
                    {
                        prefabValue   = requestPrefab;
                        requestPrefab = null;
                        GUI.changed   = true;
                    }
                    if (prefab != prefabValue)
                    {
                        Record("Change Prefab");

                        if (param[(int)PreParamType.kAnimation] is AnimationParam animationParam)
                        {
                            animationParam.Dispose();
                        }
                        if (gameObject != null)
                        {
                            GameObject.DestroyImmediate(gameObject);
                            gameObject = null;
                        }
                        if (boundsObject != null)
                        {
                            GameObject.DestroyImmediate(boundsObject);
                            boundsObject = null;
                        }
                        prefab = prefabValue;
                    }
                    bool autoViewFitValue = EditorGUILayout.Toggle("Auto view fit", autoViewFit);
                    if (autoViewFit.Equals(autoViewFitValue) == false)
                    {
                        autoViewFit = autoViewFitValue;
                    }
                    bool showBoundsValue = EditorGUILayout.Toggle("Show BoundingBox", showBounds);
                    if (showBounds.Equals(showBoundsValue) == false)
                    {
                        boundsObject.SetActive(showBoundsValue);
                        showBounds = showBoundsValue;
                    }
                }
                if (prefab != null)
                {
                    if (gameObject == null)
                    {
                        gameObject = context.InstantiatePrefabInScene(prefab);

                        if (param[(int)PreParamType.kCamera] is CameraParam cameraParam)
                        {
                            if (param[(int)PreParamType.kTexture] is TextureParam textureParam)
                            {
                                if (param[(int)PreParamType.kTransform] is TransformParam transformParam)
                                {
                                    if (autoViewFit != false)
                                    {
                                        cameraParam.ToPreset(CameraPreset.kFit, textureParam, transformParam, this);
                                    }
                                }
                            }
                        }
                    }
                    if (boundsObject == null)
                    {
                        boundsObject = new GameObject("Bounds", typeof(MeshFilter), typeof(MeshRenderer));
                        context.AddSingleGO(boundsObject);
                        boundsObject.GetComponent <MeshFilter>().sharedMesh       = boundsMesh;
                        boundsObject.GetComponent <MeshRenderer>().sharedMaterial = boundsMaterial;
                        boundsObject.transform.SetParent(gameObject.transform, false);
                        boundsObject.SetActive(showBounds);
                    }
                }
            });
            return(refreshCount);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Callback called on the Implemented IESImporterEditor (currently on HDRP Only)
        /// </summary>
        /// <param name="setupRenderPipelinePreviewCamera">Delegate provided by the Render pipeline to setup the Preview Camera</param>
        /// <param name="setupRenderPipelinePreviewFloorRenderer">Delegate provided by the Render pipeline to setup the Preview Light</param>
        /// <param name="setupRenderPipelinePreviewLight">Delegate provided by the Render pipeline to setup the Preview Wall</param>
        /// <param name="setupRenderPipelinePreviewWallRenderer">Delegate provided by the Render pipeline to setup the Preview Floor</param>
        /// <returns>true to specified IES has a Preview</returns>
        public bool CommonHasPreviewGUI(SetupRenderPipelinePreviewCamera setupRenderPipelinePreviewCamera,
                                        SetupRenderPipelinePreviewLight setupRenderPipelinePreviewLight,
                                        SetupRenderPipelinePreviewWallRenderer setupRenderPipelinePreviewWallRenderer,
                                        SetupRenderPipelinePreviewFloorRenderer setupRenderPipelinePreviewFloorRenderer)
        {
            if (m_PreviewRenderUtility == null)
            {
                m_PreviewRenderUtility = new PreviewRenderUtility();

                m_PreviewRenderUtility.ambientColor = Color.black;

                m_PreviewRenderUtility.camera.fieldOfView                = 60f;
                m_PreviewRenderUtility.camera.nearClipPlane              = 0.1f;
                m_PreviewRenderUtility.camera.farClipPlane               = 10f;
                m_PreviewRenderUtility.camera.transform.localPosition    = new Vector3(1.85f, 0.71f, 0f);
                m_PreviewRenderUtility.camera.transform.localEulerAngles = new Vector3(15f, -90f, 0f);

                setupRenderPipelinePreviewCamera(m_PreviewRenderUtility.camera);

                m_PreviewRenderUtility.lights[0].type      = (m_PrefabLightTypeProp.enumValueIndex == (int)IESLightType.Point) ? LightType.Point : LightType.Spot;
                m_PreviewRenderUtility.lights[0].color     = Color.white;
                m_PreviewRenderUtility.lights[0].intensity = 1f;
                m_PreviewRenderUtility.lights[0].range     = 10f;
                m_PreviewRenderUtility.lights[0].spotAngle = m_SpotAngleProp.floatValue;
                m_PreviewRenderUtility.lights[0].transform.localPosition    = new Vector3(0.14f, 1f, 0f);
                m_PreviewRenderUtility.lights[0].transform.localEulerAngles = new Vector3(90f, 0f, -90f);

                setupRenderPipelinePreviewLight(m_PreviewRenderUtility.lights[0]);

                m_PreviewRenderUtility.lights[1].intensity = 0f;

                GameObject previewWall = GameObject.CreatePrimitive(PrimitiveType.Plane);
                previewWall.name      = "IESPreviewWall";
                previewWall.hideFlags = HideFlags.HideAndDontSave;
                previewWall.transform.localPosition    = new Vector3(0f, 4f, 0f);
                previewWall.transform.localEulerAngles = new Vector3(0f, 0f, -90f);
                previewWall.transform.localScale       = new Vector3(1f, 1f, 10f);
                MeshRenderer previewWallRenderer = previewWall.GetComponent <MeshRenderer>();
                previewWallRenderer.lightProbeUsage      = LightProbeUsage.Off;
                previewWallRenderer.reflectionProbeUsage = ReflectionProbeUsage.Off;
                previewWallRenderer.material             = AssetDatabase.GetBuiltinExtraResource <Material>("Default-Material.mat");

                setupRenderPipelinePreviewWallRenderer(previewWallRenderer);

                m_PreviewRenderUtility.AddSingleGO(previewWall);

                GameObject previewFloor = GameObject.CreatePrimitive(PrimitiveType.Plane);
                previewFloor.name      = "IESPreviewFloor";
                previewFloor.hideFlags = HideFlags.HideAndDontSave;
                previewFloor.transform.localPosition    = new Vector3(4f, 0f, 0f);
                previewFloor.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
                previewFloor.transform.localScale       = new Vector3(1f, 1f, 10f);
                MeshRenderer previewFloorRenderer = previewFloor.GetComponent <MeshRenderer>();
                previewFloorRenderer.lightProbeUsage      = LightProbeUsage.Off;
                previewFloorRenderer.reflectionProbeUsage = ReflectionProbeUsage.Off;
                previewFloorRenderer.material             = AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat");

                setupRenderPipelinePreviewFloorRenderer(previewFloorRenderer);

                m_PreviewRenderUtility.AddSingleGO(previewFloor);
            }

            return(true);
        }