コード例 #1
0
ファイル: SpawnCommand.cs プロジェクト: veesusmikelheir/SRML
        public override bool Execute(string[] args)
        {
            if (args.Length < 1 || args.Length > 2)
            {
                Console.LogError("Incorrect number of arguments!");
                return(false);
            }

            Identifiable.Id id;
            GameObject      prefab;

            try
            {
                id     = (Identifiable.Id)Enum.Parse(typeof(Identifiable.Id), args[0], true);
                prefab = GameContext.Instance.LookupDirector.GetPrefab(id);
            }
            catch
            {
                Console.LogError("Invalid ID!");
                return(false);
            }

            int count = 0;

            if (args.Length != 2 || !Int32.TryParse(args[1], out count))
            {
                count = 1;
            }

            for (int i = 0; i < count; i++)
            {
                if (Physics.Raycast(new Ray(Camera.main.transform.position, Camera.main.transform.forward), out var hit))
                {
                    var spawned = SRBehaviour.InstantiateActor(prefab, SceneContext.Instance.Player.GetComponent <RegionMember>().setId, true);
                    spawned.transform.position = hit.point + hit.normal * PhysicsUtil.CalcRad(spawned.GetComponent <Collider>());
                    var delta      = -(hit.point - Camera.main.transform.position).normalized;
                    var newForward = (delta - Vector3.Project(delta, hit.normal)).normalized;
                    spawned.transform.rotation = Quaternion.LookRotation(delta, hit.normal);
                }
            }
            return(true);
        }