Beispiel #1
0
        public static void CreateOctMeshTree()
        {
            OctMeshTree meshTree = CreateMeshTree <OctMeshTree>("New Oct Mesh Tree.asset");

            meshTree.scaledOffset = 1;             // set default value.
            EditorUtility.SetDirty(meshTree);
        }
Beispiel #2
0
        void OnGUISelectMeshTreeTypeAndCreate()
        {
            EditorGUILayout.LabelField("Type of Mesh Tree");
            if (m_srcMesh is TerrainData)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(30);
                GUILayout.Label("Terrain Mesh Tree");
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(30);
                bool bBinaryTree = GUILayout.Toggle(m_bBinaryTree, "Binary Mesh Tree");
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(30);
                bool bOctree = GUILayout.Toggle(!m_bBinaryTree, "Oct Mesh Tree");
                EditorGUILayout.EndHorizontal();
                if (bOctree && m_bBinaryTree)
                {
                    m_bBinaryTree = !bOctree;
                }
                else if (bBinaryTree && !m_bBinaryTree)
                {
                    m_bBinaryTree = bBinaryTree;
                }
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(30);
                if (GUILayout.Button("<color=blue>What's the difference?</color>", m_errorStyle))
                {
                    Application.OpenURL("http://nyahoon.com/products/fast-shadow-receiver/create-a-mesh-tree");
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Separator();

                EditorGUILayout.LabelField("Select Source Object");

                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(30);
                bool bSceneObject = GUILayout.Toggle(m_srcMesh == m_rootObject, "Scene Object");
                EditorGUILayout.ObjectField(m_rootObject, typeof(GameObject), true);
                EditorGUILayout.EndHorizontal();
                if (bSceneObject && m_srcMesh != m_rootObject)
                {
                    m_srcMesh = m_rootObject;
                }

                EditorGUILayout.BeginHorizontal();
                GameObject prefabObject = PrefabUtility.GetPrefabParent(m_rootObject) as GameObject;
                GUILayout.Space(30);
                if (prefabObject == null)
                {
                    GUI.enabled = false;
                }
                bool bPrefabObject = GUILayout.Toggle(m_srcMesh == prefabObject, "Prefab Object");
                if (prefabObject != null)
                {
                    EditorGUILayout.ObjectField(prefabObject, typeof(GameObject), true);
                }
                else
                {
                    GUI.enabled = true;
                    if (GUILayout.Button("Create Prefab"))
                    {
                        string path = EditorUtility.SaveFilePanelInProject("Create Prefab", m_rootObject.name, "prefab", "Select a path for the prefab of " + m_rootObject.name);
                        if (!string.IsNullOrEmpty(path))
                        {
                            prefabObject = PrefabUtility.CreatePrefab(path, m_rootObject, ReplacePrefabOptions.ConnectToPrefab);
                            m_srcMesh    = prefabObject;
                            bSceneObject = false;
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
                if (bPrefabObject && m_srcMesh != prefabObject)
                {
                    m_srcMesh = prefabObject;
                }
                if (m_srcMesh == m_rootObject)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(30);
                    GUILayout.TextArea("<color=red>If you choose Scene Object, the reference to the object cannot be stored in Mesh Tree settings. So, you will need to set the reference again when you rebuild the mesh tree.</color>", m_errorStyle);
                    EditorGUILayout.EndHorizontal();
                }
                else if (m_srcMesh == prefabObject)
                {
                    // check if m_rootObject is modified from prefabObject.
                    for (int i = 0; i < srcMeshes.Length; ++i)
                    {
                        GameObject go     = srcMeshes[i].gameObject;
                        GameObject prefab = PrefabUtility.GetPrefabParent(go) as GameObject;
                        if (go.layer != prefab.layer)
                        {
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Space(30);
                            GUILayout.TextArea("<color=red>The layer of the scene object was modified from the prefab.</color>", m_errorStyle);
                            EditorGUILayout.ObjectField(go, typeof(GameObject), true);
                            EditorGUILayout.EndHorizontal();
                            break;
                        }
                        if (go.transform.localPosition != prefab.transform.localPosition || go.transform.localRotation != prefab.transform.localRotation || go.transform.localScale != prefab.transform.localScale)
                        {
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Space(30);
                            GUILayout.TextArea("<color=red>The transform of the scene object was modified from the prefab.</color>", m_errorStyle);
                            EditorGUILayout.ObjectField(go, typeof(GameObject), true);
                            EditorGUILayout.EndHorizontal();
                            break;
                        }
                    }
                }
            }

            EditorGUILayout.Separator();

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Create Mesh Tree"))
            {
                string path = GetDefaultPathFromSourceMesh(m_srcMesh, m_bBinaryTree);
                path = EditorUtility.SaveFilePanelInProject("Create New Mesh Tree", System.IO.Path.GetFileName(path), "asset", "Select a path for the new Mesh Tree", System.IO.Path.GetDirectoryName(path));
                if (!string.IsNullOrEmpty(path))
                {
                    MeshTreeBase meshTreeBase;
                    if (m_srcMesh is TerrainData)
                    {
                        TerrainMeshTree meshTree = ScriptableObject.CreateInstance <TerrainMeshTree>();
                        meshTree.terrainData = m_srcMesh as TerrainData;
                        meshTreeBase         = meshTree;
                    }
                    else if (m_bBinaryTree)
                    {
                        BinaryMeshTree meshTree = ScriptableObject.CreateInstance <BinaryMeshTree>();
                        meshTree.srcMesh      = m_srcMesh;
                        meshTree.layerMask    = m_layers;
                        meshTree.scaledOffset = 1.0f;
                        meshTreeBase          = meshTree;
                    }
                    else
                    {
                        OctMeshTree meshTree = ScriptableObject.CreateInstance <OctMeshTree>();
                        meshTree.srcMesh      = m_srcMesh;
                        meshTree.layerMask    = m_layers;
                        meshTree.scaledOffset = 1.0f;
                        meshTreeBase          = meshTree;
                    }
                    AssetDatabase.CreateAsset(meshTreeBase, path);
                    AssetDatabase.Refresh();
                    m_meshTree = AssetDatabase.LoadAssetAtPath(path, typeof(MeshTreeBase)) as MeshTreeBase;
                    if (m_receiver != null)
                    {
                        m_receiver.meshTree = m_meshTree;
                    }
                    if (m_srcMesh is TerrainData)
                    {
                        // just build and close. because TerrainMeshTree doesn't have build options.
                        MeshTreeEditor.BuildMeshTree(m_meshTree);
                        Close();
                    }
                    else
                    {
                        m_serializedObject = new SerializedObject(m_meshTree);
                        ++m_currentPage;
                    }
                }
            }
        }