static void DrawGizmoForMyScript(ModulePrototype modulePrototype, GizmoType gizmoType) { Vector3 position = modulePrototype.transform.position; if (ModulePrototype.style == null) { ModulePrototype.style = new GUIStyle(); ModulePrototype.style.alignment = TextAnchor.MiddleCenter; } ModulePrototype.style.normal.textColor = Color.black; for (int i = 0; i < 6; i++) { var face = modulePrototype.Faces[i]; Handles.Label(position + modulePrototype.transform.rotation * Orientations.Rotations[i] * Vector3.forward * MapGenerator.BlockSize / 2f, face.ToString(), ModulePrototype.style); } for (int i = 0; i < 6; i++) { if (modulePrototype.Faces[i].Walkable) { Gizmos.color = Color.red; Gizmos.DrawLine(modulePrototype.transform.position + Vector3.down * 0.1f, modulePrototype.transform.position + modulePrototype.transform.rotation * Orientations.Rotations[i] * Vector3.forward + Vector3.down * 0.1f); } } }
public Module(ModulePrototype prototype, int rotation, int index) { this.Prototype = prototype; this.Rotation = rotation; this.Index = index; this.Name = prototype.gameObject.name + " R" + rotation; }
static void DrawGizmo(ModulePrototype modulePrototype, GizmoType gizmoType) { Vector3 position = modulePrototype.transform.position; if (ModulePrototype.style == null) { ModulePrototype.style = new GUIStyle(); ModulePrototype.style.alignment = TextAnchor.MiddleCenter; } ModulePrototype.style.normal.textColor = Color.black; for (int i = 0; i < 6; i++) { var face = modulePrototype.Faces[i]; Handles.Label(position + modulePrototype.transform.rotation * Orientations.Rotations[i] * Vector3.forward * InfiniteMap.BLOCK_SIZE / 2f, face.ToString(), ModulePrototype.style); } for (int i = 0; i < 6; i++) { if (modulePrototype.Faces[i].Walkable) { Gizmos.color = Color.red; Gizmos.DrawLine(modulePrototype.transform.position + Vector3.down * 0.1f, modulePrototype.transform.position + modulePrototype.transform.rotation * Orientations.Rotations[i] * Vector3.forward + Vector3.down * 0.1f); } if (modulePrototype.Faces[i].IsOcclusionPortal) { Gizmos.color = Color.blue; var dir = modulePrototype.transform.rotation * Orientations.Rotations[i] * Vector3.forward; Gizmos.DrawWireCube(modulePrototype.transform.position + dir, (Vector3.one - new Vector3(Mathf.Abs(dir.x), Mathf.Abs(dir.y), Mathf.Abs(dir.z))) * 2f); } } }
public Module(ModulePrototype prototype, int rotation, int index, MapGenerator mapGenerator) { this.Prototype = prototype; this.Rotation = rotation; this.Models = new List <AbstractModulePrototype>(); this.Models.Add(prototype); this.name = this.Prototype.gameObject.name + (this.Rotation != 0 ? " R" + this.Rotation : ""); this.Index = index; }
public Module(GameObject prefab, int rotation, int index) { this.Rotation = rotation; this.Index = index; this.Prefab = prefab; this.Prototype = this.Prefab.GetComponent <ModulePrototype>(); this.Name = this.Prototype.gameObject.name + " R" + rotation; this.PLogP = this.Prototype.Probability * Mathf.Log(this.Prototype.Probability); }
// Start is called before the first frame update void Start() { Node root1 = new WorldSeed.Plants.Node(null, Vector3.zero); Node stem1a = new WorldSeed.Plants.Node(root1, new Vector3(0, 1, 0)); root1.main = stem1a; Node stem1b = new Node(stem1a, new Vector3(0, 2, 0)); Node leaf1 = new Node(stem1a, new Vector3(-1, 2, 0)); stem1a.main = stem1b; stem1a.lateral = leaf1; List <Node> nodes = new List <Node>() { root1, stem1a, stem1b, leaf1 }; ModulePrototype modulePrototype = new ModulePrototype() { D = 0.0f, lambda = 0.0f, root = root1, nodes = nodes }; PlantConfig plantConfig = new PlantConfig() { //pMax=20, vigorRootMin = 0.01f, vigorRootMax = 42, growthRate = 0.19f, lambda = 0.62f, //lambdaMature=0.62f, D = 0.25f, //DMature=0.25f, //Fage = 0.0f, tropismEulerAngles = new Vector3(0.52f, 0.52f, 0.52f), weightCollisions = 0.63f, weightTropism = 1 - 0.63f, //g1=-0.38, //phi=0.57, //beta=0.47, modulePrototypes = new List <ModulePrototype>() { modulePrototype } }; Plant testPlant = new WorldSeed.Plants.Plant(plantConfig, modulePrototype, new Pose(Vector3.zero, Quaternion.identity)); forest = new Forest(new List <Plant>() { testPlant }); }
public override void OnInspectorGUI() { DrawDefaultInspector(); ModulePrototype modulePrototype = (ModulePrototype)target; if (GUILayout.Button("Distribute")) { int i = 0; foreach (Transform transform in modulePrototype.transform.parent) { transform.localPosition = Vector3.forward * i * InfiniteMap.BLOCK_SIZE * 2f; i++; } } if (GUILayout.Button("Distribute (Overview)")) { int w = Mathf.FloorToInt(Mathf.Sqrt(modulePrototype.transform.parent.childCount)); int i = 0; foreach (Transform transform in modulePrototype.transform.parent) { transform.localPosition = Vector3.forward * (i / w) * AbstractMap.BLOCK_SIZE * 1.4f + Vector3.right * (i % w) * AbstractMap.BLOCK_SIZE * 1.4f; i++; } } if (GUILayout.Button("Guess connectors")) { foreach (var face in modulePrototype.Faces) { face.Fingerprint = null; } modulePrototype.GuessConnectors(); } if (GUILayout.Button("Reset connectors")) { foreach (var face in modulePrototype.Faces) { face.ResetConnector(); } } if (GUILayout.Button("Reset exlusion rules in all prototypes")) { foreach (var prototype in modulePrototype.transform.parent.GetComponentsInChildren <ModulePrototype>()) { foreach (var face in prototype.Faces) { face.ExcludedNeighbours = new ModulePrototype[0]; } } } }
static void DrawGizmo(ModulePrototype modulePrototype, GizmoType gizmoType) { var transform = modulePrototype.transform; Vector3 position = transform.position; var rotation = transform.rotation; if (ModulePrototype.editorData == null || ModulePrototype.editorData.ModulePrototype != modulePrototype) { ModulePrototype.editorData = new ModulePrototypeEditorData(modulePrototype); } Gizmos.color = new Color(1f, 1f, 1f, 0.3f); if ((gizmoType & GizmoType.Selected) != 0) { for (int i = 0; i < 6; i++) { var hint = ModulePrototype.editorData.GetConnectorHint(i); if (hint.Mesh != null) { Gizmos.DrawMesh(hint.Mesh, position + rotation * Orientations.Direction[i].ToVector3() * AbstractMap.BLOCK_SIZE, rotation * Quaternion.Euler(Vector3.up * 90f * hint.Rotation)); } } } for (int i = 0; i < 6; i++) { if (modulePrototype.Faces[i].Walkable) { Gizmos.color = Color.red; Gizmos.DrawLine(position + Vector3.down * 0.1f, position + rotation * Orientations.Rotations[i] * Vector3.forward * AbstractMap.BLOCK_SIZE * 0.5f + Vector3.down * 0.1f); } if (modulePrototype.Faces[i].IsOcclusionPortal) { Gizmos.color = Color.blue; var dir = rotation * Orientations.Rotations[i] * Vector3.forward; Gizmos.DrawWireCube(position + dir, (Vector3.one - new Vector3(Mathf.Abs(dir.x), Mathf.Abs(dir.y), Mathf.Abs(dir.z))) * AbstractMap.BLOCK_SIZE); } } if (ModulePrototype.style == null) { ModulePrototype.style = new GUIStyle(); ModulePrototype.style.alignment = TextAnchor.MiddleCenter; } ModulePrototype.style.normal.textColor = Color.black; for (int i = 0; i < 6; i++) { var face = modulePrototype.Faces[i]; Handles.Label(position + rotation * Orientations.Rotations[i] * Vector3.forward * InfiniteMap.BLOCK_SIZE / 2f, face.ToString(), ModulePrototype.style); } }
private Mesh getMesh(ModulePrototype modulePrototype) { if (this.meshes.ContainsKey(modulePrototype)) { return(this.meshes[modulePrototype]); } var mesh = modulePrototype.GetMesh(false); this.meshes[modulePrototype] = mesh; return(mesh); }
public static List <Module> CreateModules(MapGenerator mapGenerator) { int count = 0; var modules = new List <Module>(); foreach (var prototype in ModulePrototype.GetAll()) { for (int face = 0; face < 6; face++) { if (prototype.Faces[face].ExcludedNeighbours == null) { prototype.Faces[face].ExcludedNeighbours = new ModulePrototype[0]; } } for (int rotation = 0; rotation < (prototype.CreateRotatedVariants ? 4 : 1); rotation++) { modules.Add(new Module(prototype, rotation, count, mapGenerator)); count++; } } foreach (var variation in Variation.GetAll()) { foreach (var module in modules.Where(module => module.Prototype == variation.Prototype)) { module.Models.Add(variation); } } foreach (var module in modules) { module.PossibleNeighbors = new Module[6][]; for (int direction = 0; direction < 6; direction++) { var face = module.Prototype.Faces[Orientations.Rotate(direction, module.Rotation)]; module.PossibleNeighbors[direction] = modules .Where(neighbor => module.Fits(direction, neighbor) && (!mapGenerator.RespectNeighorExclusions || ( !face.ExcludedNeighbours.Contains(neighbor.Prototype) && !neighbor.Prototype.Faces[Orientations.Rotate((direction + 3) % 6, neighbor.Rotation)].ExcludedNeighbours.Contains(module.Prototype)) && (!face.EnforceWalkableNeighbor || neighbor.Prototype.Faces[Orientations.Rotate((direction + 3) % 6, neighbor.Rotation)].Walkable) && (face.Walkable || !neighbor.Prototype.Faces[Orientations.Rotate((direction + 3) % 6, neighbor.Rotation)].EnforceWalkableNeighbor)) ) .ToArray(); } module.Probability = module.Models.Sum(model => model.Probability); } return(modules); }
public static List <Module> CreateModules(bool respectNeigborExclusions) { int count = 0; var modules = new List <Module>(); foreach (var prototype in ModulePrototype.GetAll()) { for (int face = 0; face < 6; face++) { if (prototype.Faces[face].ExcludedNeighbours == null) { prototype.Faces[face].ExcludedNeighbours = new ModulePrototype[0]; } } for (int rotation = 0; rotation < 4; rotation++) { if (rotation == 0 || !prototype.CompareRotatedVariants(0, rotation)) { modules.Add(new Module(prototype, rotation, count)); count++; } } } foreach (var module in modules) { module.PossibleNeighbors = new Module[6][]; for (int direction = 0; direction < 6; direction++) { var face = module.Prototype.Faces[Orientations.Rotate(direction, module.Rotation)]; module.PossibleNeighbors[direction] = modules .Where(neighbor => module.Fits(direction, neighbor) && (!respectNeigborExclusions || ( !face.ExcludedNeighbours.Contains(neighbor.Prototype) && !neighbor.Prototype.Faces[Orientations.Rotate((direction + 3) % 6, neighbor.Rotation)].ExcludedNeighbours.Contains(module.Prototype)) && (!face.EnforceWalkableNeighbor || neighbor.Prototype.Faces[Orientations.Rotate((direction + 3) % 6, neighbor.Rotation)].Walkable) && (face.Walkable || !neighbor.Prototype.Faces[Orientations.Rotate((direction + 3) % 6, neighbor.Rotation)].EnforceWalkableNeighbor)) ) .ToArray(); } } return(modules); }
public override void OnInspectorGUI() { DrawDefaultInspector(); ModulePrototype modulePrototype = (ModulePrototype)target; if (GUILayout.Button("Distribute")) { int i = 0; foreach (Transform transform in modulePrototype.transform.parent) { transform.localPosition = Vector3.forward * i * MapGenerator.BlockSize * 2f; i++; } } if (GUILayout.Button("Guess connectors")) { foreach (var face in modulePrototype.Faces) { face.Fingerprint = null; } modulePrototype.GuessConnectors(); } if (GUILayout.Button("Reset connectors")) { foreach (var face in modulePrototype.Faces) { face.ResetConnector(); } } if (GUILayout.Button("Reset exlusion rules in all prototypes")) { foreach (var prototype in modulePrototype.transform.parent.GetComponentsInChildren <ModulePrototype>()) { foreach (var face in prototype.Faces) { face.ExcludedNeighbours = new ModulePrototype[0]; } } } }
public ModulePrototypeEditorData(ModulePrototype modulePrototype) { this.ModulePrototype = modulePrototype; this.prototypes = modulePrototype.transform.parent.GetComponentsInChildren <ModulePrototype>(); this.meshes = new Dictionary <ModulePrototype, Mesh>(); }
public void CreateModules() { this.Modules = ModulePrototype.CreateModules(this.RespectNeighorExclusions).ToArray(); }
public void CreateModules() { this.Modules = ModulePrototype.CreateModules(true).ToArray(); Module.All = this.Modules; }
public Module(ModulePrototype prototype, int rotation, int index, MapGenerator mapGenerator) { this.Prototype = prototype; this.Rotation = rotation; this.Index = index; }
private void createModules() { this.Modules = ModulePrototype.CreateModules(this).ToArray(); }