public void NewResumeAction()
    {
        // Save_game_slot equalling "new game"
        // indicates that the game has not been saved to a save slot yet.
        if (SceneManager.GetActiveScene().name == "MainMenu")
        {
            PlayerPrefs.SetString("saved_game_slot", "new game");
            Serialization.CreateDirectory(Application.persistentDataPath + "/saves/savedgames/auxiliary");

            Serialization.Save <Game>(new Game(), Application.persistentDataPath + "/saves/savedgames/auxiliary/game.dat");

            SavedObject character = new SavedObject();
            character.position_x = 6;
            character.position_y = 1.1f;
            character.position_z = 4;

            Serialization.Save <SavedObject>(character, Application.persistentDataPath + "/saves/savedgames/auxiliary/character.dat");

            LoadLevel01();
        }
        else
        {
            GameEvents.current.ResumeGame();
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        data_container = GameObject.FindGameObjectWithTag("DataContainer");
        oneill         = GameObject.FindGameObjectWithTag("OneillCenter");

        guy = data_container.GetComponent <DataContainer>().character;

        transformation = GetComponent <Transform>();
        controller     = GetComponent <CharacterController>();
        collider       = GetComponent <CapsuleCollider>();

        current_grounded  = true;
        previous_grounded = true;

        angular_speed = Mathf.Sqrt((speed * speed / 2.0f));

        time_fake    = 0.01666f;
        gravity_fake = (Physics.gravity.y * time_fake);

        lean = Quaternion.Euler(0, 0, 0);

        is_squatting = false;

        is_walking = false;
    }
예제 #3
0
        private void OnGUI()
        {
            var localSharedData = LocalSharedData;

            EditorGUI.BeginChangeCheck();

            GUILayout.Label("Local", EditorStyles.boldLabel);
            localSharedData.value = (SharedEditorData)EditorGUILayout.ObjectField("Local Shared Data", localSharedData.value, typeof(SharedEditorData), false);
            EditorGUILayout.HelpBox("Local Shared Data asset is a Database that holds all Overmodded.UnityEditor data that then can be used the in game. " +
                                    "This asset can be shared over other editors to get access to it's records. " +
                                    "(For ex. you can get reference to character defined in another unity editor project.)", MessageType.Info, true);

            EditorGUILayout.Space();
            GUILayout.Label("External", EditorStyles.boldLabel);
            var external = SharedEditorDataManager.GetListOfExternalEditorData();

            EditorGUILayout.LabelField("Total of", external.Count + " external SharedEditorData assets.");
            foreach (var e in external)
            {
                // TODO: Draw object fields.
            }

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RegisterCompleteObjectUndo(this, "SharedConfigWindow.Change");

                LocalSharedData = localSharedData;
            }
        }
예제 #4
0
    // Start is called before the first frame update
    void Start()
    {
        data_container = GameObject.FindGameObjectWithTag("DataContainer");
        guy            = Serialization.Load <SavedObject>(Application.persistentDataPath + "/saves/savedgames/auxiliary/character.dat");

        transformation = GetComponent <Transform>();
        controller     = GetComponent <CharacterController>();
        collider       = GetComponent <CapsuleCollider>();

        current_grounded  = true;
        previous_grounded = true;

        angular_speed = Mathf.Sqrt((speed * speed / 2.0f));

        time_fake    = 0.01666f;
        gravity_fake = Physics.gravity.y * time_fake;

        lean = Quaternion.Euler(0, 0, 0);

        is_squatting = false;

        is_walking = false;

        //height_standing = this.gameObject.GetComponent<CharacterController>().height;
        //height_squatting = this.gameObject.GetComponent<CharacterController>().height / 2;
    }
예제 #5
0
    public static void ChangeInstanceType()
    {
        var start = new HostObject {
            nested = new DerivedObject {
                c = 5
            }
        };

        var end = new HostObject {
            nested = new SimpleObject {
                a = 1,
                b = 2
            }
        };

        var startModel = new SavedObject(start);
        var endModel   = new SavedObject(end);

        var delta = new SavedObjectDelta(startModel, endModel);

        delta.ApplyChanges(ref end);

        Assert.AreEqual(start.nested.GetType(), end.nested.GetType());
        Assert.AreEqual(start.nested.a, end.nested.a);
        Assert.AreEqual(start.nested.b, end.nested.b);
        Assert.AreEqual(((DerivedObject)start.nested).c, ((DerivedObject)end.nested).c);
    }
