void ApplyRule(Vector3 position, VoxelChunk chunk, int voxelIndex, ref VoxelDefinition voxelDefinition, ref Color32 tintColor) { if (rules == null || env == null || voxelDefinition != this.placingVoxel) { return; } VoxelChunk otherChunk; int otherIndex; VoxelDefinition[] otherVoxelDefinitions; for (int k = 0; k < rules.Length; k++) { if (!rules [k].enabled) { continue; } Vector3 pos = position + rules [k].offset; bool res = false; switch (rules [k].condition) { case TileRuleCondition.IsEmpty: res = env.IsEmptyAtPosition(pos); break; case TileRuleCondition.IsOcuppied: res = !env.IsEmptyAtPosition(pos); break; case TileRuleCondition.Equals: if (env.GetVoxelIndex(pos, out otherChunk, out otherIndex, false)) { res = otherChunk.voxels [otherIndex].typeIndex == voxelDefinition.index; } break; case TileRuleCondition.IsAny: otherVoxelDefinitions = rules [k].compareVoxelDefinitionSet; if (otherVoxelDefinitions != null && env.GetVoxelIndex(pos, out otherChunk, out otherIndex, false)) { int otherTypeIndex = otherChunk.voxels [otherIndex].typeIndex; for (int j = 0; j < otherVoxelDefinitions.Length; j++) { if (otherVoxelDefinitions [j].index == otherTypeIndex) { res = true; break; } } } break; case TileRuleCondition.Always: res = true; break; } if (res) { switch (rules [k].action) { case TileRuleAction.CancelPlacement: voxelDefinition = null; break; case TileRuleAction.Replace: voxelDefinition = rules [k].replacementSingle; break; case TileRuleAction.Random: otherVoxelDefinitions = rules [k].replacementSet; if (otherVoxelDefinitions != null && otherVoxelDefinitions.Length > 0) { voxelDefinition = otherVoxelDefinitions [UnityEngine.Random.Range(0, otherVoxelDefinitions.Length)]; } break; case TileRuleAction.Cycle: otherVoxelDefinitions = rules [k].replacementSet; if (otherVoxelDefinitions != null && otherVoxelDefinitions.Length > 0) { voxelDefinition = otherVoxelDefinitions [cycleIndex++]; if (cycleIndex >= otherVoxelDefinitions.Length) { cycleIndex = 0; } } break; } return; // rule executed, exit } } }