Example #1
0
 private void Awake()
 {
     m_gridMaterial        = MaterialUtility.GetGridViewMaterial(defultTexture, lineWidth);
     m_meshRender          = GetComponent <MeshRenderer>();
     m_meshFilter          = GetComponent <MeshFilter>();
     m_meshRender.material = m_gridMaterial;
 }
        /// <summary>
        /// Implement this function to make a custom inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            bool isNeedBuildMat = false;

            serializedObject.Update();

            //================
            // Effect material.
            //================
            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.PropertyField(_spMaterial);
            EditorGUI.EndDisabledGroup();

            //================
            // Effect setting.
            //================
            EditorGUILayout.PropertyField(_spEffectFactor);
            EditorGUILayout.PropertyField(_spWidth);
            EditorGUILayout.PropertyField(_spSoftness);
            EditorGUILayout.PropertyField(_spColor);
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(_spColorMode);
            EditorGUILayout.PropertyField(_spNoiseTexture);
            isNeedBuildMat = EditorGUI.EndChangeCheck();

            //================
            // Advanced option.
            //================
            EditorGUILayout.PropertyField(_spEffectArea);
            EditorGUILayout.PropertyField(_spKeepAspectRatio);

            //================
            // Set Mat.
            //================
            var obj = target as LUIDissolve;

            if ((isNeedBuildMat || _spMaterial.objectReferenceValue == null || _lastGraphic != obj.targetGraphic) && _spNoiseTexture.objectReferenceValue != null)
            {
                if (obj.targetGraphic is LImageForTP)
                {
                    Shader shader = Shader.Find("UI/Hidden/UI-Effect-Dissolve(RGB+A)");
                    _spMaterial.objectReferenceValue = MaterialUtility.GetOrGenerateMaterialVariant(shader, (ColorMode)(_spColorMode.intValue));
                }
                else
                {
                    Shader shader = Shader.Find("UI/Hidden/UI-Effect-Dissolve");
                    _spMaterial.objectReferenceValue = MaterialUtility.GetOrGenerateMaterialVariant(shader, (ColorMode)(_spColorMode.intValue));
                }
                _lastGraphic = obj.targetGraphic;
            }

            serializedObject.ApplyModifiedProperties();
        }
