public static void Copy(ObjectOptions from, ObjectOptions to) { to.Parent = from.Parent; to.MinScale = from.MinScale; to.MaxScale = from.MaxScale; to.RotateX = from.RotateX; to.RotateY = from.RotateY; to.RotateZ = from.RotateZ; to.ScaleX = from.ScaleX; to.ScaleY = from.ScaleY; to.ScaleZ = from.ScaleZ; to.AlignToSurface = from.AlignToSurface; to.UniformScaling = from.UniformScaling; to.ScaleHeightOffset = from.ScaleHeightOffset; to.MinHeightOffset = from.MinHeightOffset; to.MaxHeightOffset = from.MaxHeightOffset; to.MinDot = from.MinDot; to.MaxDot = from.MaxDot; }
public void ObjectInstantiation () { var options = new ObjectOptions (); SetObjectOptions (options); var @object = new Mono.Upnp.Dcp.MediaServer1.ContentDirectory1.Object ("-1", "-1", options); Assert.AreEqual ("-1", @object.Id); AssertObject (@object, options); AssertObject (@object, @object.GetOptions ()); }
public void ObjectInstantiation() { var options = new ObjectOptions(); SetObjectOptions(options); var @object = new Mono.Upnp.Dcp.MediaServer1.ContentDirectory1.Object("-1", "-1", options); Assert.AreEqual("-1", @object.Id); AssertObject(@object, options); AssertObject(@object, @object.GetOptions()); }
static void SetObjectOptions(ObjectOptions options) { options.Title = "1"; options.Creator = "2"; options.WriteStatus = WriteStatus.Protected; options.IsRestricted = true; var resource_options = new ResourceOptions(); SetResourceOptions(resource_options); options.Resources = new[] { new Resource(new Uri("http://0"), resource_options) }; }
protected void CopyToOptions (ObjectOptions options) { if (options == null) { throw new ArgumentNullException ("options"); } options.Title = Title; options.Creator = Creator; options.WriteStatus = WriteStatus; options.IsRestricted = IsRestricted; options.Resources = new List<Resource> (Resources); }
private void tree_MouseUp(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Right) { TreeNode node = tree.GetNodeAt(e.X, e.Y); if (node != null && node.Tag != null) { tree.SelectedNode = node; ObjectOptions objectOptions = (ObjectOptions)node.Tag; if (objectOptions.Options != null) { objectOptions.Options.DisplayOptions(this, contextMenu, e.Location); } } } }
public Object (string id, string parentId, ObjectOptions options) { if (id == null) { throw new ArgumentNullException ("id"); } else if (parentId == null) { throw new ArgumentNullException ("parentId"); } else if (options == null) { throw new ArgumentNullException ("options"); } Id = id; ParentId = parentId; Title = options.Title; Creator = options.Creator; WriteStatus = options.WriteStatus; IsRestricted = options.IsRestricted; Resources = Helper.MakeReadOnlyCopy (options.Resources); Class = new Class (ClassManager.GetClassNameFromType (GetType ())); }
private IObjecOptions ProcessSingleFile(string fileName) { CheckFile(fileName); FileExtensions fileExtension = Containers.GetFileExtension(fileName); IObjecOptions objectOptions = new ObjectOptions(fileName, containers.Find(fileExtension).ObjectType); foreach (var item in optionParams) { if (item.Value) { try { objectOptions.Options.SetProperty(item.Key); } catch (ArgumentException ex) { string message = String.Format(Properties.Resources.InvalidOption, item.Key); throw new CommandLineException(String.Format("{0} {1}", message, Properties.Resources.ForThisObjectType), ex); } } } return(objectOptions); }
/// <summary> /// Returns <c>true</c> if ObjectOptions.TupleFormat is not set. /// </summary> public static bool ShouldUseTupleFormat(this ObjectOptions options) { return((options & ObjectOptions.TupleFormat) == ObjectOptions.TupleFormat); }
/// <summary> /// Returns <c>true</c> if ObjectOptions.IgnoreUnknownKey is not set. /// </summary> public static bool ShouldThrowAtUnknownKey(this ObjectOptions options) { return((options & ObjectOptions.IgnoreUnknownKey) == 0); }
/// <summary> /// Returns <c>true</c> if ObjectOptions.IncludeStatic is not set. /// </summary> public static bool ShouldIgnoreStatic(this ObjectOptions options) { return((options & ObjectOptions.IncludeStatic) == 0); }
/// <summary> /// Returns <c>true</c> if ObjectOptions.IgnoreProperties is set. /// </summary> public static bool ShouldIgnoreProperties(this ObjectOptions options) { return((options & ObjectOptions.IgnoreProperties) == ObjectOptions.IgnoreProperties); }
public JSONObjectAttribute() : base() { _options = ObjectOptions.Default; }
static void AssertObject(Mono.Upnp.Dcp.MediaServer1.ContentDirectory1.Object @object, ObjectOptions options) { Assert.AreEqual(@object.Title, options.Title); Assert.AreEqual(@object.Creator, options.Creator); Assert.AreEqual(@object.WriteStatus, options.WriteStatus); Assert.AreEqual(@object.IsRestricted, options.IsRestricted); Assert.IsTrue(@object.Resources.IsReadOnly); var object_enumerator = @object.Resources.GetEnumerator(); var options_enumerator = options.Resources.GetEnumerator(); Assert.IsTrue(object_enumerator.MoveNext()); Assert.IsTrue(options_enumerator.MoveNext()); AssertResource(object_enumerator.Current, options_enumerator.Current.GetOptions()); }
static void SetObjectOptions (ObjectOptions options) { options.Title = "1"; options.Creator = "2"; options.WriteStatus = WriteStatus.Protected; options.IsRestricted = true; var resource_options = new ResourceOptions (); SetResourceOptions (resource_options); options.Resources = new[] { new Resource (new Uri ("http://0"), resource_options) }; }
static void AssertObject (Mono.Upnp.Dcp.MediaServer1.ContentDirectory1.Object @object, ObjectOptions options) { Assert.AreEqual (@object.Title, options.Title); Assert.AreEqual (@object.Creator, options.Creator); Assert.AreEqual (@object.WriteStatus, options.WriteStatus); Assert.AreEqual (@object.IsRestricted, options.IsRestricted); Assert.IsTrue (@object.Resources.IsReadOnly); var object_enumerator = @object.Resources.GetEnumerator (); var options_enumerator = options.Resources.GetEnumerator (); Assert.IsTrue (object_enumerator.MoveNext ()); Assert.IsTrue (options_enumerator.MoveNext ()); AssertResource (object_enumerator.Current, options_enumerator.Current.GetOptions ()); }
private bool CreateRandomObjectAtLoc(Vector2 loc, float finalMinDistSqrd, out bool objectPlaced, WeightedArray weightedObjects, ObjectOptions[] objectOptions, bool preview) { objectPlaced = false; if (InBounds(loc)) { bool toCloseToProcess = true; // Don't do InNeighbourhood for clumping algorithm if (finalMinDistSqrd <= 0 || (!InNeighbourhood(loc, finalMinDistSqrd, out toCloseToProcess) && !InInnerBounds(loc))) { RaycastHit hit; if (CastRay(loc, out hit)) { int index = weightedObjects.GetRandomObjectIndex(); ObjectOptions options = objectOptions[index]; float dotResult = Vector3.Dot(hit.normal, Vector3.up); if (dotResult >= options.MinDot && dotResult <= options.MaxDot) { Vector3 pos = hit.point; Quaternion rot; Vector3 scale; ApplySettingsToObject(options, hit.normal, ref pos, out rot, out scale); GameObject newObject = weightedObjects.GetGameObject(index); if (newObject != null) { if (_activeData.SphereCollisionCheck || _activeData.BoxCollisionCheck) { Bounds bounds; if (GetBounds(newObject, _activeData.BoundsMode, pos, rot, scale, out bounds)) { if (ModeData.Mode == DistributionMode.Surface) { ModeData.Surface.gameObject.SetActive(false); } bool hasOverlap = true; LayerMask correctedMask = InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(_activeData.OverlapLayerMask); if (_activeData.SphereCollisionCheck) { hasOverlap = CheckSphereOverlap(bounds, correctedMask); } if (_activeData.BoxCollisionCheck && hasOverlap) { hasOverlap = CheckBoxOverlap(bounds, rot, correctedMask); } if (ModeData.Mode == DistributionMode.Surface) { ModeData.Surface.gameObject.SetActive(true); } if (hasOverlap) { return(!toCloseToProcess); } } } } else { return(!toCloseToProcess); } objectPlaced = true; GameObject obj = (GameObject)PrefabUtility.InstantiatePrefab(newObject); obj.transform.position = pos; obj.transform.rotation = rot; obj.transform.localScale = scale; // When not doing this the colliders aren't properly initialized and OverlapXXX won't work obj.SetActive(false); obj.SetActive(true); obj.transform.parent = options.Parent; EditorData.PlacedObjects[_activeLevel].Add(obj); if (_currNestingLevel < _maxNestingLevel) { PoissonPlacer placer = obj.GetComponent <PoissonPlacer>(); if (placer != null && placer.enabled) { PoissonHelper helper = new PoissonHelper(placer); helper.Init(); bool isValidSurface, preValid, currValid, postValid; int highestValid; helper.LoadDataHolder(); helper.ValidateSettings(false, out isValidSurface, out preValid, out currValid, out postValid, out highestValid); placer.EditorData.LastFrameValid = isValidSurface && preValid && currValid && postValid; if (highestValid >= 0) { Random.State randState = Random.state; helper.DistributePoisson(0, highestValid, preview, _currNestingLevel + 1, _maxNestingLevel); Random.state = randState; } helper.StoreDataHolder(); } } } } } return(!toCloseToProcess || objectPlaced); } return(false); }
private void ApplySettingsToObject(ObjectOptions options, Vector3 normalDir, ref Vector3 newPosition, out Quaternion newRotation, out Vector3 newScale) { newScale = new Vector3(1, 1, 1); if (options.UniformScaling == true) { float rand = Random.Range(options.MinScale, options.MaxScale); if (options.ScaleX == true) { newScale.x = rand; } if (options.ScaleY == true) { newScale.y = rand; } if (options.ScaleZ == true) { newScale.z = rand; } } else { if (options.ScaleX == true) { newScale.x = Random.Range(options.MinScale, options.MaxScale); } if (options.ScaleY == true) { newScale.y = Random.Range(options.MinScale, options.MaxScale); } if (options.ScaleZ == true) { newScale.z = Random.Range(options.MinScale, options.MaxScale); } } newRotation = new Quaternion(); if (options.AlignToSurface == true) { Quaternion q1 = (options.RotateY == true) ? Quaternion.AngleAxis(Random.Range(0, 360), normalDir) : Quaternion.identity; Quaternion q2 = Quaternion.FromToRotation(Vector3.up, normalDir); newRotation = q1 * q2; } else { Vector3 eulerAngles = new Vector3(); if (options.RotateX == true) { eulerAngles.x = Random.Range(0.0f, 360.0f); } if (options.RotateY == true) { eulerAngles.y = Random.Range(0.0f, 360.0f); } if (options.RotateZ == true) { eulerAngles.z = Random.Range(0.0f, 360.0f); } newRotation = Quaternion.Euler(eulerAngles); } float heightOffset = Random.Range(options.MinHeightOffset, options.MaxHeightOffset); if (options.ScaleY && options.ScaleHeightOffset) { heightOffset *= newScale.y; } newPosition += normalDir * heightOffset; }
public ObjectOptions GetOptions () { var options = new ObjectOptions (); CopyToOptions (options); return options; }
public JSONObjectAttribute(ObjectOptions options) : base() { _options = options; }
private void CreateOptions(WeightedArray objects, ObjectOptions[] options, ref int selectedIndex, float halfWidth) { bool disabled = (!objects?.HasWeightedElementsNonNull()) ?? true; Color oldColor = GUI.backgroundColor; GUI.backgroundColor = BACKGROUND_COLOR_SUB_MENU; EditorGUILayout.BeginVertical(SubBoxStyle); halfWidth -= (DataHolder.IsWindow) ? BoxMargin : BoxMargin * 0.5f; GUI.backgroundColor = oldColor; using (new EditorGUI.DisabledScope(disabled)) { GUIStyle centerStyle = new GUIStyle(); centerStyle.alignment = TextAnchor.MiddleCenter; string[] objectStrings = null; IEnumerable <Tuple <WeightedObject, int> > objectsNonNull = null; if (!disabled) { objectsNonNull = objects.Objects .Select((o, i) => new Tuple <WeightedObject, int>(o, i)) .Where((o) => o.Item1.Object != null && o.Item1.Weight > 0); objectStrings = objectsNonNull .Select((a, i) => i + ": " + objects.GetChance(a.Item1).ToString("F2") + "%) " + a.Item1.Object.name) .ToArray(); if (selectedIndex >= objectStrings.Count()) { selectedIndex = Mathf.Max(objectStrings.Count() - 1, 0); } } else { objectStrings = new string[] { "" }; selectedIndex = 0; } ObjectOptions selectedOptions; EditorGUILayout.BeginHorizontal(RowStyle); EditorGUILayout.BeginVertical(SubLeftColumnStyle, GUILayout.MaxWidth(halfWidth)); // Pass in an empty label or set EditorGUIUtility.fieldWidth to the EditorGUIUtility.labelWidth (== LABEL_WIDTH) // otherwise the width will be incorrect when the vertical scrollbar is visible selectedIndex = EditorGUILayout.Popup("", selectedIndex, objectStrings, PopupStyle); if (disabled) { selectedOptions = new ObjectOptions(); } else { selectedOptions = options[objectsNonNull.ElementAt(selectedIndex).Item2]; } EditorGUIUtility.fieldWidth = 0; EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(RightColumnStyle, GUILayout.MaxWidth(halfWidth)); EditorGUILayout.LabelField(""); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(RowStyle); using (new EditorGUILayout.VerticalScope(SubLeftColumnStyle, GUILayout.MaxWidth(halfWidth))) { selectedOptions.Parent = (Transform)EditorGUILayout.ObjectField("Parent:", selectedOptions.Parent, typeof(Transform), true); if (selectedOptions.Parent != null) { PrefabType prefabType = PrefabUtility.GetPrefabType(selectedOptions.Parent); if (prefabType == PrefabType.Prefab || prefabType == PrefabType.ModelPrefab) { selectedOptions.Parent = null; } } EditorGUILayout.BeginHorizontal(RowStyle); EditorGUIUtility.labelWidth = LABEL_WIDTH; EditorGUILayout.PrefixLabel("Rotate:", RowStyle); EditorGUIUtility.labelWidth = 12.0f; using (new EditorGUI.DisabledScope(selectedOptions.AlignToSurface == true)) { selectedOptions.RotateX = EditorGUILayout.Toggle("X", selectedOptions.RotateX, ToggleStyle, GUILayout.ExpandWidth(false)); } selectedOptions.RotateY = EditorGUILayout.Toggle("Y", selectedOptions.RotateY, ToggleStyle, GUILayout.ExpandWidth(false)); using (new EditorGUI.DisabledScope(selectedOptions.AlignToSurface == true)) { selectedOptions.RotateZ = EditorGUILayout.Toggle("Z", selectedOptions.RotateZ, ToggleStyle, GUILayout.ExpandWidth(false)); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(RowStyle); EditorGUIUtility.labelWidth = LABEL_WIDTH; EditorGUILayout.PrefixLabel("Scale:", RowStyle); EditorGUIUtility.labelWidth = 12.0f; selectedOptions.ScaleX = EditorGUILayout.Toggle("X", selectedOptions.ScaleX, ToggleStyle, GUILayout.ExpandWidth(false)); selectedOptions.ScaleY = EditorGUILayout.Toggle("Y", selectedOptions.ScaleY, ToggleStyle, GUILayout.ExpandWidth(false)); selectedOptions.ScaleZ = EditorGUILayout.Toggle("Z", selectedOptions.ScaleZ, ToggleStyle, GUILayout.ExpandWidth(false)); EditorGUILayout.EndHorizontal(); EditorGUIUtility.labelWidth = LABEL_WIDTH; selectedOptions.AlignToSurface = EditorGUILayout.Toggle("Align Z to surface:", selectedOptions.AlignToSurface, ToggleStyle); selectedOptions.UniformScaling = EditorGUILayout.Toggle("Uniform scaling:", selectedOptions.UniformScaling, ToggleStyle); } using (new EditorGUILayout.VerticalScope(RightColumnStyle, GUILayout.MaxWidth(halfWidth))) { // Magic number 9 EditorGUIUtility.fieldWidth = (halfWidth - LABEL_WIDTH) * 0.5f - 9.0f; EditorGUILayout.BeginHorizontal(RowStyle); // Add non-empty label to skip the first column EditorGUILayout.PrefixLabel(" ", EditorStyles.objectField, RowStyle); // Because unity layouting is pain EditorGUIUtility.labelWidth = 0.0000001f; EditorGUILayout.LabelField("Min", centerStyle, GUILayout.ExpandWidth(true)); EditorGUILayout.LabelField("Max", centerStyle, GUILayout.ExpandWidth(true)); EditorGUILayout.EndHorizontal(); EditorGUIUtility.labelWidth = LABEL_WIDTH; EditorGUILayout.BeginHorizontal(RowStyle); EditorGUILayout.PrefixLabel("Scale:", RowStyle); selectedOptions.MinScale = EditorGUILayout.FloatField(selectedOptions.MinScale, NumberFieldStyle); selectedOptions.MaxScale = EditorGUILayout.FloatField(selectedOptions.MaxScale, NumberFieldStyle); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(RowStyle); EditorGUILayout.PrefixLabel("Height offset:", RowStyle); selectedOptions.MinHeightOffset = EditorGUILayout.FloatField(selectedOptions.MinHeightOffset, NumberFieldStyle); selectedOptions.MaxHeightOffset = EditorGUILayout.FloatField(selectedOptions.MaxHeightOffset, NumberFieldStyle); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(RowStyle); EditorGUILayout.PrefixLabel("Face . Up:", RowStyle); selectedOptions.MinDot = EditorGUILayout.FloatField(selectedOptions.MinDot, NumberFieldStyle); selectedOptions.MaxDot = EditorGUILayout.FloatField(selectedOptions.MaxDot, NumberFieldStyle); EditorGUILayout.EndHorizontal(); EditorGUIUtility.fieldWidth = 0; using (new EditorGUI.DisabledScope(selectedOptions.ScaleY == false)) { selectedOptions.ScaleHeightOffset = EditorGUILayout.Toggle(new GUIContent("Scale height offset:", "If enabled the height offset is scaled by the calculated Y scale"), selectedOptions.ScaleHeightOffset, ToggleStyle); } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); }
public static void Copy(PoissonData from, PoissonData to) { to.Map = from.Map; to.ProjectionLayerMask = from.ProjectionLayerMask; to.ProjectionRaycastTriggerInteraction = from.ProjectionRaycastTriggerInteraction; to.MinDist = from.MinDist; to.MaxDist = from.MaxDist; to.DistToKeepNextLevel = from.DistToKeepNextLevel; to.MinClump = from.MinClump; to.MaxClump = from.MaxClump; to.MinClumpRange = from.MinClumpRange; to.MaxClumpRange = from.MaxClumpRange; to.UseSeed = from.UseSeed; to.Seed = from.Seed; to.Samples = from.Samples; to.SphereCollisionCheck = from.SphereCollisionCheck; to.BoxCollisionCheck = from.BoxCollisionCheck; to.PoissonObjects = from.PoissonObjects; to.ClumpObjects = from.ClumpObjects; int fromLength = (from.PoissonObjectOptions == null) ? -1 : from.PoissonObjectOptions.Length; int toLength = (to.PoissonObjectOptions == null) ? -1 : to.PoissonObjectOptions.Length; if (fromLength != toLength) { if (fromLength == -1) { to.PoissonObjectOptions = null; } else { to.PoissonObjectOptions = new ObjectOptions[fromLength]; to.PoissonObjectOptions.InitNew(); } } for (int i = 0; i < fromLength; ++i) { ObjectOptions.Copy(from.PoissonObjectOptions[i], to.PoissonObjectOptions[i]); } fromLength = (from.ClumpObjectOptions == null) ? -1 : from.ClumpObjectOptions.Length; toLength = (to.ClumpObjectOptions == null) ? -1 : to.ClumpObjectOptions.Length; if (fromLength != toLength) { if (fromLength == -1) { to.ClumpObjectOptions = null; } else { to.ClumpObjectOptions = new ObjectOptions[fromLength]; to.ClumpObjectOptions.InitNew(); } } for (int i = 0; i < fromLength; ++i) { ObjectOptions.Copy(from.ClumpObjectOptions[i], to.ClumpObjectOptions[i]); } to.OverlapLayerMask = from.OverlapLayerMask; to.OverlapRaycastTriggerInteraction = from.OverlapRaycastTriggerInteraction; to.BoundsMode = from.BoundsMode; to.MaxSamples = from.MaxSamples; to.MaxSamplesPreview = from.MaxSamplesPreview; to.MaxSubPlacersNesting = from.MaxSubPlacersNesting; }