예제 #6
0
    // Start is called before the first frame update
    void Start()
    {
        Time.timeScale   = 1f;
        Cursor.lockState = CursorLockMode.Locked;

        guy = data_container.GetComponent <DataContainer>().character;

        if (data_container.GetComponent <DataContainer>().character.rotation_x != null &&
            Serialization.SaveExists(Application.persistentDataPath + "/saves/savedgames/"
                                     + PlayerPrefs.GetString("saved_game_slot") + "/character.dat")) // It will be necessary to alter the position and rotation of the character when entering a new scene
        {
            character.GetComponent <CharacterController>().enabled = false;

            character.transform.SetPositionAndRotation(
                new Vector3(guy.position_x, guy.position_y, guy.position_z),
                Quaternion.Euler(guy.rotation_x, guy.rotation_y, guy.rotation_z));



            character.GetComponent <CharacterController>().enabled = true;

            camera.GetComponent <PlayerLooking>().enabled = false;

            camera.transform.rotation = Quaternion.Euler(guy.rotation_x, guy.rotation_y, guy.rotation_z);

            camera.GetComponent <PlayerLooking>().enabled = true;
        }
    }
예제 #7
0
    public void DestroyOrChange()
    {
        if (Serialization.SaveExists(
                Application.persistentDataPath + "/saves/savedgames/"
                + PlayerPrefs.GetString("saved_game_slot")
                + "/" + SceneManager.GetActiveScene().name
                + "/presentitems/" + this.gameObject.transform.position.sqrMagnitude + ".dat"))
        {
            object_data = Serialization.Load <SavedObject>(Application.persistentDataPath + "/saves/savedgames/"
                                                           + PlayerPrefs.GetString("saved_game_slot")
                                                           + "/" + SceneManager.GetActiveScene().name
                                                           + "/presentitems/" + this.gameObject.transform.position.sqrMagnitude + ".dat");

            this.gameObject.transform.rotation = Quaternion.Euler(
                object_data.rotation_x,
                object_data.rotation_y,
                object_data.rotation_z);

            this.gameObject.transform.position = new Vector3(
                object_data.position_x,
                object_data.position_y,
                object_data.position_z);
        }
        else
        {
            GameObject.Destroy(object_in_question);
        }
    }
예제 #8
0
 // Token: 0x06000F4A RID: 3914 RVA: 0x0003A91C File Offset: 0x00038B1C
 public WorldSave.Builder SetInstanceObject(int index, SavedObject value)
 {
     ThrowHelper.ThrowIfNull(value, "value");
     this.PrepareBuilder();
     this.result.instanceObject_[index] = value;
     return(this);
 }
        /// <summary>Tasks performed when a mod message is received.</summary>
        private void ModMessageReceived(object sender, ModMessageReceivedEventArgs e)
        {
            if (Context.IsMainPlayer != true)
            {
                return;
            }                                             //if the player using this mod is a multiplayer farmhand, don't do anything; most of this mod's functions should be limited to the host player

            if (e.FromModID != ModManifest.UniqueID)
            {
                return;
            }                                                    //if this message is from another mod, don't do anything

            //handle SavedObject messages
            if (e.Type.Equals("SavedObject", StringComparison.OrdinalIgnoreCase))
            {
                SavedObject save = e.ReadAs <SavedObject>(); //get the saved object

                /*
                 * NOTE: This is a messy solution to saving objects that weren't generated directly by a FarmConfig, which means they aren't associated with a SavedObjects list.
                 *       For now, the objects will be added to the first available FarmData entry and forced to expire overnight (preventing them actually being written to a file).
                 */

                save.DaysUntilExpire = 1;                            //set the object to expire overnight
                Utility.FarmDataList[0].Save.SavedObjects.Add(save); //store it in the first listed FarmData
            }
        }
