//----------------------------------------------------------------------------------------------- public bool fullLinesClear(CubeInfo [,]cubesArray, ref ArrayList height) { bool isFullLine = false; int counter; for (int i = 0; i < this.cells.GetLength(0); i++) { counter = 0; for (int y = 0; y < this.cells.GetLength(1); y++) { if (this.cells[i, y]) counter++; } if (counter == this.cells.GetLength(1)) { isFullLine = true; if(height == null) height=new ArrayList(); height.Add (i); for (int g = i; g > 0; g--) { for (int h = 0; h < this.cells.GetLength(1); h++) { if ((g - 1) <= (this.cells.GetLength(0) - 1)) { this.cells[g, h] = this.cells[g - 1, h]; cubesArray[g, h].cubeColored.renderer.material.color = cubesArray[g-1, h].cubeColored.renderer.material.color; } else this.cells[g, h] = false; } } } } return isFullLine; }
protected override void RefreshTree() { base.RefreshTree(); if (CubeInfo != null) { // Если задано уникальное имя измерения, то создаем для данного измерения узел if (!String.IsNullOrEmpty(DimensionUniqueName)) { DimensionInfo info = CubeInfo.GetDimension(DimensionUniqueName); if (info != null) { DimensionTreeNode dimNode = AddDimensionNode(null, info); CreateHierarchies(dimNode, info, false); dimNode.IsExpanded = true; return; } else { LogManager.LogError(this, String.Format(Localization.MetadataResponseException_DimensionByUniqueName_InCube_NotFound, DimensionUniqueName, CubeName)); } } // Отображаем все измерения CreateDimensions(null, CubeInfo, true); } }
List <GameObject> GetAttackRange() { List <GameObject> attacks = new List <GameObject>(); foreach (GameObject go in attackList) { if (go == lastAttack) { continue; } CubeInfo ci = go.GetComponent <CubeInfo>(); int[] sides = { ci.side1, ci.side2, ci.side3 }; foreach (int i in sides) { if (i == currentSide) { attacks.Add(go); } } } Vector3 currentPos = lastAttack.transform.position; foreach (GameObject go in attacks) { if (currentPos.x != go.transform.position.x && currentPos.z != go.transform.position.z) { attacks.Remove(go); break; } } return(attacks); }
CubeInfo initNewCube() { CubeInfo instance = null; instance = Instantiate(cubePrefabs, Vector3.zero, Quaternion.identity) as CubeInfo; return(instance); }
public void BeginDraw() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.collider != null) { switch (Settings.Instance.currBrush) { case Brush.Voxel: { click = true; break; } case Brush.Rect: case Brush.Line: case Brush.Fill: { beginCube = new CubeInfo(hit.collider.transform.parent.GetComponent <CubeInfo>()); beginSide = Settings.Instance.String2Sides(hit.collider.name); click = true; break; } } } } }
private void ActivateMarkedCube(Vector2 markedCoord, bool isSpecial) { //Check if there is a cube above the marked tile and if there is deactivate it //find cube above marked tile CubeInfo cube = gameManager.GetCubeAboveMarkedTile(markedCoord); //If there is a cube above it Deactivate the cube if (cube != null) { StartCoroutine(gameManager.DeactivateCube(cube)); gameManager.addedPauseTime += 0.8f; } //If it isn't a special trigger then unmark normally if (!isSpecial) { markedTile.UnmarkTile(); markedTile = null; tileMarked = false; } else//Otherwise unmark as special { floorCreation.UnmarkAllSpecialBlocks(); gameManager.specialBlockCoords.Clear(); } }
NodeInfo GetNodeInfo(CubeInfo cube_info, byte id, byte level, NodeInfo parent) { NodeInfo node_info; if (cube_info.free_nodes == 0) { Nodes nodes = new Nodes(); nodes.next = cube_info.node_queue; cube_info.node_queue = nodes; cube_info.next_node = 0; cube_info.free_nodes = NodesInAList; } ++cube_info.nodes; --cube_info.free_nodes; cube_info.node_queue.nodes[cube_info.next_node] = new NodeInfo(); node_info = cube_info.node_queue.nodes[cube_info.next_node]; node_info.parent = parent; node_info.id = id; node_info.level = level; ++cube_info.next_node; return(node_info); }
void Reduce(CubeInfo cube_info, NodeInfo node_info) { // Traverse any children. if (node_info.census != 0) { for (int id = 0; id < MaxTreeDepth; id++) { if ((node_info.census & (1 << id)) != 0) { Reduce(cube_info, node_info.child[id]); } } } if (node_info.quantize_error <= cube_info.pruning_threshold) { PruneChild(cube_info, node_info); } else { // Find minimum pruning threshold. if (node_info.number_unique > 0) { cube_info.colors++; } if (node_info.quantize_error < cube_info.next_threshold) { cube_info.next_threshold = node_info.quantize_error; } } }
public ColorQuantizer(int NumColors) { m_pCubeInfo = null; m_pQuantizeInfo = new QuantizeInfo(); m_Depth = 8; m_Colors = NumColors; m_pQuantizeInfo.Clear(); m_pQuantizeInfo.number_colors = NumColors; m_pQuantizeInfo.dither = 0; // Depth of color tree is: Log4(colormap size)+2. int colors = NumColors; for (m_Depth = 1; colors != 0; m_Depth++) { colors >>= 2; } if (m_pQuantizeInfo.dither > 0) { m_Depth--; } m_Depth += 2; m_pCubeInfo = GetCubeInfo(m_pQuantizeInfo, m_Depth); }
private void SearchPath(CubeInfo[,] cubeArray, CubeInfo cube) { for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if ((i == 0 || j == 0) && (i != 0 || j != 0) && cubeArray[cube.x - i, cube.z - j].cubAtt != CubeAttribute.NotMove && !closeList.Contains(cubeArray[cube.x - i, cube.z - j])) { cubeArray[cube.x - i, cube.z - j].parent = cube; OpenListAdd(cubeArray[cube.x - i, cube.z - j]); if (cubeArray[cube.x - i, cube.z - j].cubAtt == CubeAttribute.End) { return; } } } } CloseListAdd(cube); for (int i = openlist.Count - 1; i > 0; i--) { if (openlist[i].f < openlist[i - 1].f) { CubeInfo temp; temp = openlist[i]; openlist[i] = openlist[i - 1]; openlist[i - 1] = temp; } } SearchPath(cubeArray, openlist[0]); }
private void HandleMouseInput() { if (_commandManager.AcceptInput() && Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000)) { if (hit.collider.gameObject.layer >= 10 && hit.collider.gameObject.layer <= 15) { var distance = Camera.main.transform.position - Vector3.zero; var com = hit.collider.gameObject.GetComponent <SelectionTriggerController>(); _selectedCube = hit.collider.gameObject.GetComponent <CubeSelectionReference>().Cube; _isMouseMoving = true; _mousePosition = Input.mousePosition; _targetCubeLayer = hit.collider.gameObject.layer; return; } } } if (Input.GetMouseButtonUp(0) && _isMouseMoving) { _isMouseMoving = false; } if (_isMouseMoving) { UpdateMouseVariables(); if (_mouseDistance > _MinimumDragThreshold) { Move(false); } } }
public IEnumerator DeactivateCube(CubeInfo cube) { //Remove the deactivated cube from the list GameObject parent = cube.transform.parent.gameObject; //deactivate the block and move it to a holder cube.DeactivateCube(); while (parent.GetComponent <CubeMovement>().isMoving) { yield return(null); } activePuzzleBlocks.Remove(parent); inactiveBlocks.Add(parent); parent.transform.position = inactiveCubeHolder.position; parent.transform.parent = inactiveCubeHolder; //Check the type of block that was deactivated - if it was special or forbidden do extra. //If forbidden cube was deactivated -3 to block counter if (cube.typeOfCube == CubeInfo.CubeType.forbidden) { DeductFromFallenBlockCounter(3); } //If it was special mark the 9 floor tiles around the cubes pos as marked. if (cube.typeOfCube == CubeInfo.CubeType.special) { MarkFloorCubesForSpecial(cube.coord); } CheckIfPuzzleIsFinished(); }
public List <List <CubeInfo> > BuildCubes() { List <List <CubeInfo> > currentCubes = new List <List <CubeInfo> >(); for (int h = 1; h < cubesAmountY + 1; h++) { if ((h * posY) + ((h - 1) * posY) + cubeUnitSize - posY + marginUnitSize / 2 > resolutionHeight) { continue; } currentCubes.Add(new List <CubeInfo>()); for (int w = 1; w < cubesAmountX + 1; w++) { if ((w * posX) + ((w - 1) * posX) + cubeUnitSize - posX + marginUnitSize / 2 > resolutionWidth) { continue; } GameObject cube = Instantiate( cubes, new Vector3(transform.position.x + (w * posX) + ((w - 1) * posX), transform.position.x + (h * posY) + ((h - 1) * posY), cubeUnitSize / 2), cubes.transform.rotation ); cube.transform.localScale = new Vector3(cubeUnitSize, cubeUnitSize, cubeUnitSize); cube.SetActive(false); CubeInfo cubeInfo = new CubeInfo(); cubeInfo.SetGameOBJ(cube); cubeInfo.SetIsAlive(false); currentCubes[h - 1].Add(cubeInfo); } } for (int x = 0; x < currentCubes.Count; x++) { for (int y = 0; y < currentCubes[x].Count; y++) { if (x == 0 || y == 0 || x == currentCubes.Count - 1 || y == currentCubes[x].Count - 1) { SetCubeColor(currentCubes[x][y].gameOBJ, Color.black); } else { if (Random.Range(0, 1000) < seed) { currentCubes[x][y].SetIsAlive(true); SetCubeColor(currentCubes[x][y].gameOBJ, orange); } else { SetCubeColor(currentCubes[x][y].gameOBJ, black); } } } } return(currentCubes); }
public CubeInfo() { g = 0; h = 0; f = 0; parent = null; position = new Vector3(1, 1, 1); color = Color.white; cubAtt = CubeAttribute.CanMove; }
public void PaintFill(CubeInfo start, Sides currSide, CubeInfo[,,] cubeMap) { if (start.y == -1) { return; } AttachFill(start, currSide, cubeMap, true); }
public void PaintCube(CubeInfo info, int material) { if (info.material != -1) { info.material = material; info.meshRenderer.material = materials[material]; } }
public UnitBuoInfo(CubeInfo cube, BuoyanceType type, int x, int y, int z) { this.cube = cube; Type = type; this.x = x; this.y = y; this.z = z; }
private void Path(CubeInfo cube) { cube.color = Color.red; if (cube.cubAtt == CubeAttribute.Start) { return; } Path(cube.parent); }
public void AttachCube(CubeInfo info, Sides side, int material) { if (info.neighbors[(int)side] != null) { info.neighbors[(int)side].material = material; info.neighbors[(int)side].meshRenderer.material = materials[material]; info.neighbors[(int)side].gameObject.SetActive(true); } }
public void AttachFill(CubeInfo start, Sides currSide, CubeInfo[,,] cubeMap, bool paint = false) { if (currSide == Sides.Up) { int mat = -1; if (start.y > 0) { mat = cubeMap[start.x, start.y - 1, start.z].material; } floodfillUp(start.x, start.y, start.z, start.material, Settings.Instance.currMaterial, mat, cubeMap, paint); } else if (currSide == Sides.Down) { int mat = -1; if (start.y < cubeMap.GetLength(1)) { mat = cubeMap[start.x, start.y + 1, start.z].material; } floodfillDown(start.x, start.y, start.z, start.material, Settings.Instance.currMaterial, mat, cubeMap, paint); } else if (currSide == Sides.Front) { int mat = -1; if (start.z < cubeMap.GetLength(2)) { mat = cubeMap[start.x, start.y, start.z + 1].material; } floodfillFront(start.x, start.y, start.z, start.material, Settings.Instance.currMaterial, mat, cubeMap, paint); } else if (currSide == Sides.Back) { int mat = -1; if (start.z > 0) { mat = cubeMap[start.x, start.y, start.z - 1].material; } floodfillBack(start.x, start.y, start.z, start.material, Settings.Instance.currMaterial, mat, cubeMap, paint); } if (currSide == Sides.Right) { int mat = -1; if (start.x > 0) { mat = cubeMap[start.x - 1, start.y, start.z].material; } floodfillRight(start.x, start.y, start.z, start.material, Settings.Instance.currMaterial, mat, cubeMap, paint); } else if (currSide == Sides.Left) { int mat = -1; if (start.x < cubeMap.GetLength(0)) { mat = cubeMap[start.x + 1, start.y, start.z].material; } floodfillLeft(start.x, start.y, start.z, start.material, Settings.Instance.currMaterial, mat, cubeMap, paint); } }
public void EraseFill(CubeInfo start, Sides currSide, CubeInfo[,,] cubeMap) { if (currSide == Sides.Up) { int mat = -1; if (start.y > 0) { mat = cubeMap[start.x, start.y - 1, start.z].material; } floodfillUp(start.x, start.y, start.z, start.material, -1, mat, cubeMap); } else if (currSide == Sides.Down) { int mat = -1; if (start.y < cubeMap.GetLength(1)) { mat = cubeMap[start.x, start.y + 1, start.z].material; } floodfillDown(start.x, start.y, start.z, start.material, -1, mat, cubeMap); } else if (currSide == Sides.Front) { int mat = -1; if (start.z < cubeMap.GetLength(2)) { mat = cubeMap[start.x, start.y, start.z + 1].material; } floodfillFront(start.x, start.y, start.z, start.material, -1, mat, cubeMap); } else if (currSide == Sides.Back) { int mat = -1; if (start.z > 0) { mat = cubeMap[start.x, start.y, start.z - 1].material; } floodfillBack(start.x, start.y, start.z, start.material, -1, mat, cubeMap); } if (currSide == Sides.Right) { int mat = -1; if (start.x > 0) { mat = cubeMap[start.x - 1, start.y, start.z].material; } floodfillRight(start.x, start.y, start.z, start.material, -1, mat, cubeMap); } else if (currSide == Sides.Left) { int mat = -1; if (start.x < cubeMap.GetLength(0)) { mat = cubeMap[start.x + 1, start.y, start.z].material; } floodfillLeft(start.x, start.y, start.z, start.material, -1, mat, cubeMap); } }
private void LoadCube() { CubeInfo cubeInfo = SaveManager.LoadCube(); Vector3 cubePosition = new Vector3(); cubePosition.x = cubeInfo.position[0]; cubePosition.y = cubeInfo.position[1]; cubePosition.z = cubeInfo.position[2]; GameObject.Find("Cube").transform.position = cubePosition; }
public CubeInfo(CubeInfo ci) { position = ci.position; material = ci.material; for (int i = 0; i < ci.neighbors.Length; ++i) { neighbors[i] = ci.neighbors[i]; } meshRenderer = ci.meshRenderer; }
public void StartAStar(CubeInfo[,] cubeArray, CubeInfo start, CubeInfo end) { openlist = new List <CubeInfo>(); closeList = new List <CubeInfo>(); SetMap(cubeArray, start, end); OpenListAdd(start); SearchPath(cubeArray, start); Path(end); Clear(); }
public static void SaveCube(Cube cube) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Create); CubeInfo cubeInfo = new CubeInfo(cube); formatter.Serialize(stream, cubeInfo); stream.Close(); Debug.Log("Saved to " + path); }
void Reduction(CubeInfo cube_info, int number_colors) { cube_info.next_threshold = 0.0; while (cube_info.colors > number_colors) { cube_info.pruning_threshold = cube_info.next_threshold; cube_info.next_threshold = cube_info.root.quantize_error - 1; cube_info.colors = 0; Reduce(cube_info, cube_info.root); } }
public CubeInfo Info() { var info = new CubeInfo() { id = Id, positionId = PositionId, transform = transform }; return(info); }
private void delBlocks(Player player, string rangeS) { float range = 0; float.TryParse(rangeS, out range); if (range <= 0) { sendError(player, GetMessage("InvalidCommand")); } else { if (range > 50) { range = 50; } Vector3 playerPosition = getPositionV3(player); if (playerPosition[0] != 0) { float delta = range / 2; List <CubeInfo> cubs = new List <CubeInfo>(); for (float x = playerPosition.x - delta; x < playerPosition.x + delta; x++) { for (float y = playerPosition.y - delta; y < playerPosition.y + delta; y++) { for (float z = playerPosition.z - delta; z < playerPosition.z + delta; z++) { Vector3Int testPosition = new Vector3Int((int)x, (int)y, (int)z); CubeInfo cubInfo = BlockManager.DefaultCubeGrid.GetCubeInfoAtLocal(testPosition); sendError(player, "cubInfo " + cubInfo); return; if ((int)cubInfo.Prefab == 0 && cubInfo.MaterialID != CubeInfo.Air.MaterialID) { cubs.Add(cubInfo); } } } } if (cubs.Count == 0) { //todo translate sendError(player, "No cube in range"); } else { sendError(player, cubs.Count + " cubs found in range"); } } } }
public bool Equals(CubeInfo cubeInfo) { if (Position == cubeInfo.Position) { return(true); } else { return(false); } }
private void Start() { foreach (var cube in cubes) { var info = new CubeInfo(); info.name = cube.name; info.color = Color.white; info.visitCount = 0; _cubes[info.name] = info; } }
void Start() { _matrix = GetComponent<CubeMatrix>(); for (var y = 0; y < height; y++) { for (var x = 0; x < loop; x++) { var cube = _matrix[x, y]; var cubeInfo = new CubeInfo(){ state = State.Off, materials = stateMaterials[0], renderer = cube.GetComponent<Renderer>() }; _cubeInfos[x, y] = cubeInfo; } } }
public void LoadPersistedData(string name, bool visualise = false) { /// Reseting the ID for every new deserialized item so the ids match the original ids. this.UI.classVisualisation.Reset(); CubeInfo[] infos = GetAllSavedCubes(); CubeInfo info = infos.FirstOrDefault(x => x.Name == name); if (info == null) { Debug.Log("No info with the given name!!!"); return; } List <ClassVisualisation.MethodAndParameterNodes[]> methodInfoWithParamInfo = new List <ClassVisualisation.MethodAndParameterNodes[]>(); /// Creating and regestering the class nodes for (int i = 0; i < info.ClassInfos.Length; i++) { ClassInfo cin = info.ClassInfos[i]; Type type = Assembly.GetExecutingAssembly().GetType(cin.Name); Vector3 position = cin.Position; var spellClass = this.UI.classVisualisation.GenerateClassVisualisation(this.UI.classVisualisation.GenerateNodeData(type), position, out Node one); this.UI.connTracker.RegisterClassNameForPersistence(new ClassTracking { Name = type.FullName, node = one }, info.Name); methodInfoWithParamInfo.Add(spellClass); } ///... List <InputCanvas.InputElements> inputs = new List <InputCanvas.InputElements>(); /// Establish the DirectInputs List <ResultCanvas.VariableInput> variablesForDisplay = new List <ResultCanvas.VariableInput>(); for (int i = 0; i < info.directInputs.Length; i++) { DirectInput DI = info.directInputs[i]; /// CONSTANT if (DI.Name == null) { var cnst = this.UI.inputCanvas.CreateInputCanvas(DI.Value, DI.ID, this.UI, false); this.UI.connTracker.RegisterDirectInput(new DirectInput(DI.ID, null, DI.Value), info.Name); inputs.Add(cnst); } else /// VARIABLE { var var = this.UI.inputCanvas.CreateInputCanvas(default, DI.ID, this.UI, true, DI.Name);
public void showEffect(Model model, int _y, CubeInfo cubeInfo) { float _x = model.cells.GetLength (1)/2; float position_x = -_x * cubeInfo.cubeSize + 1.5f + cubeInfo.cubeSize/2; float _z = cubeInfo.cubeSize; GameObject effectGO; effectBlow = new Blow[model.cells.GetLength(1)]; float y = (model.cells.GetLength(0)-1-_y)*cubeInfo.cubeSize + cubeInfo.cubeSize/2; if (model != null) { for (int i=0; i<model.cells.GetLength(1); i++) { effectGO =(GameObject) Instantiate(effectPSPrefab,new Vector3(position_x, y, -_z), Quaternion.identity); effectBlow[i]=effectGO.GetComponent<Blow>(); position_x += cubeInfo.cubeSize; } } }
// ============================================================ // FONCTIONS // ============================================================ void ApplyColorFirstRow(CubeInfo[,] cubes, float hauteurBasses, float hauteurMoyennes, float hauteurAigues) { //On effecte la premiere rangée des cubes du plancher (depth = 0) int largeur = cubes.GetLength(0); int idxMidRight = 0; int idxGraves = 3*largeur/4; int idxMidLeft = largeur/2; int idxAigues = largeur/4; float ampli = 0.1f; float g = 0f; float r = 0f; float b = 0f; float timeSin=Mathf.Sin(Time.time/7f); float fastTime=Mathf.Sin(Time.time*2); Renderer renderer; //Color col; ///Valeurs connues: /// MidsR: cubes[idxMidRight,0].lastColor = cubes[idxMidRight,0].GetComponent<Renderer>().material.GetColor("_Color"); ampli = cubes[idxMidRight,0].transform.localScale.y; g = ((timeSin*0.7f) * (ampli/6f))-0.4f; r = (ampli/6f) - (g); b = 0.8f - (ampli/3); renderer = cubes[idxMidRight, 0].GetComponent<Renderer>(); renderer.material.color = new Color(r,g,b); //MidsL cubes[idxMidLeft,0].lastColor = cubes[idxMidLeft,0].GetComponent<Renderer>().material.GetColor("_Color"); ampli = cubes[idxMidLeft,0].transform.localScale.y; g = ((timeSin*0.7f) * (ampli/6f))-0.4f; r = (ampli/6f) - (0.8f*g); b = 0.8f - (ampli/3); cubes[idxMidLeft,0].GetComponent<Renderer>().material.SetColor("_Color", new Color(r,g,b)); // Graves: cubes[idxGraves,0].lastColor = cubes[idxGraves,0].GetComponent<Renderer>().material.GetColor("_Color"); ampli = cubes[idxGraves,0].transform.localScale.y; g = ((0.8f - ((timeSin*0.7f) * (ampli/6)))-0.2f); r = (ampli/4f) - (0.8f*g); b = 0.8f - (ampli/3); cubes[idxGraves,0].GetComponent<Renderer>().material.SetColor("_Color", new Color(r,g,b)); // Aigues: cubes[idxAigues,0].lastColor = cubes[idxAigues,0].GetComponent<Renderer>().material.GetColor("_Color"); ampli = cubes[idxAigues,0].transform.localScale.y; g = (ampli/4f); r = 0.4f*fastTime - (ampli/6); b = 0.5f - (ampli/6); cubes[idxAigues,0].GetComponent<Renderer>().material.SetColor("_Color", new Color(r,g,b)); float prop1 = 0f; float prop2 = 0f; //interpoller: int dist = idxAigues - idxMidRight; for(int i = idxMidRight+1; i<idxAigues; i++){ prop1 = (1f - (float)(i-idxMidRight)/dist); prop2 = 1f-prop1; r = prop1*cubes[idxMidRight,0].GetComponent<Renderer>().material.GetColor("_Color").r + prop2*cubes[idxAigues,0].GetComponent<Renderer>().material.GetColor("_Color").r; g = prop1*cubes[idxMidRight,0].GetComponent<Renderer>().material.GetColor("_Color").g + prop2*cubes[idxAigues,0].GetComponent<Renderer>().material.GetColor("_Color").g; b = prop1*cubes[idxMidRight,0].GetComponent<Renderer>().material.GetColor("_Color").b + prop2*cubes[idxAigues,0].GetComponent<Renderer>().material.GetColor("_Color").b; cubes[i,0].lastColor = cubes[i,0].GetComponent<Renderer>().material.GetColor("_Color"); cubes[i,0].GetComponent<Renderer>().material.SetColor("_Color", new Color(r,g,b)); } dist = idxMidLeft - idxAigues; for(int i = idxAigues+1; i<idxMidLeft; i++){ prop1 = (1f - (float)(i-idxAigues)/dist); prop2 = 1f-prop1; r = prop1*cubes[idxAigues,0].GetComponent<Renderer>().material.GetColor("_Color").r + prop2*cubes[idxMidLeft,0].GetComponent<Renderer>().material.GetColor("_Color").r; g = prop1*cubes[idxAigues,0].GetComponent<Renderer>().material.GetColor("_Color").g + prop2*cubes[idxMidLeft,0].GetComponent<Renderer>().material.GetColor("_Color").g; b = prop1*cubes[idxAigues,0].GetComponent<Renderer>().material.GetColor("_Color").b + prop2*cubes[idxMidLeft,0].GetComponent<Renderer>().material.GetColor("_Color").b; cubes[i,0].lastColor = cubes[i,0].GetComponent<Renderer>().material.GetColor("_Color"); cubes[i,0].GetComponent<Renderer>().material.SetColor("_Color", new Color(r,g,b)); } dist = idxGraves - idxMidLeft; for(int i = idxMidLeft+1; i<idxGraves; i++){ prop1 = (1f - (float)(i-idxMidLeft)/dist); prop2 = 1f-prop1; r = prop1*cubes[idxMidLeft,0].GetComponent<Renderer>().material.GetColor("_Color").r + prop2*cubes[idxGraves,0].GetComponent<Renderer>().material.GetColor("_Color").r; g = prop1*cubes[idxMidLeft,0].GetComponent<Renderer>().material.GetColor("_Color").g + prop2*cubes[idxGraves,0].GetComponent<Renderer>().material.GetColor("_Color").g; b = prop1*cubes[idxMidLeft,0].GetComponent<Renderer>().material.GetColor("_Color").b + prop2*cubes[idxGraves,0].GetComponent<Renderer>().material.GetColor("_Color").b; cubes[i,0].lastColor = cubes[i,0].GetComponent<Renderer>().material.GetColor("_Color"); cubes[i,0].GetComponent<Renderer>().material.SetColor("_Color", new Color(r,g,b)); } dist = largeur - idxGraves; for(int i = idxGraves+1; i<largeur; i++){ prop1 = (1f - (float)(i-idxGraves)/dist); prop2 = 1f-prop1; r = prop1*cubes[idxGraves,0].GetComponent<Renderer>().material.GetColor("_Color").r + prop2*cubes[idxMidRight,0].GetComponent<Renderer>().material.GetColor("_Color").r; g = prop1*cubes[idxGraves,0].GetComponent<Renderer>().material.GetColor("_Color").g + prop2*cubes[idxMidRight,0].GetComponent<Renderer>().material.GetColor("_Color").g; b = prop1*cubes[idxGraves,0].GetComponent<Renderer>().material.GetColor("_Color").b + prop2*cubes[idxMidRight,0].GetComponent<Renderer>().material.GetColor("_Color").b; cubes[i,0].lastColor = cubes[i,0].GetComponent<Renderer>().material.GetColor("_Color"); cubes[i,0].GetComponent<Renderer>().material.SetColor("_Color", new Color(r,g,b)); } }
// ============================================================ void CopyFirstRow(CubeInfo[,] original, CubeInfo[,] copy, int z0, int nZ) { for (int i = 0; i<original.GetLength(0); i++) { for (int j = z0; j<(z0+nZ); j++) { copy[i,j].lastScaleY = original[i,0].lastScaleY; copy[i,j].lastScaleZ = original[i,0].lastScaleZ; copy[i,j].transform.localScale = original[i,0].transform.localScale; copy[i,j].lastColor = original[i,0].lastColor; copy[i,j].GetComponent<Renderer>().material.SetColor("_Color",original[i,0].GetComponent<Renderer>().material.GetColor("_Color")); } } }
// ============================================================ void ApplyScaleWave(CubeInfo[,] cubes) { for(int i = 0; i<cubes.GetLength(0); i++){ for(int j = 1; j<cubes.GetLength(1); j++) { //Le jratio sert a prendre en compte l'effet conique. Si on ne divisait pas par jratio, //on aurait l'impression que les scale augmente avec la profondeur cubes[i,j].lastScaleY = cubes[i,j].transform.localScale.y / cubes[i,j].jRatio; cubes[i,j].lastScaleZ = cubes[i,j].transform.localScale.z; cubes[i,j].transform.localScale = new Vector3( cubes[i,j].jWidth, cubes[i,j].jRatio * cubes[i,j-1].lastScaleY, cubes[i,j-1].lastScaleZ) ; } } }
// ============================================================ void ApplyScaleFirstRow(CubeInfo[,] cubes, float hauteurBasses, float hauteurMoyennes, float hauteurAigues) { //On effecte la premiere rangée des cubes du plancher (depth = 0) int largeur = cubes.GetLength(0); int idxMidRight = 0; int idxGraves = 3*largeur/4; int idxMidLeft = largeur/2; int idxAigues = largeur/4; //float timeSin=Mathf.Sin(Time.time/7f); //float fastTime=Mathf.Sin(Time.time*2); ///Valeurs connues: /// MidsR: cubes[idxMidRight,0].lastScaleY = cubes[idxMidRight,0].transform.localScale.y; cubes[idxMidRight,0].lastScaleZ = cubes[idxMidRight,0].transform.localScale.z; cubes[idxMidRight,0].transform.localScale = new Vector3( cubes[idxMidRight,0].jWidth, hauteurMoyennes, 1.0f + hauteurMoyennes/5.0f) ; //MidsL cubes[idxMidLeft,0].lastScaleY = cubes[idxMidLeft,0].transform.localScale.y; cubes[idxMidLeft,0].lastScaleZ = cubes[idxMidLeft,0].transform.localScale.z; cubes[idxMidLeft,0].transform.localScale = new Vector3( cubes[idxMidLeft,0].jWidth, hauteurMoyennes,1.0f + hauteurMoyennes/5.0f) ; // Graves: cubes[idxGraves,0].lastScaleY = cubes[idxGraves,0].transform.localScale.y; cubes[idxGraves,0].lastScaleZ = cubes[idxGraves,0].transform.localScale.z; cubes[idxGraves,0].transform.localScale = new Vector3( cubes[idxGraves,0].jWidth, hauteurBasses,1.0f + hauteurBasses/5.0f) ; // Aigues: cubes[idxAigues,0].lastScaleY = cubes[idxAigues,0].transform.localScale.y; cubes[idxAigues,0].lastScaleZ = cubes[idxAigues,0].transform.localScale.z; cubes[idxAigues,0].transform.localScale = new Vector3( cubes[idxAigues,0].jWidth, hauteurAigues, 1.0f + hauteurAigues/5.0f) ; float prop1 = 0f; float prop2 = 0f; //interpoller: float scale = 0f; float scalez = 0f; int dist = idxAigues - idxMidRight; for(int i = idxMidRight+1; i<idxAigues; i++){ cubes[i,0].lastScaleY = cubes[i,0].transform.localScale.y; cubes[i,0].lastScaleZ = cubes[i,0].transform.localScale.z; prop1 = (1f - (float)(i-idxMidRight)/dist); prop2 = 1f-prop1; scale = (prop1*hauteurMoyennes) + (prop2*hauteurAigues); scalez = (prop1*(1.0f + hauteurMoyennes/5.0f)) + (prop2*(1.0f + hauteurAigues/5.0f)); cubes[i,0].transform.localScale = new Vector3( cubes[i,0].jWidth, scale, scalez) ; } dist = idxMidLeft - idxAigues; for(int i = idxAigues+1; i<idxMidLeft; i++){ cubes[i,0].lastScaleY = cubes[i,0].transform.localScale.y; cubes[i,0].lastScaleZ = cubes[i,0].transform.localScale.z; prop1 = (1f - (float)(i-idxAigues)/dist); prop2 = 1f-prop1; scale = (prop1*hauteurAigues) + (prop2*hauteurMoyennes); scalez = (prop1*(1.0f + hauteurAigues/5.0f)) + (prop2*(1.0f + hauteurMoyennes/5.0f)); cubes[i,0].transform.localScale = new Vector3( cubes[i,0].jWidth, scale, scalez) ; } dist = idxGraves - idxMidLeft; for(int i = idxMidLeft+1; i<idxGraves; i++){ cubes[i,0].lastScaleY = cubes[i,0].transform.localScale.y; cubes[i,0].lastScaleZ = cubes[i,0].transform.localScale.z; prop1 = (1f - (float)(i-idxMidLeft)/dist); prop2 = 1f-prop1; scale = (prop1*hauteurMoyennes) + (prop2*hauteurBasses); scalez = (prop1*(1.0f+hauteurMoyennes/5.0f)) + (prop2*(1.0f+hauteurBasses/5.0f)); cubes[i,0].transform.localScale = new Vector3( cubes[i,0].jWidth, scale, scalez) ; } dist = largeur - idxGraves; for(int i = idxGraves+1; i<largeur; i++){ cubes[i,0].lastScaleY = cubes[i,0].transform.localScale.y; cubes[i,0].lastScaleZ = cubes[i,0].transform.localScale.z; prop1 = (1f - (float)(i-idxGraves)/dist); prop2 = 1f-prop1; scale = (prop1*hauteurBasses) + (prop2*hauteurMoyennes); scalez = (prop1*(1.0f + hauteurBasses/5.0f)) + (prop2*(1.0f + hauteurMoyennes/5.0f)); cubes[i,0].transform.localScale = new Vector3( cubes[i,0].jWidth, scale, scalez); } }
// ============================================================ void ApplyColorWave(CubeInfo[,] cubes) { for(int i = 0; i<cubes.GetLength(0); i++){ for(int j = 1; j<cubes.GetLength(1); j++){ cubes[i,j].lastColor = cubes[i,j].GetComponent<Renderer>().material.GetColor("_Color"); cubes[i,j].GetComponent<Renderer>().material.SetColor("_Color", cubes[i,j-1].lastColor); } } }
private bool flexTunnel(CubeInfo[,] cubes1,CubeInfo[,] cubes2, float sinOffsetX, float sinOffsetY, int flexionID) { bool flexionDone = false; float amp = 1000f; // Si c'est la premiere frame de cette flexion, avertir TunnelSpinner pour qu'il cesse d'enregistrer la position if ( firstFlexFrame[flexionID]==true ) { firstFlexFrame[flexionID] = false; startFlexion(); } if ((song.time() - song.flexionTime[flexionID])<Mathf.Min (2,song.flexionLength[flexionID]/3)) { // La force d'amplication du sinus commence a 0 et augmente jusqu'a 4 amp = (song.time()-song.flexionTime[flexionID])/2; } else if ((song.time() - song.flexionTime[flexionID])<(song.flexionLength[flexionID]-4)) { amp = 1f; } else { // La force d'amplication du sinus diminue jusqu'a 0 (parabole inversée) amp = Mathf.Max ((song.flexionLength[flexionID]-(song.time()-song.flexionTime[flexionID]))/4,0); } for(int i = 0; i<cubes1.GetLength(0); i++){ for(int j = 1; j<cubes1.GetLength(1); j++){ cubes1[i,j].transform.localPosition = new Vector3 ((cubes1[i,j].posSansFlexion.x+ amp*Mathf.Pow((float)j,2f)*sinOffsetX),cubes1[i,j].posSansFlexion.y + amp*Mathf.Pow((float)j,2f)*sinOffsetY,cubes1[i,j].transform.localPosition.z); } } for(int i = 0; i<cubes2.GetLength(0); i++){ for(int j = 1; j<cubes2.GetLength(1); j++){ cubes2[i,j].transform.localPosition = new Vector3 ((cubes2[i,j].posSansFlexion.x+ amp*Mathf.Pow((float)j,2f)*sinOffsetX),cubes2[i,j].posSansFlexion.y+ amp*Mathf.Pow((float)j,2f)*sinOffsetY,cubes2[i,j].transform.localPosition.z); } } // Stop the flexion script when amp and the offset are small if (amp < 0.0001f){ flexionDone = true; endFlexion(); } return flexionDone; }
private void ReadGndFile() { string Root = textBox2.Text; using( FileStream s = File.OpenRead( textBox1.Text ) ) { using( BinaryReader bin = new BinaryReader( s, Encoding.GetEncoding( "ISO-8859-1" ) ) ) { bin.BaseStream.Position += 6; mHeader = new HeaderInfo(); mHeader.Width = bin.ReadUInt32(); mHeader.Height = bin.ReadUInt32(); mHeader.Ratio = bin.ReadUInt32(); mHeader.TextureCount = bin.ReadUInt32(); mHeader.TextureSize = bin.ReadUInt32(); mTextures = new TextureInfo[ mHeader.TextureCount ]; for( int i = 0; i < mTextures.Length; i++ ) { mTextures[ i ] = new TextureInfo(); mTextures[ i ].TexPath = ReadWord( bin, 40 ).ToLower(); mTextures[ i ].Unknown = ReadWord( bin, 40 ).ToCharArray(); mTextures[ i ].TextureBmp = Bitmap.FromFile( Root + @"\" + mTextures[ i ].TexPath ) as Bitmap; } mLightmapCount = (uint)bin.ReadInt32(); mGrid = new GridInfo(); mGrid.X = bin.ReadUInt32(); mGrid.Y = bin.ReadUInt32(); mGrid.Cells = bin.ReadUInt32(); mLightmaps = new LitghmapInfo[ mLightmapCount ]; for( int i = 0; i < mLightmaps.Length; i++ ) { mLightmaps[ i ] = new LitghmapInfo(); mLightmaps[ i ].brightness = bin.ReadChars( 64 ); mLightmaps[ i ].colorrbg = bin.ReadChars( 192 ); } mTileCount = (uint)bin.ReadInt32(); mTiles = new TileInfo[ mTileCount ]; for( int i = 0; i < mTiles.Length; i++ ) { mTiles[ i ] = new TileInfo(); mTiles[ i ].VectorWidth = ReadVector4( bin ); mTiles[ i ].VectorHeight = ReadVector4( bin ); mTiles[ i ].TextureIndex = bin.ReadUInt16(); mTiles[ i ].Lightmap = bin.ReadUInt16(); mTiles[ i ].color = bin.ReadChars( 4 ); } mCubeCount = mHeader.Width * mHeader.Height; mCubes = new CubeInfo[ mCubeCount ]; for( int i = 0; i < mCubes.Length; i++ ) { mCubes[ i ] = new CubeInfo(); mCubes[ i ].Height = ReadVector4( bin ); mCubes[ i ].tile_up = bin.ReadInt32(); mCubes[ i ].tile_side = bin.ReadInt32(); mCubes[ i ].tile_aside = bin.ReadInt32(); } } } }
void SmoothMap(int skyHeight) { CubeInfo[,,] temp = new CubeInfo[map.GetLength(0), map.GetLength(1), map.GetLength(2)]; for (int x = 1; x < map.GetLength(0) - 1; x++) { for (int y = skyHeight + 1; y < map.GetLength(1) - 1; y++) { for (int z = 1; z < map.GetLength(2) - 1; z++) { int neighbourWallTiles = GetSurroundingCubeCount(x, y, z); if (neighbourWallTiles > 13) temp[x, y, z] = CubeInfo.Grass; else if (neighbourWallTiles < 13) temp[x, y, z] = CubeInfo.None; } } } for (int x = 1; x < map.GetLength(0) - 1; x++) { for (int y = skyHeight + 1; y < map.GetLength(1) - 1; y++) { for (int z = 1; z < map.GetLength(2) - 1; z++) { map[x, y, z].mapinfo = temp[x, y, z]; } } } }