示例#1
0
 void Awake()
 {
     Instance = this;
 }
示例#2
0
 void Awake()
 {
     instance = this;
     textMesh = GetComponent <TextMesh>();
     SetText("");
 }
 public static void DestroyInstance()
 {
     Instance = null;
 }
示例#4
0
        public override async Task Execute()
        {
            var bottom = new Vector3(0, Height, 0);

            var duration = TimeSpan.FromSeconds(2);
            var elapsed  = TimeSpan.Zero;

            var easingFunctions = ((EasingFunction[])Enum.GetValues(typeof(EasingFunction))).Reverse().ToList();

            easingFunctions.RemoveAt(0);

            {
                var startPosition = FirstPosition;
                var endPosition   = FirstPosition - bottom;

                var sphere = SpherePrefab.InstantiateSingle(FirstPosition);
                Entity.Scene.Entities.Add(sphere);

                Script.AddOverTimeAction(progress =>
                {
                    sphere.Transform.Position = MathUtilEx.Interpolate(startPosition, endPosition, progress, EasingFunction.ElasticEaseOut);
                }, TimeSpan.FromSeconds(2));
            }



            var startPositions = new List <Vector3>();
            var transforms     = new List <TransformComponent>();

            for (var i = 0; i < easingFunctions.Count; i++)
            {
                var startPosition = FirstPosition + new Vector3(i + 1, 0, 0);
                var sphere        = SpherePrefab.InstantiateSingle(startPosition);

                transforms.Add(sphere.Transform);
                startPositions.Add(startPosition);
                Entity.Scene.Entities.Add(sphere);
            }



            while (Game.IsRunning)
            {
                var progress = (float)(elapsed.TotalSeconds / duration.TotalSeconds);

                if (progress > 1.0f)
                {
                    progress = 1.0f;
                }

                DebugText.Print($"Progress = {progress}", new Int2(10));

                for (var i = 0; i < transforms.Count; i++)
                {
                    var t = transforms[i];

                    var easing = easingFunctions[i];

                    t.Position = MathUtilEx.Interpolate(startPositions[i], startPositions[i] - bottom, progress, easing);
                }

                elapsed += Game.UpdateTime.Elapsed;

                if (Input.IsKeyPressed(Keys.Space))
                {
                    //reset
                    elapsed = TimeSpan.Zero;
                }

                await Script.NextFrame();
            }
        }
示例#5
0
    public void Update()
    {
        int x = (int)InputManager.GetMousePos().x;
        int y = (int)InputManager.GetMousePos().y;

        if (Input.GetKey(KeyCode.E))
        {
            if (isServer)
            {
                Furniture f = World.Instance.Furniture.GetFurnitureAt(x, y);
                if (f != null)
                {
                    Destroy(f.gameObject);
                }
            }
            if (CanPlaceTile(x, y))
            {
                SetTile(null, x, y);
            }
        }

        if (isServer && Input.GetKeyDown(KeyCode.H))
        {
            Pawn.SpawnPawn("Caveman", InputManager.GetMousePos());
        }

        if (!DebugText._Instance.Active)
        {
            return;
        }

        if (isServer)
        {
            int chunks = 0;
            int count  = 0;
            foreach (int index in PendingOperations.Keys)
            {
                if (AnyPendingOperationsFor(index))
                {
                    chunks++;
                }
                else
                {
                    continue;
                }

                count += PendingOperations[index].Count;
            }
            DebugText.Log(count + " pending tile operations over " + chunks + " chunks.");

            if (Saving)
            {
                DebugText.Log("Saving '" + Name + "' ... ", Color.green);
                DebugText.Log("Chunks Pending: " + ChunksLeftToSave, Color.green);
                DebugText.Log("Tile Ops Pending: " + OperationsPendingInSave, Color.green);
            }
        }

        DebugText.Log(loading.Count + " chunks are loading.");
        DebugText.Log(unloading.Count + " chunks are unloading.");
    }
