Skip to content

Commit

Permalink
Auto creation player for PIE mode
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrpg committed Nov 5, 2023
1 parent 5aa343b commit fe34e7d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Assets/Editor/SceneList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,36 @@ public void OnGUI()
{
var goPIE = new GameObject("PlayInEditor");
playInEditor = goPIE.AddComponent<PlayInEditor>();
EditorUtility.SetDirty(goPIE);
}

playInEditor.spawnScene = scene.Key;
playInEditor.SpawnScene();

var goPlayer = GameObject.Find("Player");
if (goPlayer == null) // auto create player
{
goPlayer = new GameObject("Player");

var cc = goPlayer.AddComponent<CharacterComponent>();

{
var c = new Character();
c.CharProto = ResourceManager.Load<CharacterProto>("Entities/Character/Player", ResourceManager.EXT_ASSET);
c.creatureProto = ResourceManager.Load<CreatureProto>("Entities/Creature/BaseMale11", ResourceManager.EXT_ASSET);
c.Caps = Character.CharacterCaps.Player;
c.fraction = "player";
cc.SetEntity(c);
}

cc.InvalidateData();
var enterPoint = GameObject.Find("EnterPoint");
if (enterPoint != null) // auto place to EnterPoint
{
cc.transform.position = enterPoint.transform.position;
}
EditorUtility.SetDirty(goPlayer);
}
}
}
}
Expand Down

0 comments on commit fe34e7d

Please sign in to comment.