Exemplo n.º 1
0
    private bool IsGrounded()
    {
        bool       hitGround = false;
        float      distance  = 0;
        RaycastHit hit;//RaycastHit 结构体 用于存储射线碰撞信息

        //如果是下落状态(速度向下),就检测character向下的射线检测
        if (verticalSpeed < 0 && Physics.Raycast(transform.position, Vector3.down, out hit))
        {
            Debug.DrawLine(transform.position, hit.point, Color.red);
            //由于character是胶囊型,所以check是人物和地面碰撞检测距离(应该是一个接近0的很小的值)
            float check = (character.height + character.radius) / 2f + ground_offset - 0.8f;
            distance  = hit.distance;
            hitGround = distance <= check;//如果距离小于check,则检测为碰撞
        }
        if (hitGround)
        {
            screen.Log(TAG, string.Format("Grounded,distance = {0}", distance));
        }
        else
        {
            screen.Log(TAG, string.Format("Not Grounded,distance = {0}", distance));
        }
        //悬空状态
        if (!hitGround && distance == 0 && verticalSpeed < -10.0f)
        {
            Fail_Canvas.enabled = true;
        }
        return(hitGround);
    }
Exemplo n.º 2
0
    void Start()
    {
        if (instance != null)
        {
            Destroy(this);
        }
        else
        {
            instance    = this;
            debugScreen = GameObject.Find("Debug Screen");
            debugScreen.SetActive(false);
            world       = GameObject.Find("World").GetComponent <World>();
            screen      = DebugScreen.GetInstance();
            player      = GameObject.Find("Player");
            settingMenu = GetComponent <SettingMenu>();
            if (MainScene == SceneManager.GetActiveScene().buildIndex)
            {
                inputController = new PlayerInputController();
                screen.Log("[InputController]", "Play");
            }
            else
            {
                screen.Log("[InputController]", "Edit");
                inputController = new EditInputController();
            }

            inputController.StartAll();
            WorldInit();
        }
    }
Exemplo n.º 3
0
        private void FixedUpdate()
        {
            if (this.sceneLoadTimer == 0)
            {
                var  allObjects   = FindObjectsOfType <GameObject>();
                bool foundManager = false;
                foreach (var obj in allObjects)
                {
                    var gameNetworkManager = obj.GetComponent <GameNetworkManager>();
                    if (gameNetworkManager)
                    {
                        foundManager = true;
                        DebugScreen.Log("Found game network manager, dumping channel data.");
                        foreach (var channel in gameNetworkManager.channels)
                        {
                            DebugScreen.Log(channel.ToString());
                        }
                    }
                }

                if (!foundManager)
                {
                    DebugScreen.Log("No network manager was found.");
                }

                this.sceneLoadTimer = -1;
            }

            this.sceneLoadTimer = this.sceneLoadTimer > 0 ? this.sceneLoadTimer - 1 : this.sceneLoadTimer;
        }
Exemplo n.º 4
0
        public static void OnInject()
        {
            DebugScreen.Instantiate();
            DebugScreen.Log("Tridev Loader started!");

            LoadMods();
        }