示例#6
0
        public override void Update()
        {
            Cube?.Transform.Rotate(new Vector3(MathUtil.DegreesToRadians(60) * Game.GetDeltaTime(), 0, 0));


            DebugText.Print($"ScreenToWorldRaySegment {MainCamera.ScreenToWorldRaySegment(Input.MousePosition)}", new Int2(20, 40));


            var ray = MainCamera.ScreenToWorldRaySegment(Input.MousePosition);

            HitResult hitResult = simulation.Raycast(ray);
            Entity hitEntity = hitResult.Collider?.Entity;

            if (hitResult.Succeeded && hitEntity != selected)
            {
                if (hitEntity != hovered)
                {
                    hovered = hitEntity;
                    EntityHover.Broadcast(hitEntity); 
                }
            }
            else
            {
                if (hovered != null)
                {
                    hovered = null;
                    EntityHover.Broadcast(null);
                }                
            }

            if (Input.IsMouseButtonPressed(MouseButton.Left))
            {
                message = "";   

                if (hitResult.Succeeded)
                {
                    selected = hitEntity;

                    message = selected.Name;
                    EntitySelected.Broadcast(selected);
                    DebugText.Print($"Clicked on {message}", new Int2(20, 60));

                    selectedScreenPoint = MainCamera.WorldToScreenPoint(selected.Transform.Position);
                    worldMousePoint = MainCamera.ScreenToWorldPoint(new Vector3(Input.MousePosition, selectedScreenPoint.Z));
                    offset = selected.Transform.Position - worldMousePoint;
                } else
                {
                    selected = null;
                    selectedScreenPoint = Vector3.Zero;
                    worldMousePoint = Vector3.Zero;
                    EntitySelected.Broadcast(null);
                }
            }
            else if (selected != null && Input.IsMouseButtonDown(MouseButton.Left))
            {
                var currentWorldMousePoint = MainCamera.ScreenToWorldPoint(new Vector3(Input.MousePosition, selectedScreenPoint.Z));
                // mouseEntity.Transform.Position = currentWorldMousePoint;
                selected.Transform.Position = currentWorldMousePoint + offset;
                worldMousePoint = currentWorldMousePoint;
            }

        }
示例#7
0
 private void HandleTwo(Vector2 position)
 {
     DebugText.Print($"Even Two - {position}", new Int2(10, 20));
 }
示例#8
0
 void DebugPrint()
 {
     DebugText.Print("Hunger : " + GetHunger().Get());
     DebugText.Print("Thirst : " + GetThirst().Get());
 }
示例#9
0
        public override async Task Execute()
        {
            await Task.Yield(); // don't execute initialization on call

            Start();

            // Wait for scripts to get initialized????
            await Script.NextFrame();

            await newGameEvent.ReceiveAsync();

            while (true)
            {
                await Script.NextFrame();

                DebugText.Print($"Generation: {generation}\nAlive: {dead.Count(d => !d)}/{ai.Count}\nScore: {score}\nHighscore: {highscore}", new Int2(20, 300));

                var profiler = Profiler.Begin(AIProfilingKey);

                // get current state
                float dist = 0, height = 0;
                PipesScript.ProvideAiInformation(ref dist, ref height);

                for (int i = 0; i < characterScripts.Length; i++)
                {
                    if (dead[i])
                    {
                        continue;
                    }

                    var character = characterScripts[i];

                    if (!character.isRunning || character.isDying)
                    {
                        dead[i] = true;
                        // disable collisions to save some processing time
                        characterPhysics[i].CanCollideWith = (CollisionFilterGroupFlags)0;
                        neat.AddWithScore(ai[i], score);
                        continue;
                    }

                    var position = character.Movement.Position.Y;

                    // we try to find a function that given to positions
                    // tries to jump so that they come close together
                    var aiResult = ai[i].Compute(neat.options, new double[] { position, height });
                    if (aiResult[0] > 0.5)
                    {
                        character.Jump();
                    }
                }

                score++;

                highscore = score > highscore ? score : highscore;

                if (dead.All(d => d))
                {
                    GlobalEvents.GameOver.Broadcast();
                    ResetRound();
                }

                profiler.End();
            }
        }
