コード例 #1
0
        public void UpdateMaterial()
        {
            if (SharedMaterial == null)
            {
                SharedMaterial = new Material(EditMap.DecalsInfo.Current.AlbedoMaterial);
            }


            if (Type == TerrainDecalType.TYPE_NORMALS || Type == TerrainDecalType.TYPE_NORMALS_ALPHA)
            {
                Texture1            = DecalsInfo.AssignTextureFromPath(ref SharedMaterial, "_NormalTex", Tex1Path);
                Texture1.anisoLevel = 6;
                Texture1.filterMode = FilterMode.Bilinear;

                DrawAlbedo = false;
                DrawNormal = true;
            }
            else if (Type == TerrainDecalType.TYPE_GLOW ||
                     Type == TerrainDecalType.TYPE_GLOW_MASK)
            {
                Texture1 = DecalsInfo.AssignTextureFromPath(ref SharedMaterial, "_MainTex", Tex1Path);
                Texture2 = DecalsInfo.AssignTextureFromPath(ref SharedMaterial, "_Glow", Tex2Path);

                DrawAlbedo = true;
                DrawNormal = false;
            }
            else             // Albedo
            {
                Texture1 = DecalsInfo.AssignTextureFromPath(ref SharedMaterial, "_MainTex", Tex1Path);
                Texture2 = DecalsInfo.AssignTextureFromPath(ref SharedMaterial, "_Mask", Tex2Path);

                DrawAlbedo = true;
                DrawNormal = false;
            }
        }
コード例 #2
0
    public UnitInstance FillGameObjectValues(GameObject Obj, MapLua.SaveLua.Army.Unit Source, MapLua.SaveLua.Army.UnitsGroup Group, Vector3 position, Quaternion rotation)
    {
        if (Obj.transform.childCount > 0)
        {
            foreach (Transform child in Obj.transform)
            {
                Destroy(child.gameObject);
            }
        }

        Obj.name = Source.Name;

        UnitInstance UInst = Obj.GetComponent <UnitInstance>();

        //UInst.Owner = Owner;
        UInst.Owner     = Source;
        Source.Instance = UInst;
        //Group.Units.Add(Source);
        UInst.orders       = Source.orders;
        UInst.platoon      = Source.platoon;
        UInst.UnitRenderer = this;
        UInst.SetMatrix(UInst.GetSnapPosition(position), rotation);
        UInst.ArmyColor = Group.Owner.ArmyColor;

        if (BP.SelectionSize.x > 0 && BP.SelectionSize.y > 0)
        {
            UInst.Col.size = BP.SelectionSize * 0.1f;
        }
        else
        {
            UInst.Col.size = BP.Size * 0.1f;
        }
        UInst.Col.center = Vector3.up * (BP.Size.y * 0.05f);

        if (BP.HasTermac)
        {
            if (BP.Termac_Albedo != null)
            {
                DecalsInfo.CreateGameObjectFromDecal(BP.Termac_Albedo);
                BP.Termac_Albedo.Obj.tr.parent        = UInst.transform;
                BP.Termac_Albedo.Obj.tr.localPosition = Vector3.zero;
            }

            if (BP.Termac_Normal != null)
            {
                DecalsInfo.CreateGameObjectFromDecal(BP.Termac_Normal);
                BP.Termac_Normal.Obj.tr.parent        = UInst.transform;
                BP.Termac_Normal.Obj.tr.localPosition = Vector3.zero;
            }
        }

        AddInstance(UInst);
        return(UInst);
    }
コード例 #3
0
    static void LoadTermacs(UnitBluePrint BP)
    {
        if (BP.Termacs.Length == 0)
        {
            return;
        }

        if (!string.IsNullOrEmpty(BP.Termacs[0].Albedo))
        {
            BP.HasTermac                  = true;
            BP.Termac_Albedo              = new Decal();
            BP.Termac_Albedo.TexPathes    = new string[2];
            BP.Termac_Albedo.TexPathes[0] = TarmacsDirectory + BP.Termacs[0].Albedo + TarmacsFormat;
            BP.Termac_Albedo.TexPathes[1] = "";
            BP.Termac_Albedo.CutOffLOD    = BP.Termacs[0].FadeOut;
            BP.Termac_Albedo.Type         = TerrainDecalType.TYPE_ALBEDO;

            BP.Termac_Albedo.Scale = new Vector3(BP.Termacs[0].Width, 1, BP.Termacs[0].Length);

            DecalsInfo.MargeShared(BP.Termac_Albedo);
            BP.Termac_Albedo.Shared.IsTarmac = true;
        }

        if (!string.IsNullOrEmpty(BP.Termacs[0].Normal))
        {
            BP.HasTermac                  = true;
            BP.Termac_Normal              = new Decal();
            BP.Termac_Normal.TexPathes    = new string[2];
            BP.Termac_Normal.TexPathes[0] = TarmacsDirectory + BP.Termacs[0].Normal + TarmacsFormat;
            BP.Termac_Normal.TexPathes[1] = "";
            BP.Termac_Normal.CutOffLOD    = BP.Termacs[0].FadeOut;
            BP.Termac_Normal.Type         = TerrainDecalType.TYPE_NORMALS;

            BP.Termac_Normal.Scale = new Vector3(BP.Termacs[0].Width, 1, BP.Termacs[0].Length);

            DecalsInfo.MargeShared(BP.Termac_Normal);
            BP.Termac_Normal.Shared.IsTarmac = true;
        }
    }
