private RenderTexture GetPreviewTexture(GStylizedTerrain t, string mapName, int resolution, FilterMode filter)
        {
            if (previewTextures == null)
            {
                previewTextures = new Dictionary <string, RenderTexture>();
            }

            string key = string.Format("{0}_{1}", t.GetInstanceID(), mapName);

            if (!previewTextures.ContainsKey(key) ||
                previewTextures[key] == null)
            {
                RenderTexture rt = new RenderTexture(resolution, resolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
                rt.wrapMode          = TextureWrapMode.Clamp;
                previewTextures[key] = rt;
            }
            else if (previewTextures[key].width != resolution || previewTextures[key].height != resolution)
            {
                previewTextures[key].Release();
                Object.DestroyImmediate(previewTextures[key]);
                RenderTexture rt = new RenderTexture(resolution, resolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
                rt.wrapMode          = TextureWrapMode.Clamp;
                previewTextures[key] = rt;
            }

            previewTextures[key].filterMode = filter;
            return(previewTextures[key]);
        }
        internal static RenderTexture Internal_GetRenderTexture(GStylizedTerrain t, int resolution, int id = 0)
        {
            if (internal_RenderTextures == null)
            {
                internal_RenderTextures = new Dictionary <string, RenderTexture>();
            }

            string key = string.Format("{0}_{1}", t != null ? t.GetInstanceID() : 0, id);

            if (!internal_RenderTextures.ContainsKey(key) ||
                internal_RenderTextures[key] == null)
            {
                RenderTexture rt = new RenderTexture(resolution, resolution, 0, GGeometry.HeightMapRTFormat, RenderTextureReadWrite.Linear);
                internal_RenderTextures[key] = rt;
            }
            else if (internal_RenderTextures[key].width != resolution ||
                     internal_RenderTextures[key].height != resolution ||
                     internal_RenderTextures[key].format != GGeometry.HeightMapRTFormat)
            {
                internal_RenderTextures[key].Release();
                Object.DestroyImmediate(internal_RenderTextures[key]);
                RenderTexture rt = new RenderTexture(resolution, resolution, 0, GGeometry.HeightMapRTFormat, RenderTextureReadWrite.Linear);
                internal_RenderTextures[key] = rt;
            }

            internal_RenderTextures[key].wrapMode = TextureWrapMode.Clamp;

            return(internal_RenderTextures[key]);
        }
Example #3
0
        private void DrawNeighboringGUI()
        {
            string label = "Neighboring";
            string id    = "neighboring" + instance.GetInstanceID().ToString();

            GenericMenu menu = new GenericMenu();

            menu.AddItem(
                new GUIContent("Reset"),
                false,
                () => { ResetNeighboring(); });
            menu.AddItem(
                new GUIContent("Connect"),
                false,
                () => { GStylizedTerrain.ConnectAdjacentTiles(); });

            isNeighboringFoldoutExpanded = GEditorCommon.Foldout(label, false, id, () =>
            {
                EditorGUI.BeginChangeCheck();
                instance.AutoConnect    = EditorGUILayout.Toggle("Auto Connect", instance.AutoConnect);
                instance.GroupId        = EditorGUILayout.DelayedIntField("Group Id", instance.GroupId);
                instance.TopNeighbor    = EditorGUILayout.ObjectField("Top Neighbor", instance.TopNeighbor, typeof(GStylizedTerrain), true) as GStylizedTerrain;
                instance.BottomNeighbor = EditorGUILayout.ObjectField("Bottom Neighbor", instance.BottomNeighbor, typeof(GStylizedTerrain), true) as GStylizedTerrain;
                instance.LeftNeighbor   = EditorGUILayout.ObjectField("Left Neighbor", instance.LeftNeighbor, typeof(GStylizedTerrain), true) as GStylizedTerrain;
                instance.RightNeighbor  = EditorGUILayout.ObjectField("Right Neighbor", instance.RightNeighbor, typeof(GStylizedTerrain), true) as GStylizedTerrain;

                if (EditorGUI.EndChangeCheck())
                {
                    if (instance.TopNeighbor != null || instance.BottomNeighbor != null || instance.LeftNeighbor != null || instance.RightNeighbor != null)
                    {
                        GAnalytics.Record(GAnalytics.MULTI_TERRAIN, true);
                    }
                }
            }, menu);
        }
Example #4
0
        public static string GetNeighboringFoldoutID(GStylizedTerrain t)
        {
            string id = "neighboring" + t.GetInstanceID().ToString();

            return(id);
        }
Example #5
0
        private void CreateStaticObstacles(GStylizedTerrain t)
        {
            if (t.TerrainData == null)
            {
                return;
            }
            if (t.TerrainData.Foliage.Trees == null)
            {
                return;
            }
            if (t.TerrainData.Foliage.Trees.Prototypes.Count == 0)
            {
                return;
            }

#if UNITY_EDITOR
            string title = "Creating static obstacles";
            string info  = t.name;
            GCommonGUI.CancelableProgressBar(title, info, 0);
#endif

            Vector3 terrainSize = new Vector3(
                t.TerrainData.Geometry.Width,
                t.TerrainData.Geometry.Height,
                t.TerrainData.Geometry.Length);

            Transform             root       = GUtilities.GetChildrenWithName(transform, string.Format("{0}_{1}", t.name, t.GetInstanceID()));
            List <GTreePrototype> prototypes = t.TerrainData.Foliage.Trees.Prototypes;

            GameObject[] templates = new GameObject[prototypes.Count];
            for (int i = 0; i < prototypes.Count; ++i)
            {
                if (!prototypes[i].IsValid)
                {
                    continue;
                }
                GameObject  template   = Instantiate(prototypes[i].Prefab) as GameObject;
                Component[] components = template.GetComponentsInChildren <Component>();
                for (int j = 0; j < components.Length; ++j)
                {
                    if (components[j] is Collider)
                    {
                        GUtilities.DestroyObject(components[j]);
                    }
                    if (components[j] is MeshRenderer)
                    {
                        MeshRenderer mr = components[j] as MeshRenderer;
                        mr.sharedMaterials   = new Material[] { GInternalMaterials.NavHelperDummyGameObjectMaterial };
                        mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                        mr.receiveShadows    = false;
                    }
                }
#if UNITY_EDITOR
                GameObjectUtility.SetStaticEditorFlags(template, StaticEditorFlags.NavigationStatic);
#endif
                template.name = prototypes[i].Prefab.name;
                templates[i]  = template;
            }

            List <GTreeInstance> instances = t.TerrainData.Foliage.TreeInstances;
            for (int i = 0; i < instances.Count; ++i)
            {
#if UNITY_EDITOR
                GCommonGUI.CancelableProgressBar(title, info, i * 1.0f / instances.Count);
#endif
                GTreeInstance tree = instances[i];
                if (templates[tree.PrototypeIndex] == null)
                {
                    continue;
                }

                GameObject g = Instantiate(templates[tree.PrototypeIndex]) as GameObject;
                g.transform.parent = root;

                Vector3 localPos = new Vector3(
                    tree.Position.x * terrainSize.x,
                    tree.Position.y * terrainSize.y,
                    tree.Position.z * terrainSize.z);
                Vector3 worldPos = t.transform.TransformPoint(localPos);
                g.transform.position   = worldPos;
                g.transform.rotation   = tree.Rotation;
                g.transform.localScale = tree.Scale;
                g.name = templates[tree.PrototypeIndex].name;
            }

            for (int i = 0; i < templates.Length; ++i)
            {
                GUtilities.DestroyGameobject(templates[i]);
            }
#if UNITY_EDITOR
            GCommonGUI.ClearProgressBar();
#endif
        }
Example #6
0
        private void DeleteStaticObstacles(GStylizedTerrain t)
        {
            Transform root = GUtilities.GetChildrenWithName(transform, string.Format("{0}_{1}", t.name, t.GetInstanceID()));

            GUtilities.DestroyGameobject(root.gameObject);
        }