示例#10
0
 private void HandleOne(Vector2 position)
 {
     DebugText.Print($"Even One - {position}", new Int2(10, 10));
 }
示例#11
0
 void OnDestroy()
 {
     singleton = null;
 }
示例#12
0
 void Awake()
 {
     singleton = this;
 }
示例#13
0
 void Start()
 {
     Instance = this;
 }
示例#14
0
 public void Awake()
 {
     DebuggerText = this;
 }
示例#15
0
 private void DelayedAction()
 {
     DebugText.Print("Delay", new Int2(10, 30));
 }
示例#16
0
文件: Entity.cs 项目: wildrabbit/ld33
    protected virtual void Awake()
    {
        m_renderer = GetComponent<SpriteRenderer>();
        m_audioSource = GetComponent<AudioSource>();
        m_body = GetComponent<Rigidbody2D>();
        m_weapon = GetComponentInChildren<Weapon>();

        m_mainCollider = GetComponent<Collider2D>();
        m_bodyCollider = transform.FindChild("bodyCollision").GetComponent<Collider2D>();

        m_lifeData = new CharacterLife();
        m_hitTime = 0.0f;
        m_lastShoot = -1.0f;

        Canvas debugCanvas = GameObject.Find("DebugCanvas").GetComponent<Canvas>();
        if (m_debugLabelPrefab != null && debugCanvas != null)
        {
            m_debugLabelInstance = Instantiate<DebugText>(m_debugLabelPrefab);
            m_debugLabelInstance.Initialize(this, debugCanvas.transform);
        }
    }
示例#17
0
 private void DelayRepeatAction()
 {
     DebugText.Print("Delay Repeat", new Int2(10, 40));
 }
示例#18
0
 public override void Update()
 {
     DebugText.Print("The original prefab", new Int2(310, 320));
     DebugText.Print("The prefab instance PileOfBoxes", new Int2(560, 370));
     DebugText.Print("The prefab instance PileOfBoxes2 with custom parent", new Int2(565, 650));
 }
示例#19
0
 public override void Update()
 {
     DebugText.Print($"Object value: {Object.Value}", new Int2(20));
 }
示例#20
0
    // Update is called once per frame
    void Update()
    {
        if (Started)
        {
            Tank   currentPlayer = GetCurrentPlayer();
            string message       = currentPlayer.TankName + "'s Turn. Health: " + currentPlayer.Health.ToString("0.00");
            message += " Fuel: " + currentPlayer.Fuel.ToString("0.00");
            message += " Munition: " + BulletPrefabs[currentPlayer.BulletType].name;
            DebugText.SetText(message);

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (Paused)
                {
                    Paused = false;
                    PauseMenuRef.Unpause();
                }
                else
                {
                    Paused = true;
                    PauseMenuRef.gameObject.SetActive(true);
                }
            }

            if (WaitingToNextPlayer)
            {
                NextPlayerTimer -= Time.deltaTime;
                if (NextPlayerTimer <= 0f)
                {
                    WaitingToNextPlayer = false;

                    CurrentPlayer++;
                    if (CurrentPlayer >= PlayerTanks.Count)
                    {
                        CurrentPlayer = 0;
                        NextTurn();
                    }

                    Winner = CheckWinner();
                    if (Winner == -1)
                    {
                        GetCurrentPlayer().StartTurn();
                    }
                    else
                    {
                        WaitingToEndGame = true;
                        EndGameTimer     = 8f;
                    }

                    if (!OnlineGame || PhotonNetwork.IsMasterClient)
                    {
                        if (Random.Range(0, 10) > 6)
                        {
                            BonusBoxRef.Spawn(Terrain.GetReference().HighestPoint + 2f);
                        }
                    }
                }
            }

            if (WaitingToEndGame)
            {
                EndGameTimer -= Time.deltaTime;
                if (EndGameTimer <= 3f)
                {
                    DarkOverlay.GetReference().SetDarkness(1f);
                }
                if (EndGameTimer <= 0f)
                {
                    DarkOverlay.GetReference().SetDarkness(0f);
                    WaitingToEndGame = false;

                    GameOverRef.gameObject.SetActive(true);
                    GameOverText.text = "Game Over\n\nThe winner is " + PlayerTanks[Winner].TankName;
                    EndGame();
                }
            }
        }
    }
