Beispiel #1
0
    SortByPriority()
    {
        SsPart[] sorted = new SsPart[_parts.Length];
        for (int i = 0; i < _parts.Length; ++i)
        {
            sorted[i] = _parts[i];
        }

        // sort
        Array.Sort(sorted);

        // change index in submesh array to change draw order
        int index = 0;

        for (int i = 0; i < _parts.Length; ++i)
        {
            if (!sorted[i]._res.IsRoot)
            {
                sorted[i].SetToSubmeshArray(index);
                // change material order same as submesh
                _materials[index] = sorted[i]._material;
                ++index;
            }
        }

        // update material list
        _matChanged = true;
    }
Beispiel #2
0
    public void OnSoundKey(SsPart part, SsAttrValueInterface val)
    {
        SsSoundKeyValue sv = val as SsSoundKeyValue;

        Debug.LogWarning(part.Sprite.gameObject.name + ": " + sv.SoundId);
        part.OnSoundKey -= OnSoundKey;
    }
    public void OnUserDataKey(SsPart part, SsAttrValueInterface val)
    {
        var udk = val as SsUserDataKeyValue;

        Debug.LogWarning(part.Sprite.gameObject.name + ": " + udk.String);
        part.OnUserDataKey -= OnUserDataKey;
    }
Beispiel #4
0
//	void Awake()
//	{
//		tag = "bee";
//	}

    void Start()
    {
        _xpos = Random.Range(-200, 200);
        _ypos = Random.Range(500, 700);
        _zpos = -0.01f;
        _rot  = Vector3.zero;
        Update();
        ChangeAnime("bee_ssa");
        _bodyPart = _sprite.GetPart("体");
        Reset();
        _sprite.Play();
        _sprite.AnimFrame = Random.Range(0, 3);
    }
Beispiel #5
0
    // Transform at a child part in world space.
    public Transform               TransformAt(string name)
    {
        if (name == null)
        {
            return(_transform);
        }
        SsPart e = GetPart(name);

        if (e == null)
        {
            return(null);
        }
        return(e._transform);
    }
Beispiel #6
0
    public void Swing()
    {
        ChangeAnime("attack_ssa");
        // set animation finished callback to turn off the collision detection
        _sprite.AnimationFinished = SwingFinished;
        _sprite.PlayCount         = 1;
        // get a part to use as the trigger to start collision detection
        SsPart part = _sprite.GetPart("基点");

        // set the callbacks of sound/user key.
        part.OnSoundKey    += OnSoundKey;
        part.OnUserDataKey += OnUserDataKey;
        // save current sword length
        _orgSwordLength = SsGameTest._instance._swordLength;
        _orgSwordWidth  = SsGameTest._instance._swordWidth;
        // change current state
        _updateFunc = _Swinging;
    }
Beispiel #7
0
    public void OnUserDataKey(SsPart part, SsAttrValueInterface val)
    {
        SsUserDataKeyValue u = val as SsUserDataKeyValue;

        if (u.String == "HIT!!!")
        {
            // start collision detection
            _swordObject.EnableCollision(true);
            SsGameTest._instance._swordLength *= 1.5f;
            SsGameTest._instance._swordWidth  *= 1.25f;
        }
        if (u.String == "DONE")
        {
            // restore the sword length
            SsGameTest._instance._swordLength = _orgSwordLength;
            SsGameTest._instance._swordWidth  = _orgSwordWidth;
            part.OnUserDataKey -= OnUserDataKey;
        }
    }
