示例#1
0
        void _SerializeToJson()
        {
            var info       = new MechanicDoorSaveInfo();
            var switchList = new List <Switch>();

            door           = GetComponent <MechanicDoor>();
            signalReceiver = GetComponent <SwitchSignalReceiver>();

            if (signalReceiver && door)
            {
                info.open           = door.IsOpen;
                info.allowEnter     = door.IsAllowEnter;
                info.useInstantOpen = door.IsUseInstantOpen;

                foreach (var obj in signalReceiver.Switches)
                {
                    if (obj)
                    {
                        switchList.Add(obj);
                    }
                }

                info.switchStates = new bool[switchList.Count];

                for (int i = 0; i < switchList.Count; i++)
                {
                    info.switchStates[i] = switchList[i].IsTurnOn;
                }
            }

            json = JsonConvert.SerializeObject(info, Formatting.None);
        }
示例#2
0
        void _DeserializeToInfo(string json)
        {
            var info = JsonConvert.DeserializeObject <MechanicDoorSaveInfo>(json);

            door           = GetComponent <MechanicDoor>();
            signalReceiver = GetComponent <SwitchSignalReceiver>();

            if (signalReceiver && door)
            {
                door.IsOpen           = info.open;
                door.IsAllowEnter     = info.allowEnter;
                door.IsUseInstantOpen = info.useInstantOpen;

                for (int i = 0; i < info.switchStates.Length; i++)
                {
                    signalReceiver.Switches[i].IsTurnOn = info.switchStates[i];
                }
            }
        }
示例#3
0
 protected override void Awake()
 {
     base.Awake();
     signalReceiver = GetComponent <SwitchSignalReceiver>();
 }