示例#21
0
        public override void Update(GameTime gameTime)
        {
            if (input.KeyPress(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                SystemCore.ScreenManager.AddAndSetActive(new MainMenuScreen());
            }

            if (input.KeyPress(Microsoft.Xna.Framework.Input.Keys.O))
            {
                heading -= 10;
                playerObj.GetComponent <DoomMovementComponent>().TurnRightToHeading(heading);
            }
            if (input.KeyPress(Microsoft.Xna.Framework.Input.Keys.P))
            {
                heading += 10;
                playerObj.GetComponent <DoomMovementComponent>().TurnRightToHeading(heading);
            }

            if (heading > 360)
            {
                heading = 0;
            }
            if (heading < 0)
            {
                heading = 360;
            }

            if (input.MouseLeftPress())
            {
                //PathToMousePoint();
            }


            UpdateCamera();

            if (!mapHandler.FloodFillComplete)
            {
                mapHandler.FloodFillStep();
            }

            if (mapHandler.FloodFillComplete && playerObj.GetComponent <DoomMovementComponent>().path == null && !doNothing)
            {
                playerObj.GetComponent <DoomMovementComponent>().PathToPoint(mapHandler.LevelEnd);
                endOfLevelSeeking = true;
            }

            //check if we can see anything. If so, path to it.
            if (!doNothing)
            {
                if (collectItems)
                {
                    PickUpObjects();
                }
            }


            apiHandler.Update();


            if (playerObj != null)
            {
                DebugText.Write(playerObj.Transform.AbsoluteTransform.Translation.ToString());
            }


            base.Update(gameTime);
        }
示例#22
0
 public void Update()
 {
     DebugText.Log(Chunk.InstanceCount + " chunks instantiated.");
 }
示例#23
0
 private void Awake()
 {
     instance = this;
 }
 protected override void OnPrefabInit()
 {
     Instance = this;
 }
示例#25
0
 public override void _Ready()
 {
     lines = new Dictionary <string, string>();
     DebugText.instance = this;
 }
示例#26
0
 public override void Cancel()
 {
     base.Cancel();
     DebugText.Update(Game.UpdateTime);
 }
        public static void DrawText(Vector3 position, object text, Color color, Camera camera = null)
        {
                        #if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                return;
            }

            var runtimeObject = DebugUtilsRuntimeObject.Instance;
            var debugText     = new DebugText(position, text, color, camera);

            if (Time.deltaTime == Time.fixedDeltaTime)
            {
                if (!subscribedFixed)
                {
                    subscribedFixed           = true;
                    SceneView.duringSceneGui += SceneViewGUIFixed;
                    runtimeObject.RegisterFixedUpdateAction(WaitForNextFixed);
                    RegisterGUI();
                }

                debugTextFixed.Add(debugText);
            }
            else
            {
                if (!subscribedUpdate)
                {
                    subscribedUpdate          = true;
                    SceneView.duringSceneGui += SceneViewGUIUpdate;
                    runtimeObject.RegisterUpdateAction(WaitForNextUpdate);
                    RegisterGUI();
                }

                debugTextUpdate.Add(debugText);
            }

            void RegisterGUI()
            {
                if (!GizmosEnabled)
                {
                    return;
                }
                runtimeObject.RegisterOnGUIAction(() =>
                {
                    foreach (DebugText t in debugTextUpdate)
                    {
                        if (t.Camera == null)
                        {
                            continue;
                        }
                        DoDrawText(t.Position, t.Text, t.Color, t.Camera);
                    }

                    foreach (DebugText t in debugTextFixed)
                    {
                        if (t.Camera == null)
                        {
                            continue;
                        }
                        DoDrawText(t.Position, t.Text, t.Color, t.Camera);
                    }
                });
            }
                        #endif
        }
