SpriteR init_resource_sprite() { SpriteR sprite = SpriteR.new_sprite(); sprite.set_sorting_layer("UI"); sprite.transform.SetParent(gameObject.transform); return(sprite); }
void Awake() { if (spriteRenderer == null) { spriteRenderer = GetComponent <SpriteRenderer>(); } if (instance == null) { instance = this; } }
public static SpriteR new_sprite() { if (instance == null) { Debug.Log("SpriteR new_sprite() fail,instance not exist!!"); return(null); } SpriteR s = Instantiate(instance, new Vector3(0, 0, 0), Quaternion.identity) as SpriteR; s.init(); return(s); }
public void init(int x, int y) { cur_obj = gameObject; pos_x = x; pos_y = y; building = null; terrian = null; //Debug.Log("name="+cur_obj.name); //GameObject obj = GameObject.Find("Front"); //if (obj != null)front = obj.GetComponent<Front>(); /* * for(int i = 0; i < cur_obj.transform.childCount; i++){ * GameObject obj = gameObject.transform.GetChild(i).gameObject; * if (obj.name == "Front"){ * front = obj.GetComponent<Front>(); * Debug.Log("init front"); * break; * } * } * type = Random.Range(0, BlockSprites.get().frontSprite.Length); * front.set_sprite(BlockSprites.get().frontSprite[type]); */ midsprite = SpriteR.new_sprite(); midsprite.set_sorting_layer("mid"); midsprite.transform.SetParent(cur_obj.transform); mid_type = Random.Range(0, BlockSprites.get().midSprite.Length); midsprite.set_sprite(BlockSprites.get().midSprite[mid_type]); frontsprite = SpriteR.new_sprite(); frontsprite.set_sorting_layer("front"); frontsprite.transform.SetParent(cur_obj.transform); front_type = Random.Range(0, BlockSprites.get().frontSprite.Length); frontsprite.set_sprite(BlockSprites.get().frontSprite[front_type]); front2sprite = SpriteR.new_sprite(); front2sprite.set_sorting_layer("front2"); front2sprite.transform.SetParent(cur_obj.transform); //front2_type = Random.Range(0, BlockSprites.get().front2Sprite.Length); front2_type = 1; front2sprite.set_sprite(BlockSprites.get().front2Sprite[front2_type]); front3sprite = SpriteR.new_sprite(); front3sprite.set_sorting_layer("front3"); front3sprite.transform.SetParent(cur_obj.transform); front3sprite.set_sprite(BlockSprites.get().transparent); }