コード例 #4
0
        public PropGameObject CreatePropGameObject(Vector3 position, Quaternion rotation, Vector3 scale, bool AllowFarLod = true)
        {
            //Reset scale, because it's not supported anyway
            scale = Vector3.one;

            PropGameObject NewProp = GameObject.Instantiate(PropsInfo.Current.PropObjectPrefab, PropsInfo.Current.PropsParent).GetComponent <PropGameObject>();

            NewProp.gameObject.name = BP.Name;

            if (BP.LODs.Length > 0)
            {
                if (BP.LODs[0].Mesh)
                {
                    NewProp.Mf.sharedMesh     = BP.LODs[0].Mesh;
                    NewProp.Mr.sharedMaterial = BP.LODs[0].Mat;
                    NewProp.Col.size          = NewProp.Mf.sharedMesh.bounds.size;
                }
                bool Lod1Exist = BP.LODs.Length > 1 && BP.LODs[1].Mesh != null;
                if (Lod1Exist)
                {
                    NewProp.Mf1.sharedMesh     = BP.LODs[1].Mesh;
                    NewProp.Mr1.sharedMaterial = BP.LODs[1].Mat;
                }
                else
                {
                    NewProp.Mf1.gameObject.SetActive(false);
                }
                bool Lod2Exist = Lod1Exist && AllowFarLod && BP.LODs.Length > 2 && BP.LODs[2].Mesh != null;
                if (Lod2Exist)
                {
                    NewProp.Mf2.sharedMesh     = BP.LODs[2].Mesh;
                    NewProp.Mr2.sharedMaterial = BP.LODs[2].Mat;
                }
                else
                {
                    NewProp.Mf2.gameObject.SetActive(false);
                }



                scale.x *= BP.LocalScale.x;
                scale.y *= BP.LocalScale.y;
                scale.z *= BP.LocalScale.z;
                NewProp.Tr.localScale = scale;
                Lods = NewProp.Lodg.GetLODs();

                float DeltaSize = 0.01f;
                if (BP.LODs[0].Mesh != null)
                {
                    Vector3 bs = BP.LODs[0].Mesh.bounds.size;
                    DeltaSize = Mathf.Max(scale.x * bs.x, scale.y * bs.y, scale.z * bs.z);
                    Lods[0].screenRelativeTransitionHeight = DeltaSize / DecalsInfo.FrustumHeightAtDistance(BP.LODs[0].LODCutoff * 0.1f);
                }
                if (Lod1Exist)
                {
                    Vector3 bs = BP.LODs[1].Mesh.bounds.size;
                    DeltaSize = Mathf.Max(scale.x * bs.x, scale.y * bs.y, scale.z * bs.z);
                    Lods[1].screenRelativeTransitionHeight = DeltaSize / DecalsInfo.FrustumHeightAtDistance(BP.LODs[1].LODCutoff * 0.1f);
                }
                if (Lod2Exist)
                {
                    Vector3 bs = BP.LODs[2].Mesh.bounds.size;
                    DeltaSize = Mathf.Max(scale.x * bs.x, scale.y * bs.y, scale.z * bs.z);
                    Lods[2].screenRelativeTransitionHeight = DeltaSize / DecalsInfo.FrustumHeightAtDistance(BP.LODs[2].LODCutoff * 0.1f);
                }


                if (!Lod1Exist && !Lod2Exist)
                {
                    Lods = new LOD[] { Lods[0] }
                }
                ;
                else if (!Lod2Exist)
                {
                    Lods = new LOD[] { Lods[0], Lods[1] }
                }
                ;

                NewProp.Lodg.SetLODs(Lods);

                NewProp.Tr.localPosition = position;
                NewProp.Tr.localRotation = rotation;
            }
            else
            {
                Debug.LogWarning("Prop is empty! " + BP.Path);
            }

            return(NewProp);
        }
    }
