Ejemplo n.º 1
0
        protected IEnumerator GenerateMinorItems()
        {
            StructureTemplateGroup structureGroup = Template.Exterior;

            yield return(StartCoroutine(StructureBuilder.AddGenericWorldItemsToStructure(structureGroup.GenericWItemsPieces, MinorGroup.transform, true, MinorGroup, null)));

            yield return(StartCoroutine(StructureBuilder.AddUniqueWorldItemsToStructure(structureGroup.UniqueWorlditems, MinorGroup.transform, true, MinorGroup, null)));

            yield break;
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
 static void ClearStructures()
 {
     foreach (UnityEngine.Object obj in UnityEditor.Selection.objects)
     {
         GameObject sbGo = obj as GameObject;
         if (sbGo != null)
         {
             Debug.Log("Clearing " + sbGo.name);
             StructureBuilder sb = sbGo.GetComponent <StructureBuilder> ();
             if (sb != null)
             {
                 StructureBuilder.EditorClearStructure(sb.transform);
             }
         }
     }
 }
Ejemplo n.º 4
0
        public IEnumerator GenerateStructureItems()
        {
            yield return(null);

            Transform structureItems = null;
            WIGroup   group          = null;

            State = BuilderState.BuildingItems;
            WorldChunk chunk = null;

            switch (Mode)
            {
            case BuilderMode.Exterior:
            default:
                group          = ParentStructure.StructureGroup;
                chunk          = group.GetParentChunk();
                structureItems = group.gameObject.FindOrCreateChild("_ITEMS_EXT");
                var generateExtItems = StructureBuilder.GenerateExteriorItems(
                    ParentStructure,
                    Template.Exterior,
                    group,
                    structureItems);
                while (generateExtItems.MoveNext())
                {
                    /*if (chunk.TargetMode == ChunkMode.Unloaded) {
                     *              Debug.Log("Cancelling build, chunk is unloading");
                     *              yield break;
                     *      }*/
                    yield return(generateExtItems.Current);
                }
                break;

            case BuilderMode.Interior:
                for (int i = 0; i < InteriorVariants.Count; i++)
                {
                    int interiorVariant = InteriorVariants [i];
                    if (!ParentStructure.StructureGroupInteriors.ContainsKey(interiorVariant))
                    {
                        //Debug.Log ("Didn't find interior variant " + interiorVariant.ToString () + " in " + ParentStructure.name + " - waiting for a bit...");
                        double timeOut = WorldClock.RealTime + 10f;
                        while (ParentStructure != null && !ParentStructure.worlditem.Is(WIActiveState.Invisible) && !ParentStructure.StructureGroupInteriors.ContainsKey(interiorVariant))
                        {
                            //waiting for interior groups to spawn

                            /*if (chunk.TargetMode == ChunkMode.Unloaded) {
                             *              Debug.Log("Cancelling build, chunk is unloading");
                             *              yield break;
                             *      }*/
                            yield return(null);

                            if (WorldClock.RealTime > timeOut)
                            {
                                //Debug.Log ("Timed out waiting for interior group " + interiorVariant.ToString () + " in " + ParentStructure.name);
                                break;
                            }
                        }
                    }

                    try {
                        group          = ParentStructure.StructureGroupInteriors [interiorVariant];
                        structureItems = group.gameObject.FindOrCreateChild("_ITEMS_INT_" + interiorVariant.ToString());
                    } catch (Exception e) {
                        Debug.LogError(e.ToString());
                        continue;
                    }

                    if (!ParentStructure.State.InteriorsLoadedOnce.Contains(interiorVariant) && interiorVariant < Template.InteriorVariants.Count)
                    {
                        /*#if UNITY_EDITOR
                         * Debug.Log ("Generating items for interior variant " + interiorVariant.ToString ());
                         #endif*/
                        var generateIntItems = StructureBuilder.GenerateInteriorItems(
                            ParentStructure,
                            interiorVariant,
                            Template.InteriorVariants [interiorVariant],
                            group,
                            structureItems);
                        while (generateIntItems.MoveNext())
                        {
                            /*if (chunk.TargetMode == ChunkMode.Unloaded) {
                             *              Debug.Log("Cancelling build, unloading");
                             *              yield break;
                             *      }*/
                            yield return(generateIntItems.Current);
                        }
                    }

                    /*#if UNITY_EDITOR
                     * else {
                     *      Debug.Log ("Didn't generate items for interior variant "
                     + interiorVariant.ToString ()
                     + " because it has either been loaded once (" + ParentStructure.State.InteriorsLoadedOnce.Contains (interiorVariant).ToString()
                     + ") or it's out of range (" + (interiorVariant >= Template.InteriorVariants.Count).ToString () + ")");
                     + }
                     #endif*/

                    yield return(null);
                }
                break;

            case BuilderMode.Minor:
                //minor structures don't generate items
                break;
            }
        }
Ejemplo n.º 5
0
        public IEnumerator GenerateStructureMeshes()
        {
            State = BuilderState.BuildingMeshes;
            switch (Mode)
            {
            case BuilderMode.Exterior:
            default:
                mCurrentTemplateGroup = Template.Exterior;
                //extract the fires from the template and add it to the template
                //StructureTemplate.ExtractChildPiecesFromLayer (ref ParentStructure.DestroyedFires, Template.Exterior.DestroyedFires);
                //StructureTemplate.ExtractFXPiecesFromLayer (ref ParentStructure.DestroyedFX, Template.Exterior.DestroyedFX);
                if (ParentStructure.DestroyedFX == null)
                {
                    ParentStructure.DestroyedFX = new List <FXPiece> ();
                }
                if (ParentStructure.DestroyedFires == null)
                {
                    ParentStructure.DestroyedFires = new List <ChildPiece> ();
                }
                ParentStructure.DestroyedFX.AddRange(Template.Exterior.DestroyedFXPieces);
                ParentStructure.DestroyedFires.AddRange(Template.Exterior.DestroyedFiresPieces);
                switch (Template.BuildMethod)
                {
                case StructureBuildMethod.MeshCombiner:
                    //before we actually generate the meshes
                    //see if it's cached

                    /*Structure cachedInstance = null;
                     * if (Structures.Get.GetCachedInstance(Template.Name, ParentStructure, out cachedInstance)) {
                     *              //hooray it's cached
                     *              //duplicate it piece for piece
                     *              yield return StartCoroutine(StructureBuilder.InstantiateMeshes(
                     *                              ParentStructure,
                     *                              cachedInstance,
                     *                              this));
                     *
                     * } else {*/
                    //otherwise just generate the meshes normally
                    var generateMeshes = StructureBuilder.GenerateMeshes(
                        mCurrentTemplateGroup,
                        PrimaryCombiner,
                        LODCombiner,
                        DestroyedCombiner,
                        LODDestroyedCombiner,
                        GetChildName(false, false),
                        ParentStructure.ExteriorMeshes,
                        ParentStructure.ExteriorRenderers,
                        ParentStructure.ExteriorRenderersDestroyed,
                        ParentStructure.ExteriorLodRenderers,
                        ParentStructure.ExteriorLodRenderersDestroyed,
                        false,
                        Template.UseLOD,
                        this,
                        Template.Name);
                    while (generateMeshes.MoveNext())
                    {
                        yield return(generateMeshes.Current);
                    }
                    /*}*/
                    //non-destroyed custom colliders
                    var generateCustomColliders = StructureBuilder.GenerateColliders(
                        GetChildName(false, false),
                        ParentStructure.ExteriorLayers,
                        ParentStructure.ExteriorBoxColliders,
                        ParentStructure.ExteriorMeshColliders,
                        ParentStructure.ExteriorBoxCollidersDestroyed,
                        ParentStructure.ExteriorMeshCollidersDestroyed,
                        ParentStructure.ExteriorMeshes,
                        mCurrentTemplateGroup.CustomStructureColliders,
                        false,                                                      //exterior
                        this);
                    while (generateCustomColliders.MoveNext())
                    {
                        yield return(generateCustomColliders.Current);
                    }
                    //non-destroyed static colliders
                    var generateStaticColliders = StructureBuilder.GenerateColliders(
                        GetChildName(false, false),
                        ParentStructure.ExteriorLayers,
                        ParentStructure.ExteriorBoxColliders,
                        ParentStructure.ExteriorMeshColliders,
                        ParentStructure.ExteriorBoxCollidersDestroyed,
                        ParentStructure.ExteriorMeshCollidersDestroyed,
                        ParentStructure.ExteriorMeshes,
                        mCurrentTemplateGroup.StaticStructureColliders,
                        false,                                                      //exterior
                        this);
                    while (generateStaticColliders.MoveNext())
                    {
                        yield return(generateStaticColliders.Current);
                    }

                    break;

                case StructureBuildMethod.MeshInstances:
                    if (ParentStructure.DestroyedFX == null)
                    {
                        ParentStructure.DestroyedFX = new List <FXPiece> ();
                    }
                    if (ParentStructure.DestroyedFires == null)
                    {
                        ParentStructure.DestroyedFires = new List <ChildPiece> ();
                    }                                                                                                                           //extract the fires from the template and add it to the template
                    ParentStructure.DestroyedFires.AddRange(Template.Exterior.DestroyedFiresPieces);
                    ParentStructure.DestroyedFX.AddRange(Template.Exterior.DestroyedFXPieces);
                    //StructureTemplate.ExtractChildPiecesFromLayer (ref ParentStructure.DestroyedFires, Template.Exterior.DestroyedFires);
                    //StructureTemplate.ExtractFXPiecesFromLayer (ref ParentStructure.DestroyedFX, Template.Exterior.DestroyedFX);
                    var instanceMeshes = InstanceMeshes(
                        mCurrentTemplateGroup,
                        GetChildName(false, false),
                        mExteriorRenderers,
                        mExteriorLODRenderers,
                        Globals.StructureExteriorLODRatio);
                    while (instanceMeshes.MoveNext())
                    {
                        yield return(instanceMeshes.Current);
                    }
                    break;
                }

                if (ParentStructure.ExteriorMovmementNodes == null)
                {
                    ParentStructure.ExteriorMovmementNodes = new List <MovementNode> ();
                }
                ParentStructure.ExteriorMovmementNodes.AddRange(mCurrentTemplateGroup.MovementNodes);
                mCurrentTemplateGroup = null;
                break;

            case BuilderMode.Interior:
                //we're not caching interior meshes yet
                for (int i = 0; i < InteriorVariants.Count; i++)
                {
                    int interiorVariant = InteriorVariants [i];
                    if (interiorVariant < Template.InteriorVariants.Count)
                    {
                        mCurrentTemplateGroup = Template.InteriorVariants [interiorVariant];

                        var generateMeshes = StructureBuilder.GenerateMeshes(
                            mCurrentTemplateGroup,
                            PrimaryCombiner,
                            LODCombiner,
                            DestroyedCombiner,
                            LODDestroyedCombiner,
                            GetChildName(true, false),
                            ParentStructure.InteriorMeshes,
                            ParentStructure.InteriorRenderers,
                            ParentStructure.InteriorRenderersDestroyed,
                            null,
                            null,
                            true,
                            Template.UseLOD,
                            this,
                            Template.Name);
                        while (generateMeshes.MoveNext())
                        {
                            yield return(generateMeshes.Current);
                        }
                        MaterialLookup.Clear();
                        //non-destroyed custom colliders
                        var generateCustomColliders = StructureBuilder.GenerateColliders(
                            GetChildName(true, false),
                            ParentStructure.InteriorLayers,
                            ParentStructure.InteriorBoxColliders,
                            ParentStructure.InteriorMeshColliders,
                            ParentStructure.InteriorBoxCollidersDestroyed,
                            ParentStructure.InteriorMeshCollidersDestroyed,
                            ParentStructure.InteriorMeshes,
                            mCurrentTemplateGroup.CustomStructureColliders,
                            true,                                                          //interior
                            this);
                        while (generateCustomColliders.MoveNext())
                        {
                            yield return(generateCustomColliders.Current);
                        }
                        //non-destroyed static colliders
                        var generateStaticColliders = StructureBuilder.GenerateColliders(
                            GetChildName(true, true),
                            ParentStructure.InteriorLayers,
                            ParentStructure.InteriorBoxColliders,
                            ParentStructure.InteriorMeshColliders,
                            ParentStructure.InteriorBoxCollidersDestroyed,
                            ParentStructure.InteriorMeshCollidersDestroyed,
                            ParentStructure.InteriorMeshes,
                            mCurrentTemplateGroup.StaticStructureColliders,
                            true,                                                          //interior
                            this);
                        while (generateStaticColliders.MoveNext())
                        {
                            yield return(generateStaticColliders.Current);
                        }
                        yield return(null);


                        if (ParentStructure.InteriorMovementNodes == null)
                        {
                            ParentStructure.InteriorMovementNodes = new List <MovementNode> ();
                        }
                        ParentStructure.InteriorMovementNodes.AddRange(mCurrentTemplateGroup.MovementNodes);
                        //Debug.Log ("Done generating interior variant " + interiorVariant.ToString () + ", state is " + State.ToString ());
                    }                     /*else {
                                           *    Debug.Log ("Didn't generate items for interior variant "
                                           + interiorVariant.ToString ()
                                           + " because it has either been loaded once (" + ParentStructure.State.InteriorsLoadedOnce.Contains (interiorVariant).ToString()
                                           + ") or it's out of range (" + (interiorVariant >= Template.InteriorVariants.Count).ToString () + ")");
                                           + }*/
                }
                //Debug.Log ("Finished generating states");
                mCurrentTemplateGroup = null;
                break;

            case BuilderMode.Minor:
                mCurrentTemplateGroup = Template.Exterior;
                switch (Template.BuildMethod)
                {
                case StructureBuildMethod.MeshCombiner:
                    var generateMeshes = StructureBuilder.GenerateMeshes(
                        mCurrentTemplateGroup,
                        PrimaryCombiner,
                        LODCombiner,
                        DestroyedCombiner,
                        LODDestroyedCombiner,
                        GetChildName(false, false, MinorParent.Number),
                        MinorParent.ExteriorMeshes,
                        MinorParent.ExteriorRenderers,
                        MinorParent.ExteriorRenderersDestroyed,
                        MinorParent.ExteriorLODRenderers,
                        MinorParent.ExteriorLODRenderersDestroyed,
                        false,
                        Template.UseLOD,
                        this,
                        Template.Name);
                    while (generateMeshes.MoveNext())
                    {
                        yield return(generateMeshes.Current);
                    }
                    StructurePiece.transform.ResetLocal();

                    var generateCustomColliders = StructureBuilder.GenerateColliders(
                        GetChildName(false, false, MinorParent.Number),
                        MinorParent.ExteriorLayers,
                        MinorParent.ExteriorBoxColliders,
                        MinorParent.ExteriorMeshColliders,
                        MinorParent.ExteriorBoxColliders,
                        MinorParent.ExteriorMeshColliders,
                        MinorParent.ExteriorMeshes,
                        mCurrentTemplateGroup.StaticStructureColliders,
                        false,
                        this);
                    while (generateCustomColliders.MoveNext())
                    {
                        yield return(generateCustomColliders.Current);
                    }

                    var generateStaticColliders = StructureBuilder.GenerateColliders(
                        GetChildName(false, false, MinorParent.Number),
                        MinorParent.ExteriorLayers,
                        MinorParent.ExteriorBoxColliders,
                        MinorParent.ExteriorMeshColliders,
                        MinorParent.ExteriorBoxColliders,
                        MinorParent.ExteriorMeshColliders,
                        MinorParent.ExteriorMeshes,
                        mCurrentTemplateGroup.CustomStructureColliders,
                        false,
                        this);
                    while (generateStaticColliders.MoveNext())
                    {
                        yield return(generateStaticColliders.Current);
                    }
                    break;

                case StructureBuildMethod.MeshInstances:
                    var instanceMeshes = InstanceMeshes(
                        mCurrentTemplateGroup,
                        GetChildName(false, false, MinorParent.Number),
                        mExteriorRenderers,
                        mExteriorLODRenderers,
                        Globals.StructureExteriorLODRatio);
                    while (instanceMeshes.MoveNext())
                    {
                        yield return(instanceMeshes.Current);
                    }
                    break;
                }
                //StructurePiece.transform.ResetLocal();
                mCurrentTemplateGroup = null;
                break;
            }
            State = Builder.BuilderState.Finished;
        }
Ejemplo n.º 6
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> ();
                }
            }
        }