Beispiel #8
0
    public override bool ChangeAnime(string name)
    {
        if (EqulasAnime(name))
        {
            return(false);
        }

        // due to lose children transform while changing animation, detach temporarily
        Transform swordTransform = _swordObject._sprite.TransformAt(null);

        swordTransform.parent = null;

        base.ChangeAnime(name);

        // create and get the transform of my hand.
        SsPart    handPart      = _sprite.GetPart("前手");
        Transform handTransform = handPart.CreateTransform();

#if false // obsolete since version 1.06
        // reset sword position
        swordTransform.localPosition = Vector3.zero;
        swordTransform.localRotation = Quaternion.identity;
        swordTransform.localScale    = Vector3.one;
        // attach
        swordTransform.parent = handTransform;
#else
        // attach
        swordTransform.parent = handTransform;
        // reset sword position
        swordTransform.localPosition = Vector3.zero;
        swordTransform.localRotation = Quaternion.identity;
        swordTransform.localScale    = Vector3.one;
#endif
        // move a bit over the hand
        _swordObject._zpos -= 0.01f;

#if false // obsolete since version 1.06
        // due to sword flashes at root positon, give it correct position at first frame.
        _sprite.UpdateAlways();
#endif
        return(true);
    }
Beispiel #9
0
    // Use this for initialization
    void Start()
    {
        sprite = GetComponent <SsSprite>();

        // 0番=ルートパーツを参照する
        SsPart part = sprite.GetPart(0);

        // ルートパーツが持つ全ユーザーデータキーの文字列とフレーム位置のペアで辞書を作る
        SsPartRes res      = part._res;
        int       endFrame = res.FrameNum - 1;

        // 末尾キーから先頭キーに向かって遡る
        for (int i = res.UserKeys.Count - 1; i >= 0; --i)
        {
            SsUserDataKeyFrame userDataKey = (SsUserDataKeyFrame)res.GetKey(SsKeyAttr.User, i);

            // 文字列が格納されていない場合は無視する
            if (!userDataKey.Value.IsString)
            {
                continue;
            }

            var se = new StartEndFrame();

            // 1つ右のキーフレーム、または全フレーム数-1を終了フレームとする
            se.end = endFrame;

            // "文字列"領域に書かれた文字列をキーにして開始・終了位置フレームを登録する
            se.start = userDataKey.Time;
            labelToFrame[userDataKey.Value.String] = se;

            // このキーフレームの位置-1が1つ左の区間の終了フレームになる
            endFrame = userDataKey.Time - 1;
        }

        // 登録したラベルと区間を列挙する
        Debug.Log("User data keys...");
        foreach (var e in labelToFrame)
        {
            Debug.Log("[" + e.Key + "] start:" + e.Value.start + " end:" + e.Value.end);
        }
    }
Beispiel #10
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            SsPart partAlphaParent = sprAlpha.GetPart("parent");
            SsPart partHideParent  = sprHide.GetPart("parent");
            switch (state)
            {
            case 0:
                // half-transparent and hide
                partAlphaParent.ForceAlpha(0.5f);
                partHideParent.ForceShow(false);
                break;

            case 1:
                // opaque and show
                partAlphaParent.ForceAlpha(1f);
                partHideParent.ForceShow(true);
                break;
            }
            state = (state + 1) % 2;
        }
    }
 void Start()
 {
     _sprite = GetComponent<SsSprite>();
     _sprite.Animation = ssdb.GetAnime(_defaultAnimeName);
     _mainPart = _sprite.GetPart("part 1");
 }
Beispiel #12
0
	public void OnUserDataKey(SsPart part, SsAttrValueInterface val)
	{
		SsUserDataKeyValue u = val as SsUserDataKeyValue;
		if (u.String == "HIT!!!")
		{
			// start collision detection
			_swordObject.EnableCollision(true);
			SsGameTest._instance._swordLength *= 1.5f;
			SsGameTest._instance._swordWidth *= 1.25f;
		}
		if (u.String == "DONE")
		{
			// restore the sword length
			SsGameTest._instance._swordLength = _orgSwordLength;
			SsGameTest._instance._swordWidth = _orgSwordWidth;
			part.OnUserDataKey -= OnUserDataKey;
		}
	}	
 public void OnUserDataKey(SsPart part, SsAttrValueInterface val)
 {
     var udk = val as SsUserDataKeyValue;
     Debug.LogWarning(part.Sprite.gameObject.name + ": " + udk.String);
     part.OnUserDataKey -= OnUserDataKey;
 }