Exemplo n.º 5
0
        public void LoadAssemblies()
        {
            // Get the directory assemblies are stored in, then gather all the files with a .DLL extension.
            var librariesFolder = Path.Combine(AppContext.BaseDirectory, "mods", "libraries");

            // Create the libraries folder if it doesn't exist.
            if (!Directory.Exists(librariesFolder))
            {
                Directory.CreateDirectory(librariesFolder);
            }
            var libraryFiles      = Directory.GetFiles(librariesFolder).Where(x => x.ToUpper().EndsWith(".DLL")).ToList();
            var libraryAssemblies = libraryFiles.Select(x => Assembly.LoadFrom(x)).ToList();

            // Store assemblies based on their name, used to remove duplicate assemblies by looking at their version.
            var duplicateAssemblies = new Dictionary <string, List <Assembly> >();

            foreach (var assembly in libraryAssemblies)
            {
                var name = assembly.GetName().Name;
                if (!duplicateAssemblies.ContainsKey(name))
                {
                    duplicateAssemblies.Add(name, new List <Assembly>());
                }

                duplicateAssemblies[name].Add(assembly);
            }

            // Unloads any duplicate assemblies.
            foreach (var keyValuePair in duplicateAssemblies)
            {
                Assembly selectedAssembly = null;
                foreach (var assembly in keyValuePair.Value)
                {
                    if (selectedAssembly == null)
                    {
                        selectedAssembly = assembly;
                    }
                    else
                    {
                        var selectedVersion  = selectedAssembly.GetName().Version;
                        var duplicateVersion = assembly.GetName().Version;
                        if (selectedVersion < duplicateVersion)
                        {
                            selectedAssembly = assembly;
                        }
                        else
                        {
                            DebugScreen.Log($"Rejected duplicate library with version {duplicateVersion}," +
                                            $" using {selectedVersion}");
                        }
                    }
                }

                if (selectedAssembly != null)
                {
                    DebugScreen.Log($"Loaded external library {selectedAssembly.GetName().Name}");
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds the given item to the item registry.
        /// </summary>
        /// <param name="owner">The mod associated with the registered item.</param>
        /// <param name="item">The item to register.</param>
        /// <returns>The item that was registered, or null if registration failed.</returns>
        public T RegisterItem <T>(Mod owner, T item) where T : ModItem
        {
            var itemDef = new ModItemDefinition(owner, item.id, item);

            if (IsItemPresent(itemDef.Id))
            {
                throw new Exception($"Attempted to register an item with the id '${itemDef.Id}' but it was already registered.");
            }

            this.itemIds.Add(itemDef.Id, this.itemIds.Count);
            this.itemIdList.Insert(this.itemIds.Count - 1, itemDef.Id);
            this.registeredItems.Insert(this.itemIds.Count - 1, itemDef);

            DebugScreen.Log($"Registered new item with id {itemDef.Id}");

            return(item);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Tells all subscriptions managed by this list that an event has been fired.
        /// </summary>
        /// <param name="eventFired">The event that was fired.</param>
        public void HandleFiredEvent <T>(T eventFired) where T : EventBase
        {
            if (typeof(T) != this.type)
            {
                throw new ArgumentException("Attempted to handle a fired event on an event list with the incorrect event type.");
            }

            foreach (var sortedSubscription in GetSortedSubscriptions <T>())
            {
                try {
                    sortedSubscription.HandleFiredEvent(eventFired);
                } catch (Exception e) {
                    DebugScreen.Log($"Failed to handle event {this.type}, caused by subscription by {sortedSubscription.Subscriber.Id}");
                    DebugScreen.Log(e.ToString());
                }
            }
        }
Exemplo n.º 8
0
    private void GetGlobalInput()
    {
        if (Input.GetKeyDown(KeyCode.F1))
        {
            world.SaveWorld();
        }
        if (Input.GetKeyDown(KeyCode.F2))
        {
            world.LoadWorld("auto_save2020-05-25-16-23");
        }

        if (Input.GetKeyDown(KeyCode.F3))
        {
            debugScreen.SetActive(!debugScreen.activeSelf);
        }
        if (Input.GetKeyDown(KeyCode.F4))
        {
            if (MainScene == SceneManager.GetActiveScene().buildIndex)
            {
                SceneManager.LoadScene(EditScene);
            }
            else if (EditScene == SceneManager.GetActiveScene().buildIndex)
            {
                SceneManager.LoadScene(MainScene);
            }
        }

        if (Input.GetKeyDown(KeyCode.F5))
        {
            //进入debug模式,人物可飞行,按键触发脚下方块陷落
            DebugMode = !DebugMode;
            DebugPlayerBehaviour d = player.GetComponent <DebugPlayerBehaviour>();
            d.enabled = !d.enabled;
        }
        screen.Log("[GameManager]", "DebugMode = " + DebugMode);

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            UpdateSettingMenu();
        }
    }
Exemplo n.º 9
0
 public void Jump()
 {
     screen.Log(TAG, "Jumping");
 }
Exemplo n.º 10
0
 private void Start()
 {
     DebugScreen.Log("Firing setup.");
     TridevModHelper.Instance.EventBus.FireEvent(new EventSetup());
     orig_Start();
 }
Exemplo n.º 11
0
 private void Awake()
 {
     DebugScreen.Log("Added DebugBehaviour");
     SceneManager.activeSceneChanged += (current, next) => { this.sceneLoadTimer = 360; };
     DontDestroyOnLoad(this);
 }
Exemplo n.º 12
0
    private void GetPlayerInput()
    {
        float scrool = Input.GetAxis("Mouse ScrollWheel");

        if (Input.GetKeyDown(KeyCode.E))
        {
            IncreaseEditMode(true);
        }
        if (Input.GetKeyDown(KeyCode.Q))
        {
            IncreaseEditMode(false);
        }
        bool leftClick  = Input.GetMouseButtonDown(0);
        bool rightClick = Input.GetMouseButtonDown(1);

        if (editMode == EditMode.CubeMode)
        {
            int length = (int)CubeType.Length;
            UpdateSelectIndex(length, scrool);

            if (breakBlock.gameObject.activeSelf)
            {
                if (leftClick)
                {
                    screen.Log("Click", "Left");
                    BreakBlock();
                }
                else if (rightClick)
                {
                    screen.Log("Click", "Right");
                    CreateBlock();
                }
            }
        }
        else if (editMode == EditMode.PlayerMode)
        {
            //right click place player
            if (rightClick)
            {
                SetPlayerPosition();
                screen.Log("Click", "Right");
            }
        }
        else if (editMode == EditMode.MonsterMode)
        {
            //Monster Mode
            int length = (int)MonsterType.LENGTH;
            UpdateSelectIndex(length, scrool);

            //TODO: setMonster
            if (rightClick)
            {
                SetMonster((MonsterType)selectIndex);
            }

            if (leftClick)
            {
                BreakMonster();
            }
        }



        UpdatePrompt();
    }