示例#28
0
 void Awake()
 {
     SharedInstance = this;
     textMesh       = GetComponent <TextMesh>();
 }
示例#29
0
        public void CreateUI()
        {
            // https://github.com/stride3d/stride/blob/master/samples/Tutorials/CSharpBeginner/CSharpBeginner/CSharpBeginner.Game/Code/TutorialUI.cs#L34


            // 2. create our grid of buttons...
            var numButtons = 50;

            var grid = new UniformGrid {
                Name = "grid 1",
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch,
                BackgroundColor     = Color.Yellow,
                Columns             = 2, Rows = numButtons,
            };
            var scrollV = new ScrollViewer {
                Name                = "scroll 1",
                ScrollMode          = ScrollingMode.Vertical,
                BackgroundColor     = Color.Purple,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch,
                ScrollBarThickness  = 50,
            };


            var mainCanvas = new Canvas {
                BackgroundColor = new Color(1.0f, 0f, 0f, 0.5f),
            };



            // https://github.com/stride3d/stride/blob/273dfddd462fd3746569f833e1493700c070b14d/sources/engine/Stride.UI.Tests/Regression/CanvasGridTest.cs
            for (int i = 0; i < numButtons; i++)
            {
                var cur_i       = i;
                var startButton = new Button {
                    Content = new TextBlock {
                        Text = "Button #" + i,
                        Font = myFont, TextColor = Color.Black,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        BackgroundColor     = Color.LightBlue,
                    },
                    Padding         = new Thickness(77, 30, 25, 30),
                    ClickMode       = ClickMode.Press,
                    BackgroundColor = Color.Green,
                    MinimumWidth    = 250f,
                };
                var objPos = new Vector3(0f, 4f, 1f * i);
                startButton.Click += (object sender, Stride.UI.Events.RoutedEventArgs e) =>
                {
                    // do something to show we clicked a button
                    // like set the text of some other UI control
                    DebugText.Print("Button Clicked #" + cur_i, new Int2(50, 50));
                };

                startButton.DependencyProperties.Set(GridBase.RowPropertyKey, i / 2);
                startButton.DependencyProperties.Set(GridBase.ColumnPropertyKey, i % 2);


                grid.Children.Add(startButton);
            }

            scrollV.Content = grid;
            mainCanvas.Children.Add(scrollV);

            var mainMenuRoot = new ModalElement {
                Width  = 500,
                Height = 500,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Bottom,
                DefaultHeight       = 200,
                OverlayColor        = new Color(0.5f, 0f, 0f, 0.5f), // clear
                Content             = mainCanvas,
            };

            Entity.Get <UIComponent>().Page = new UIPage {
                RootElement = mainMenuRoot
            };
        }
 public override void Update()
 {
     DebugText.Print("Total of ammo of the automatically created AmmoComponent3: " + ammoComponent3.GetTotalAmmo().ToString(), new Int2(440, 200));
 }
示例#31
0
 public override void Update()
 {
     // We display the stored ammo count on screen
     DebugText.Print("Ammo count 1: " + ammoCount1.ToString(), new Int2(300, 200));
     DebugText.Print("Ammo count 2: " + ammoCount2.ToString(), new Int2(300, 220));
 }