예제 #10
0
            //this override caues GrubFTM to spawn FlyFTM, rather than the base game's Fly
            public override void behaviorAtGameTick(GameTime time)
            {
                base.behaviorAtGameTick(time); //perform Grub's normal method

                //if this spawns a Fly, replace it with a FlyFTM (note: this method is used to avoid overriding the entire method & working around readonly object fields)
                if (Health == -500 && currentLocation.characters[currentLocation.characters.Count - 1] is Fly oldFly)
                {
                    int    ID     = Utility.RNG.Next(int.MinValue, -1);                        //generate a random ID for saving purposes (note: the ID is below -1 to avoid matching any known NPC values set by base game functions)
                    FlyFTM newFly = new FlyFTM(oldFly.Position, oldFly.hard)                   //make a replacement fly of the correct subclass
                    {
                        currentLocation = oldFly.currentLocation,                              //set its current location
                        id = ID                                                                //assign the ID to it
                    };
                    currentLocation.characters[currentLocation.characters.Count - 1] = newFly; //replace the old fly with the new one

                    SavedObject save = new SavedObject()                                       //create save data for the new fly (set to expire overnight)
                    {
                        MapName         = currentLocation.Name,
                        Tile            = Position,
                        Type            = SavedObject.ObjectType.Monster,
                        ID              = ID,
                        DaysUntilExpire = 1
                    };

                    if (Context.IsMainPlayer)                                //if this method was run by the host player
                    {
                        Utility.FarmDataList[0].Save.SavedObjects.Add(save); //store the save data in the first listed FarmData
                    }
                    else //if this method was run by a client player (farmhand)
                    {
                        //send a message to the host player to process this save data
                        Utility.Helper.Multiplayer.SendMessage <SavedObject>(save, "SavedObject", new string[] { Utility.Helper.ModRegistry.ModID }, new long[] { Game1.MasterPlayer.UniqueMultiplayerID });
                    }
                }
            }
예제 #11
0
 // Token: 0x06000F4C RID: 3916 RVA: 0x0003A97C File Offset: 0x00038B7C
 public WorldSave.Builder AddInstanceObject(SavedObject value)
 {
     ThrowHelper.ThrowIfNull(value, "value");
     this.PrepareBuilder();
     this.result.instanceObject_.Add(value);
     return(this);
 }
    // Start is called before the first frame update
    void Start()
    {
        counter = 0;

        data_container = GameObject.FindGameObjectWithTag("DataContainer");

        Cursor.lockState = CursorLockMode.Locked;

        guy = data_container.GetComponent <DataContainer>().character;

        data_container.GetComponent <DataContainer>().game.current_scene_name = SceneManager.GetActiveScene().name;

        //Debug.Log(guy.rotation_x + " " + guy.rotation_y + " " + guy.rotation_z);
        if (guy.position_x == 0 && guy.position_y == 0 && guy.position_z == 0)
        {
            character = GameObject.Instantiate(Resources.Load <GameObject>(character_model_name),
                                               new Vector3(start_location_default.x, start_location_default.y, start_location_default.z),
                                               Quaternion.Euler(guy.rotation_x, guy.rotation_y, guy.rotation_z));
        }
        else
        {
            character = GameObject.Instantiate(Resources.Load <GameObject>(character_model_name),
                                               new Vector3(guy.position_x, guy.position_y, guy.position_z),
                                               Quaternion.Euler(guy.rotation_x, guy.rotation_y, guy.rotation_z));
        }

        // The scene's backup camera is deleted, so that the player character's camera can work.
        GameObject.FindGameObjectWithTag("CameraBackup").SetActive(false);

        // The camera is instantiated
        camera = Resources.Load <Camera>("CameraPrefab");

        // The player character has the camera attached to the main body's camera anchor
        Universals.BuildCharacter(character, camera);
    }
예제 #13
0
        protected string GetPrayerBlogs()
        {
            string    sql = "Select * from PrayerRequest Inner Join Users on Users.ID = PrayerRequest.UserID order by PrayerRequest.Added desc";
            DataTable dt  = new DataTable();

            try
            {
                dt = gData.GetDataTable2(sql);
            }catch (Exception)
            {
                MsgBox("Error", "Contact [email protected]", this);
            }
            string html = "<table class=saved><tr><th width=20%>User</th><th width=20%>Added<th width=50%>Subject";

            for (int y = 0; y < dt.Rows.Count; y++)
            {
                SavedObject s         = RowToObject(dt.Rows[y]);
                string      sUserName = NotNull(s.Props.UserName);
                if (sUserName == "")
                {
                    sUserName = "******";
                }
                string sAnchor = "<a href='PrayerView.aspx?id=" + s.Props.id.ToString() + "'>";

                string div = sAnchor + "<tr><td>" + DataOps.GetAvatar(s.Props.Picture) + "&nbsp;"
                             + sUserName + "</td>" + UICommon.GetTd(dt.Rows[y], "Added", sAnchor)
                             + UICommon.GetTd(dt.Rows[y], "subject", sAnchor) + "</tr>";
                html += div + "\r\n";
            }
            html += "</table>";
            return(html);
        }
