Пример #1
0
    // put on all edit pigs on start to initialize
    void Start()
    {
        EditModeOBJ eo = gameObject.AddComponent <EditModeOBJ>();

        eo.data.pos        = gameObject.transform.position;
        eo.data.rot        = gameObject.transform.rotation;
        eo.data.scale      = gameObject.transform.localScale;
        eo.data.objectType = EditModeOBJ.ObjectType.RealPig;
        eo.data.OBJname    = name;
    }
Пример #2
0
    public void SpawnOBJ()
    {
        //check sprite to prefab
        string spriteName = SpawnButton.image.sprite.name;

        if (SpawnButton.image.sprite.name == spriteName)
        {
            //set target to corresponding prefab and give it needed variables
            targetSpawnOBJ = CoinPrefab;
            targetSpawnOBJ.GetComponent <HoldItem>().destinationTransform = placementTransform;
            // set strings for names
            string EditObjName = string.Concat("SpawnOBJ", SpawnOBjCount);
            string RealObjName = string.Concat("Real", SpawnOBjCount);
            //create edit objects and remove components
            GameObject SpawnedEditObj = Instantiate(targetSpawnOBJ, placementTransform.position, placementTransform.rotation);
            Rigidbody  EditObjRB      = SpawnedEditObj.GetComponent <Rigidbody>();
            EditObjRB.isKinematic = true;
            EditObjRB.useGravity  = false;
            SpawnedEditObj.RemoveComponent <HoldItem>();
            SpawnedEditObj.RemoveComponent <ItemRespawn>();
            //give parent and edit attributes
            SpawnedEditObj.transform.parent = GameObject.Find("EditLevel").transform;
            SpawnedEditObj.name             = EditObjName;
            SpawnedEditObj.transform.tag    = "EditOBJ";
            SpawnedEditObj.SetActive(true);
            //spawn real equivalent
            GameObject SpawnedRealObj = Instantiate(targetSpawnOBJ, placementTransform.position, placementTransform.rotation);
            SpawnedRealObj.name = RealObjName;
            //parent to inactive real level
            SpawnedRealObj.transform.parent = GameObject.Find("RealLevel").transform;

            SpawnOBjCount++;
            //save edit object data
            EditModeOBJ eo = SpawnedEditObj.AddComponent <EditModeOBJ>();
            eo.data.pos        = SpawnedEditObj.transform.position;
            eo.data.rot        = SpawnedEditObj.transform.rotation;
            eo.data.scale      = SpawnedEditObj.transform.localScale;
            eo.data.objectType = EditModeOBJ.ObjectType.RealCoin1;
            eo.data.OBJname    = name;
        }
        else if (SpawnButton.image.sprite.name == "PigIcon")
        {
            targetSpawnOBJ = PigPrefab;
            string EditObjName = string.Concat("SpawnOBJ", SpawnOBjCount);
            string RealObjName = string.Concat("Real", SpawnOBjCount);

            GameObject SpawnedEditObj = Instantiate(targetSpawnOBJ, placementTransform.position, placementTransform.rotation);
            Rigidbody  EditObjRB      = SpawnedEditObj.GetComponent <Rigidbody>();
            EditObjRB.isKinematic = true;
            EditObjRB.useGravity  = false;

            SpawnedEditObj.transform.parent = GameObject.Find("EditLevel").transform;
            SpawnedEditObj.name             = EditObjName;
            SpawnedEditObj.transform.tag    = "EditOBJ";
            SpawnedEditObj.SetActive(true);

            GameObject SpawnedRealObj = Instantiate(targetSpawnOBJ, placementTransform.position, placementTransform.rotation);
            SpawnedRealObj.name             = RealObjName;
            SpawnedRealObj.transform.parent = GameObject.Find("RealLevel").transform;

            //SpawnedRealObj.SetActive(false);
            SpawnOBjCount++;

            EditModeOBJ eo = SpawnedEditObj.AddComponent <EditModeOBJ>();
            eo.data.pos        = SpawnedEditObj.transform.position;
            eo.data.rot        = SpawnedEditObj.transform.rotation;
            eo.data.scale      = SpawnedEditObj.transform.localScale;
            eo.data.objectType = EditModeOBJ.ObjectType.RealPig;
        }
    }
