Beispiel #1
0
        public void DuplicateAsMeshStructure()
        {
            Transform normal = transform.FindChild("==NORMAL==");

            if (normal != null)
            {
                Debug.Log("Can't create template - not empty");
                return;
            }
            StructureBuilder.CreateTemporaryPrefab(this, transform, StructureBuilder.GetTemplateName(name));
        }
Beispiel #2
0
        public void CreateStructureFootprint()
        {
            StructureTemplate template = null;

            if (Mods.Get.Editor.LoadMod <StructureTemplate> (ref template, "Structure", StructureBuilder.GetTemplateName(name)))
            {
                GameObject footprint = gameObject.FindOrCreateChild("__FOOTPRINT").gameObject;
                GameObject shingle   = gameObject.FindOrCreateChild("__SHINGLE").gameObject;
                shingle.transform.localPosition = template.CommonShingleOffset;
                for (int i = 0; i < template.Footprint.Count; i++)
                {
                    GameObject fp = footprint.FindOrCreateChild("Footprint" + i.ToString()).gameObject;
                    fp.transform.localPosition = template.Footprint [i].Position;
                    fp.transform.localScale    = template.Footprint [i].Scale;
                    fp.GetOrAdd <StructureFootprint> ();
                }
            }
        }
Beispiel #3
0
        public void CreateFoundation()
        {
            if (!Manager.IsAwake <Mods> ())
            {
                Manager.WakeUp <Mods> ("__MODS");
            }
            Mods.Get.Editor.InitializeEditor(true);

            if (!Manager.IsAwake <Structures> ())
            {
                Manager.WakeUp <Structures> ("Frontiers_Structures");
            }
            Structures.Get.Initialize();

            if (!Manager.IsAwake <WorldItems> ())
            {
                Manager.WakeUp <WorldItems> ("Frontiers_WorldItems");
            }
            WorldItems.Get.Initialize();

            StructureTemplate template = null;

            if (Mods.Get.Editor.LoadMod <StructureTemplate> (ref template, "Structure", StructureBuilder.GetTemplateName(name)))
            {
                GameObject foundation = gameObject.FindOrCreateChild("__TEMP_FOUNDATION").gameObject;
                foreach (StructureLayer staticLayer in template.Exterior.StaticStructureLayers)
                {
                    string prefabName = staticLayer.PrefabName.Trim().ToLower();
                    if (prefabName.Contains("foundation"))
                    {
                        StructurePackPrefab prefab = null;
                        if (Structures.Get.PackStaticPrefab(staticLayer.PackName, staticLayer.PrefabName, out prefab))
                        {
                            List <ChildPiece> staticPieces = null;
                            if (StructureTemplate.ExtractChildPiecesFromLayer(ref staticPieces, staticLayer.Instances))
                            {
                                //ChildPiece[] staticPieces = StructureTemplate.ExtractChildPiecesFromLayer(staticLayer.Instances);
                                for (int i = 0; i < staticPieces.Count; i++)
                                {
                                    ChildPiece piece = staticPieces [i];
                                    GameObject instantiatedPrefab = UnityEditor.PrefabUtility.InstantiatePrefab(prefab.Prefab) as GameObject;
                                    //instantiate a new prefab - keep it as a prefab!
                                    instantiatedPrefab.name             = prefab.Prefab.name;
                                    instantiatedPrefab.transform.parent = foundation.transform;
                                    instantiatedPrefab.tag   = staticLayer.Tag;
                                    instantiatedPrefab.layer = staticLayer.Layer;
                                    //put it in the right place
                                    instantiatedPrefab.transform.localPosition = piece.Position;
                                    instantiatedPrefab.transform.localRotation = Quaternion.identity;
                                    instantiatedPrefab.transform.Rotate(piece.Rotation);
                                    instantiatedPrefab.transform.localScale = piece.Scale;

                                    Material[] variationsArray = null;
                                    if (staticLayer.Substitutions != null && staticLayer.Substitutions.Count > 0)
                                    {
                                        MeshRenderer pmr = prefab.MRenderer;
                                        variationsArray = pmr.sharedMaterials;
                                        string newMaterialName = string.Empty;
                                        for (int j = 0; j < variationsArray.Length; j++)
                                        {
                                            if (staticLayer.Substitutions.TryGetValue(variationsArray [j].name, out newMaterialName))
                                            {
                                                Material sharedMaterial = null;
                                                if (Structures.Get.SharedMaterial(newMaterialName, out sharedMaterial))
                                                {
                                                    variationsArray [j] = sharedMaterial;
                                                }
                                            }
                                        }
                                        instantiatedPrefab.GetComponent <Renderer>().materials = variationsArray;
                                    }
                                }
                                staticPieces.Clear();
                                staticPieces = null;
                            }
                        }
                    }
                }
            }
        }