예제 #14
0
    // Start is called before the first frame update
    void Start()
    {
        //data_container = GameObject.FindGameObjectWithTag("DataContainer");
        data_container = Universals.GetDataContainer();

        guy = data_container.GetComponent <DataContainer>().character;

        Cursor.lockState = CursorLockMode.Locked;

        accelerator_x = 0;
        accelerator_y = 0;
        accelerator_z = 0;

        md = new Vector2();

        controller = GetComponent <CharacterController>();

        usage_target      = null;
        current_grounded  = true;
        previous_grounded = true;
        is_walking        = false;

        mouse_look.y = transform.localRotation.x; //data_container.character.rotation_y;//-transform.localRotation.x;
        mouse_look.x = guy.rotation_y;            //character.transform.localRotation.y;

        DoOnStart();
    }
예제 #15
0
    public static void RunCollectionApplyTest()
    {
        var start = new CollectionHolder();

        start.dict["foo1"] = "bar1";
        start.dict["foo2"] = "bar2";
        start.list         = new List <int> {
            1, 2
        };
        start.arr = new[] { true, false };

        var end = new CollectionHolder();

        end.dict["foo1"] = "baz";
        end.list         = new List <int> {
            1, 3, 4
        };
        end.arr = new bool[] { };

        // Compute in-memory representation.
        var startModel = new SavedObject(start);
        var endModel   = new SavedObject(end);

        // Compute differental.
        var delta = new SavedObjectDelta(startModel, endModel);

        // Apply differental.
        delta.ApplyChanges(ref end);

        // Compare.
        CollectionAssert.AreEqual(start.dict, end.dict);
        CollectionAssert.AreEqual(start.list, end.list);
        CollectionAssert.AreEqual(start.arr, end.arr);
    }
예제 #16
0
    public static void RunCollectionTest()
    {
        var obj = new CollectionHolder();

        obj.dict["foo1"] = "bar1";
        obj.dict["foo2"] = "bar2";
        obj.list.Add(1);
        obj.list.Add(2);
        obj.arr    = new[] { true, false };
        obj.nested = new CollectionHolder();
        obj.nested.dict["nested1"] = "ack1";
        obj.nested.arr             = new[] { true };

        Dictionary <ObjectDataPath[], object> model         = new SavedObject(obj).state;
        Dictionary <string, object>           readableModel = SavedObjectDelta.ReadableModel(model);

        // TODO: If list is null, we will include it, but if it is empty we will
        //       not

        Assert.AreEqual(11, readableModel.Count);
        Assert.AreEqual(obj.GetType(), readableModel["GetType()"]);
        Assert.AreEqual("bar1", readableModel["dict.foo1"]);
        Assert.AreEqual("bar2", readableModel["dict.foo2"]);
        Assert.AreEqual(1, readableModel["list.0"]);
        Assert.AreEqual(2, readableModel["list.1"]);
        Assert.AreEqual(true, readableModel["arr.0"]);
        Assert.AreEqual(false, readableModel["arr.1"]);
        Assert.AreEqual(obj.nested.GetType(), readableModel["nested:GetType()"]);
        Assert.AreEqual("ack1", readableModel["nested:dict.nested1"]);
        Assert.AreEqual(true, readableModel["nested:arr.0"]);
        Assert.AreEqual(null, readableModel["nested:nested"]);
    }
    public virtual void InstantiateObjectData()
    {
        if (this.object_data == null)
        {
            this.object_data = new SavedObject();
        }

        if (this.object_data.ints == null)
        {
            this.object_data.ints = new List <int>();
        }

        if (this.object_data.floats == null)
        {
            this.object_data.floats = new List <float>();
        }

        if (this.object_data.strings == null)
        {
            this.object_data.strings = new List <string>();
        }

        if (this.object_data.bools == null)
        {
            this.object_data.bools = new List <bool>();
        }

        if (this.object_data.objects == null)
        {
            this.object_data.objects = new List <SavedObject>();
        }
    }
