public void DoBreakBoneAnimation( ref Character _CharacterRef, int _PartIndex = 0 /* <= 0, for random */) { if (_PartIndex <= 0) { _PartIndex = Random.Range(1, _CharacterRef.mesh.m_nPartCount); } GlobalSingleton.DEBUG("DoBreakBoneAnimation Obj = " + _CharacterRef.ToString() + ", nPartIndex = " + _PartIndex); s_DummyIndex = (s_DummyIndex + 1) % m_DummyPoints.Count; GameObject obj = m_DummyPoints[s_DummyIndex]; obj.transform.position = _CharacterRef.transform.position; _CharacterRef.mesh.BreakPart(_PartIndex, obj); BoneAnimation boneAnimation = obj.AddComponent <BoneAnimation>(); boneAnimation.m_StartPoint = _CharacterRef.transform.position; boneAnimation.m_EndPoint = new Vector3( Random.Range(-32.0f, 32.0f), Random.Range(-1.0f, 1.0f), Random.Range(-10.0f, 5.0f)); Invoke("OnBoneAnimationFinish", 5.0f); }
void OnAction(Character _CharRef, Character _OtherRef, int _ChunkIndex, ActionKey _Action) { GlobalSingleton.DEBUG(_CharRef.name + "," + _ChunkIndex + "," + _Action); switch (_Action) { case ActionKey.Attack: _CharRef.DoChangeModel(_ChunkIndex, MODELTYPE.E_ATTACK); _CharRef.DoAction(_ChunkIndex, AnimationState.Attack, 1.2f); _CharRef.SetOpponentTarget(_ChunkIndex); _OtherRef.DoAction(_ChunkIndex, AnimationState.Hitted, 1.2f); _OtherRef.SetOpponentTarget(_ChunkIndex); break; case ActionKey.Defend: _CharRef.DoChangeModel(_ChunkIndex, MODELTYPE.E_DEFENSE); _OtherRef.ClearOpponentTarget(_ChunkIndex); // _CharRef.DoAction(_ChunkIndex, AnimationState.Defend, 2.0f); break; case ActionKey.Concentrate: _CharRef.DoChangeModel(_ChunkIndex, MODELTYPE.E_CONCENTRATE); _OtherRef.ClearOpponentTarget(_ChunkIndex); break; } }
public virtual void Draw(GameObject _Root) { GlobalSingleton.DEBUG("Draw, size = " + m_nSize + ", sizeof vertices = " + m_Vertices.Length); for (int i = 0; i < m_Vertices.Length; ++i) { int voxel = m_Vertices[i]; if (voxel > 0) { GameObject obj = Object.Instantiate(Resources.Load(s_VoxelPrefab)) as GameObject; m_VoxelCache.Add(obj); Vector3 localScale = _Root.transform.localScale; obj.transform.parent = _Root.transform; obj.transform.position = _Root.transform.position + new Vector3( localScale.x * (i % m_nSize - m_nSize / 2), localScale.y * (m_nSize / 2 - i / m_nSize), 0); // use Sprites-Default material #if VERTEX_COLOR_256 || VERTEX_COLOR_8 MeshFilter cube = obj.GetComponent <MeshFilter>(); Vector3[] vertices = cube.mesh.vertices; #if VERTEX_COLOR_256 int colorScale = 256; #elif VERTEX_COLOR_8 int colorScale = 8; #endif #if GRAY_SCALE_COLOR float grayScale = (voxel % colorScale) / (float)colorScale; float r = grayScale, g = grayScale, b = grayScale; #else float r = (voxel % colorScale) / (float)colorScale; float g = (voxel % colorScale) / (float)colorScale; float b = (voxel % colorScale) / (float)colorScale; #endif Color[] colors = Enumerable.Repeat( new Color(r, g, b, 1.0f), vertices.Length).ToArray(); cube.mesh.colors = colors; #endif } } }
public virtual bool DoParse() { GlobalSingleton.DEBUG("DoParse, SourceStr = " + m_SourceStr); // remove unused char(space, new line, etc...) m_SourceStr = System.Text.RegularExpressions.Regex.Replace(m_SourceStr, @"\t|\n|\r| ", string.Empty); string[] attrSegment = m_SourceStr.Split(';'); for (int i = 0; i < attrSegment.Length; ++i) { string[] element = attrSegment[i].Split(':'); if (element[0] == "name") { m_Name = element[1]; } else if (element[0] == "size") { int.TryParse(element[1], out m_nSize); } else if (element[0] == "vertices") { string valueStr = element[1]; string[] verticesStr = valueStr.Split(','); m_Vertices = System.Array.ConvertAll(verticesStr, s => int.Parse(s)); } else if (element[0] == "partmask") { string valueStr = element[1]; string[] verticesStr = valueStr.Split(','); m_PartMask = System.Array.ConvertAll(verticesStr, s => int.Parse(s)); // calculate part count while (System.Array.IndexOf(m_PartMask, m_nPartCount + 1) >= 0) { m_nPartCount++; } } } return(true); }
public virtual void BreakPart(int _PartIndex, GameObject _Root) { GlobalSingleton.DEBUG("BreakPart, part index = " + _PartIndex); // size of m_Vertices and m_PartMask should be the same. if ((m_PartMask == null) || (m_PartMask.Length != m_Vertices.Length)) { return; } int voxelIndex = -1; for (int i = 0; i < m_PartMask.Length; ++i) { int voxel = m_Vertices[i]; if (voxel > 0) { voxelIndex++; } if (m_PartMask[i] != _PartIndex) { continue; } GameObject obj = Object.Instantiate(Resources.Load(s_VoxelPrefab)) as GameObject; Vector3 localScale = _Root.transform.localScale; obj.transform.parent = _Root.transform; obj.transform.position = _Root.transform.position + new Vector3( localScale.x * (i % m_nSize - m_nSize / 2), localScale.y * (m_nSize / 2 - i / m_nSize), 0); // use Sprites-Default material #if VERTEX_COLOR_256 || VERTEX_COLOR_8 MeshFilter cube = obj.GetComponent <MeshFilter>(); Vector3[] vertices = cube.mesh.vertices; #if VERTEX_COLOR_256 int colorScale = 256; #elif VERTEX_COLOR_8 int colorScale = 8; #endif #if GRAY_SCALE_COLOR float grayScale = (voxel % colorScale) / (float)colorScale; float r = grayScale, g = grayScale, b = grayScale; #else float r = (voxel % colorScale) / (float)colorScale; float g = (voxel % colorScale) / (float)colorScale; float b = (voxel % colorScale) / (float)colorScale; #endif Color[] colors = Enumerable.Repeat( new Color(r, g, b, 1.0f), vertices.Length).ToArray(); cube.mesh.colors = colors; #endif // hide the voxelerase m_VoxelCache[voxelIndex].SetActive(false); // erase the flag m_PartMask[i] = 0; } }
public Mesh_VoxelChunk(string _SourceStr) : base(_SourceStr) { GlobalSingleton.DEBUG("Ctor for String"); m_SourceStr = _SourceStr; }
public override bool DoParse() { GlobalSingleton.DEBUG(typename + "DoParse, SourceStr = " + m_SourceStr); // remove unused char(space, new line, etc...) m_SourceStr = System.Text.RegularExpressions.Regex.Replace(m_SourceStr, @"\t|\n|\r| ", string.Empty); string[] attrSegment = m_SourceStr.Split(';'); for (int i = 0; i < attrSegment.Length; ++i) { string[] element = attrSegment[i].Split(':'); if (element[0] == "name") { m_Name = element[1]; } else if (element[0] == "chunk") { char[] trim = { '[', ']' }; string[] chunks = element[1].Trim(trim).Split('#'); GlobalSingleton.DEBUG(element[1]); for (int j = 1; j < chunks.Length; ++j) { string[] chunkSegment = chunks[j].Split('|'); // if (chunkSegment.Length < 5) // continue; string name = chunkSegment[0]; string model = chunkSegment[1]; string[] vector3String = chunkSegment[2].Split(','); Vector3 localPosition = new Vector3 ( float.Parse(vector3String[0]), float.Parse(vector3String[1]), float.Parse(vector3String[2]) ); GlobalSingleton.DEBUG("chunk = " + name + "," + localPosition); Chunk c = new Chunk(); c.Model = model; c.LocalPos = localPosition; // c.Scale = localScale; // c.Size = size; m_ChunkMap.Add(name, c); } } else if (!m_ModelMap.ContainsKey(element[0])) { if (element.Length < 5) { continue; } string[] pos3String = element[1].Split(','); Vector3 localPosition = new Vector3 ( float.Parse(pos3String[0]), float.Parse(pos3String[1]), float.Parse(pos3String[2]) ); string[] scale2String = element[2].Split(','); Vector2 localScale = new Vector2 ( float.Parse(scale2String[0]), float.Parse(scale2String[1]) ); string[] size2String = element[3].Split(','); Vector2 size = new Vector2 ( float.Parse(size2String[0]), float.Parse(size2String[1]) ); GlobalSingleton.DEBUG("add model: " + element[0]); string valueStr = element[4]; string[] verticesStr = valueStr.Split(','); Chunk c = new Chunk(); c.Model = element[0]; c.LocalPos = localPosition; c.Scale = localScale; c.Size = size; c.Vertex = System.Array.ConvertAll(verticesStr, s => int.Parse(s)); m_ModelMap.Add(element[0], c); } } GlobalSingleton.DEBUG(typename + "DoParse End : " + m_ChunkMap.Count()); return(true); }
public override void BreakPart(int _PartIndex, GameObject _Root) { GlobalSingleton.DEBUG(typename + "BreakPart, part index = " + _PartIndex); }
public void AttachModel(string chunk, string model, Chunk c) { // if (m_ChunkCache.ContainsKey(chunk) && c.Model == model) // return; List <GameObject> Purge; if (m_ChunkCache.TryGetValue(chunk, out Purge)) { foreach (GameObject o in Purge) { GameObject.Destroy(o); } m_ChunkCache.Remove(chunk); } Chunk c0; if (m_ModelMap.TryGetValue(model, out c0)) { Vector2 size = c0.Size; Vector2 scale = c0.Scale; Vector3 objectPos = c.LocalPos + c0.LocalPos; int[] vertex = c0.Vertex; m_ChunkMap[chunk].Model = model; m_ChunkCache.Add(chunk, new List <GameObject>()); GlobalSingleton.DEBUG("AttachModel:" + chunk + "," + model + "," + scale + "," + objectPos + "," + size); int _w = (int)size.x; int _h = (int)size.y; int _size = _w * _h; for (int i = 0; i < _size /*vertex.Length*/; ++i) { int voxel = vertex[i]; if (voxel > 0) { GameObject obj = Object.Instantiate(Resources.Load(s_VoxelPrefab)) as GameObject; m_ChunkCache[chunk].Add(obj); Vector3 localScale = root.transform.localScale; obj.transform.parent = root.transform; obj.transform.localScale = new Vector3( localScale.x * scale.x, localScale.y * scale.y, localScale.z); obj.transform.position = this.CalculatePositionFromRootPosition(root.transform.position , localScale, scale, objectPos, _w, _h, i); #if VERTEX_COLOR_256 || VERTEX_COLOR_8 Color color = CalculateColorFromRootPosition(voxel); MeshFilter cube = obj.GetComponent <MeshFilter>(); Vector3[] vertices = cube.mesh.vertices; Color[] colors = Enumerable.Repeat(color, vertices.Length).ToArray(); cube.mesh.colors = colors; #else // use Sprites-Default material #endif } } } }