public void Init(bool isMyCharacter, int idx) { m_isMyCharacter = isMyCharacter; m_Model = transform.Find("people_face_01").gameObject; m_Model.transform.localPosition = Vector3.zero; m_Model.transform.localRotation = Quaternion.identity; m_Animator = GetComponentInChildren <Animator>(); m_Animator.enabled = false; m_animatorController = m_Animator.runtimeAnimatorController; m_CostumeComponent = Common.GetOrAddComponent <CostumeComponent>(gameObject); m_CostumeComponent.Init(); m_StackComponent = Common.GetOrAddComponent <StackComponent>(gameObject); m_StackComponent.Init(this); m_FSMCompnent = Common.GetOrAddComponent <FSMComponent>(gameObject); m_FSMCompnent.Init(this); m_InputComponent = Common.GetOrAddComponent <InputComponent>(gameObject); m_InputComponent.Init(this); OnVictory = m_StackComponent.OnVictory; if (m_BillBoard == null) { m_BillBoard = gameObject.GetComponentInChildren <BillBoard>(); } m_BillBoard.gameObject.SetActive(true); if (m_isMyCharacter) { m_MyPlayerColor = Color.green; if (PlayerPrefs.HasKey("myName")) { NickName = PlayerPrefs.GetString("myName"); } else { NickName = "Runner"; } m_BillBoard.InitProfileSprite(null); } else { m_MyPlayerColor = color[idx]; m_BillBoard.SetName(Common.strName[Random.Range(0, Common.strName.Length)]); m_BillBoard.InitProfileSprite(Common.regionName[Random.Range(0, Common.regionName.Length)]); } m_BillBoard.SetColor(m_MyPlayerColor); }
//添加某一类型的组件 public BasicComponent AddComponent(ComponentType type) { if (ExistSpecialComponent(type)) { //Debug.Log("Exist same component Type" + type); return(GetSpecicalComponent(type)); } //Debug.Log ("Add component" + type + " in " + gameObject); PropertyComponent property = GetComponent <PropertyComponent> (); switch (type) { case ComponentType.Property: PropertyComponent propertyComp = gameObject.AddComponent <PropertyComponent> (); propertyComp.Init(ComponentType.Property, this); m_components.Add(propertyComp); return(propertyComp); case ComponentType.Dead: DeadComponent deadComp = gameObject.AddComponent <DeadComponent> (); deadComp.Init(ComponentType.Dead, this); deadComp.hp = property.HP; m_components.Add(deadComp); return(deadComp); case ComponentType.State: StateComponent stateComp = gameObject.AddComponent <StateComponent> (); stateComp.Init(ComponentType.State, this); m_components.Add(stateComp); stateComp.m_actionPoint = property.AP; return(stateComp); case ComponentType.Ability: AbilityComponent abilityComp = gameObject.AddComponent <AbilityComponent> (); abilityComp.Init(ComponentType.Ability, this); m_components.Add(abilityComp); return(abilityComp); case ComponentType.Hide: HideComponent hideComp = gameObject.AddComponent <HideComponent> (); hideComp.Init(ComponentType.Hide, this); m_components.Add(hideComp); return(hideComp); case ComponentType.Move: MoveComponent moveComp = gameObject.AddComponent <MoveComponent> (); moveComp.Init(ComponentType.Move, this); m_components.Add(moveComp); moveComp.moveSpeed = property.moveSpd; moveComp.SPD = property.SPD; return(moveComp); case ComponentType.Attack: AttackComponent attackComp = gameObject.AddComponent <AttackComponent> (); attackComp.Init(ComponentType.Attack, this); m_components.Add(attackComp); attackComp.STR = property.STR; return(attackComp); case ComponentType.Input: InputComponent inputComp = gameObject.AddComponent <InputComponent> (); inputComp.Init(ComponentType.Input, this); m_components.Add(inputComp); return(inputComp); case ComponentType.CheerUp: CheerUpComponent cheerUpComp = gameObject.AddComponent <CheerUpComponent> (); cheerUpComp.Init(ComponentType.CheerUp, this); m_components.Add(cheerUpComp); return(cheerUpComp); case ComponentType.Monitor: MonitorComponent monitorComp = gameObject.AddComponent <MonitorComponent> (); monitorComp.Init(ComponentType.Monitor, this); m_components.Add(monitorComp); monitorComp.m_SightArea = property.HRZ; return(monitorComp); case ComponentType.Knock: KnockComponent knockComp = gameObject.AddComponent <KnockComponent> (); knockComp.Init(ComponentType.Knock, this); m_components.Add(knockComp); knockComp.m_ridus = property.HRZ; return(knockComp); case ComponentType.Item: ItemComponent itemComp = gameObject.AddComponent <ItemComponent> (); itemComp.Init(ComponentType.Item, this); itemComp.item = property.item; itemComp.numLimit = property.itemLimit; m_components.Add(itemComp); return(itemComp); case ComponentType.AI: AIComponent aiComp = gameObject.AddComponent <AIComponent> (); aiComp.Init(ComponentType.AI, this); m_components.Add(aiComp); return(aiComp); case ComponentType.UI: UIComponent uiComp = gameObject.AddComponent <UIComponent>(); uiComp.Init(ComponentType.UI, this); m_components.Add(uiComp); return(uiComp); default: return(null); } }
//--------------------------------------------------------------------------- public Player(string name, Guid parent) : base(name, parent) { Index = (PlayerIndex)PlayerCount++; AddComponent <TransformComponent>().Init(new Vector3(Index == PlayerIndex.One ? 340 : 420, 400, 0)); AddComponent <PlayerAttributesComponent>().Init(500.0f, 250.0f, 125.0f, 2.0f, 1.0f); AddComponent <InventoryComponent>(); MovementAnimationComponent animation = AddComponent <MovementAnimationComponent>(); if (Index == PlayerIndex.One) { animation.Init(AssetManager.Get().Find <Texture2D>(ESpriteAssets.WalkingAnimation), Vector2.One); } else { animation.Init(AssetManager.Get().Find <Texture2D>(ESpriteAssets.WalkingAnimation2), Vector2.One); } animation.AddSetting((int)Tag.MoveLeft, new AnimationSetting(8, 2, 8, 15, true, true)); animation.AddSetting((int)Tag.MoveRight, new AnimationSetting(8, 2, 0, 7, true)); AddComponent <ShadowComponent>().Init(AssetManager.Get().Find <Texture2D>(ESpriteAssets.RedOrb), new Vector2(6.0f, 2.0f), new Vector2(0.0f, 10.0f)); AddComponent <ActorPhysicsComponent>().Init(BodyType.Dynamic, 0.8f, 1.0f, true); CircleColliderComponent collider = AddComponent <CircleColliderComponent>(); collider.Init(44, BodyType.Dynamic); //collider.SetCollisionCategory(ECollisionCategory.Player); AddComponent <LightingComponent>().Init(AssetManager.Get().Find <Texture2D>(ELightAssets.CircleLight), Vector2.Zero, new Vector2(5.0f, 5.0f), Color.White, 0.6f); InputComponent input = AddComponent <InputComponent>(); if (input != null) { input.Init(Index); input.ClearActions(); switch (Index) { case PlayerIndex.One: input.MapAction(EGameAction.MOVE_LEFT, EInput.KEYBOARD_LEFT, EInput.GAMEPAD_THUMBSTICK_LEFT_LEFT); input.MapAction(EGameAction.MOVE_RIGHT, EInput.KEYBOARD_RIGHT, EInput.GAMEPAD_THUMBSTICK_LEFT_RIGHT); input.MapAction(EGameAction.MOVE_UP, EInput.KEYBOARD_UP, EInput.GAMEPAD_THUMBSTICK_LEFT_UP); input.MapAction(EGameAction.MOVE_DOWN, EInput.KEYBOARD_DOWN, EInput.GAMEPAD_THUMBSTICK_LEFT_DOWN); input.MapAction(EGameAction.LOOK_LEFT, EInput.GAMEPAD_THUMBSTICK_RIGHT_LEFT); input.MapAction(EGameAction.LOOK_RIGHT, EInput.GAMEPAD_THUMBSTICK_RIGHT_RIGHT); input.MapAction(EGameAction.LOOK_UP, EInput.GAMEPAD_THUMBSTICK_RIGHT_UP); input.MapAction(EGameAction.LOOK_DOWN, EInput.GAMEPAD_THUMBSTICK_RIGHT_DOWN); input.MapAction(EGameAction.INVENTORY_NEXT_ITEM, EInput.KEYBOARD_E, EInput.GAMEPAD_DPAD_DOWN); input.MapAction(EGameAction.INVENTORY_PREVIOUS_ITEM, EInput.KEYBOARD_Q, EInput.GAMEPAD_DPAD_UP); input.MapAction(EGameAction.INVENTORY_USE_ITEM, EInput.GAMEPAD_X); input.MapAction(EGameAction.INVENTORY_DROP_ITEM, EInput.GAMEPAD_TRIGGER_RIGHT); input.MapAction(EGameAction.PLAYER_ATTACK, EInput.GAMEPAD_TRIGGER_LEFT); break; case PlayerIndex.Two: input.MapAction(EGameAction.MOVE_LEFT, EInput.KEYBOARD_A, EInput.GAMEPAD_THUMBSTICK_LEFT_LEFT); input.MapAction(EGameAction.MOVE_RIGHT, EInput.KEYBOARD_D, EInput.GAMEPAD_THUMBSTICK_LEFT_RIGHT); input.MapAction(EGameAction.MOVE_UP, EInput.KEYBOARD_W, EInput.GAMEPAD_THUMBSTICK_LEFT_UP); input.MapAction(EGameAction.MOVE_DOWN, EInput.KEYBOARD_S, EInput.GAMEPAD_THUMBSTICK_LEFT_DOWN); input.MapAction(EGameAction.LOOK_LEFT, EInput.GAMEPAD_THUMBSTICK_RIGHT_LEFT); input.MapAction(EGameAction.LOOK_RIGHT, EInput.GAMEPAD_THUMBSTICK_RIGHT_RIGHT); input.MapAction(EGameAction.LOOK_UP, EInput.GAMEPAD_THUMBSTICK_RIGHT_UP); input.MapAction(EGameAction.LOOK_DOWN, EInput.GAMEPAD_THUMBSTICK_RIGHT_DOWN); input.MapAction(EGameAction.INVENTORY_NEXT_ITEM, EInput.KEYBOARD_E, EInput.GAMEPAD_DPAD_DOWN); input.MapAction(EGameAction.INVENTORY_PREVIOUS_ITEM, EInput.KEYBOARD_Q, EInput.GAMEPAD_DPAD_UP); input.MapAction(EGameAction.INVENTORY_USE_ITEM, EInput.GAMEPAD_X); input.MapAction(EGameAction.INVENTORY_DROP_ITEM, EInput.GAMEPAD_TRIGGER_RIGHT); input.MapAction(EGameAction.PLAYER_ATTACK, EInput.GAMEPAD_TRIGGER_LEFT); break; } } //playerIndicatorP1 = EntityFactory.Create<Entity>(GUID, "PlayerIndicatorP1"); //playerIndicatorP1.AddComponent<TransformComponent>().Init(new Vector3(0, -65, 0)); //piAnimationP1 = playerIndicatorP1.AddComponent<AnimationComponent>(); //piAnimationP1.Init(AssetManager.Get().Find<Texture2D>("PlayerIndicatorAnimationP1"), new Vector2(0.4f, 0.4f)); //piAnimationP1.AddSetting(0, new AnimationSetting(8, 1, 0, 7, false)); //playerIndicatorP1.Disable(); //RangeWeapon weapon = EntityFactory.Create<RangeWeapon>(GUID, "Primary Weapon P1"); //weapon.Init(); //if (Index == PlayerIndex.One) //{ // //GetComponent<ActorPhysicsComponent>().AddJoint(weapon.GetComponent<PhysicsComponent>()); //} MeleeWeapon weapon = EntityFactory.Create <MeleeWeapon>(GUID, "Primary Weapon P1"); if (Index == PlayerIndex.One) { GetComponent <ActorPhysicsComponent>().AddJoint(weapon.GetComponent <PhysicsComponent>()); } }