Пример #3
0
    // create objects based on data within level.
    void CreateGamestateFromFile()
    {
        //objects for spawning
        GameObject EditObj;
        GameObject RealOBJ;

        //emptys for setting building parenting
        EditLevel = new GameObject();
        RealLevel = new GameObject();
        for (int editcount = 0; editcount < level.editorObjects.Count; editcount++)
        {
            if (level.editorObjects[editcount].objectType == EditModeOBJ.ObjectType.Room)
            {
                //put position of edit level empty to building position from file
                EditLevel.transform.position   = level.editorObjects[editcount].pos;
                EditLevel.transform.rotation   = level.editorObjects[editcount].rot;
                EditLevel.transform.localScale = level.editorObjects[editcount].scale;
                //change name of empty for re-editing
                EditLevel.name = "EditLevel";
                //set parent for set active states
                EditLevel.transform.parent = GameObject.Find("LevelCreater").transform;

                //put position of edit level empty to building position from file
                RealLevel.transform.position   = level.editorObjects[editcount].pos;
                RealLevel.transform.rotation   = level.editorObjects[editcount].rot;
                RealLevel.transform.localScale = level.editorObjects[editcount].scale;
                //change name of empty for re-editing and setting active on play
                RealLevel.name = "RealLevel";
                //set parent for set active states
                RealLevel.transform.parent = GameObject.Find("LevelCreater").transform;
                //set false until test/play
                RealLevel.SetActive(false);

                //spawn real building and set transforms
                EditObj = Instantiate(BuildingPrefab);
                EditObj.transform.position   = level.editorObjects[editcount].pos;
                EditObj.transform.rotation   = level.editorObjects[editcount].rot;
                EditObj.transform.localScale = level.editorObjects[editcount].scale;
                EditObj.name = level.editorObjects[editcount].OBJname;

                //set building parent for spawning level
                EditObj.transform.parent = EditLevel.transform;
                //EditLevel.transform = EditObj.transform;

                //spawn real building and set transforms;
                RealOBJ = Instantiate(BuildingPrefab);
                RealOBJ.transform.position   = level.editorObjects[editcount].pos;
                RealOBJ.transform.rotation   = level.editorObjects[editcount].rot;
                RealOBJ.transform.localScale = level.editorObjects[editcount].scale;
                //set to false and parenting
                RealOBJ.transform.parent = RealLevel.transform;

                //save data for edit obj
                EditModeOBJ eo = EditObj.AddComponent <EditModeOBJ>();
                eo.data.pos        = EditObj.transform.position;
                eo.data.rot        = EditObj.transform.rotation;
                eo.data.objectType = EditModeOBJ.ObjectType.Room;
            }
        }

        for (int i = 0; i < level.editorObjects.Count; i++)
        {
            if (level.editorObjects[i].objectType == EditModeOBJ.ObjectType.RealCoin1)
            {
                //spawn edit coin with transforms
                EditObj = Instantiate(CoinPrefab);
                EditObj.transform.position   = level.editorObjects[i].pos;
                EditObj.transform.rotation   = level.editorObjects[i].rot;
                EditObj.transform.localScale = level.editorObjects[i].scale;
                EditObj.name = level.editorObjects[i].OBJname;
                //set parent for spawning level
                EditObj.transform.parent = EditLevel.transform;
                //remove scripts from edit obj
                EditObj.RemoveComponent <HoldItem>();
                EditObj.RemoveComponent <ItemRespawn>();

                //spawn real obj
                RealOBJ = Instantiate(CoinPrefab);
                //set script variables
                RealOBJ.GetComponent <HoldItem>().destinationTransform = placementTransform;
                //set transforms
                RealOBJ.transform.position   = level.editorObjects[i].pos;
                RealOBJ.transform.rotation   = level.editorObjects[i].rot;
                RealOBJ.transform.localScale = level.editorObjects[i].scale;
                RealOBJ.name = string.Concat("Real", level.editorObjects[i].OBJname);
                //set false and parent
                RealOBJ.transform.parent = RealLevel.transform;

                //save data for edit obj
                EditModeOBJ eo = EditObj.AddComponent <EditModeOBJ>();
                eo.data.pos        = EditObj.transform.position;
                eo.data.rot        = EditObj.transform.rotation;
                eo.data.objectType = EditModeOBJ.ObjectType.RealCoin1;
            }
            else if (level.editorObjects[i].objectType == EditModeOBJ.ObjectType.Pedestal)
            {
                //spawn edit pedestal with transforms
                EditObj = Instantiate(PedestalPrefab);
                EditObj.transform.position   = level.editorObjects[i].pos;
                EditObj.transform.rotation   = level.editorObjects[i].rot;
                EditObj.transform.localScale = level.editorObjects[i].scale;
                EditObj.name = level.editorObjects[i].OBJname;
                //set parent for spawning level
                EditObj.transform.parent = EditLevel.transform;

                //make real pedestal with transforms
                RealOBJ = Instantiate(PedestalPrefab);
                RealOBJ.transform.position   = level.editorObjects[i].pos;
                RealOBJ.transform.rotation   = level.editorObjects[i].rot;
                RealOBJ.transform.localScale = level.editorObjects[i].scale;
                RealOBJ.name = string.Concat("Real", level.editorObjects[i].OBJname);

                //save data for editobj
                EditModeOBJ eo = EditObj.AddComponent <EditModeOBJ>();
                eo.data.pos        = EditObj.transform.position;
                eo.data.rot        = EditObj.transform.rotation;
                eo.data.objectType = EditModeOBJ.ObjectType.Pedestal;
            }
            else if (level.editorObjects[i].objectType == EditModeOBJ.ObjectType.RealPig)
            {
                //make edit pig with transforms
                EditObj = Instantiate(PigPrefab);
                EditObj.transform.position   = level.editorObjects[i].pos;
                EditObj.transform.rotation   = level.editorObjects[i].rot;
                EditObj.transform.localScale = level.editorObjects[i].scale;
                EditObj.name = level.editorObjects[i].OBJname;
                //set parent for spawning level
                EditObj.transform.parent = EditLevel.transform;

                //make real pig with transforms
                RealOBJ = Instantiate(PigPrefab);
                RealOBJ.transform.position   = level.editorObjects[i].pos;
                RealOBJ.transform.rotation   = level.editorObjects[i].rot;
                RealOBJ.transform.localScale = level.editorObjects[i].scale;
                RealOBJ.name = string.Concat("Real", level.editorObjects[i].OBJname);

                //save data for edit obj
                EditModeOBJ eo = EditObj.AddComponent <EditModeOBJ>();
                eo.data.pos        = EditObj.transform.position;
                eo.data.rot        = EditObj.transform.rotation;
                eo.data.objectType = EditModeOBJ.ObjectType.Pedestal;
            }

            /*
             * else if (level.editorObjects[i].objectType == EditModeOBJ.ObjectType.Something)
             * {
             *
             * }
             * else if (level.editorObjects[i].objectType == EditModeOBJ.ObjectType.Something)
             * {
             *
             * }
             * else if (level.editorObjects[i].objectType == EditModeOBJ.ObjectType.Something)
             * {
             *
             * }
             */
        }
        //set new building and place them
        GameObject.Find("PlaceBuildingInteraction").GetComponent <PlaceBuildingEdit>().Building      = EditLevel;
        GameObject.Find("PlaceBuildingInteraction").GetComponent <PlaceBuildingEdit>().RealLevel     = RealLevel;
        GameObject.Find("PlaceBuildingInteraction").GetComponent <PlaceBuildingEdit>().placementOver = false;
        GameObject.Find("PlaceBuildingInteraction").GetComponent <PlaceBuildingEdit>().redoPlacement();
        // set spawn obj count for re-editing
        GameObject.Find("EditInteraction").GetComponent <EditItemTranslations>().SpawnOBjCount = level.editorObjects.Count + 1;
    }