예제 #18
0
    public static void ChangeInstanceType()
    {
        var start = new HostObject {
            nested = new DerivedObject {
                c = 5
            }
        };

        var end = new HostObject {
            nested = new SimpleObject {
                a = 1,
                b = 2
            }
        };

        var startModel = new SavedObject(start);
        var endModel = new SavedObject(end);

        var delta = new SavedObjectDelta(startModel, endModel);
        delta.ApplyChanges(ref end);

        Assert.AreEqual(start.nested.GetType(), end.nested.GetType());
        Assert.AreEqual(start.nested.a, end.nested.a);
        Assert.AreEqual(start.nested.b, end.nested.b);
        Assert.AreEqual(((DerivedObject)start.nested).c, ((DerivedObject)end.nested).c);
    }
예제 #19
0
        protected string GetSponsoredOrphanList()
        {
            UpdateBBPPrices();
            string    sql  = "Select * from SponsoredOrphan where UserID is null and matchpercentage > .01 order by MatchPercentage desc";
            DataTable dt   = gData.GetDataTable2(sql);
            string    html = "<table class=saved><tr><th>Child ID</th><th>Child Name<th>Added<th>Cost per Month<th>Rebate % Available<th>Monthly Rebate Amount<th>Net Due per Month<th>Net Due in USD<th>About this Charity<th>Sponsor Now</tr>";

            for (int y = 0; y < dt.Rows.Count; y++)
            {
                SavedObject s          = RowToObject(dt.Rows[y]);
                string      sAnchor    = "<a target='_blank' href='" + s.Props.URL + "'>" + s.Props.Name + "</a>";
                double      nRebate    = GetBBPAmountDouble(s.Props.MonthlyAmount) * GetDouble(s.Props.MatchPercentage);
                double      nUSDRebate = s.Props.MonthlyAmount * s.Props.MatchPercentage;
                double      nUSDTotal  = s.Props.MonthlyAmount - nUSDRebate;

                double nNetTotal    = GetBBPAmountDouble(GetDouble(s.Props.MonthlyAmount)) - nRebate;
                string sID          = dt.Rows[y]["id"].ToString();
                string sSponsorLink = "SponsorOrphanList?action=sponsornow&id=" + sID;

                string sSponsorAnchor = "<div><a href=\"" + sSponsorLink + "\"><input type='button' id='btnsponsornow' submit='true' value='Sponsor Me' style='width:140px' /></a></div>";

                string sCharityName = dt.Rows[y]["Charity"].ToString();

                string sAboutCharityLink = "<a target='_blank' href='" + "'>" + sCharityName + "</a>";

                string a1 = "<tr><td>" + s.Props.ChildID + "<td>" + sAnchor + "<td>"
                            + (s.Props.Added).ToString() + "<td>"
                            + GetBBPAmount(GetDouble(s.Props.MonthlyAmount))
                            + "<td>" + GetPerc(s.Props.MatchPercentage) + "<td>" + Math.Round(nRebate, 2).ToString()
                            + " BBP<td>" + Math.Round(nNetTotal, 2).ToString() + " BBP<td>$" + FormatTwoPlaces(nUSDTotal) + "<td>" + sAboutCharityLink + "<td>" + sSponsorAnchor + "</td></tr>";
                html += a1 + "\r\n";
            }
            html += "</table>";
            return(html);
        }
    public void DestroyOrChange()
    {
        if (Serialization.SaveExists(
                Application.persistentDataPath + "/saves/savedgames/auxiliary/"
                + SceneManager.GetActiveScene().name
                + "/presentitems/" + this.id + ".dat"))
        {
            object_data = Serialization.Load <SavedObject>(Application.persistentDataPath + "/saves/savedgames/auxiliary/"
                                                           + SceneManager.GetActiveScene().name
                                                           + "/presentitems/" + this.id + ".dat");

            Debug.Log(object_data == null);

            this.gameObject.transform.rotation = Quaternion.Euler(
                object_data.rotation_x,
                object_data.rotation_y,
                object_data.rotation_z);

            this.gameObject.transform.position = new Vector3(
                object_data.position_x,
                object_data.position_y,
                object_data.position_z);
        }
        else
        {
            Debug.Log("Item destroyed: " + this.id);
            Destroy();
        }
    }
