コード例 #1
0
    public SerObject makeSerObject(GameObject gm, string s)
    {
        SerObject obj = new SerObject();

        obj.x = gm.transform.position.x;
        obj.y = gm.transform.position.y;
        obj.z = gm.transform.position.z;

        obj.rotX = gm.transform.eulerAngles.x;
        obj.rotY = gm.transform.eulerAngles.y;
        obj.rotZ = gm.transform.eulerAngles.z;

        obj.scalX = gm.transform.localScale.x;
        obj.scalY = gm.transform.localScale.y;
        obj.scalZ = gm.transform.localScale.z;

        SerBuildableStats sbs = new SerBuildableStats();

        sbs.transparency = gm.GetComponent <BuildableStats>().transparency;
        obj.sbs          = sbs;

        // Serialize the object properties is it has one.
        if (gm.GetComponent <ObjectProperties>() != null)
        {
            obj.objProperties = gm.GetComponent <ObjectProperties>().GetSerializedData();
        }

        obj.name = s;
        return(obj);
    }
コード例 #2
0
    void forLoop(List <SerObject> ls)
    {
        foreach (SerObject ob in ls)
        {
            GameObject obj = (GameObject)Instantiate(Resources.Load(ob.name), new Vector3(-900, 0, -900), Quaternion.identity);
            obj.transform.position    = new Vector3(ob.x, ob.y, ob.z);
            obj.transform.eulerAngles = new Vector3(ob.rotX, ob.rotY, ob.rotZ);
            obj.transform.localScale  = new Vector3(ob.scalX, ob.scalY, ob.scalZ);
            obj.layer = 10;
            obj.GetComponent <BoxCollider>().enabled = true;
            SerBuildableStats bs = ob.sbs;
            if (bs != null)                                                                  //TODO remove hard code.
            {
                obj.GetComponent <BuildableStats>().transparency = (int)ob.sbs.transparency; // Loads in the build stats data.
            }
            else
            {
                List <string> s = new List <string>();
                s.Add("Continue");
                s.Add("Exit to Main Menu");
                WindowUI wui = new WindowUI(WindowImage.WARNING, WindowType.YES_NO, s, "Older Version", "It looks like you are loading this world from an older version of the game. The objects have been updated to the new format. Would you like to continue?", false, 4, ExitDefault.CLOSEOPERATION);
                wui.Display();
            }
            SerObjectProperties serializedObjectProperties = ob.objProperties;
            if (serializedObjectProperties != null)
            {
                // Note: Only one ObjectProperties can exist on an object.
                bool proper = obj.GetComponent <ObjectProperties>().SetupSerialziedData(serializedObjectProperties);
                if (!proper)
                {
                    List <string> s = new List <string>();
                    s.Add("Continue");
                    s.Add("Exit to Main Menu");
                    WindowUI wui = new WindowUI(WindowImage.WARNING, WindowType.YES_NO, s, "Older Version", "It looks like you are loading this world from an older version of the game. The objects have been updated to the new format. Would you like to continue?", false, 4, ExitDefault.CLOSEOPERATION);
                    wui.Display();
                }
            }


            World.objects.Add(obj, ob.name);
        }
    }