// Set play direction with options public void SetPlayDirection(SsAnimePlayDirection dir, bool keepFrame) { _playDirection = dir; float frame = _animeFrame; ResetAnimationStatus(); if (keepFrame) { _animeFrame = frame; } }
Init() { // if don't do this, Transforms(GameObjects) are created every time as come into ExecuteInEditMode. DeleteTransformChildren(); //Debug.Log("Init() " + gameObject.name); if (!_animation) { // clear variables //Debug.LogWarning("No anime resource attached-> " + gameObject.name); // works _partResList = null; _imageList = null; _partsNum = 0; _parts = null; _boundPartList = null; _materials = null; _vertices = null; _uvs = null; _colors = null; _extras = null; _mesh = null; _meshFilter.mesh = null; #if _USE_SHARED_MATERIAL _meshRenderer.sharedMaterials = new Material[1]; #else _meshRenderer.materials = new Material[1]; #endif // statuses _isPlaying = _isFinished = false; PlayCount = 0; Speed = 1f; _prevPlayDirection = _playDirection = SsAnimePlayDirection.Forward; ResetAnimationStatus(); _startAnimeFrame = _endAnimeFrame = _playFrameLength = 0; return; } EnsureMeshComponent(); // initialize values ResetAnimationStatus(); Pause(); _isFinished = false; // get parts and images. _partResList = _animation.PartList; _imageList = _animation.ImageList; _partsNum = _partResList.Length; // create material array. actually root doesn't need material so can cut down. _materials = new Material[_partsNum - 1]; // create vertices... int vertNum = (_partsNum - 1) * 4; _vertices = new Vector3[vertNum]; _uvs = new Vector2[vertNum]; _colors = new Color[vertNum]; _extras = new Vector2[vertNum]; // now create mesh _mesh = new Mesh(); _mesh.vertices = _vertices; // to avoid "out of bounds" error when we set triangle indices. _mesh.subMeshCount = _partsNum - 1; _mesh.uv2 = _extras; // attach to MeshFilter _meshFilter.mesh = _mesh; // create sprite parts and pass to resource used _parts = new SsPart[_partsNum]; for (int i = 0; i < _parts.Length; ++i) { SsPartRes partRes = _partResList[i]; SsImageFile image = partRes.IsRoot ? null : _imageList[partRes.SrcObjId]; _parts[i] = new SsPart(this, i, partRes, image); // set root sprite if (i == 0) { _rootPart = _parts[i]; } else { // set individual material to buffer _materials[i - 1] = _parts[i]._material; } // register bound parts separately for fast access if (partRes.Type == SsPartType.Bound) { if (_boundPartList == null) { _boundPartList = new List <SsPart>(); } _boundPartList.Add(_parts[i]); } } // set materials to affect #if _USE_SHARED_MATERIAL _meshRenderer.sharedMaterials = _materials; #else _meshRenderer.materials = _materials; #endif // attach values to the Mesh _mesh.vertices = _vertices; _mesh.uv = _uvs; // at first time must invoke vertex update to display initial posed animation. _vertChanged = true; // reflect blend settings to shader _extraChanged = true; #if false // use user data numeric value as PlayCount if (PartResList[0].UserKeys.Count > 0) { SsUserDataKeyFrame userKey = (SsUserDataKeyFrame)PartResList[0].GetKey(SsKeyAttr.User, 0); PlayCount = userKey.Value.Num; } #endif // to fix the problem that h/vFlipped animation from initial time doesn't affects mesh UpdateAlways(); }
Init() { // if don't do this, Transforms(GameObjects) are created every time as come into ExecuteInEditMode. DeleteTransformChildren(); //Debug.Log("Init() " + gameObject.name); if (!_animation) { // clear variables //Debug.LogWarning("No anime resource attached-> " + gameObject.name); // works _partResList = null; _imageList = null; _partsNum = 0; _parts = null; _boundPartList = null; _materials = null; _vertices = null; _uvs = null; _colors = null; _extras = null; _mesh = null; _meshFilter.mesh = null; #if _USE_SHARED_MATERIAL _meshRenderer.sharedMaterials = new Material[1]; #else _meshRenderer.materials = new Material[1]; #endif // statuses _isPlaying = _isFinished = false; PlayCount = 0; Speed = 1f; _prevPlayDirection = _playDirection = SsAnimePlayDirection.Forward; ResetAnimationStatus(); _startAnimeFrame = _endAnimeFrame = _playFrameLength = 0; return; } EnsureMeshComponent(); // initialize values ResetAnimationStatus(); Pause(); _isFinished = false; // get parts and images. _partResList = _animation.PartList; _imageList = _animation.ImageList; _partsNum = _partResList.Length; // create material array. actually root doesn't need material so can cut down. _materials = new Material[_partsNum - 1]; // create vertices... int vertNum = (_partsNum - 1) * 4; _vertices = new Vector3[vertNum]; _uvs = new Vector2[vertNum]; _colors = new Color[vertNum]; _extras = new Vector2[vertNum]; // now create mesh _mesh = new Mesh(); _mesh.vertices = _vertices; // to avoid "out of bounds" error when we set triangle indices. _mesh.subMeshCount = _partsNum - 1; _mesh.uv2 = _extras; // attach to MeshFilter _meshFilter.mesh = _mesh; // create sprite parts and pass to resource used _parts = new SsPart[_partsNum]; for (int i = 0; i < _parts.Length; ++i) { SsPartRes partRes = _partResList[i]; SsImageFile image = partRes.IsRoot ? null : _imageList[partRes.SrcObjId]; _parts[i] = new SsPart(this, i, partRes, image); // set root sprite if (i == 0) _rootPart = _parts[i]; else { // set individual material to buffer _materials[i - 1] = _parts[i]._material; } // register bound parts separately for fast access if (partRes.Type == SsPartType.Bound) { if (_boundPartList == null) _boundPartList = new List<SsPart>(); _boundPartList.Add(_parts[i]); } } // set materials to affect #if _USE_SHARED_MATERIAL _meshRenderer.sharedMaterials = _materials; #else _meshRenderer.materials = _materials; #endif // attach values to the Mesh _mesh.vertices = _vertices; _mesh.uv = _uvs; // update uv just in case _uvChanged = true; // at first time must invoke vertex update to display initial posed animation. _vertChanged = true; // reflect blend settings to shader _extraChanged = true; #if false // use user data numeric value as PlayCount if (PartResList[0].UserKeys.Count > 0) { SsUserDataKeyFrame userKey = (SsUserDataKeyFrame)PartResList[0].GetKey(SsKeyAttr.User, 0); PlayCount = userKey.Value.Num; } #endif // to fix the problem that h/vFlipped animation from initial time doesn't affects mesh UpdateAlways(); }
// Set play direction with options public void SetPlayDirection(SsAnimePlayDirection dir, bool keepFrame) { _playDirection = dir; float frame = _animeFrame; ResetAnimationStatus(); if (keepFrame) _animeFrame = frame; }