예제 #21
0
    private static void LoadPeg(GameObject LoadedObject, SavedObject save)
    {
        object[]     data  = save.CustomDataArray;
        CircuitInput input = LoadedObject.GetComponent <CircuitInput>();

        input.On = (bool)data[0];
    }
예제 #22
0
    public static void RunSimpleApplyTest()
    {
        var start = new SimpleObject {
            a      = 1,
            b      = 2,
            nested = new SimpleObject {
                a = 3,
                b = 4
            }
        };

        var end = new SimpleObject {
            a = 2,
            b = 2
        };

        var startModel = new SavedObject(start);
        var endModel   = new SavedObject(end);
        var delta      = new SavedObjectDelta(startModel, endModel);

        delta.ApplyChanges(ref end);

        Assert.AreEqual(end.a, start.a);
        Assert.AreEqual(end.b, start.b);
        Assert.AreEqual(end.nested.a, start.nested.a);
        Assert.AreEqual(end.nested.b, start.nested.b);
        Assert.AreEqual(end.nested.nested, start.nested.nested);
    }
예제 #23
0
    public void Save()
    {
        int          i       = 0;
        GameObject   go      = GameObject.Find("GridHolder");
        SavedObjects circles = new SavedObjects();

        circles.savedObjects = new List <SavedObject>();

        foreach (Transform child in go.transform)
        {
            SavedObject savedObject = new SavedObject();

            float   x     = child.position.x;
            float   y     = child.position.y;
            Vector2 vec   = new Vector2(x, y);
            Color   color = child.gameObject.GetComponent <SpriteRenderer>().color;

            savedObject.circlePos = vec;
            savedObject.color     = color;

            circles.savedObjects.Add(savedObject);

            i = i + 1;
        }
        string json = JsonUtility.ToJson(circles);

        File.WriteAllText(Application.dataPath + "/save.txt", json);
    } //endsave
예제 #24
0
    private static void LoadLabel(GameObject LoadedObject, SavedObject save)
    {
        object[] data  = save.CustomDataArray;
        Label    label = LoadedObject.GetComponent <Label>();

        label.text.text     = (string)data[0];
        label.text.fontSize = (float)data[1];
    }
예제 #25
0
    private static void LoadDisplay(GameObject LoadedObject, SavedObject save)
    {
        object[] data    = save.CustomDataArray;
        Display  display = LoadedObject.GetComponentInChildren <Display>();

        display.DisplayColor = DisplayColor.Yellow;
        display.Input.On     = (bool)data[0];
    }
예제 #26
0
 public void ReadObjectSave(ref SavedObject saveobj)
 {
     if (!saveobj.HasFireBarrel)
     {
         return;
     }
     this.SetOn(saveobj.FireBarrel.OnFire);
 }
예제 #27
0
    private static void LoadBlotter(GameObject LoadedObject, SavedObject save)
    {
        object[] data    = save.CustomDataArray;
        Blotter  blotter = LoadedObject.GetComponent <Blotter>();

        blotter.Input.On  = (bool)data[0];
        blotter.Output.On = (bool)data[1];
    }
예제 #28
0
    private static void LoadInverter(GameObject LoadedObject, SavedObject save)
    {
        object[] data    = save.CustomDataArray;
        Inverter notgate = LoadedObject.GetComponent <Inverter>();

        notgate.Input.On  = (bool)data[0];
        notgate.Output.On = (bool)data[1];
    }
예제 #29
0
    private static void LoadThroughPeg(GameObject LoadedObject, SavedObject save)
    {
        object[]       data   = save.CustomDataArray;
        CircuitInput[] inputs = LoadedObject.GetComponentsInChildren <CircuitInput>();

        inputs[0].On = (bool)data[0];
        inputs[1].On = (bool)data[0];
    }
예제 #30
0
    private static void LoadSwitch(GameObject LoadedObject, SavedObject save)
    {
        object[] data          = save.CustomDataArray;
        Switch   circuitswitch = LoadedObject.GetComponentInChildren <Switch>();

        circuitswitch.On = (bool)data[0];
        circuitswitch.UpdateLever(false); // apply the effects of the bool we just loaded, don't play sound
    }
