public void CopyValues(PositionProvider source) { Location = source.Location; Direction = source.Direction; PositionOffset = source.PositionOffset; RandomMultitude = source.RandomMultitude; RandomPositionOption = source.RandomPositionOption; RandomTransforms = source.RandomTransforms.ToArray(); Degree = source.Degree; RelativeTo = source.RelativeTo; RotationFacing = source.RotationFacing; PositionRefrence = source.PositionRefrence; RotationRefrence = source.RotationRefrence; RotationOffset = source.RotationOffset; RotationOffsetType = source.RotationOffsetType; RotationOffsetVector = source.RotationOffsetVector; RotationRandomOffset = source.RotationRandomOffset; }
private Vector3 CalulatePosition() { switch (Location) { case PositionLocation.Transform: if (PositionRefrence == null) { throw new NullReferenceException("Transform must be set"); } return(PositionRefrence.position + (Vector3)PositionOffset); case PositionLocation.Direction: return(GetScreenPosition(Direction, PositionOffset, RelativeTo)); case PositionLocation.Random: var matching = Enum.GetValues(typeof(RandomPositionOption)) .Cast <RandomPositionOption>() .Where(c => (RandomPositionOption & c) == c) .ToArray(); if (matching.Length == 0) { throw new Exception("Random cannot operate without options."); } if (RandomMemory == null) { RandomMemory = new List <int>(); } else if (RandomMemory.Count() >= matching.Length) { RandomMemory.Clear(); } System.Random rand = new System.Random(); int selected; do { selected = rand.Next(matching.Length); } while (matching.Length > 1 && RandomMemory.Contains(selected)); RandomMemory.Add(selected); RandomPositionOption myEnum = matching[selected]; Direction randomDirection; Vector2 randomOffset = Vector2.Scale( RandomMultitude, new Vector2(UnityEngine.Random.value, UnityEngine.Random.value) ); switch (myEnum) { case RandomPositionOption.Transforms: if (RandomTransformMemory == null) { RandomMemory = new List <int>(); } else if (RandomTransformMemory.Count() >= matching.Length) { RandomMemory.Clear(); } do { selected = rand.Next(RandomTransforms.Length); } while (RandomTransforms.Length > 1 && RandomTransformMemory.Contains(selected)); RandomTransformMemory.Add(selected); if (RandomTransforms.Length == 0) { throw new Exception("Empty array of transforms."); } if (RandomTransforms[selected] == null) { throw new NullReferenceException("Transform at " + selected + " is null."); } return(RandomTransforms[selected].position + (Vector3)(randomOffset + PositionOffset)); case RandomPositionOption.Center: randomDirection = Direction.Center; break; case RandomPositionOption.East: randomDirection = Direction.East; break; case RandomPositionOption.West: randomDirection = Direction.West; break; case RandomPositionOption.South: randomDirection = Direction.South; break; case RandomPositionOption.North: randomDirection = Direction.North; break; case RandomPositionOption.NorthEast: randomDirection = Direction.NorthEast; break; case RandomPositionOption.NorthWest: randomDirection = Direction.NorthWest; break; case RandomPositionOption.SouthEast: randomDirection = Direction.SouthEast; break; case RandomPositionOption.SouthWest: randomDirection = Direction.SouthWest; break; default: throw new Exception("Missing Random Options"); } return(GetScreenPosition(randomDirection, PositionOffset + randomOffset, RelativeTo)); default: break; } throw new Exception("What the f**k?"); }
private void DrawPositionProperties(Rect position, SerializedProperty property) { int parts = 2; //parts width float width1 = Mathf.Min(70, position.width / parts); float lastWidth = position.width - (width1); float personalSpace = 2f; // Calculate rects var firstRect = new Rect(position.x, position.y, width1, LineHeight); var lastRect = new Rect(position.x + width1 + personalSpace, position.y, lastWidth - personalSpace, LineHeight); EditorGUI.PropertyField(firstRect, property.FindPropertyRelative("Location"), GUIContent.none); switch ((PositionLocation)property.FindPropertyRelative("Location").intValue) { case PositionLocation.Transform: EditorGUI.PropertyField(lastRect, property.FindPropertyRelative("PositionRefrence"), GUIContent.none); break; case PositionLocation.Direction: var directionRect = new Rect(position.x + width1, position.y, lastWidth / 2, LineHeight); var relativeToRect = new Rect(position.x + width1 + lastWidth / 2, position.y, lastWidth / 2, LineHeight); EditorGUI.PropertyField(directionRect, property.FindPropertyRelative("Direction"), GUIContent.none); EditorGUI.PropertyField(relativeToRect, property.FindPropertyRelative("RelativeTo"), GUIContent.none); break; case PositionLocation.Random: var randomMultRect = new Rect(position.x + width1, position.y, lastWidth / 2, LineHeight); var randPositionRect = new Rect(position.x + width1 + lastWidth / 2, position.y, lastWidth / 2, LineHeight); EditorGUI.PropertyField(randomMultRect, property.FindPropertyRelative("RandomMultitude"), GUIContent.none); RandomPositionOption enumValue = (RandomPositionOption)property.FindPropertyRelative("RandomPositionOption").intValue; Enum value = EditorGUI.EnumMaskPopup(randPositionRect, GUIContent.none, enumValue); property.FindPropertyRelative("RandomPositionOption").intValue = Convert.ToInt32(value); if ((Convert.ToInt32(value) & (int)RandomPositionOption.Transforms) == (int)RandomPositionOption.Transforms) { var arryaRect = new Rect(position.x, position.y + LineHeight, position.width, LineHeight); SerializedProperty list = property.FindPropertyRelative("RandomTransforms"); EditorGUI.PropertyField(arryaRect, list, new GUIContent("Transforms")); if (list.isExpanded) { var arraySizeRect = new Rect(position.x, arryaRect.yMax, position.width, LineHeight); list.arraySize = EditorGUI.IntField(arraySizeRect, list.arraySize); for (int i = 0; i < list.arraySize; i++) { var elementRect = new Rect(position.x, arraySizeRect.yMax + LineHeight * i, position.width, LineHeight); EditorGUI.PropertyField(elementRect, list.GetArrayElementAtIndex(i), GUIContent.none); } } } break; } }