Ejemplo n.º 1
0
 public void SetDetailObjs(GrassPrototype prototype, int x, int z, int amount)
 {
     if (prototype != null && amount > 0)
     {
         List <GameObject> objs = new List <GameObject>();
         GetDetailObjs(prototype, x, z, ref objs);
         if (objs.Count > 0)
         {
             if (amount > objs.Count)
             {
                 //Undo.RecordObject(this, "Set Detail");
                 AddDetailObjs(prototype, x, z, amount - objs.Count);
             }
             else if (amount < objs.Count)
             {
                 //Undo.RecordObject(this, "Set Detail");
                 RemoveObjs(objs.Count - amount, ref objs);
             }
         }
         else
         {
             AddDetailObjs(prototype, x, z, amount);
         }
     }
 }
Ejemplo n.º 2
0
 public void ClearDetail(GrassPrototype prototype, int x, int z)
 {
     GrassObject[] infos = GrassRootGo.GetComponentsInChildren <GrassObject>();
     foreach (GrassObject info in infos)
     {
         if (info._material == prototype._material && info._x == x && info._z == z)
         {
             //DestroyImmediate(info.gameObject);
             DestoryObj(info.gameObject);
         }
     }
 }
Ejemplo n.º 3
0
 public void RemoveDetailObjs(GrassPrototype prototype)
 {
     GrassObject[] infos = GrassRootGo.GetComponentsInChildren <GrassObject>();
     foreach (GrassObject info in infos)
     {
         if (info._material == prototype._material)
         {
             //DestroyImmediate(info.gameObject);
             DestoryObj(info.gameObject);
         }
     }
 }
Ejemplo n.º 4
0
        public void UpdateDetailsSize(GrassPrototype prototype)
        {
            GrassObject[] grassObjs = GrassRootGo.GetComponentsInChildren <GrassObject>();
            foreach (GrassObject grassObj in grassObjs)
            {
                if (grassObj._material == prototype._material)
                {
                    float width  = Random.Range(prototype._minWidth, prototype._maxWidth);
                    float height = Random.Range(prototype._minHeight, prototype._maxHeight);

                    grassObj.transform.localScale = new Vector3(width, height, 1);
                }
            }
        }
Ejemplo n.º 5
0
        private Texture2D GetImagePreView(GrassPrototype prototype)
        {
            Texture2D image = null;

            if (prototype != null)
            {
                Material m = prototype._material;
                if (m != null)
                {
                    image = m.mainTexture as Texture2D;
                }
            }

            return(image);
        }
Ejemplo n.º 6
0
 public void SetPrototypeMaterial(GrassPrototype prototype, Material newMaterial)
 {
     if (prototype._material == null && newMaterial != null)
     {
         if (!newMaterial.shader.name.Contains("Grass"))
         {
             Debug.LogError("Must use the specfied \"Grass\" shader!");
         }
         else
         {
             if (!IsExistMaterail(newMaterial))
             {
                 prototype._material = newMaterial;
             }
         }
     }
 }
Ejemplo n.º 7
0
 public void GetDetailObjs(GrassPrototype prototype, int x, int z, ref List <GameObject> objs)
 {
     //GrassEditor.Detail detail = null;
     GrassObject[] infos = GrassRootGo.GetComponentsInChildren <GrassObject>();
     foreach (GrassObject info in infos)
     {
         if (info._material == prototype._material && info._x == x && info._z == z)
         {
             /*
              * if (detail == null) {
              *  detail = new GrassEditor.Detail();
              *  detail.objs = new List<GameObject>();
              * }
              * detail.objs.Add(info.gameObject);
              */
             objs.Add(info.gameObject);
         }
     }
     // return detail;
 }
Ejemplo n.º 8
0
        private bool AddDetailObjs(GrassPrototype prototype, int x, int z, int amount)
        {
            for (int i = 0; i < amount; i++)
            {
                Vector3    pos = new Vector3(x + Random.Range(0.0f, 1.0f), 0, z + Random.Range(0.0f, 1.0f));
                Ray        ray = new Ray(new Vector3(pos.x, 100000, pos.z), Vector3.down);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, _editor._layerMask))
                {
                    pos.y = hit.point.y;


                    GameObject go = new GameObject(prototype._material.name);
                    //Undo.RegisterCreatedObjectUndo(go, go.name);
                    //go.layer = LayerMask.NameToLayer("Vegetation");
                    //go.hideFlags = HideFlags.HideInHierarchy;
                    go.tag = "EditorOnly";
                    GameObjectUtility.SetStaticEditorFlags(go, StaticEditorFlags.LightmapStatic | StaticEditorFlags.BatchingStatic);
                    go.hideFlags = HideFlags.NotEditable;

                    go.transform.position         = pos;
                    go.transform.localEulerAngles = new Vector3(0, Random.Range(0, 360), 0);
                    float width  = Random.Range(prototype._minWidth, prototype._maxWidth);
                    float height = Random.Range(prototype._minHeight, prototype._maxHeight);
                    go.transform.localScale = new Vector3(width, height, 1);
                    go.transform.SetParent(GrassRootGo.transform);

                    MeshFilter meshFilter = go.AddComponent <MeshFilter>();
                    Mesh       mesh       = _editor._grassMesh;
                    meshFilter.mesh = mesh;

                    MeshRenderer meshRenderer = go.AddComponent <MeshRenderer>();
                    meshRenderer.sharedMaterial = prototype._material;
                    SerializedObject   so = new SerializedObject(meshRenderer);
                    SerializedProperty goScaleProperty = so.FindProperty("m_ScaleInLightmap");
                    goScaleProperty.floatValue = _editor._scaleInLightmap;
                    so.ApplyModifiedProperties();

                    GrassObject info = go.AddComponent <GrassObject>();
                    info._material = prototype._material;
                    //info._x = x;
                    //info._z = z;


                    //fix y
                    if (_editor._isKeepInDeep)
                    {
                        float minY = pos.y;
                        for (int v = 0; v < mesh.vertexCount; v++)
                        {
                            if (mesh.vertices[v].y == 0)
                            {
                                Vector3 posWorld = go.transform.TransformPoint(mesh.vertices[v]);
                                if (Physics.Raycast(posWorld, Vector3.down, out hit, Mathf.Infinity, _editor._layerMask))
                                {
                                    if (hit.point.y < minY)
                                    {
                                        minY = hit.point.y;
                                    }
                                }
                            }
                        }
                        if (minY < pos.y)
                        {
                            pos.y = minY;
                            go.transform.position = pos;
                        }
                    }

                    UtilityFuncs.MarkCurrentSceneIsDirty();
                }
            }

            return(true);
        }