コード例 #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
        public override void FinishLoad()
        {
            if (!door)
            {
                door = GetComponent <MechanicDoor>();
            }

            if (door)
            {
                if (door.DoorType == Door.TargetType.Scene)
                {
                    var expectID = GameController.expectDoorWrapID;
                    if (expectID == door.WrapID)
                    {
                        GameController.expectDoor = this.gameObject;
                    }
                }
            }
            else
            {
                Debug.Log("Can't find ref of door.");
            }
        }