Ejemplo n.º 7
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;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public void DrawEditor()
        {
            UnityEngine.GUI.color = Color.cyan;
            if (GUILayout.Button("Load Next Available Template"))
            {
                LoadNextAvailabeTemplate();
            }
            if (GUILayout.Button("Create Structure Transforms"))
            {
                StructureBuilder.CreateStructureTransforms(transform);
            }
            if (GUILayout.Button("\nCalculate Structure Footprint\n"))
            {
                CalculateFootprint();
            }
            if (GUILayout.Button("\nCreate Structure Footprint\n"))
            {
                CreateStructureFootprint();
            }
            if (GUILayout.Button("\nDuplicate Foundation\n"))
            {
                CreateFoundation();
            }
            if (GUILayout.Button("\nCopy Colliders\n"))
            {
                StructureBuilder.EditorCopyStaticColliders(transform);
            }
            if (GUILayout.Button("\nDuplicate as mesh structure\n"))
            {
                DuplicateAsMeshStructure();
            }
            if (GUILayout.Button("\nToggle Destroyed\n"))
            {
                StructureBuilder.ToggleDestroyedPrefabs();
            }
            if (Template != null)
            {
                Template.UseLOD = GUILayout.Toggle(Template.UseLOD, "Use LOD");
            }

            UnityEngine.GUI.color = Color.yellow;
            GUILayout.Label("FILE SAVE AND LOAD OPTIONS:");

            if (GUILayout.Button("\n(SAVE TEMPLATE)\n"))
            {
                StructureBuilder.SaveEditorStructureToTemplate(transform);
            }

            GUILayout.Label("Exterior Custom Colliders Normal: " + NumExteriorCustomCollidersNormal.ToString());
            GUILayout.Label("Exterior Custom Colliders Destroyed: " + NumExteriorCustomCollidersDestroyed.ToString());
            GUILayout.Label("Exterior Static Colliders Normal: " + NumExteriorStaticCollidersNormal.ToString());
            GUILayout.Label("Exterior Static Colliders Destroyed: " + NumExteriorStaticCollidersDestroyed.ToString());

            GUILayout.Label("Interior Custom Colliders Normal: " + NumInteriorCustomCollidersNormal.ToString());
            GUILayout.Label("Interior Custom Colliders Destroyed: " + NumInteriorCustomCollidersDestroyed.ToString());
            GUILayout.Label("Interior Static Colliders Normal: " + NumInteriorStaticCollidersNormal.ToString());
            GUILayout.Label("Interior Static Colliders Destroyed: " + NumInteriorStaticCollidersDestroyed.ToString());

            if (Application.isPlaying)
            {
                if (ParentStructure != null)
                {
                    UnityEngine.GUI.color = Color.red;
                    GUILayout.Label("BUILDING STRUCTURE: " + ParentStructure.name);
                }
            }
            else
            {
                if (Template != null)
                {
                }
            }
        }