//キャラ描画 private void DrawChar() { Sprite sp = m_parent.GetSelectedSprite(); Vector2 pos = new Vector2(-sp.pivot.x, +sp.pivot.y - sp.rect.height); CharaCell cell = m_parent.GetSelectedCharCell(); //顔奥表示 if (cell.faceZ == 1) { DrawFace(pos, cell); } { //DebugPanel.Log("sp.rect", sp.rect); //Vector2 pos = new Vector2((1 * GRIDSIZE) + 0, (1 * GRIDSIZE) - 0); Vector2 size = new Vector2(sp.rect.width, sp.rect.height); Rect drawRect = new Rect((pos + m_camPos) * mag, size * mag); //DebugPanel.Log("drawRect", drawRect); //DebugPanel.Log("sp.pivot.", sp.pivot); if (sp != null) { GUI.DrawTextureWithTexCoords(drawRect, sp.texture, CharaCellEditorMain.GetSpriteNormalRect(sp)); //描画 } } //顔手前表示 if (cell.faceZ == 0) { DrawFace(pos, cell); } DrawGridLine3(); }
void RefreshFromSpriteFile() { if (EditorUtility.DisplayDialogComplex("RefreshFromSpriteFile", "スプライトからCharaCellデータを再生しますか?", "OK", "キャンセル", "") == 0) { Debug.Log("RefreshFromSpriteFile"); var newCharCells = new CharaCellObject(); // 現在のスプライトにあるものを抽出、ない場合は新たに作成 for (int i = 0; i < m_bodySprites.Length; ++i) { string id = CharaCell.ReplaceHyphen(m_bodySprites[i].name); CharaCell item = m_charCells.param.FirstOrDefault(x => x.ID == id); if (item == null) { item = new CharaCell(); item.ID = id; } newCharCells.param.Add(item); } m_charCells = newCharCells; UpdateCharaCellDict(); AssetDatabase.Refresh(); } }
//顔描画 private void DrawFace(Vector2 pos, CharaCell cell) { const int BASEY = -32; float angle = cell.faceAngle * 90; Vector2 zuraRev = Vector2.zero; switch (cell.faceAngle) { case 0: angle = 0; zuraRev.y -= 1; break; case 1: zuraRev.x += 1; break; case 2: zuraRev.y += 1; break; case 3: zuraRev.x -= 1; break; } //顔 { Sprite kao = m_parent.GetSelectedKaoSprite(); Vector2 kaopos = new Vector2(-kao.pivot.x + cell.faceX, cell.faceY + BASEY); // kaopos += zuraRev; Vector2 size = new Vector2(kao.rect.width, kao.rect.height); Rect drawRect = new Rect((m_camPos + kaopos) * mag, size * mag); Vector2 rotatePivot = new Vector2(drawRect.center.x, drawRect.center.y - drawRect.height / 2); GUIUtility.RotateAroundPivot(angle, rotatePivot); // RotateAroundPivot等は行列の掛け算なので、一旦初期値に戻す GUI.DrawTextureWithTexCoords(drawRect, kao.texture, CharaCellEditorMain.GetSpriteNormalRect(kao)); //描画 GUI.matrix = Matrix4x4.identity; } //ずら { Sprite zura = m_parent.GetSelectedZuraSprite(); Vector2 zurapos = new Vector2(-zura.pivot.x + cell.faceX, cell.faceY + BASEY); zurapos += zuraRev; Vector2 size = new Vector2(zura.rect.width, zura.rect.height); Rect drawRect = new Rect((m_camPos + zurapos) * mag, size * mag); Vector2 rotatePivot = new Vector2(drawRect.center.x, drawRect.center.y - drawRect.height / 2); GUIUtility.RotateAroundPivot(angle, rotatePivot); // RotateAroundPivot等は行列の掛け算なので、一旦初期値に戻す GUI.DrawTextureWithTexCoords(drawRect, zura.texture, CharaCellEditorMain.GetSpriteNormalRect(zura)); //描画 GUI.matrix = Matrix4x4.identity; } }
// 画像一覧をボタン選択出来る形にして出力 void DrawImageParts() { m_scrollPosition = EditorGUILayout.BeginScrollView(m_scrollPosition, GUI.skin.box); //if(imgDirectory != null) { float x = 0.0f; float y = 00.0f; //float size = 48; //float h = 50.0f; float maxW = TIPSIZE * 5; EditorGUILayout.BeginVertical(); int index = 0; bool isEnd = false; foreach (var sp in m_bodySprites) { string spname = CharaCell.ReplaceHyphen(sp.name); GUIContent contents = new GUIContent(); if (!m_charCellDict.ContainsKey(spname)) { Debug.Log($"NotFound {spname}"); m_isLoadSprite = false; return; } contents.text = spname + "\n No:" + m_charCellDict[spname].faceNo.ToString() + " X:" + m_charCellDict[spname].faceX.ToString() + " Y:" + m_charCellDict[spname].faceY.ToString(); if ((m_charCellDict[spname].faceNo == 0) && (m_charCellDict[spname].faceX == 0) && (m_charCellDict[spname].faceY == 0)) { contents.text += " *AllZero*"; } //GUILayout.FlexibleSpace(); if (m_selectedSprite == index) { GUI.color = new Color(1f, 0.5f, 1f, 1f); } if (GUILayout.Button(contents, GUILayout.MaxWidth(TIPSIZE * 5), GUILayout.Height(TIPSIZE), GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false))) { m_selectedSprite = index; RefreshEditorWindow(); } if (m_selectedSprite == index) { GUI.color = new Color(1f, 1f, 1f, 1f); } Rect lastRect = GUILayoutUtility.GetLastRect(); lastRect.width = TIPSIZE; lastRect.height = TIPSIZE; GUI.DrawTextureWithTexCoords(lastRect, sp.texture, GetSpriteNormalRect(sp)); y += TIPSIZE; index++; } EditorGUILayout.EndVertical(); } EditorGUILayout.EndScrollView(); }