// Use this for initialization void Start() { goAlpha = GameObject.Find("ChangeAttrByScript_alpha_ssa"); goHide = GameObject.Find("ChangeAttrByScript_hide_ssa"); sprAlpha = goAlpha.GetComponent <SsSprite>(); sprHide = goHide.GetComponent <SsSprite>(); }
void Reset() { _timer = SsGameTest._instance._attackTime + Random.Range(-1, +1); _toTarget = Random.Range(0, 100) <= SsGameTest._instance._attackRate; if (_toTarget && _player) { // pursue to the player SsSprite playerSprite = _player.GetComponent <SsSprite>(); Vector3 targetPos = playerSprite.Position; targetPos.y += 450; targetPos.x += Random.Range(-80, +80); _velocity = (targetPos - _pos) / (_timer / Time.deltaTime); _velocity.z = 0f; // go red _bodyPart.IndividualizeMaterial(true); _bodyPart.GetMaterial().color = Color.red; } else { // random flying _velocity = new Vector3(Random.Range(-2f, 2f) / 4, Random.Range(-2f, 2f) / 4, 0f); // calm down _bodyPart.RevertChangedMaterial(); } _wafture = Random.Range(1f, 2f); _waftSpeed = Random.Range(4f, 8f); _zrot = 0f; _sprite.vFlip = false; _updateFunc = _Idling; }
CleanupSpritePrefabs() { // list up all assets from root so far... List <string> allAssets = new List <string>(); Stack <string> paths = new Stack <string>(); paths.Push(Application.dataPath + "/SpriteStudioPrefabs/"); while (paths.Count != 0) { string path = paths.Pop(); string[] files = Directory.GetFiles(path, "*_ssa.prefab"); foreach (var e in files) { allAssets.Add(e.Substring(Application.dataPath.Length - 6)); } foreach (string e in Directory.GetDirectories(path)) { paths.Push(e); } } foreach (var path in allAssets) { // delete spite prefab which has no longer animation. SsSprite e = AssetDatabase.LoadAssetAtPath(path, typeof(SsSprite)) as SsSprite; if (e.Animation == null) { Debug.Log(e + " was removed"); AssetDatabase.DeleteAsset(path); } } }
// Use this for initialization void Start() { _sprite = GetComponent<SsSprite>(); _buttons = FindObjectsOfType(typeof(SsButtonBehaviour)) as SsButtonBehaviour[]; foreach (var e in _buttons) e.OnPushed += OnPushed; _cube = GameObject.Find("Cube"); }
// Create game object with this script and animation which in 'Resources' folder. static public GameObject CreateGameObjectWithAnime(string name, string animName) { GameObject go = new GameObject(name); SsSprite sprite = go.AddComponent <SsSprite>(); SsAnimation anim = (SsAnimation)Resources.Load(animName, typeof(SsAnimation)); sprite.Animation = anim; return(go); }
public void SwingFinished(SsSprite sprite) { // restore the sword length surely SsGameTest._instance._swordLength = _orgSwordLength; SsGameTest._instance._swordWidth = _orgSwordWidth; // end collision detection _swordObject.EnableCollision(false); _updateFunc = _Idling; ChangeAnime("stand_ssa"); }
// Use this for initialization void Start() { _sprite = GetComponent <SsSprite>(); _buttons = FindObjectsOfType(typeof(SsButtonBehaviour)) as SsButtonBehaviour[]; foreach (var e in _buttons) { e.OnPushed += OnPushed; } _cube = GameObject.Find("Cube"); }
CreateSpritePrefab(SsAnimation anime) { var po = new PrefabricatableObject("SpriteStudioPrefabs", anime.name); SsSprite spr = po.GetOrAddComponent <SsSprite>(); spr.Animation = null; // force to update when the same animation attached spr.Animation = anime; #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9 spr.gameObject.SetActive(true); #endif po.Close(true); }
// public void OnHierarchyChange() // { // Debug.LogWarning("OnHierarchyChange()"); // AddShaderKeeper(); // } // public void OnSelectionChange() // { // Debug.LogWarning("OnSelectionChange()"); // AddShaderKeeper(); // } public static void AddShaderKeeper() { // if null or not changed or prefab is ignored. if (!SsSpriteEditor.LastSprite) return; if (SsSpriteEditor.LastSprite == _lastSprite) return; if (PrefabUtility.GetPrefabType(SsSpriteEditor.LastSprite.gameObject) == PrefabType.Prefab) return; // it seems to be added new sprite possibly... _lastSprite = SsSpriteEditor.LastSprite; //Debug.Log("sprite added to this scene!!" + _lastSprite); // add shader keeper to current scene if it doesn't exist. SsAssetPostProcessor.AddShaderKeeperToCurrentScene(); }
void AnimeFinished(SsSprite sprite) { // all bees in visible now are fell out of the scene. foreach (GameObject e in SsGameTest._instance._bees) { BeeObject bo = e.GetComponent <BeeObject>(); if (bo.IsFalling()) { continue; } bo.OnHit(); } // vaporize Object.Destroy(gameObject); }
// 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); } }
// Intersects with another sprite? public bool IntersectsByBounds(SsSprite other, bool ignoreZ) { if (!_mesh || !other._mesh) { return(false); } if (ignoreZ) { // create temporary and modify it then test. Bounds b = other._bounds; Vector3 v = b.center; v.z = _bounds.center.z; b.center = v; return(_bounds.Intersects(b)); } else { return(_bounds.Intersects(other._bounds)); } }
// 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); } }
// public void OnHierarchyChange() // { // Debug.LogWarning("OnHierarchyChange()"); // AddShaderKeeper(); // } // public void OnSelectionChange() // { // Debug.LogWarning("OnSelectionChange()"); // AddShaderKeeper(); // } static public void AddShaderKeeper() { // if null or not changed or prefab is ignored. if (!SsSpriteEditor.LastSprite) { return; } if (SsSpriteEditor.LastSprite == _lastSprite) { return; } if (PrefabUtility.GetPrefabType(SsSpriteEditor.LastSprite.gameObject) == PrefabType.Prefab) { return; } // it seems to be added new sprite possibly... _lastSprite = SsSpriteEditor.LastSprite; //Debug.Log("sprite added to this scene!!" + _lastSprite); // add shader keeper to current scene if it doesn't exist. SsAssetPostProcessor.AddShaderKeeperToCurrentScene(); }
// Intersects with another sprite by bounding parts? public bool IntersectsByBoundingParts(SsSprite other, bool ignoreZ, bool useAABB) { foreach (var m in _boundPartList) { foreach (var o in other._boundPartList) { if (useAABB) { if (m.IntersectsByAABB(o, ignoreZ)) { return(true); } } else { if (m.Intersects(o, ignoreZ)) { return(true); } } } } return(false); }
public void FlashFinished(SsSprite sprite) { _flashing = false; _sprite.AnimationFinished = null; }
void Start() { _sprite = GetComponent <SsSprite>(); _sprite.Animation = ssdb.GetAnime(_defaultAnimeName); _mainPart = _sprite.GetPart("part 1"); }
public void Init() { this.myMecanimAnimator = this.GetComponent<Animator> (); this.mySSAnimator = this.GetComponent<SsSprite> (); this.myState = TuruState.Idle; this.mySSAnimator.Animation = this.SSAnimations [0]; }
void Awake() { _transform = transform; _sprite = GetComponent<SsSprite>(); _sprite.DrawBoundingBox = SsGameTest._instance._boundingBox; }
// Intersects with another sprite? public bool IntersectsByBounds(SsSprite other, bool ignoreZ) { if (!_mesh || !other._mesh) return false; if (ignoreZ) { // create temporary and modify it then test. Bounds b = other._bounds; Vector3 v = b.center; v.z = _bounds.center.z; b.center = v; return _bounds.Intersects(b); } else return _bounds.Intersects(other._bounds); }
public void JumpFinished(SsSprite sprite) { _updateFunc = _Idling; ChangeAnime("stand_ssa"); }
SsPart( SsSprite manager, int index, ///< index of parts SsPartRes partRes, ///< part resource SsImageFile imageFile) ///< source image path, texture and material. { _mgr = manager; _index = index; _vIndex = (index - 1) * 4; _subMeshIndex = index - 1; _res = partRes; _mesh = _mgr._mesh; if (_res.HasParent) { _parent = _mgr.Sprite(_res.ParentId); if (_parent == null) { Debug.LogError("##### parent sprite must be created already!!"); //throw ArgumentNullException; Debug.Break(); return; } } // attach parent's transform to inherit its SRT. _pivotMatrix = Matrix4x4.identity; switch (_res.Type) { case SsPartType.Root: // root has only position, no vertices #if _APPLY_ROOT_POS_AS_PIVOT _rootPivot = new Vector3(-_res.PosX(0), +_res.PosY(0), 0f); #endif break; case SsPartType.Normal: case SsPartType.Bound: // each vertices are attached to pivot _vertPositions = new Vector3[4]; _orgVertices = new Vector3[4]; for (int i = 0; i < _vertPositions.Length; ++i) { _orgVertices[i] = _vertPositions[i] = _res.OrgVertices[i]; #if _MOVE_BOUND_PART_TO_THE_FRONT if (_res.Type == SsPartType.Bound) { _vertPositions[i].z = -0.1f; _orgVertices[i].z = -0.1f; } #endif } break; default: // other types don't require vertices. break; } // set startup value _visible = !_res.Hide(0); _flipH = false; _flipV = false; _pos = Vector3.zero; _quaternion = Quaternion.identity; _scale = Vector3.one; #if _MAKE_ROOT_TO_LOCAL_TRANSFORM _rotChanged = false; #endif // not any normal types don't require a material, colors, and vertices. if (_res.Type != SsPartType.Normal && _res.Type != SsPartType.Bound) { return; } // shortcut #if _USE_UNIFIED_SHADER _useUnifiedShader = _res.imageFile.useUnifiedShader; #endif _useCgShader = (SystemInfo.graphicsShaderLevel >= 20); if (_res.Type == SsPartType.Bound) { #if !_BOUND_PART_DRAW_AS_INVALID // set vertex color to transparent red. // this alpha value will be overwritten in AlphaValue property later. _vertexColor = new Color(1, 0, 0, 1); for (int i = 0; i < 4; ++i) { // set UVs to a point at left-top. _mgr._uvs[_vIndex + i] = Vector2.zero; // set vertex colors _mgr._colors[_vIndex + i] = _vertexColor; } // invisible is default. _visible = false; #else _visible = _mgr.DrawBoundingParts; #endif } else { // default vertex color _vertexColor = new Color(1, 1, 1, 1); for (int i = 0; i < 4; ++i) { // set UVs. use precalculated UVs, it is stored clockwise _mgr._uvs[_vIndex + i] = _res.UVs[i]; // set vertex colors _mgr._colors[_vIndex + i] = _vertexColor; } // set blend type and _shaderType ColorBlendType = SsColorBlendOperation.Non; } // set boolean about having transparency if (_res.Type == SsPartType.Bound) { #if _BOUND_PART_DRAW_AS_INVALID // become purple that mean invalid. _material = null; #else // needs any appropriate material _hasTransparency = true; AlphaValue = 0.5f; #endif } else { _hasTransparency = _res.HasTrancparency || (_parent != null && _res.Inherits(SsKeyAttr.Trans)); // always inherits parent's alpha whether the immediate parent has transparency or not. 2012.12.19 bug fixed // set alpha value AlphaValue = _res.Trans(0); // set appropriate material. _shaderType was set inside ColorBlendType property. _material = imageFile.GetMaterial(_shaderType); } //--------- calculates various info... Update(true); // set triangle indices. never changed so far. #if _USE_TRIANGLE_STRIP _triIndices = new int[] { _vIndex + 0, _vIndex + 1, _vIndex + 3, _vIndex + 2 }; // order is LT->RT->LB->RB. #else _triIndices = new int[] { _vIndex + 0, _vIndex + 1, _vIndex + 2, _vIndex + 2, _vIndex + 3, _vIndex + 0 }; // order is LT->RT->RB->RB->LB->LT #endif SetToSubmeshArray(_index - 1); }
void AnimeFinished(SsSprite sprite) { // all bees in visible now are fell out of the scene. foreach (GameObject e in SsGameTest._instance._bees) { BeeObject bo = e.GetComponent<BeeObject>(); if (bo.IsFalling()) continue; bo.OnHit(); } // vaporize Object.Destroy(gameObject); }
void OnEnable() { // SsTimer.StartTimer(); _sprite = target as SsSprite; // add shader keeper if it doesn't exist during show the sprite object substance. PrefabType prefabType = PrefabUtility.GetPrefabType(_sprite); if (_sprite != LastSprite && prefabType != PrefabType.Prefab) { //SsTimer.StartTimer(); SsEditorWindow.AddShaderKeeper(); //SsTimer.EndTimer("checking or add shader keeper"); } _animeFrame = _sprite._animeFrame; _startAnimeFrame = _sprite._startAnimeFrame; _endAnimeFrame = _sprite._endAnimeFrame; _hFlip = _sprite.hFlip; _vFlip = _sprite.vFlip; _drawBoundingBox = _sprite.DrawBoundingBox; _subAnimations = null;//_sprite.subAnimations; // get latest animation list // SsTimer.StartTimer(); if (!databaseGo) databaseGo = SsAssetPostProcessor.GetDatabaseGo(); // SsTimer.EndTimer("load database asset"); if (databaseGo) { //SsTimer.StartTimer(); _database = databaseGo.GetComponent<SsAssetDatabase>(); List<SsAnimation> animeList = _database.animeList; _animeNames = new string[animeList.Count + 1]; for (int i = 0; i < animeList.Count; ++i) _animeNames[i + 1] = animeList[i].name; System.Array.Sort(_animeNames, 1, _animeNames.Length - 1); _animeNames[0] = "<none>"; // get the index of this animation in the list if (_sprite.Animation) { string myAnimeName = _sprite.Animation.name; for (int i = 1; i < _animeNames.Length; ++i) { if (myAnimeName == _animeNames[i]) { _selectedAnimeIndex = i; break; } } } //SsTimer.EndTimer("make anime list"); } else { Debug.LogError("Not found animation list: '" + SsAssetDatabase.filePath + "' needs to reimport animation data"); } LastSprite = _sprite; // SsTimer.EndTimer("SsSpriteEditor.OnEnable()"); }
public void AnimeFinished(SsSprite sprite) { ChangeAnime("stand_ssa", 0); }
void OnEnable() { // SsTimer.StartTimer(); _sprite = target as SsSprite; // add shader keeper if it doesn't exist during show the sprite object substance. PrefabType prefabType = PrefabUtility.GetPrefabType(_sprite); if (_sprite != LastSprite && prefabType != PrefabType.Prefab) { //SsTimer.StartTimer(); SsEditorWindow.AddShaderKeeper(); //SsTimer.EndTimer("checking or add shader keeper"); } _animeFrame = _sprite._animeFrame; _startAnimeFrame = _sprite._startAnimeFrame; _endAnimeFrame = _sprite._endAnimeFrame; _hFlip = _sprite.hFlip; _vFlip = _sprite.vFlip; _drawBoundingBox = _sprite.DrawBoundingBox; _subAnimations = null; //_sprite.subAnimations; // get latest animation list // SsTimer.StartTimer(); if (!databaseGo) { databaseGo = SsAssetPostProcessor.GetDatabaseGo(); } // SsTimer.EndTimer("load database asset"); if (databaseGo) { //SsTimer.StartTimer(); _database = databaseGo.GetComponent <SsAssetDatabase>(); List <SsAnimation> animeList = _database.animeList; _animeNames = new string[animeList.Count + 1]; for (int i = 0; i < animeList.Count; ++i) { _animeNames[i + 1] = animeList[i].name; } System.Array.Sort(_animeNames, 1, _animeNames.Length - 1); _animeNames[0] = "<none>"; // get the index of this animation in the list if (_sprite.Animation) { string myAnimeName = _sprite.Animation.name; for (int i = 1; i < _animeNames.Length; ++i) { if (myAnimeName == _animeNames[i]) { _selectedAnimeIndex = i; break; } } } //SsTimer.EndTimer("make anime list"); } else { Debug.LogError("Not found animation list: '" + SsAssetDatabase.filePath + "' needs to reimport animation data"); } LastSprite = _sprite; // SsTimer.EndTimer("SsSpriteEditor.OnEnable()"); }
void Awake() { _transform = transform; _sprite = GetComponent <SsSprite>(); _sprite.DrawBoundingBox = SsGameTest._instance._boundingBox; }
// Intersects with another sprite by bounding parts? public bool IntersectsByBoundingParts(SsSprite other, bool ignoreZ, bool useAABB) { foreach (var m in _boundPartList) { foreach (var o in other._boundPartList) { if (useAABB) { if (m.IntersectsByAABB(o, ignoreZ)) return true; } else { if (m.Intersects(o, ignoreZ)) return true; } } } return false; }
void Start() { _sprite = GetComponent<SsSprite>(); _sprite.Animation = ssdb.GetAnime(_defaultAnimeName); _mainPart = _sprite.GetPart("part 1"); }
// Use this for initialization void Start () { goAlpha = GameObject.Find("ChangeAttrByScript_alpha_ssa"); goHide = GameObject.Find("ChangeAttrByScript_hide_ssa"); sprAlpha = goAlpha.GetComponent<SsSprite>(); sprHide = goHide.GetComponent<SsSprite>(); }