From 49b25e755b70ec412feaaf0b898d6f7e09d2bea6 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 28 Jun 2022 09:40:37 +0800 Subject: +node example --- .../LibNoiseEditor/Plugins/LibNoise/ModuleBase.cs | 187 +++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 Other/NodeEditorExamples/Assets/Examples/LibNoiseEditor/Plugins/LibNoise/ModuleBase.cs (limited to 'Other/NodeEditorExamples/Assets/Examples/LibNoiseEditor/Plugins/LibNoise/ModuleBase.cs') diff --git a/Other/NodeEditorExamples/Assets/Examples/LibNoiseEditor/Plugins/LibNoise/ModuleBase.cs b/Other/NodeEditorExamples/Assets/Examples/LibNoiseEditor/Plugins/LibNoise/ModuleBase.cs new file mode 100644 index 00000000..c6cef0f1 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/Examples/LibNoiseEditor/Plugins/LibNoise/ModuleBase.cs @@ -0,0 +1,187 @@ +using System; +using System.Xml.Serialization; +using UnityEngine; +using Debug = System.Diagnostics.Debug; + +namespace LibNoise +{ + + #region Enumerations + + /// + /// Defines a collection of quality modes. + /// + public enum QualityMode + { + Low, + Medium, + High, + } + + #endregion + + /// + /// Base class for noise modules. + /// + public abstract class ModuleBase : IDisposable + { + #region Fields + + private ModuleBase[] _modules; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of Helpers. + /// + /// The number of source modules. + protected ModuleBase(int count) + { + if (count > 0) + { + _modules = new ModuleBase[count]; + } + } + + #endregion + + #region Indexers + + /// + /// Gets or sets a source module by index. + /// + /// The index of the source module to aquire. + /// The requested source module. + public virtual ModuleBase this[int index] + { + get + { + Debug.Assert(_modules != null); + Debug.Assert(_modules.Length > 0); + if (index < 0 || index >= _modules.Length) + { + throw new ArgumentOutOfRangeException("Index out of valid module range"); + } + if (_modules[index] == null) + { + throw new ArgumentNullException("Desired element is null"); + } + return _modules[index]; + } + set + { + Debug.Assert(_modules.Length > 0); + if (index < 0 || index >= _modules.Length) + { + throw new ArgumentOutOfRangeException("Index out of valid module range"); + } + if (value == null) + { + throw new ArgumentNullException("Value should not be null"); + } + _modules[index] = value; + } + } + + #endregion + + #region Properties + protected ModuleBase[] Modules + { + get { return _modules; } + } + + /// + /// Gets the number of source modules required by this noise module. + /// + public int SourceModuleCount + { + get { return (_modules == null) ? 0 : _modules.Length; } + } + + #endregion + + #region Methods + + /// + /// Returns the output value for the given input coordinates. + /// + /// The input coordinate on the x-axis. + /// The input coordinate on the y-axis. + /// The input coordinate on the z-axis. + /// The resulting output value. + public abstract double GetValue(double x, double y, double z); + + /// + /// Returns the output value for the given input coordinates. + /// + /// The input coordinate. + /// The resulting output value. + public double GetValue(Vector3 coordinate) + { + return GetValue(coordinate.x, coordinate.y, coordinate.z); + } + + /// + /// Returns the output value for the given input coordinates. + /// + /// The input coordinate. + /// The resulting output value. + public double GetValue(ref Vector3 coordinate) + { + return GetValue(coordinate.x, coordinate.y, coordinate.z); + } + + #endregion + + #region IDisposable Members + + [XmlIgnore] +#if !XBOX360 && !ZUNE + [NonSerialized] +#endif + private bool _disposed; + + /// + /// Gets a value whether the object is disposed. + /// + public bool IsDisposed + { + get { return _disposed; } + } + + /// + /// Immediately releases the unmanaged resources used by this object. + /// + public void Dispose() + { + if (!_disposed) + { + _disposed = Disposing(); + } + GC.SuppressFinalize(this); + } + + /// + /// Immediately releases the unmanaged resources used by this object. + /// + /// True if the object is completely disposed. + protected virtual bool Disposing() + { + if (_modules != null) + { + for (var i = 0; i < _modules.Length; i++) + { + _modules[i].Dispose(); + _modules[i] = null; + } + _modules = null; + } + return true; + } + + #endregion + } +} \ No newline at end of file -- cgit v1.1-26-g67d0