예제 #31
0
 public void ReadObjectSave(ref SavedObject saveobj)
 {
     if (saveobj.HasDeployable)
     {
         this.creatorID = saveobj.Deployable.CreatorID;
         this.ownerID   = saveobj.Deployable.OwnerID;
     }
 }
        public static void ShowInspectorForSerializedObject(UnityObject[] targets)
        {
            CheckForNewBaseBehaviorType(targets[0].GetType());
            DrawOpenScriptButton(targets[0]);

            // TODO: How do we show a mixed value?
            // TODO: We could have a global call of some sort?
            // TODO: We have the edit path w.r.t. metadata, so we can compute the
            //       deltas at the start and then export it as a list which
            //       property editors can check against.

            // Capture object state if we are doing multi-object editing.
            var preeditState = new SavedObject();
            if (fiSettings.EnableMultiEdit && targets.Length > 1)
                preeditState = new SavedObject(targets[0]);

            // Run the editor
            BehaviorEditor.Get(targets[0].GetType()).EditWithGUILayout(targets[0]);

            // Inspector for the serialized state
            var inspectedObject = targets[0] as ISerializedObject;
            if (inspectedObject != null) {
                EditorGUI.BeginChangeCheck();
                DrawSerializedState(inspectedObject);
                if (EditorGUI.EndChangeCheck()) {
                    EditorUtility.SetDirty(targets[0]);
                    inspectedObject.RestoreState();
                }
            }

            // Apply changes to other objects that are being edited.
            if (fiSettings.EnableMultiEdit && targets.Length > 1) {
                var posteditState = new SavedObject(targets[0]);
                var delta = new SavedObjectDelta(posteditState, preeditState);
                for (int i = 1; i < targets.Length; ++i) {
                    UnityObject obj = targets[i];
                    delta.ApplyChanges(ref obj);
                }
            }
        }
예제 #33
0
 public void ReadObjectSave(ref SavedObject saveobj)
 {
     if (saveobj.HasDeployable)
     {
         this.creatorID = saveobj.Deployable.CreatorID;
         this.ownerID = saveobj.Deployable.OwnerID;
     }
 }
예제 #34
0
    public static void CycleTest()
    {
        // TODO: This needs to be fixed. The cyclic object should appear in the
        //       dict.
        Debug.LogError("Fix CycleTest to include cycled object");

        var obj = new SimpleObject();
        obj.a = 1;
        obj.b = 2;
        obj.nested = obj;

        Dictionary<ObjectDataPath[], object> model = new SavedObject(obj).state;
        Dictionary<string, object> readableModel = SavedObjectDelta.ReadableModel(model);

        Assert.AreEqual(3, readableModel.Count);
        Assert.AreEqual(obj.GetType(), readableModel["GetType()"]);
        Assert.AreEqual(obj.a, readableModel["a"]);
        Assert.AreEqual(obj.b, readableModel["b"]);
        //Assert.AreEqual(obj.nested, readableModel["nested"]);

        // Also test vectors, which are cyclic on normalized
        new SavedObject(new Vector3(1, 1, 1));
    }
예제 #35
0
    public static void RunCollectionApplyTest()
    {
        var start = new CollectionHolder();
        start.dict["foo1"] = "bar1";
        start.dict["foo2"] = "bar2";
        start.list = new List<int> { 1, 2 };
        start.arr = new[] { true, false };

        var end = new CollectionHolder();
        end.dict["foo1"] = "baz";
        end.list = new List<int> { 1, 3, 4 };
        end.arr = new bool[] { };

        // Compute in-memory representation.
        var startModel = new SavedObject(start);
        var endModel = new SavedObject(end);

        // Compute differental.
        var delta = new SavedObjectDelta(startModel, endModel);

        // Apply differental.
        delta.ApplyChanges(ref end);

        // Compare.
        CollectionAssert.AreEqual(start.dict, end.dict);
        CollectionAssert.AreEqual(start.list, end.list);
        CollectionAssert.AreEqual(start.arr, end.arr);
    }