Beispiel #14
0
    UpdateAlways()
    {
        if (_animation == null)
        {
            return;
        }
        if (_parts == null)
        {
            return;
        }
        // when this object is created from prefab, Unity comes here though all of _parts is not yet constructed...
        if (_parts[_partsNum - 1] == null)
        {
            return;
        }

        if (!Application.isPlaying)
        {
            if (_animeFrame < _startAnimeFrame)
            {
                _animeFrame = _startAnimeFrame;
            }
            else if (_animeFrame > _endAnimeFrame)
            {
                _animeFrame = _endAnimeFrame;
            }
        }

        // check for automatic destruction by life time
        if (_lifeTime > 0)
        {
            _lifeTimeCount += Time.deltaTime;
            if (_lifeTimeCount >= _lifeTime)
            {
                Destroy(gameObject);
                return;
            }
        }

        if (subAnimations != null)
        {
            // apply sub animations
            foreach (var e in subAnimations)
            {
                if (e.Animation == null)
                {
                    continue;
                }

                if (e.BindsToAllParts)
                {
                    // bind to all parts in the main animation
                    for (int i = 1; i < _parts.Length; ++i)
                    {
                        // bind animation from all parts in the sub animation
                        for (int index = 0; index < e.Animation.PartList.Length; ++index)
                        {
                            _parts[i].AddSubAnime(e, e.Animation.PartList[index]);
                        }
                    }
                }
                else
                {
                    // bind each part by name or index
                    for (int index = 0; index < e.Animation.PartList.Length; ++index)
                    {
                        SsPart part = null;
                        if (e.BindsByPartName)
                        {
                            // bind part by name
                            part = GetPart(e.Animation.PartList[index].Name);
                        }
                        else
                        {
                            // bind by index
                            part = GetPart(index);
                        }
                        if (part != null)
                        {
                            // register sub anime to do inside Update() below.
                            part.AddSubAnime(e, e.Animation.PartList[index]);
                        }
                    }
                }
            }
        }

        // update all parts
        foreach (SsPart e in _parts)
        {
            e.Update();
        }

        if (_prioChanged)
        {
            // sort draw order by priority
            SortByPriority();
            _prioChanged = false;
        }

        // update mesh contents if anything was changed.
        if (_vertChanged)
        {
            _mesh.vertices = _vertices;
            updateBoundingBox();
            _vertChanged = false;
        }
        if (_uvChanged)
        {
            _mesh.uv   = _uvs;
            _uvChanged = false;
        }
        if (_colorChanged)
        {
            _mesh.colors  = _colors;
            _colorChanged = false;
        }
        if (_extraChanged)
        {
            _mesh.uv2     = _extras;
            _extraChanged = false;
        }

        // update materials
        if (_matChanged)
        {
#if _USE_SHARED_MATERIAL
            _meshRenderer.sharedMaterials = _materials;
#else
            _meshRenderer.materials = _materials;
#endif
            _matChanged = false;
        }

        if (_isPlaying)
        {
            // step animation frame
            float step = Time.deltaTime * _animation.FPS * Speed * _currentStepSign;
#if _TEST_FRAME_SKIP
            if (Time.deltaTime * _animation.FPS > 1)
            {
                ++_frameSkipCount;
            }
//				Debug.Log("lost frame at " + Time.frameCount);
#endif
            _prevFrame   = _animeFrame;
            _animeFrame += step;

            //if (step >= _playFrameLength)
            //	Debug.LogWarning("Too long frameskip!! " + step);

            // end of animation
            if (_animeFrame < _startAnimeFrame ||
                (int)_animeFrame > _endAnimeFrame)                 // 2012.02.05 cares about last frame
            {
                bool clipFrame = true;
                if (IsRoundTrip)
                {
                    // reverse direction
                    _prevStepSign     = _currentStepSign;
                    _currentStepSign *= -1;
                    if (!_returnTrip)
                    {
                        // now onto return path during round trip
                        _returnTrip = true;
                    }
                    else
                    {
                        _returnTrip = false;
                    }
                }
                else
                {
                    clipFrame = false;
                }

                if (!_returnTrip)
                {
                    if (PlayCount == 0)
                    {
                        // endless
                    }
                    else
                    {
                        if (++_currentPlayCount >= PlayCount)
                        {
                            // really end
                            clipFrame   = true;
                            _isPlaying  = false;
                            _isFinished = true;
                            if (AnimationFinished != null)
                            {
                                AnimationFinished(this);
                            }
                            // destroy the client game object
                            if (DestroyAtEnd)
                            {
                                Destroy(gameObject);
                            }
                        }
                    }
                }

                float overrun = 0;
                if (_animeFrame < _startAnimeFrame)
                {
                    overrun  = (_animeFrame - _startAnimeFrame) % _playFrameLength;
                    overrun *= -1;
                }
                else if ((int)_animeFrame > _endAnimeFrame)
                {
                    overrun = (_animeFrame - 1 - _endAnimeFrame) % _playFrameLength;
                }
                if (overrun < 0)
                {
                    overrun = 0;
                }

                if (clipFrame)
                {
                    // stop
                    if (IsRoundTrip)
                    {
                        // reverse direction

                        // reflect overrun
                        if (_animeFrame < _startAnimeFrame)
                        {
                            _animeFrame = _startAnimeFrame + overrun;
                        }
                        else if (_animeFrame > _endAnimeFrame)
                        {
                            _animeFrame = _endAnimeFrame - overrun;
                        }
                    }
                    else
                    {
                        // stop
                        if (_animeFrame < _startAnimeFrame)
                        {
                            _animeFrame = _startAnimeFrame;
                        }
                        else if (_animeFrame > _endAnimeFrame)
                        {
                            _animeFrame = _endAnimeFrame;
                        }
                    }
                }
                else
                {
                    // repeat
                    if (_animeFrame < _startAnimeFrame)
                    {
                        _animeFrame = _endAnimeFrame + 1 - overrun;                         // 2012.02.05 cares about last frame
                    }
                    else if (_animeFrame > _endAnimeFrame)
                    {
                        _animeFrame = _startAnimeFrame + overrun;
                    }
                }
            }

            // step sub animations
            foreach (var e in subAnimations)
            {
                e.StepFrame(Time.deltaTime);
            }
        }
    }
 void Start()
 {
     _sprite           = GetComponent <SsSprite>();
     _sprite.Animation = ssdb.GetAnime(_defaultAnimeName);
     _mainPart         = _sprite.GetPart("part 1");
 }
