Exemple #1
0
        private static GameObject Create(PaintTools what, Color color)
        {
            if (what == PaintTools.Grass)
            {
                return(null);
            }

            GameObject rootObject = new GameObject();

            rootObject.transform.parent        = SceneManager.RightHanded;
            rootObject.transform.localPosition = Vector3.zero;
            rootObject.transform.localRotation = Quaternion.identity;
            rootObject.transform.localScale    = Vector3.one;

            GameObject gobject = new GameObject();

            gobject.transform.parent = rootObject.transform;
            gobject.name             = Utils.CreateUniqueName(
                what == PaintTools.Volume ? "Volume"
                : what == PaintTools.Grass ? "Grass"
                : "Paint");

            gobject.transform.localPosition = Vector3.zero;
            gobject.transform.localRotation = Quaternion.identity;
            gobject.transform.localScale    = Vector3.one;
            gobject.tag = "PhysicObject";

            Mesh mesh = new Mesh
            {
                indexFormat = UnityEngine.Rendering.IndexFormat.UInt32
            };
            MeshFilter meshFilter = gobject.AddComponent <MeshFilter>();

            meshFilter.mesh = mesh;
            MeshRenderer renderer      = gobject.AddComponent <MeshRenderer>();
            MaterialID   materialId    = color.a == 1f ? MaterialID.ObjectOpaque : MaterialID.ObjectTransparent;
            Material     paintMaterial = ResourceManager.GetMaterial(materialId);

            renderer.sharedMaterial = paintMaterial;
            renderer.material.SetColor("_BaseColor", color);
            renderer.material.SetFloat("_Opacity", color.a);

            // Update scene data for live sync
            SceneManager.AddMaterialParameters(Utils.GetMaterialName(gobject), materialId, color);

            gobject.AddComponent <MeshCollider>();

            if (what == PaintTools.Volume)
            {
                gobject.AddComponent <VolumeController>();
            }
            else if (what == PaintTools.Grass)
            {
                //gobject.AddComponent<GrassController>();
            }
            else
            {
                gobject.AddComponent <PaintController>();
            }

            return(gobject);
        }