예제 #36
0
    public static void RunCollectionTest()
    {
        var obj = new CollectionHolder();
        obj.dict["foo1"] = "bar1";
        obj.dict["foo2"] = "bar2";
        obj.list.Add(1);
        obj.list.Add(2);
        obj.arr = new[] { true, false };
        obj.nested = new CollectionHolder();
        obj.nested.dict["nested1"] = "ack1";
        obj.nested.arr = new[] { true };

        Dictionary<ObjectDataPath[], object> model = new SavedObject(obj).state;
        Dictionary<string, object> readableModel = SavedObjectDelta.ReadableModel(model);

        // TODO: If list is null, we will include it, but if it is empty we will
        //       not

        Assert.AreEqual(11, readableModel.Count);
        Assert.AreEqual(obj.GetType(), readableModel["GetType()"]);
        Assert.AreEqual("bar1", readableModel["dict.foo1"]);
        Assert.AreEqual("bar2", readableModel["dict.foo2"]);
        Assert.AreEqual(1, readableModel["list.0"]);
        Assert.AreEqual(2, readableModel["list.1"]);
        Assert.AreEqual(true, readableModel["arr.0"]);
        Assert.AreEqual(false, readableModel["arr.1"]);
        Assert.AreEqual(obj.nested.GetType(), readableModel["nested:GetType()"]);
        Assert.AreEqual("ack1", readableModel["nested:dict.nested1"]);
        Assert.AreEqual(true, readableModel["nested:arr.0"]);
        Assert.AreEqual(null, readableModel["nested:nested"]);
    }
예제 #37
0
    public static void RunFieldPropertyTest()
    {
        var obj = new SimpleObject {
            a = 1,
            b = 2,
            nested = new SimpleObject {
                a = 3,
                b = 4
            }
        };
        Dictionary<ObjectDataPath[], object> model = new SavedObject(obj).state;
        Dictionary<string, object> readableModel = SavedObjectDelta.ReadableModel(model);

        Assert.AreEqual(7, readableModel.Count);
        Assert.AreEqual(obj.GetType(), readableModel["GetType()"]);
        Assert.AreEqual(1, readableModel["a"]);
        Assert.AreEqual(2, readableModel["b"]);
        Assert.AreEqual(obj.nested.GetType(), readableModel["nested:GetType()"]);
        Assert.AreEqual(3, readableModel["nested:a"]);
        Assert.AreEqual(4, readableModel["nested:b"]);
        Assert.AreEqual(null, readableModel["nested:nested"]);
    }
예제 #38
0
    public static void RunSimpleApplyTest()
    {
        var start = new SimpleObject {
            a = 1,
            b = 2,
            nested = new SimpleObject {
                a = 3,
                b = 4
            }
        };

        var end = new SimpleObject {
            a = 2,
            b = 2
        };

        var startModel = new SavedObject(start);
        var endModel = new SavedObject(end);
        var delta = new SavedObjectDelta(startModel, endModel);

        delta.ApplyChanges(ref end);

        Assert.AreEqual(end.a, start.a);
        Assert.AreEqual(end.b, start.b);
        Assert.AreEqual(end.nested.a, start.nested.a);
        Assert.AreEqual(end.nested.b, start.nested.b);
        Assert.AreEqual(end.nested.nested, start.nested.nested);
    }
예제 #39
0
    public static void SimpleIntegrationExample()
    {
        var inspected = new SimpleObject() {
            a = 1,
            b = 2
        };
        var previousState = new SavedObject(inspected);

        inspected.a = 5;

        var currentState = new SavedObject(inspected);

        var delta = new SavedObjectDelta(currentState, previousState);

        var hello = new SimpleObject();
        delta.ApplyChanges(ref hello);

        Assert.AreEqual(5, hello.a);
        Assert.AreEqual(0, hello.b);
    }
예제 #40
0
 public void WriteObjectSave(ref SavedObject.Builder saveobj)
 {
     NetEntityID netEntityID;
     using (Recycler<objectDeployable, objectDeployable.Builder> recycler = objectDeployable.Recycler())
     {
         objectDeployable.Builder builder = recycler.OpenBuilder();
         builder.SetCreatorID(this.creatorID);
         builder.SetOwnerID(this.ownerID);
         saveobj.SetDeployable(builder);
     }
     using (Recycler<objectICarriableTrans, objectICarriableTrans.Builder> recycler1 = objectICarriableTrans.Recycler())
     {
         objectICarriableTrans.Builder builder1 = recycler1.OpenBuilder();
         if (!this._carrier || (int)NetEntityID.Of(this._carrier, out netEntityID) == 0)
         {
             builder1.ClearTransCarrierID();
         }
         else
         {
             builder1.SetTransCarrierID(netEntityID.id);
         }
         saveobj.SetCarriableTrans(builder1);
     }
 }