Example #3
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            //================
            // Effect material.
            //================
            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.PropertyField(_spMaterial);
            EditorGUI.EndDisabledGroup();

            //================
            // Effect setting.
            //================
            EditorGUILayout.PropertyField(_spEffectFactor);
            EditorGUILayout.PropertyField(_spWidth);
            EditorGUILayout.PropertyField(_spRotation);
            EditorGUILayout.PropertyField(_spSoftness);
            EditorGUILayout.PropertyField(_spBrightness);
            EditorGUILayout.PropertyField(_spGloss);

            //================
            // Advanced option.
            //================
            EditorGUILayout.PropertyField(_spEffectArea);

            //================
            // Set Mat.
            //================
            var obj = target as LUIShiny;

            if (_spMaterial.objectReferenceValue == null || _lastGraphic != obj.targetGraphic)
            {
                if (obj.targetGraphic is LImageForTP)
                {
                    Shader shader = Shader.Find("UI/Hidden/UI-Effect-Shiny(RGB+A)");
                    _spMaterial.objectReferenceValue = MaterialUtility.GetOrGenerateMaterialVariant(shader);
                }
                else
                {
                    Shader shader = Shader.Find("UI/Hidden/UI-Effect-Shiny");
                    _spMaterial.objectReferenceValue = MaterialUtility.GetOrGenerateMaterialVariant(shader);
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
Example #4
0
        /// <summary>
        /// Create a pb_Model from a pb_Object, optionally converting to quad topology.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="mesh"></param>
        /// <param name="quads"></param>
        public Model(string name, ProBuilderMesh mesh, bool quads = true)
        {
            mesh.ToMesh(quads ? MeshTopology.Quads : MeshTopology.Triangles);
            mesh.Refresh(RefreshMask.UV | RefreshMask.Colors | RefreshMask.Normals | RefreshMask.Tangents);
            this.name = name;
            vertices  = mesh.GetVertices();
            submeshes = Submesh.GetSubmeshes(mesh.facesInternal, MaterialUtility.GetMaterialCount(mesh.renderer), quads ? MeshTopology.Quads : MeshTopology.Triangles);
            materials = new Material[submeshCount];

            for (int i = 0; i < submeshCount; ++i)
            {
                materials[i] = mesh.renderer.sharedMaterials[Math.Clamp(i, 0, materials.Length - 1)];
            }

            matrix = mesh.transform.localToWorldMatrix;
            mesh.ToMesh(MeshTopology.Triangles);
            mesh.Refresh();
            mesh.Optimize();
        }
Example #5
0
        private static Material GetMaterial(int colourId)
        {
            var materialExistence = MaterialUtility.CheckIfMaterialExists(colourId);

            if (materialExistence == MaterialUtility.MaterialExistence.Legacy)
            {
                Debug.LogWarning("Legacy material " + colourId);
            }
            else if (materialExistence == MaterialUtility.MaterialExistence.None)
            {
                Debug.LogError("Missing material " + colourId);
            }

            if (materialExistence != MaterialUtility.MaterialExistence.None)
            {
                return(MaterialUtility.LoadMaterial(colourId, materialExistence == MaterialUtility.MaterialExistence.Legacy));
            }

            return(null);
        }
Example #6
0
 protected override string GetTextureChannelAsString()
 {
     return(MaterialUtility.GetAsShaderString(Channel));
 }
        public override ShaderSource GenerateShaderSource(ShaderGeneratorContext context, MaterialComputeColorKeys baseKeys)
        {
            if (!Enabled || Texture == null) // generate shader from default value when the texture is null or disabled
            {
                var fallbackValue = GenerateShaderFromFallbackValue(context, baseKeys);
                if (fallbackValue != null)
                {
                    return(fallbackValue);
                }
            }

            // generate shader from the texture
            // TODO: Use a generated UsedTexcoordIndex when backing textures
            var usedTexcoord = "TEXCOORD" + MaterialUtility.GetTextureIndex(TexcoordIndex);

            var textureKey = context.GetTextureKey(this, baseKeys);
            var samplerKey = context.GetSamplerKey(Sampler);

            UsedKey = textureKey;

            var scale       = Scale;
            var scaleFactor = context.CurrentOverrides.UVScale;

            if (scaleFactor != Vector2.One)
            {
                scale *= scaleFactor;
            }

            var channelStr = GetTextureChannelAsString();

            // "TTEXTURE", "TStream"
            ShaderClassSource shaderSource;

            // TODO: Workaround bad to have to copy all the new ShaderClassSource(). Check how to improve this
            if (context.OptimizeMaterials)
            {
                var scaleStr  = MaterialUtility.GetAsShaderString(scale);
                var offsetStr = MaterialUtility.GetAsShaderString(Offset);

                // If materials are optimized, we precompute best shader combination (note: will generate shader permutations!)
                if (context.IsNotPixelStage)
                {
                    if (Offset != Vector2.Zero)
                    {
                        shaderSource = new ShaderClassSource("ComputeColorTextureLodScaledOffsetSampler", textureKey, usedTexcoord, samplerKey, channelStr, scaleStr, offsetStr, 0.0f);
                    }
                    else if (scale != Vector2.One)
                    {
                        shaderSource = new ShaderClassSource("ComputeColorTextureLodScaledSampler", textureKey, usedTexcoord, samplerKey, channelStr, scaleStr, 0.0f);
                    }
                    else
                    {
                        shaderSource = new ShaderClassSource("ComputeColorTextureLodSampler", textureKey, usedTexcoord, samplerKey, channelStr, 0.0f);
                    }
                }
                else
                {
                    if (Offset != Vector2.Zero)
                    {
                        shaderSource = new ShaderClassSource("ComputeColorTextureScaledOffsetSampler", textureKey, usedTexcoord, samplerKey, channelStr, scaleStr, offsetStr);
                    }
                    else if (scale != Vector2.One)
                    {
                        shaderSource = new ShaderClassSource("ComputeColorTextureScaledSampler", textureKey, usedTexcoord, samplerKey, channelStr, scaleStr);
                    }
                    else
                    {
                        shaderSource = new ShaderClassSource("ComputeColorTextureSampler", textureKey, usedTexcoord, samplerKey, channelStr);
                    }
                }
            }
            else
            {
                // Try to avoid shader permutations, by putting UV scaling/offset in shader parameters
                var textureScale  = (ValueParameterKey <Vector2>)context.GetParameterKey(MaterialKeys.TextureScale);
                var textureOffset = (ValueParameterKey <Vector2>)context.GetParameterKey(MaterialKeys.TextureOffset);

                context.Parameters.Set(textureScale, scale);
                context.Parameters.Set(textureOffset, Offset);

                if (context.IsNotPixelStage)
                {
                    shaderSource = new ShaderClassSource("ComputeColorTextureLodScaledOffsetDynamicSampler", textureKey, usedTexcoord, samplerKey, channelStr, textureScale, textureOffset, 0.0f);
                }
                else
                {
                    shaderSource = new ShaderClassSource("ComputeColorTextureScaledOffsetDynamicSampler", textureKey, usedTexcoord, samplerKey, channelStr, textureScale, textureOffset);
                }
            }

            return(shaderSource);
        }
Example #8
0
        public override ShaderSource GenerateShaderSource(ShaderGeneratorContext context, MaterialComputeColorKeys baseKeys)
        {
            if (string.IsNullOrEmpty(MixinReference))
            {
                return(new ShaderClassSource("ComputeColor"));
            }
            var mixinName = MixinReference;

            object[] generics = null;
            if (Generics.Count > 0)
            {
                // TODO: correct generic order
                var mixinGenerics = new List <object>();
                foreach (var genericKey in Generics.Keys)
                {
                    var generic = Generics[genericKey];
                    if (generic is ComputeColorParameterTexture)
                    {
                        var textureParameter = ((ComputeColorParameterTexture)generic);
                        var textureKey       = context.GetTextureKey(textureParameter.Texture, baseKeys);
                        mixinGenerics.Add(textureKey.ToString());
                    }
                    else if (generic is ComputeColorParameterSampler)
                    {
                        var pk = context.GetSamplerKey((ComputeColorParameterSampler)generic);
                        mixinGenerics.Add(pk.ToString());
                    }
                    else if (generic is ComputeColorParameterFloat)
                    {
                        mixinGenerics.Add(((ComputeColorParameterFloat)generic).Value.ToString(CultureInfo.InvariantCulture));
                    }
                    else if (generic is ComputeColorParameterInt)
                    {
                        mixinGenerics.Add(((ComputeColorParameterInt)generic).Value.ToString(CultureInfo.InvariantCulture));
                    }
                    else if (generic is ComputeColorParameterFloat2)
                    {
                        mixinGenerics.Add(MaterialUtility.GetAsShaderString(((ComputeColorParameterFloat2)generic).Value));
                    }
                    else if (generic is ComputeColorParameterFloat3)
                    {
                        mixinGenerics.Add(MaterialUtility.GetAsShaderString(((ComputeColorParameterFloat3)generic).Value));
                    }
                    else if (generic is ComputeColorParameterFloat4)
                    {
                        mixinGenerics.Add(MaterialUtility.GetAsShaderString(((ComputeColorParameterFloat4)generic).Value));
                    }
                    else if (generic is ComputeColorStringParameter)
                    {
                        mixinGenerics.Add(((ComputeColorStringParameter)generic).Value);
                    }
                    else
                    {
                        throw new Exception("[Material] Unknown node type: " + generic.GetType());
                    }
                }
                generics = mixinGenerics.ToArray();
            }

            var shaderClassSource = new ShaderClassSource(mixinName, generics);

            if (CompositionNodes.Count == 0)
            {
                return(shaderClassSource);
            }

            var mixin = new ShaderMixinSource();

            mixin.Mixins.Add(shaderClassSource);

            foreach (var comp in CompositionNodes)
            {
                if (comp.Value != null)
                {
                    var compShader = comp.Value.GenerateShaderSource(context, baseKeys);
                    if (compShader != null)
                    {
                        mixin.Compositions.Add(comp.Key, compShader);
                    }
                }
            }

            return(mixin);
        }
Example #9
0
        private static void AddPartToBrick(Brick brick, string ldrawID, Matrix4x4 transformation, string materialID, string fullName)
        {
            // Report if material is missing.
            var materialExistence = MaterialUtility.CheckIfMaterialExists(materialID);

            if (materialExistence == MaterialUtility.MaterialExistence.None)
            {
                missingMaterials.Add($"Brick ID {ldrawID}\tMaterial ID {materialID}");
            }
            else if (materialExistence == MaterialUtility.MaterialExistence.Legacy)
            {
                legacyMaterials.Add($"Brick ID {ldrawID}\tMaterial ID {materialID}");
            }

            // 1. Peel off anything from 'p' onwards and check if it includes a number. (Pattern constant + pattern sequential #)
            var patternSplit = Regex.Split(ldrawID, "(p[a-z]*[0-9]*)");

            // 2. If something was peeled off, make a note of it. We cannot map the pattern sequential id to a decoration imageId and we also don't know the surfaceName.
            if (patternSplit.Length > 1)
            {
                //Debug.Log("PATTERN: " + patternSplit[0] + patternSplit[1]);
                missingDecorations.Add($"Brick ID {fullName}");
            }

            // 3. Peel off anything from 'd' onwards and check if it includes a number. (Sticker + sticker number)
            var stickerSplit = Regex.Split(patternSplit[0], "(d[0-9]+)");

            // 4. If something was peeled off, make a note of it.
            if (stickerSplit.Length > 1)
            {
                //Debug.Log("STICKER: " + stickerSplit[0] + stickerSplit[1]);
                missingStickers.Add($"Brick ID {fullName}");
            }

            // 5. Reassemble remaining id + ".dat" and use as ldrawID.
            var designID = stickerSplit[0];

            ldrawID = designID + ".dat";

            // Apply mapping to another designID.
            if (LDrawBrickToLEGOBrick.ContainsKey(ldrawID))
            {
                designID = LDrawBrickToLEGOBrick[ldrawID];
            }

            // 6. If a mesh does not exist with exact designID, make a note of it and try to peel off any trailing letters.
            var partExistenceResult = PartUtility.CheckIfPartExists(designID);

            if (partExistenceResult.existence == PartUtility.PartExistence.None)
            {
                var versionSplit = Regex.Split(designID, "([a-z]+)");
                designID = versionSplit[0];

                // 6b. If there was something to peel off, look again with new designID.
                if (versionSplit.Length > 1)
                {
                    partExistenceResult = PartUtility.CheckIfPartExists(designID);
                    if (partExistenceResult.existence == PartUtility.PartExistence.None)
                    {
                        // Missing part.
                        missingParts.Add($"Brick ID {fullName}");
                    }
                    else
                    {
                        // Changed part.
                        changedParts.Add($"Brick ID {fullName}\tChanges to {designID}");

                        // Legacy part.
                        if (partExistenceResult.existence == PartUtility.PartExistence.Legacy)
                        {
                            // FIXME Check if colliders and connectivity info are available.
                            legacyParts.Add($"Brick ID {fullName}");
                        }
                    }
                }
                else
                {
                    // Missing part.
                    missingParts.Add($"Brick ID {fullName}");
                }
            }
            else if (partExistenceResult.existence == PartUtility.PartExistence.Legacy)
            {
                // Legacy part.
                // FIXME Check if colliders and connectivity info are available.
                legacyParts.Add($"Brick ID {fullName}");
            }

            // Reconstruct potentially changed ldrawID.
            ldrawID = designID + ".dat";

            // Apply transformation for ldrawID.
            if (LDrawBrickToTransformation.ContainsKey(ldrawID))
            {
                transformation *= LDrawBrickToTransformation[ldrawID];
            }
            else if (partExistenceResult.existence != PartUtility.PartExistence.None)
            {
                missingTransformations.Add($"Brick ID {fullName}");
            }

            var part = new Part()
            {
                transformation = transformation,
                designID       = designID,
                materialID     = materialID
            };

            brick.parts.Add(part);

            // Assign design ID of part to brick. This is incorrect for multi-part bricks but we do not know the correct design ID.
            brick.designID = designID;
        }
 public void InitMaterial(Texture weiyitexture, Texture yinbiantexture)
 {
     lineMaterial        = MaterialUtility.GetLineMaterial(Color.white);
     weiyiMaterial       = MaterialUtility.GetStandedMaterial(weiyitexture);
     meshRender.material = yinbianMaterial = MaterialUtility.GetStandedMaterial(yinbiantexture);
 }
        public VegetationItemModelInfo(VegetationItemInfoPro vegetationItemInfo, EnvironmentSettings environmentSettings, List <GameObject> windSamplerList, int cameraCount)
        {
            EnvironmentSettings = environmentSettings;
            VegetationItemInfo  = vegetationItemInfo;
            VegetationModel     = vegetationItemInfo.VegetationPrefab;

            if (vegetationItemInfo.PrefabType == VegetationPrefabType.Texture)
            {
                VegetationModel = Resources.Load("DefaultGrassPatch") as GameObject;
            }

            if (VegetationModel == null)
            {
                VegetationModel = Resources.Load("MissingVegetationItemCube") as GameObject;
                Debug.LogError("The vegetation prefab of item: " + vegetationItemInfo.Name + " is missing. Please replace or delete VegetationItem.");
            }

            DistanceBand = vegetationItemInfo.GetDistanceBand();

#if UNITY_EDITOR
            MaterialUtility.EnableMaterialInstancing(VegetationModel);
#endif
            SelectedVegetationModelLOD0 = MeshUtils.SelectMeshObject(VegetationModel, LODLevel.LOD0);
            SelectedVegetationModelLOD1 = MeshUtils.SelectMeshObject(VegetationModel, LODLevel.LOD1);
            SelectedVegetationModelLOD2 = MeshUtils.SelectMeshObject(VegetationModel, LODLevel.LOD2);
            SelectedVegetationModelLOD3 = MeshUtils.SelectMeshObject(VegetationModel, LODLevel.LOD3);

            ShaderControler = ShaderSelector.GetShaderControler(vegetationItemInfo.ShaderName);
            if (ShaderControler != null)
            {
                ShaderControler.Settings = vegetationItemInfo.ShaderControllerSettings;
            }
            LODCount = MeshUtils.GetLODCount(VegetationModel, ShaderControler);

            CreateCameraWindSamplerItems(windSamplerList);

            if (ShaderControler != null)
            {
                LODFadePercentage = ShaderControler.Settings.LODFadePercentage;
                LODFadeCrossfade  = ShaderControler.Settings.LODFadeCrossfade;
            }

            VegetationMeshLod0 = GetVegetationMesh(VegetationModel, LODLevel.LOD0);
            VegetationMeshLod1 = GetVegetationMesh(VegetationModel, LODLevel.LOD1);
            VegetationMeshLod2 = GetVegetationMesh(VegetationModel, LODLevel.LOD2);
            VegetationMeshLod3 = GetVegetationMesh(VegetationModel, LODLevel.LOD3);

            VegetationRendererLOD0  = SelectedVegetationModelLOD0.GetComponentInChildren <MeshRenderer>();
            VegetationMaterialsLOD0 = CreateMaterials(VegetationRendererLOD0.sharedMaterials, 0);

            VegetationRendererLOD1  = SelectedVegetationModelLOD1.GetComponentInChildren <MeshRenderer>();
            VegetationMaterialsLOD1 = CreateMaterials(VegetationRendererLOD1.sharedMaterials, 1);

            VegetationRendererLOD2  = SelectedVegetationModelLOD2.GetComponentInChildren <MeshRenderer>();
            VegetationMaterialsLOD2 = CreateMaterials(VegetationRendererLOD2.sharedMaterials, 2);

            VegetationRendererLOD3  = SelectedVegetationModelLOD3.GetComponentInChildren <MeshRenderer>();
            VegetationMaterialsLOD3 = CreateMaterials(VegetationRendererLOD3.sharedMaterials, 3);

            if (vegetationItemInfo.PrefabType == VegetationPrefabType.Texture)
            {
                SetGrassTexture(VegetationMaterialsLOD0, vegetationItemInfo.VegetationTexture);
                SetGrassTexture(VegetationMaterialsLOD1, vegetationItemInfo.VegetationTexture);
                SetGrassTexture(VegetationMaterialsLOD2, vegetationItemInfo.VegetationTexture);
                SetGrassTexture(VegetationMaterialsLOD3, vegetationItemInfo.VegetationTexture);
            }

            VegetationMaterialPropertyBlockLOD0 = new MaterialPropertyBlock();
            VegetationRendererLOD0.GetPropertyBlock(VegetationMaterialPropertyBlockLOD0);
            if (VegetationMaterialPropertyBlockLOD0 == null)
            {
                VegetationMaterialPropertyBlockLOD0 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockLOD1 = new MaterialPropertyBlock();
            VegetationRendererLOD1.GetPropertyBlock(VegetationMaterialPropertyBlockLOD1);
            if (VegetationMaterialPropertyBlockLOD1 == null)
            {
                VegetationMaterialPropertyBlockLOD1 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockLOD2 = new MaterialPropertyBlock();
            VegetationRendererLOD2.GetPropertyBlock(VegetationMaterialPropertyBlockLOD2);
            if (VegetationMaterialPropertyBlockLOD2 == null)
            {
                VegetationMaterialPropertyBlockLOD2 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockLOD3 = new MaterialPropertyBlock();
            VegetationRendererLOD3.GetPropertyBlock(VegetationMaterialPropertyBlockLOD3);
            if (VegetationMaterialPropertyBlockLOD3 == null)
            {
                VegetationMaterialPropertyBlockLOD3 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockShadowsLOD0 = new MaterialPropertyBlock();
            VegetationRendererLOD0.GetPropertyBlock(VegetationMaterialPropertyBlockShadowsLOD0);
            if (VegetationMaterialPropertyBlockShadowsLOD0 == null)
            {
                VegetationMaterialPropertyBlockShadowsLOD0 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockShadowsLOD1 = new MaterialPropertyBlock();
            VegetationRendererLOD1.GetPropertyBlock(VegetationMaterialPropertyBlockShadowsLOD1);
            if (VegetationMaterialPropertyBlockShadowsLOD1 == null)
            {
                VegetationMaterialPropertyBlockShadowsLOD1 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockShadowsLOD2 = new MaterialPropertyBlock();
            VegetationRendererLOD2.GetPropertyBlock(VegetationMaterialPropertyBlockShadowsLOD2);
            if (VegetationMaterialPropertyBlockShadowsLOD2 == null)
            {
                VegetationMaterialPropertyBlockShadowsLOD2 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockShadowsLOD3 = new MaterialPropertyBlock();
            VegetationRendererLOD3.GetPropertyBlock(VegetationMaterialPropertyBlockShadowsLOD3);
            if (VegetationMaterialPropertyBlockShadowsLOD3 == null)
            {
                VegetationMaterialPropertyBlockShadowsLOD3 = new MaterialPropertyBlock();
            }

            LOD1Distance = GetLODDistance(VegetationModel, 0);
            LOD2Distance = GetLODDistance(VegetationModel, 1);
            LOD3Distance = GetLODDistance(VegetationModel, 2);

            vegetationItemInfo.Bounds = MeshUtils.CalculateBoundsInstantiate(VegetationModel);
            BoundingSphereRadius      = (vegetationItemInfo.Bounds.extents.magnitude * VegetationItemInfo.MaxScale * VegetationItemInfo.YScale) + 5;

            CreateCameraBuffers(cameraCount);

            HeightRuleCurveArray = new NativeArray <float>(256, Allocator.Persistent);
            UpdateHeightRuleCurve();


            SteepnessRuleCurveArray = new NativeArray <float>(256, Allocator.Persistent);
            UpdateSteepnessRuleCurve();

            //DistanceFalloffCurveArray = new NativeArray<float>(256, Allocator.Persistent);
            //UpdateDistanceFalloutCurve();

            if (vegetationItemInfo.VegetationType == VegetationType.Tree)
            {
                CreateBillboardMaterial();
            }
        }
Example #12
0
        public static void CreateHub()
        {
            GameObject hub = new GameObject("Hub");

            GameObject floor = GameObject.CreatePrimitive(PrimitiveType.Plane);

            floor.name                    = "Hub Floor";
            floor.transform.parent        = hub.transform;
            floor.transform.localPosition = Vector3.zero;
            floor.transform.localScale    = new Vector3(2f, 1f, 2f);
            floor.GetComponent <MeshRenderer>().material = MaterialUtility.Tiles20x20();

            GameObject roof = GameObject.CreatePrimitive(PrimitiveType.Plane);

            roof.name                                   = "Hub Roof";
            roof.transform.parent                       = hub.transform;
            roof.transform.localPosition                = new Vector3(0f, 20f, 0f);
            roof.transform.localEulerAngles             = new Vector3(180f, 0f, 0f);
            roof.transform.localScale                   = new Vector3(2f, 1f, 2f);
            roof.GetComponent <MeshRenderer>().material = MaterialUtility.Tiles20x20();

            GameObject wallFront = GameObject.CreatePrimitive(PrimitiveType.Plane);

            wallFront.name                                   = "Hub Wall Front";
            wallFront.transform.parent                       = hub.transform;
            wallFront.transform.localPosition                = new Vector3(0f, 10f, 10f);
            wallFront.transform.localEulerAngles             = new Vector3(-90f, 0f, 0f);
            wallFront.transform.localScale                   = new Vector3(2f, 1f, 2f);
            wallFront.GetComponent <MeshRenderer>().material = MaterialUtility.Tiles20x20();

            GameObject wallBack = GameObject.CreatePrimitive(PrimitiveType.Plane);

            wallBack.name                                   = "Hub Wall Back";
            wallBack.transform.parent                       = hub.transform;
            wallBack.transform.localPosition                = new Vector3(0f, 10f, -10f);
            wallBack.transform.localEulerAngles             = new Vector3(90f, 0f, 0f);
            wallBack.transform.localScale                   = new Vector3(2f, 1f, 2f);
            wallBack.GetComponent <MeshRenderer>().material = MaterialUtility.Tiles20x20();

            GameObject wallLeft = GameObject.CreatePrimitive(PrimitiveType.Plane);

            wallLeft.name                                   = "Hub Wall Left";
            wallLeft.transform.parent                       = hub.transform;
            wallLeft.transform.localPosition                = new Vector3(-10f, 10f, 0f);
            wallLeft.transform.localEulerAngles             = new Vector3(0f, 0f, -90f);
            wallLeft.transform.localScale                   = new Vector3(2f, 1f, 2f);
            wallLeft.GetComponent <MeshRenderer>().material = MaterialUtility.Tiles20x20();

            GameObject wallRight = GameObject.CreatePrimitive(PrimitiveType.Plane);

            wallRight.name                                   = "Hub Wall Right";
            wallRight.transform.parent                       = hub.transform;
            wallRight.transform.localPosition                = new Vector3(10f, 10f, 0f);
            wallRight.transform.localEulerAngles             = new Vector3(0f, 0f, 90f);
            wallRight.transform.localScale                   = new Vector3(2f, 1f, 2f);
            wallRight.GetComponent <MeshRenderer>().material = MaterialUtility.Tiles20x20();

            GameObject cubeFlying = GameObject.CreatePrimitive(PrimitiveType.Cube);

            cubeFlying.name                                   = "Hub Cube Flying";
            cubeFlying.transform.parent                       = hub.transform;
            cubeFlying.transform.localPosition                = new Vector3(2f, 2f, 2f);
            cubeFlying.transform.localEulerAngles             = new Vector3(0f, 0f, 0f);
            cubeFlying.transform.localScale                   = Vector3.one;
            cubeFlying.GetComponent <MeshRenderer>().material = MaterialUtility.Tiles2x2();

            GameObject cubeLying = GameObject.CreatePrimitive(PrimitiveType.Cube);

            cubeLying.name                                   = "Hub Cube Lying";
            cubeLying.transform.parent                       = hub.transform;
            cubeLying.transform.localPosition                = new Vector3(-3f, 0.5f, -1f);
            cubeLying.transform.localEulerAngles             = new Vector3(0f, 0f, 0f);
            cubeLying.transform.localScale                   = Vector3.one;
            cubeLying.GetComponent <MeshRenderer>().material = MaterialUtility.Tiles2x2();

            GameObject cubeTiny = GameObject.CreatePrimitive(PrimitiveType.Cube);

            cubeTiny.name                                   = "Hub Cube Large";
            cubeTiny.transform.parent                       = hub.transform;
            cubeTiny.transform.localPosition                = new Vector3(4f, 0.25f, -2f);
            cubeTiny.transform.localEulerAngles             = new Vector3(0f, 0f, 0f);
            cubeTiny.transform.localScale                   = Vector3.one * 0.5f;
            cubeTiny.GetComponent <MeshRenderer>().material = MaterialUtility.Tiles3x3();

            GameObject cubeLarge = GameObject.CreatePrimitive(PrimitiveType.Cube);

            cubeLarge.name                                   = "Hub Cube Tiny";
            cubeLarge.transform.parent                       = hub.transform;
            cubeLarge.transform.localPosition                = new Vector3(-4f, 2.5f, 4f);
            cubeLarge.transform.localEulerAngles             = new Vector3(0f, 0f, 0f);
            cubeLarge.transform.localScale                   = Vector3.one * 1.5f;
            cubeLarge.GetComponent <MeshRenderer>().material = MaterialUtility.Tiles3x3();
        }
Example #13
0
        /// <summary>
        /// Implement this function to make a custom inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            bool isNeedBuildMat = false;

            var graphic = (target as LRawImageForCapScreen);

            serializedObject.Update();

            //================
            // Basic properties.
            //================
            EditorGUILayout.PropertyField(_spTexture);
            EditorGUILayout.PropertyField(_spColor);
            EditorGUILayout.PropertyField(_spRaycastTarget);
            //================
            // Effect material.
            //================
            var spMaterial = serializedObject.FindProperty("m_EffectMaterial");

            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.PropertyField(spMaterial);
            EditorGUI.EndDisabledGroup();

            //================
            // Blur effect.
            //================
            GUILayout.Space(10);
            EditorGUILayout.LabelField("Blur Effect", EditorStyles.boldLabel);
            isNeedBuildMat = LUIBlurEffectEditor.DrawBlurProperties(serializedObject);

            //================
            // Advanced option.
            //================
            GUILayout.Space(10);
            EditorGUILayout.LabelField("Advanced Option", EditorStyles.boldLabel);

            EditorGUI.BeginChangeCheck();

            if (_spBlurMode.intValue != 0)
            {
                EditorGUILayout.PropertyField(_spIterations); // Iterations.
            }
            DrawDesamplingRate(_spReductionRate);             // Reduction rate.

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Result Texture Setting", EditorStyles.boldLabel);

            EditorGUILayout.PropertyField(_spFilterMode); // Filter Mode.
            DrawDesamplingRate(_spDesamplingRate);        // Desampling rate.

            serializedObject.ApplyModifiedProperties();

            // Debug.
            using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox))
            {
                GUILayout.Label("Debug");

                if (GUILayout.Button("Capture", "ButtonLeft"))
                {
                    graphic.Release();
                    EditorApplication.delayCall += graphic.Capture;
                }

                EditorGUI.BeginDisabledGroup(!(target as LRawImageForCapScreen).capturedTexture);
                if (GUILayout.Button("Release", "ButtonRight"))
                {
                    graphic.Release();
                }
                EditorGUI.EndDisabledGroup();
            }

            if (isNeedBuildMat || (spMaterial.objectReferenceValue == null && _spBlurMode.intValue != 0))
            {
                Shader shader = Shader.Find("UI/Hidden/UI-EffectCapture-Blur");
                spMaterial.objectReferenceValue = MaterialUtility.GetOrGenerateMaterialVariant(shader, (BlurMode)_spBlurMode.intValue);
                serializedObject.ApplyModifiedProperties();
            }
        }