Beispiel #16
0
    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();
    }
Beispiel #17
0
//	void Awake()
//	{
//		tag = "bee";
//	}

	void Start()
	{
		_xpos = Random.Range(-200, 200);
		_ypos = Random.Range(500, 700);
		_zpos = -0.01f;
		_rot = Vector3.zero;
		Update();
		ChangeAnime("bee_ssa");
		_bodyPart = _sprite.GetPart("体");
		Reset();
		_sprite.Play();
		_sprite.AnimFrame = Random.Range(0, 3);
	}
	SortByPriority()
	{
		SsPart[] sorted = new SsPart[_parts.Length];
		for (int i = 0; i < _parts.Length; ++i)
			sorted[i] = _parts[i];
		
		// sort
		Array.Sort(sorted);
		
		// change index in submesh array to change draw order
		int index = 0;
		for (int i = 0; i < _parts.Length; ++i)
		{
			if (!sorted[i]._res.IsRoot)
			{
				sorted[i].SetToSubmeshArray(index);
				// change material order same as submesh
				_materials[index] = sorted[i]._material;
				++index;
			}
		}
			
		// update material list
		_matChanged = true;
	}
	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();
	}
Beispiel #20
0
	public void OnSoundKey(SsPart part, SsAttrValueInterface val)
	{
		SsSoundKeyValue sv = val as SsSoundKeyValue;
		Debug.LogWarning(part.Sprite.gameObject.name + ": " + sv.SoundId);
		part.OnSoundKey -= OnSoundKey;
	}