示例#32
0
    public void DrawMap()
    {
        currentGreenPoints.Clear();
        if (LibPlacenote.Instance.GetStatus() != LibPlacenote.MappingStatus.RUNNING)
        {
            return;
        }

        LibPlacenote.PNFeaturePointUnity[] map = LibPlacenote.Instance.GetMap();
        if (map == null)
        {
            return;
        }

        Vector3[] points = new Vector3[map.Length];
        Color[]   colors = new Color[map.Length];

        int totBrown = 0;
        int totGreen = 0;

        for (int i = 0; i < map.Length; ++i)
        {
            points [i].x = map [i].point.x;
            points [i].y = map [i].point.y;
            points [i].z = -map [i].point.z;
            colors [i].r = 1 - map [i].measCount / 10f;
            colors [i].b = 0;
            colors [i].g = map [i].measCount / 10f;

            if (map [i].measCount > 6)
            {
                currentGreenPoints.Add(new Vector3(map [i].point.x, map [i].point.y, map [i].point.z));
                totGreen++;
            }
            else
            {
                totBrown++;
            }

            if (map [i].measCount < 4)
            {
                colors [i].a = 0f;
            }
            else
            {
                colors [i].a = 0.2f + 0.8f * (map [i].measCount / 10f);
            }
        }

        DebugText.SetGreenDots(totGreen.ToString());
        DebugText.SetBrownDots(totBrown.ToString());
        FindObjectOfType <BatteryUpload> ().SetFillAmount((float)totGreen / 50f);
        // Need to update indicies too!
        int[] indices = new int[map.Length];
        for (int i = 0; i < map.Length; ++i)
        {
            indices [i] = i;
        }

        // Create GameObject container with mesh components for the loaded mesh.
        Mesh mesh = new Mesh();

        mesh.vertices = points;
        mesh.colors   = colors;
        mesh.SetIndices(indices, MeshTopology.Points, 0);

        MeshFilter mf = mMap.GetComponent <MeshFilter> ();

        if (mf == null)
        {
            mf = mMap.AddComponent <MeshFilter> ();
        }
        mf.mesh = mesh;

        MeshRenderer mr = mMap.GetComponent <MeshRenderer> ();

        if (mr == null)
        {
            mr = mMap.AddComponent <MeshRenderer> ();
        }

        mr.material = mPtCloudMat;
    }
	//----------------------------------------------//
	// 関数名	Initialize							//
	//	Function Initialize
	// 機能		ゲームで使うオブジェクトの初期化		//
	//	Initialization of objects to use in the game function
	// 引数		なし									//
	//	No argument
	// 戻り値	なし									//
	//	No return value
	//----------------------------------------------//
	protected override void Initialize()
	{
		// Initialization of the camera to be used in all scenes
		camera = new Camera((float)GraphicsDevice.Viewport.Width / (float)GraphicsDevice.Viewport.Height);

		// Load the model()
		// Do not keep up with the constructor is not called before initialize the scene
		ModelManager.GetInstance().LoadModel(this.Content);

		// Load the texture
		TextureManager.GetInstance().LoadTexture(this.Content);

		// Read the font used to debug text
		DebugText.Init(this.Content.Load<SpriteFont>(@"フォント\SpriteFont1"));

		// Create a debug text actually
		debugText = DebugText.GetInstance();

		// Display the mouse cursor on the screen
		this.IsMouseVisible = true;

		// Title of the window
		base.Window.Title = "XNA Game Studio";

		// Initialization of BasicEffect
		basicEffect = new BasicEffect(graphics.GraphicsDevice);

		// I call the initilization of the current scene from the scene manager
		sceneManager.Initialize();
		
		// I get the Kinect
		/*
		kinectSensor = KinectSensor.KinectSensors[0];
		if (kinectSensor == null || kinectSensor.Status != KinectStatus.Connected)
		{
			throw new Exception("Kinect is not connected。");
		}
		 * */

		// I want to enable the skeleton data of Kinect
		
#if KINECT
		kinect.GetInstance().SkeletonStream.Enable(new TransformSmoothParameters()
		{
			Smoothing = 0.5f,
			Correction = 0.5f,
			Prediction = 0.5f,
			JitterRadius = 0.5f,
			MaxDeviationRadius = 0.5f
		});

#endif
		// Initialization of class the underlying
		base.Initialize();
		
	}