コード例 #5
0
        public PropGameObject CreatePropGameObject(Vector3 position, Quaternion rotation, Vector3 scale, bool AllowFarLod = true)
        {
            if (IsTemp)
            {
                IsTemp = false;
                for (int i = 0; i < BP.LODs.Length; i++)
                {
                    if (BP.LODs[i].Albedo != null)
                    {
                        AddToMemory(BP.LODs[i].AlbedoName, BP.LODs[i].Albedo);
                    }
                    else if (BP.LODs[i].AlbedoLoaded)
                    {
                        BP.LODs[i].Albedo            = LoadTexture2DFromGamedata(GetGamedataFile.EnvScd, BP.LODs[i].AlbedoName, false, !IsTemp, true);
                        BP.LODs[i].Albedo.anisoLevel = 2;
                        BP.LODs[i].Mat.SetTexture("_MainTex", BP.LODs[i].Albedo);
                    }

                    if (BP.LODs[i].Normal != null)
                    {
                        AddToMemory(BP.LODs[i].NormalsName, BP.LODs[i].Normal);
                    }
                    else if (BP.LODs[i].NormalLoaded)
                    {
                        BP.LODs[i].Normal            = LoadTexture2DFromGamedata(GetGamedataFile.EnvScd, BP.LODs[i].NormalsName, true, !IsTemp, true);
                        BP.LODs[i].NormalLoaded      = BP.LODs[i].Normal != null;
                        BP.LODs[i].Normal.anisoLevel = 2;
                        BP.LODs[i].Mat.SetTexture("_BumpMap", BP.LODs[i].Normal);
                    }
                }
            }

            //Reset scale, because it's not supported anyway
            scale = Vector3.one;

            PropGameObject NewProp = GameObject.Instantiate(PropsInfo.Current.PropObjectPrefab, PropsInfo.Current.PropsParent).GetComponent <PropGameObject>();

            NewProp.gameObject.name = BP.Name;

            if (BP.LODs.Length > 0)
            {
                if (BP.LODs[0].Mesh)
                {
                    NewProp.Mf.sharedMesh     = BP.LODs[0].Mesh;
                    NewProp.Mr.sharedMaterial = BP.LODs[0].Mat;
                    NewProp.Col.size          = NewProp.Mf.sharedMesh.bounds.size;
                }
                bool Lod1Exist = BP.LODs.Length > 1 && BP.LODs[1].Mesh != null;
                if (Lod1Exist)
                {
                    NewProp.Mf1.sharedMesh     = BP.LODs[1].Mesh;
                    NewProp.Mr1.sharedMaterial = BP.LODs[1].Mat;
                }
                else
                {
                    NewProp.Mf1.gameObject.SetActive(false);
                }
                bool Lod2Exist = Lod1Exist && AllowFarLod && BP.LODs.Length > 2 && BP.LODs[2].Mesh != null;
                if (Lod2Exist)
                {
                    NewProp.Mf2.sharedMesh     = BP.LODs[2].Mesh;
                    NewProp.Mr2.sharedMaterial = BP.LODs[2].Mat;
                }
                else
                {
                    NewProp.Mf2.gameObject.SetActive(false);
                }



                scale.x *= BP.LocalScale.x;
                scale.y *= BP.LocalScale.y;
                scale.z *= BP.LocalScale.z;
                NewProp.Tr.localScale = scale;
                Lods = NewProp.Lodg.GetLODs();

                float DeltaSize = 0.01f;
                if (BP.LODs[0].Mesh != null)
                {
                    Vector3 bs = BP.LODs[0].Mesh.bounds.size;
                    DeltaSize = Mathf.Max(scale.x * bs.x, scale.y * bs.y, scale.z * bs.z);
                    Lods[0].screenRelativeTransitionHeight = DeltaSize / DecalsInfo.FrustumHeightAtDistance(BP.LODs[0].LODCutoff * 0.1f);
                }
                if (Lod1Exist)
                {
                    Vector3 bs = BP.LODs[1].Mesh.bounds.size;
                    DeltaSize = Mathf.Max(scale.x * bs.x, scale.y * bs.y, scale.z * bs.z);
                    Lods[1].screenRelativeTransitionHeight = DeltaSize / DecalsInfo.FrustumHeightAtDistance(BP.LODs[1].LODCutoff * 0.1f);
                }
                if (Lod2Exist)
                {
                    Vector3 bs = BP.LODs[2].Mesh.bounds.size;
                    DeltaSize = Mathf.Max(scale.x * bs.x, scale.y * bs.y, scale.z * bs.z);
                    Lods[2].screenRelativeTransitionHeight = DeltaSize / DecalsInfo.FrustumHeightAtDistance(BP.LODs[2].LODCutoff * 0.1f);
                }


                if (!Lod1Exist && !Lod2Exist)
                {
                    Lods = new LOD[] { Lods[0] }
                }
                ;
                else if (!Lod2Exist)
                {
                    Lods = new LOD[] { Lods[0], Lods[1] }
                }
                ;

                NewProp.Lodg.SetLODs(Lods);

                NewProp.Tr.localPosition = position;
                NewProp.Tr.localRotation = rotation;
            }
            else
            {
                Debug.LogWarning("Prop is empty! " + BP.Path);
            }

            return(NewProp);
        }
    }