private void ClickCustom(GameObject game, BaseEventData baseEvent) { switch (game.name) { case "customsPass": SceneStateController.Instance.SetState(SceneType.CombatScene, typeof(CombatScene)); break; case "cardUpgrade": UnityTool.M_Debug("卡牌升级界面"); break; case "role": UnityTool.M_Debug("人物属性界面"); break; case "stop": UnityTool.M_Debug("商城"); break; case "cardBag": UnityTool.M_Debug("卡包"); break; } }
private void Update() { // 1、 RayHit 方法将返回指定方向上打到的物体; GameObject hit_Object = gameObject.RayHit(Vector3.down); if (hit_Object) { UnityTool.Log(hit_Object.name); } // 2、 RayHit 的一个重载方法,判断物体是否击中了一个物体,返回 bool值; /*bool is_Hit = gameObject.RayHit(RayCastedObject,Vector3.down); * * if(is_Hit) UnityTool.Log(string.Format("{0}物体发出的射线击中了{1}",gameObject.name,RayCastedObject.name));*/ // 3、返回从一个物体发出的射线所击中的点;注意:若没有击中任何物体,返回(0,0,0); /*Vector3 hit_Point = gameObject.RayHitPoint(Vector3.down); * * UnityTool.Log(hit_Point);*/ // 4、 判断该物体是否被射线击中; /* bool is_Hited = gameObject.RayHit(RayCastedObject, Vector3.down); * * if (is_Hited) UnityTool.Log(RayCastedObject.name + "被击中了。");*/ }
private void InitCamp(EnemyType enemyType) { string gameObjectName = null; string name = ""; string icon = ""; float trainTime = 0f; switch (enemyType) { case EnemyType.Elf: gameObjectName = "CaptiveCamp_Elf"; name = "伏兵营"; icon = "CaptiveCamp"; trainTime = 3f; break; default: Debug.LogError("无法根据战士类型" + enemyType + "初始化兵营"); break; } GameObject gameObject = gameObject = GameObject.Find(gameObjectName); Vector3 position = UnityTool.FindChild(gameObject, "TrainPoint").transform.position; CaptiveCamp camp = new CaptiveCamp(gameObject, name, icon, enemyType, position, trainTime); CampOnClick campOnClick = gameObject.AddComponent <CampOnClick>(); campOnClick.camp = camp; mCamptiveCamp.Add(enemyType, camp); }
private void Update() { // 按键 S 表示 Record (记录) 步骤操作; if (Input.GetKeyDown(KeyCode.S)) { UndoRedoService.Record(); UnityTool.Log("Record"); } // 按键 U 表示 Undo (撤销) 操作; if (Input.GetKeyDown(KeyCode.U)) { UndoRedoService.Undo(); UnityTool.Log("Undo"); } // 按键 R 表示 Redo (重做) 操作; if (Input.GetKeyDown(KeyCode.R)) { UndoRedoService.Redo(); UnityTool.Log("Redo"); } }
/// <summary> /// 初始化 /// </summary> public override void Initialize(string s) { m_RootUI = UnityTool.FindGameObject(s); bagBtn = UITool.GetUIComponent <Button>(m_RootUI, "UIBagBtn"); Hp = UITool.GetUIComponent <Slider>(m_RootUI, "HP"); Mp = UITool.GetUIComponent <Slider>(m_RootUI, "MP"); HPText = UITool.GetUIComponent <Text>(m_RootUI, "HPText"); MPText = UITool.GetUIComponent <Text>(m_RootUI, "MPText"); SkillContent = UITool.GetUIComponent <Transform>(m_RootUI, "SkillContent"); bagBtn.onClick.AddListener(_ctrl.OnBagBtnClick); for (int i = 0; i < SkillContent.childCount; i++) { int k = i; Transform obj = SkillContent.GetChild(i); obj.GetComponent <Button>().onClick.RemoveAllListeners(); obj.GetComponent <Button>().onClick.AddListener(() => { _ctrl.UseSkill(k, obj); }); } }
//---------------------------------------------------------------------------------------- //ToEqip状态的事件 //拔剑,持盾 public void RHandTakeWeapon() { //剑父对象的替换 UnityTool.SetParent(_player.RWeapontrans, _player.Sword.transform); UnityTool.SetParent(_player.LWeapontrans, _player.Shield.transform); _player.GetWeaponAttr(); }
// 该函数将被自动调用; public override void SceneAwake() { UnityTool.Log("Scene1 Awake......."); // 执行下一步操作;注意: 该操作从当前位置开始,一直执行到 ## 分隔符才结束; //RequestExecuteService.ExecuteNextStep(); // 若要精确按步骤来执行,可以这样: // 注意: 在执行的过程中若遇到分隔符 ## ,则自动跳过该分隔符,分隔符 ## 不算做步骤; //RequestExecuteService.ExecuteNextStep(10); // 向后执行 10 步; // 若要执行指定的步骤,可以这样: // 注意: 该步骤的位置是从当前位置开始的,该步骤的位置 等于 要执行步骤的 前一个; //RequestExecuteService.ExecuteNextPosition(3); // 通知组件执行从当前步骤开始的第 3 个步骤; // 你可以定位到任意操作步骤,如: // 下面两句话,现将指针向后移动 5 个步骤,再执行移动步骤后的 前面第 2 个 步骤; //RequestExecuteService.MoveToStepPosition(5); //RequestExecuteService.ExecuteNextPosition(-2); }
private void FunctionTest() { UnityTool.Log("FunctionTest Execute ......"); RequestExecuteService.ExecuteNextStep(); }
//用户输入处理 private void inputProcess() { if (Input.GetKeyDown(KeyCode.Alpha1)) //区别GetButtonDown { addCommand(ENUM_CommandType.ProduceCharacter, new ProduceEnemyCommand()); } else if (Input.GetKeyDown(KeyCode.Alpha2)) { addCommand(ENUM_CommandType.ProduceCharacter, new ProduceSoldierCommand()); } else if (Input.GetKeyDown(KeyCode.Alpha3)) { if (m_characterSystem.getPlayer() == null) { GameObject mainCamera = UnityTool.findGameObject("Main Camera"); mainCamera.SetActive(false); Cursor.lockState = CursorLockMode.Locked; //mainCamera.GetComponent<Camera>().enabled = false; addCommand(ENUM_CommandType.ProduceCharacter, new ProducePlayerCommand()); } } else if (Input.GetKeyDown(KeyCode.Alpha4)) { getPlayer().addMoveSpeed(2); } else if (Input.GetKeyDown(KeyCode.Alpha5)) { getPlayer().reduceMoveSpeed(2); } }
void Start() { UnityTool.M_Debug("游戏初始挂载"); //加载到一号场景 m_SceneStateController.SetState(SceneType.RoleSelectScene, typeof(RoleSelectScene)); }
public void SetDoor() { if (m_Soldier != null) { m_Soldier.SetDoor(UnityTool.FindChildGameObject(UnityTool.FindGameObject("Door"), "Point").transform); } }
public void OnInit(AbsCharacter _charater) { owner = _charater; GameObject parent = UnityTool.FindChild(_charater.CharacterGameObject, "weapon-point"); UnityTool.AttachGameObject(parent, gameObject); }
private void Awake() { TriggerReceptObject = GameObject.Find("TriggerReceptObject"); // 1、测试触发器事件,首先要是物体可以移动,这里,给物体添加了一个鼠标拖拽事件,让该物体可以移动; gameObject.OnMouseDrag(EventParames.DontDestory | EventParames.DontSetTrue); // 2、为该物体添加触发事件,当两物体接触时,将触发事件,并执行客户端定义的函数,下例中将执行客户端自定义的 MyTriggerFunction; // 注意该函数的参数表示: 碰撞物体.OnTrigger(被碰撞物体,触发函数,[控制参数设置]); 一般事件中后两个参数都是一样的; //gameObject.OnTrigger(TriggerReceptObject,MyTriggerFunction,EventParames.DontDestory); // 3、关闭该事件; //gameObject.OffTrigger(); // 4、OnIntersect 判断两物体是否交叉; // 将它放在 Update 事件中,可以监听两物体是否交叉,用以模拟触发器效果; gameObject.OnUpdate(() => { bool is_Trigger = gameObject.OnIntersect(TriggerReceptObject); if (is_Trigger) { UnityTool.Log(string.Format("{0}物体和{1}物体接触了!", gameObject.name, TriggerReceptObject.name)); } }, EventParames.DontDestory | EventParames.NoOrder); }
public override void Init() { base.Init(); GameObject canvas = GameObject.Find("Canvas"); mRootUI = UnityTool.FindChild(canvas, "GameStateUI"); GameObject heart1 = UnityTool.FindChild(mRootUI, "Heart1"); GameObject heart2 = UnityTool.FindChild(mRootUI, "Heart2"); GameObject heart3 = UnityTool.FindChild(mRootUI, "Heart3"); mHearts = new List <GameObject>(); mHearts.Add(heart1); mHearts.Add(heart2); mHearts.Add(heart3); mSoldierCount = UITool.FindChild <Text>(mRootUI, "SoldierCount"); mEnemyCount = UITool.FindChild <Text>(mRootUI, "EnemyCount"); mCurrentStage = UITool.FindChild <Text>(mRootUI, "StageCount"); mPauseBtn = UITool.FindChild <Button>(mRootUI, "PauseBtn"); mGameOverUI = UnityTool.FindChild(mRootUI, "GameOver"); mBackMenuBtn = UITool.FindChild <Button>(mRootUI, "BackMenuBtn"); mMessage = UITool.FindChild <Text>(mRootUI, "Message"); mEnergySlider = UITool.FindChild <Slider>(mRootUI, "EnergySlider"); mEnergyText = UITool.FindChild <Text>(mRootUI, "EnergyText"); mMessage.text = ""; mGameOverUI.SetActive(false); }
private void InitCamp(EnemyType enemyType) { GameObject gameObject = null; string gameObjectName = null; string name = ""; string icon = ""; Vector3 position = Vector3.zero; float trainTime = 0; switch (enemyType) { case EnemyType.Elf: gameObjectName = "CaptiveCamp_Elf"; name = "俘兵营"; icon = "CaptiveCamp"; trainTime = 3; break; default: Debug.LogError("无法根据敌人类型:" + enemyType + "初始化兵营"); break; } gameObject = GameObject.Find(gameObjectName); GameObject gameObjectPos = UnityTool.FindChild(gameObject, "TrainPoint"); if (gameObjectPos != null) { position = gameObjectPos.transform.position; gameObjectPos.SetActive(false); } CaptiveCamp camp = new CaptiveCamp(gameObject, name, icon, enemyType, position, trainTime); camp.IsCaptiveCamp = true; gameObject.AddComponent<CampOnClick>().Camp = camp;//添加点击组件 mCaptiveCamps.Add(enemyType, camp); }
private void Awake() { _instance = this; gameTrans = UnityTool.FindChild(gameObject, "Game").transform; lvInfoMgr = LevelInfoMgr.Instance; mapMaker = GetComponent <MapMaker>(); enemyBuilder = new EnemyBuilder(); towerBuilder = new TowerBuilder(); bullectBuilder = new BullectBuilder(); currentLevel = GameRoot.Instance.pickLevel; info = lvInfoMgr.levelInfoList[currentLevel]; //初始化地图 mapMaker.InitAllGrid(); mapMaker.LoadLevelMap(currentLevel); //获得关卡数据和回合数据 SetLevelData(info); level = new Level(info); level.HandleRound(); beginPos = level.roundInfoList[0].pathList[0]; EventCenter.Broadcast(EventType.SetStartPos, beginPos); isPause = true; EventCenter.AddListener <int>(EventType.UseItemInGame, UseItem); }
//初始化俘兵营 private void InitCamp(EnemyType enemyType) { GameObject gameObject = null; string gameObjectName = null; string name = null; string iconSprite = null; Vector3 position = Vector3.zero; float trainTime = 0; switch (enemyType) { case EnemyType.Elf: gameObjectName = "CaptiveCamp_Elf"; name = "俘兵营"; iconSprite = "CaptiveCamp"; trainTime = 3; break; default: Debug.LogError("无法根据俘兵类型" + enemyType + "初始化兵营"); break; } gameObject = GameObject.Find(gameObjectName); position = UnityTool.FindChild(gameObject, "TrainPoint").transform.position; CaptiveCamp camp = new CaptiveCamp(gameObject, name, iconSprite, enemyType, position, trainTime); //添加监听点击脚本 CampOnClick campOnClick = gameObject.AddComponent <CampOnClick>(); campOnClick.Camp = camp; mCaptiveCamps.Add(enemyType, camp); }
/// <summary> /// 配置文件根据界定符,目前是 ## ; 来将步骤分为粗细两种粒度; Step 是粗粒度的步骤,即以 ## 分割的步骤; /// /// Position 是细粒度的步骤,即安配置文件中的头描述定义分割的; 一般情况下是一行; /// </summary> public override void SceneAwake() { UnityTool.Log("Scene1 Awake......."); // 执行下一步操作;注意: 该操作从当前位置开始,一直执行到 ## 分隔符才结束; //RequestExecuteService.ExecuteNextStep(); // 下面两句话先执行 第 3 个步骤,再执行 第 -2 个(相对位置)步骤; // 配置文件中的步骤将先向后执行,在以执行到的位置为起点,向前执行; RequestExecuteService.ExecuteNextStep(3); RequestExecuteService.ExecuteNextStep(-2); // 跳转场景;默认跳到下一个场景; // 注意: 当前场景值为0,正值往后跳,负值往前跳; // 当前场景不能跳转当前场景,避免发生循环调用; RequestExecuteService.GotoScene(4); }
private void InitCamp(EnemyType enemyType) { GameObject gameObject = null; string gameObjectName = null; string name = null; string icon = null; Vector3 position = Vector3.zero; float trainTime = 0; switch (enemyType) { case EnemyType.Elf: gameObjectName = "CaptiveCamp_Elf"; name = "俘兵营"; icon = "CaptiveCamp"; trainTime = 3; break; default: Debug.Log("CampSystem InitCamp() " + enemyType + "can't solve"); break; } gameObjectName = "Camp/" + gameObjectName; gameObject = GameObject.Find(gameObjectName); position = UnityTool.FindChild(gameObject, "TrainPoint").transform.position; CaptiveCamp camp = new CaptiveCamp(gameObject, name, icon, enemyType, position, trainTime); gameObject.AddComponent <CampMono>().OnInit(camp); captiveCamps.Add(enemyType, camp); }
public override void Init() { base.Init(); GameObject canvas = GameObject.Find("Canvas"); mRootUI = UnityTool.FindChild(canvas, "GamePauseUI"); mCurretStageLevel = UITools.FindChild <Text>(mRootUI, "CurretStageLevel"); mContinueBtn = UITools.FindChild <Button>(mRootUI, "ContinueButton"); mBackMenuBtn = UITools.FindChild <Button>(mRootUI, "BackMenuButton"); mContinueBtn.onClick.AddListener(() => { mRootUI.SetActive(false); Time.timeScale = 1; }); mBackMenuBtn.onClick.AddListener(() => { if (mFacade.IsGameOver == false) { mFacade.IsGameOver = true; } Time.timeScale = 1; }); Hide(); }
/// <summary> /// 添加坦克标识 /// </summary> public void AddFlag() { int number; GameObject go = UnityTool.FindOneOfActiveChild(mTank.Turret.AnyTuret, "Turret"); if (mTurretType == TurretType.ShellTurret) { number = 0; } else { number = 1; } Material[] materialarry = go.GetComponent <Renderer>().materials; Material material = FactoryManager.assetFactory.LoadMaterial("Blue"); for (int i = 0; i < materialarry.Length; i++) { if (i == number) { materialarry[i] = material; } } go.GetComponent <Renderer>().sharedMaterials = materialarry; }
public override void Init() { base.Init(); GameObject canvas = GameObject.Find("Canvas"); mRootUI = UnityTool.FindChild(canvas, "CampInfoUI"); mCampIcon = UITool.FindChild <Image>(mRootUI, "CampIcon"); mCampName = UITool.FindChild <Text>(mRootUI, "CampName"); mCampLevel = UITool.FindChild <Text>(mRootUI, "CampLv"); mWeaponLevel = UITool.FindChild <Text>(mRootUI, "WeaponLv"); mCampUpgradeBtn = UITool.FindChild <Button>(mRootUI, "CampUpgradeBtn"); mWeaponUpgradeBtn = UITool.FindChild <Button>(mRootUI, "WeaponUpgradeBtn"); mTrainBtn = UITool.FindChild <Button>(mRootUI, "TrainBtn"); mTrainBtnText = UITool.FindChild <Text>(mRootUI, "TrainCostText"); mCancelTrainBtn = UITool.FindChild <Button>(mRootUI, "CancelTrainBtn"); mAliveCount = UITool.FindChild <Text>(mRootUI, "AliveCount"); mTrainCount = UITool.FindChild <Text>(mRootUI, "TrainCount"); mTrainTime = UITool.FindChild <Text>(mRootUI, "TrainTime"); mTrainBtn.onClick.AddListener(OnTrainClick); mCancelTrainBtn.onClick.AddListener(OnCancelTrainClick); mCampUpgradeBtn.onClick.AddListener(OnCampUpgradeClick); mWeaponUpgradeBtn.onClick.AddListener(OnWeaponUpgradeClick); Hide(); }
void HitFrameTrigger(string str) { string[] ts = str.Split('_'); //for(int i = 0; i < ts.Length; i++) //{ // print(ts[i]); //} Transform tar = null; string str2 = ts[1] + "_" + ts[2]; //print(str2); switch (ts[0]) { case "behit": tar = hitPos.Find(str2); break; case "block": GameObject go = UnityTool.FindChild(gameObject, str2); tar = go.transform; break; } hitEffect.transform.position = tar.position; hitEffect.Play(); print(tar.name); }
public Transform bodyObj = null; // 玩家身体IK标记物 void Start() { // animator = GetComponent <Animator>(); leftHandObj = UnityTool.findChildGameObject(gameObject, "LeftHandIK").transform; rightHandObj = UnityTool.findChildGameObject(gameObject, "RightHandIK").transform; }
public override void Init() { base.Init(); GameObject canvas = GameObject.Find("Canvas"); mRootUI = UnityTool.FindChild(canvas, "GameStateInfoUI"); GameObject heart1 = UnityTool.FindChild(mRootUI, "heart1"); GameObject heart2 = UnityTool.FindChild(mRootUI, "heart2"); GameObject heart3 = UnityTool.FindChild(mRootUI, "heart3"); mHearts = new List <GameObject>(); mHearts.Add(heart1); mHearts.Add(heart2); mHearts.Add(heart3); mSoldierNum = UITool.FindChild <Text>(mRootUI, "SoldierNum"); mEnemyNum = UITool.FindChild <Text>(mRootUI, "EnemyNum"); mStageNum = UITool.FindChild <Text>(mRootUI, "StageNum"); mBtnPause = UITool.FindChild <Button>(mRootUI, "BtnPause"); mEnergySlider = UITool.FindChild <Slider>(mRootUI, "EnergySlider"); mEnergyNum = UITool.FindChild <Text>(mRootUI, "EnergyNum"); mMessage = UITool.FindChild <Text>(mRootUI, "Message"); mGameOver = UnityTool.FindChild(mRootUI, "GameOver"); mBtnBackMain = UITool.FindChild <Button>(mGameOver, "BtnBackMain"); AddListeners(); mMessage.text = ""; mStageNum.text = mCurrentStageNum.ToString(); mGameOver.SetActive(false); }
/// <summary> /// 重定位指针,该函数将根据当前指针位置按 Step 或 Position 重定位指针; /// /// 格式为 goto:[step|position],count=(int)数值; /// /// 注意: 正直是向前定位,负值是向后定位; /// </summary> /// <param name="count"></param> /// <param name="number"></param> public void GotoStep(int count, int number) { UnityTool.Log("..............."); if (count == 0) { return; } if (!RefDict.ContainsKey(index)) { RefDict.Add(index, number); } if (RefDict[index] >= number) { MoveIndexToPosition(1); // 移向下一步并返回; } else { RefDict[index]++; // 引用计数加一; MoveIndexToStep(count); } }
public IEnumerator LoadScene(string nextScene) { Scene curScene = SceneManager.GetActiveScene(); if (string.IsNullOrEmpty(nextScene) || m_isLoading || curScene.name.Equals(nextScene)) { yield break; } m_isLoading = true; SceneManager.LoadScene(SceneConst.SceneName, LoadSceneMode.Additive); yield return(StartCoroutine(AsyncLoadScene(nextScene))); FreshProcessEvent.Invoke(SceneConst.LOADSCENEPROCESS); m_unloadAsync = SceneManager.UnloadSceneAsync(curScene); /* * //使用LoadSceneMode.Additive进行场景切换,无法完全释放资源。即使使用Resources.UnloadUnusedAssets()也不行 * //可能出现如下情况: * //1.资源没有引用了,但是还没有回收 * //2.被UnityEngine.EventSystems.StandaloneInputModule和UnityEngine.EventSystems引用 * //当然如果单纯从一个场景切换另外一个场景,直接使用UnityEngine.SceneManagement.SceneManager.LoadScene("xxx") * //直接切换场景,这个会进行内存回收 */ yield return(m_unloadAsync); FreshProcessEvent.Invoke(SceneConst.UNSCENEPROCESS); //场景中必须有一个对象挂载SceneBase SceneBase sceneLoader = UnityTool.GetTopObject("SceneLoader").GetComponent <SceneBase>(); if (sceneLoader == null) { Debug.LogError("lack of gameobject of name 'SceneLoader'"); yield break; } yield return(new WaitUntil(sceneLoader.FinishConfigRes)); FreshProcessEvent.Invoke(SceneConst.INITNETPROCESS); yield return(new WaitUntil(sceneLoader.FinishGetData)); FreshProcessEvent.Invoke(SceneConst.INITCONFIGPROCESS); yield return(new WaitUntil(sceneLoader.FinishInit)); FreshProcessEvent.Invoke(SceneConst.INITSCENEPROCESS); yield return(new WaitForSeconds(1f)); FreshProcessEvent.Invoke(1f); m_loadAsync = SceneManager.UnloadSceneAsync(SceneConst.SceneName); yield return(m_loadAsync); m_isLoading = false; }
//关闭 public void Hide(UIType uIType) { if (m_DataPool.ContainsKey(uIType)) { m_DataPool[uIType].Hide(); UnityTool.M_Debug("关闭" + uIType.ToString()); } }
private WeaponAttr _rweaponAttr = null; //右手武器属性 //设置武器手持挂载点信息 public void SetWeapon(Transform theTarget, out Transform lweapontrans, out Transform rweapontrans) { _lweapontrans = UnityTool.DeepFind(theTarget, "weaponHandleL").transform; _rweapontrans = UnityTool.DeepFind(theTarget, "weaponHandleR").transform; lweapontrans = _lweapontrans; rweapontrans = _rweapontrans; }
public override void Initialize(string s) { m_RootUI = UnityTool.FindGameObject(s); closeBtn = UITool.GetUIComponent <Button>(m_RootUI, "CloseBtn"); closeBtn.onClick.AddListener(_ctrl.OnCloseBtnClick); }