using System.Collections; using System.Collections.Generic; using UnityEngine; public class GhostCommand : ICommand { string _nameGhostObject; bool _makeGhost; bool _previousState; public GhostCommand(string nameGhostObject, bool isMakeGhost, bool previousState) { _nameGhostObject = nameGhostObject; _makeGhost = isMakeGhost; _previousState = previousState; Debug.Assert(GameObject.Find(_nameGhostObject) != null, "No object found to toggle ghost collisions."); } public void Execute() { TurnGhost(true); UpdateGhostList(_makeGhost); if (SceneModeManager.SelectedName == _nameGhostObject) { SetActiveGhostButton(_makeGhost); } } public string GetAction() { return _makeGhost ? "Deactivate Collisions" : "Activate Collisions"; } public void Undo() { TurnGhost(false); UpdateGhostList(!_makeGhost); if (SceneModeManager.SelectedName == _nameGhostObject) { SetActiveGhostButton(!_makeGhost); } } public void UpdateCommand() { return; } public void TurnGhost(bool isExecute) { GameObject go = GameObject.Find(_nameGhostObject); MoveObject moveObject = go.GetComponent(); moveObject.IgnoreCollision = isExecute ? _makeGhost : _previousState; } private void UpdateGhostList(bool setGhost) { if (setGhost) { _G.GHOSTLIST.Add(_nameGhostObject); } else { _G.GHOSTLIST.Remove(_nameGhostObject); } } static public void SetActiveGhostButton(bool setGhost) { GameObject objectControl = Get.o1("HIDER/CONTROL"); if (objectControl == null) { return; } GameObject iconGhost = objectControl.transform.Find("Ghost").gameObject; if (iconGhost != null) { iconGhost.SetActive(setGhost); } } }