graph TD
A[ View ]
B[ ViewModel ]
C[ Model ]
A -->| User Interaction | B
B -->| Notify Changes | A
B <-->| Data Binding | A
B -->| Calls | C
C -->| Data | B
publicclassBindableProperty<T> { publicdelegatevoidValueChangedHandler(T oldValue, T newValue);
publicevent ValueChangedHandler OnValueChanged;
private T _value; public T Value { get { return _value; } set { if (!object.Equals(_value, value)) { T oldValue = _value; _value = value; // 通知值發生改變 OnValueChanged?.Invoke(oldValue, _value); } } }
graph TD
A[ User ] -->| Interacts with | B[ View ]
B -->| Sends user input to | C[ Controller ]
C -->| Updates | D[ Model ]
D -->| Notifies changes to | B[ View ]
B -->| Displays data from | D[ Model ]
graph TD
A[ User ] -->| Interacts with | B[ View ]
B -->| Sends user input to | C[ Presenter ]
C -->| Updates | D[ Model ]
D -->| Notifies changes to | C[ Presenter ]
C -->| Updates | B[ View ]
B -->| Displays data from | C[ Presenter ]
privatevoidUpdate() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, Mathf.Infinity, layerToClick)) { healthPresenter?.Damage(damageValue); } } } }
privatevoidOnDrawGizmosSelected() { Color transparentGreen = new Color(0.0f, 1.0f, 0.0f, 0.35f); Color transparentRed = new Color(1.0f, 0.0f, 0.0f, 0.35f);
publicclassPooledObject : MonoBehaviour { private ObjectPool pool; public ObjectPool Pool { get => pool; set => pool = value; } publicvoidRelease() { pool.ReturnToPool(this); } }
privatevoidGetProductAtClick() { // check click with raycast if (Input.GetMouseButtonDown(0)) { // choose a random factory factory = factories[Random.Range(0, factories.Length)];
// instantiate product at raycast intersection Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, layerToClick) && factory != null) { factory.GetProduct(hitInfo.point + offset); } } } }