// Moves effector to given position. Returns time robot needs to reach target. // Assumes constant speed and linear movement. public TimeSpan MoveTo(PointF target) { float distance = Effector.DistanceTo(target); Effector = target; return(TimeSpan.FromSeconds(distance / MovementSpeed)); }
public void DescriptionTestMethod3() { Assert.AreEqual("對全部敵方手下造成1點傷害", new DealSpellDamageToAllEnemyMinionsEffect(1, 1).Description(GameUnitTest.InitialGameStatus(), 0)); Assert.AreEqual("對全部敵方手下造成1點傷害", new DealSpellDamageToAllEnemyMinionsEffect(1, 1).Description(GameUnitTest.InitialGameStatus(), 1)); Game game = GameUnitTest.InitialGameStatus(); Card card; CardManager.Instance.FindCard(11, out card); CardRecord record = game.GameCardManager.CreateCardRecord(card); game.Field1.AddCard(record.CardRecordID, 0); Assert.AreEqual("對全部敵方手下造成*2點傷害", new DealSpellDamageToAllEnemyMinionsEffect(1, 1).Description(game, 1)); CardRecord record2 = game.GameCardManager.CreateCardRecord(card); game.Field1.AddCard(record2.CardRecordID, 0); Assert.AreEqual("對全部敵方手下造成*3點傷害", new DealSpellDamageToAllEnemyMinionsEffect(1, 1).Description(game, 1)); Effect effect; CardManager.Instance.FindEffect(6, out effect); Effector effector = game.GameCardManager.CreareEffector(effect); record2.AddEffector(effector.EffectorID); Assert.AreEqual("對全部敵方手下造成*5點傷害", new DealSpellDamageToAllEnemyMinionsEffect(1, 1).Description(game, 1)); game.GameCardManager.LoadEffector(new SpellDamageEffector(0, 0)); record2.AddEffector(0); Assert.AreEqual("對全部敵方手下造成*5點傷害", new DealSpellDamageToAllEnemyMinionsEffect(1, 1).Description(game, 1)); game.GameCardManager.LoadEffector(new TauntEffector(10, 2)); record2.AddEffector(10); Assert.AreEqual("對全部敵方手下造成*5點傷害", new DealSpellDamageToAllEnemyMinionsEffect(1, 1).Description(game, 1)); }
/*public Player(int id, List<EventEntity> list) * { * planets = list; * this.id = id; * if (id > GlobalData.HUMAN_PLAYER) * { * AI = new ClasicAI(this); * Clock.Instance.AddListener(this); * } * }*/ void Start() { if (Id > GlobalData.HUMAN_PLAYER) { switch (typeAI) { case AIType.Dumb: AI = new DumbAI(); break; case AIType.Random: AI = new RandomAI(); break; case AIType.Classic: AI = new ClasicAI(this); break; case AIType.Montecarlo: AI = new MontecarloAI(this.Id); break; } Clock.Instance.AddListener(this); myEffector = new Effector(this); deactivated = false; } }
private void SetUpInstance() { if (instance == null) { instance = this; } }
protected Func <BattleUnit, bool> DefaultUnitRule(Effector effect) { return((BattleUnit targetBattler) => { if (!effect.AcceptsEmptyGrids()) { if (targetBattler == null) { return false; } if (effect.TargetsHostiles()) { return actor.align != targetBattler.unit.align; } else { return actor.align == targetBattler.unit.align; } } else if (!effect.AcceptsFullGrids()) { return targetBattler == null; } else { return true; } }); }
public void Execute(Actions action) { switch (action) { case Actions.Wait: default: return; case Actions.Heal: HealMyPlanets(); return; case Actions.Upgrade: LevelUpMyPlanets(); return; case Actions.AttackNeutral: //print("Hay neutrales"); EventEntity objective = GetNearestPlanet(map, myPlayer, true); Attack(objective, Random.value > 0.25f); return; case Actions.AttackEnemy: objective = Effector.GetNearestPlanet(map, myPlayer); Attack(objective, Random.value > 0.25f); return; } }
public IEnumerator PlaySkillRoutine(BattleUnit actor, Result <bool> executeResult) { actor.battle.Log(actor + " casts " + skillName + "...", true); Targeter targeter = Object.Instantiate(data.targeter); Effector effect = Object.Instantiate(data.effect); effect.actor = actor; targeter.actor = actor; effect.skill = this; targeter.skill = this; yield return(targeter.ExecuteRoutine(effect, executeResult)); if (!executeResult.canceled) { if (costMP > 0) { actor.unit.stats.Sub(StatTag.MP, costMP); } if (costCD > 0) { actor.unit.stats.Add(StatTag.CD, costCD); actor.maxCD = costCD; } } }
void Shoot() { if (target != null && towerProjectile != null) { //Debug.Log ("shooting"); for (int i = 0; i < numberOfShots; i++) { GameObject projectile = Instantiate(towerProjectile, this.gameObject.transform.position + new Vector3(i * 0.5f, 0, i * 0.5f), Quaternion.identity) as GameObject; projectile.transform.parent = this.gameObject.transform; projectile.transform.localScale = towerProjectile.transform.localScale; projectile.transform.localRotation = towerProjectile.transform.rotation; projectile.GetComponent <Projectile> ().target = target; projectile.GetComponent <Projectile> ().range = towerBody.range; Utils.RotateModel(projectile, target, 150); Effector effector = projectile.AddComponent <Effector> () as Effector; effector.slowDuration = baseEffector.slowDuration; effector.slowPercentage = baseEffector.slowPercentage; target = hostileMobsInRange [randomGen.Next(hostileMobsInRange.Count)].gameObject; } } }
protected override IEnumerator InternalExecuteRoutine(Effector effect, Result <bool> result) { DirectionCursor cursor = battle.SpawnDirectionCursor(actor.location); Result <EightDir> dirResult = new Result <EightDir>(); yield return(cursor.SelectTargetDirRoutine(dirResult, actor, (Vector2Int v) => { float d = Mathf.Abs(actor.battler.transform.position.y - map.terrain.HeightAt(v.x, v.y)); return d <= BattleEvent.AttackHeightMax && DefaultSelectRule(effect)(v); }, true)); battle.DespawnDirCursor(); if (dirResult.canceled) { result.Cancel(); } else { float d = Mathf.Abs(actor.battler.transform.position.y - map.terrain.HeightAt(actor.battler.location + dirResult.value.XY())); if (d <= BattleEvent.AttackHeightMax) { yield return(effect.ExecuteDirectionRoutine(dirResult.value)); result.value = true; } else { result.Cancel(); } } }
public void SetEffector(Effector effector) { if (this.effector != null) { this.effector.Remove(); } this.effector = effector; effector.Initialize(status); }
public void UpdateParticleSubState(float elaspe) { if (SubStates != null) { var effector = Effector.Get(false); for (int i = 0; i < SubStates.Length; i++) { if (CurLiveTime <= FireDelay) { continue; } unsafe { CGfxParticleState **pStates; int num = 0; CGfxParticleSubState.SDK_GfxParticleSubState_GetParticles(SubStates[i].CoreObject, &pStates, &num); if (num > 0) { //宏图处理粒子状态变更 effector.OnParticleStateTick(this, pStates, num, i, SubStates[i], elaspe, i); } } //这里处理SubState里面的粒子如果死亡,移除状态 CGfxParticleSubState.SDK_GfxParticleSubState_Simulate(SubStates[i].CoreObject, elaspe); if (TrailNode != null) { TrailNode.Clear(); } if (SubStates[i].MacrossNode != null) { effector.ParticleData.ParticleSystem = this; effector.ParticleData.ParticleSubState = SubStates[i]; effector.ParticleData.ParticleEmitterShape = SubStates[i].Shape; SubStates[i].MacrossNode.Update(elaspe, effector.ParticleData); } var TransformNode = SubStates[i].TransformNode; if (TransformNode != null) { float tick = 0; if (TransformNode.Loop) { tick = ((EngineNS.CEngine.Instance.EngineTimeSecond - TransformNode.StartTick) % TransformNode.Duration) / TransformNode.Duration; } else { tick = MathHelper.FClamp((EngineNS.CEngine.Instance.EngineTimeSecond - TransformNode.StartTick) / TransformNode.Duration, 0f, 1f); } SubStates[i].TransformNode.SetMatrix(tick); } } } }
//Weapon - Projectile public Item(int id, string title, Sprite image, Defs.ItemCategory category, int stackLimit, float weight, Defs.WeaponType weaponType, GameObject weaponObject, AudioClip[] windupSound, AudioClip[] releaseSound, AudioClip[] hitSound, AudioClip[] flightSound, Effector costEffector, Effector selfEffector, Effector selfOnHitEffector, Effector targetEffector, float windupTime, float strikeTime, float recoveryTime, GameObject projectileObject, float range, float speed, int targetLimit) { //Required this.ID = id; this.Title = title; this.Image = image; this.Category = category; this.StackLimit = stackLimit; this.Weight = weight; //Effectors this.CostEffector = costEffector; this.SelfEffector = selfEffector; this.SelfOnHitEffector = selfOnHitEffector; this.TargetEffector = targetEffector; //Weapon Specific this.WeaponType = weaponType; this.WeaponObject = weaponObject; //General this.WindupSound = windupSound; this.StrikeSound = releaseSound; this.HitSound = hitSound; this.WindupTime = windupTime; this.StrikeTime = strikeTime; this.RecoveryTime = recoveryTime; //Projectile this.ProjectileObject = projectileObject; this.FlightSound = flightSound; this.Range = range; this.Speed = speed; this.TargetLimit = targetLimit; }
public IEnumerator TryAIUse(AIController ai) { Targeter targeter = Object.Instantiate(data.targeter); Effector effect = Object.Instantiate(data.effect); effect.actor = ai.unit; targeter.actor = ai.unit; effect.skill = this; targeter.skill = this; return(targeter.TryAIUse(ai, effect)); }
public HeadIK(FullBodyIK fullBodyIK) { _settings = fullBodyIK.settings; _internalValues = fullBodyIK.internalValues; _neckBone = _PrepareBone(fullBodyIK.headBones.neck); _headBone = _PrepareBone(fullBodyIK.headBones.head); _leftEyeBone = _PrepareBone(fullBodyIK.headBones.leftEye); _rightEyeBone = _PrepareBone(fullBodyIK.headBones.rightEye); _headEffector = fullBodyIK.headEffectors.head; _eyesEffector = fullBodyIK.headEffectors.eyes; }
public HeadIK( FullBodyIK fullBodyIK ) { _settings = fullBodyIK.settings; _internalValues = fullBodyIK.internalValues; _neckBone = _PrepareBone( fullBodyIK.headBones.neck ); _headBone = _PrepareBone( fullBodyIK.headBones.head ); _leftEyeBone = _PrepareBone( fullBodyIK.headBones.leftEye ); _rightEyeBone = _PrepareBone( fullBodyIK.headBones.rightEye ); _headEffector = fullBodyIK.headEffectors.head; _eyesEffector = fullBodyIK.headEffectors.eyes; }
protected override void ComposePrioritizedEffectors(List <Effector> effList) { Effector actionEffector = null; Object actionObject = null; Reflex reflex = null; #if PRIORITYDISTANCE // find the nearest attractor foreach (KeyValuePair <Reflex, ActionSet> pair in itemSets) { Action testTarget = pair.Value.Closest(); if (testTarget != null && (actionTarget == null || actionTarget.distance > testTarget.distance)) { actionTarget = testTarget; actionObject = pair.Key; } } #else // find the highest priority action ActionSet prioritizedSet = null; foreach (KeyValuePair <Reflex, ActionSet> pair in itemSets) { ActionSet testSet = pair.Value; Effector testEffector = pair.Value.ClosestAction(); if (testEffector != null) { if (prioritizedSet == null || testSet.priority < prioritizedSet.priority) { prioritizedSet = testSet; actionEffector = testEffector; actionObject = pair.Key; } } } #endif if (actionEffector != null) { actionEffector.used = true; // let the reflex know it was prioritized and used reflex = actionObject as Reflex; if (reflex != null) { reflex.Used(reflex != lastReflex); } effList.Add(actionEffector); return; } lastReflex = reflex; }
private async Task captureThread() { var count = 0; try { var capture = new VideoCapture(deviceId); while (!cancelToken.IsCancellationRequested) { if (capture.IsOpened()) { Bitmap bitmap = null; var normalFrame = new Mat(); capture.Read(normalFrame); try { bitmap = Effector?.ToBitmap(normalFrame); } catch (Exception e) { error = e.Message; } if (bitmap == null) { bitmap = BitmapConverter.ToBitmap(normalFrame); } normalFrame.Dispose(); if (count == 0) { count++; BeginInvoke(new MethodInvoker(() => { if (this.bitmap != null) { this.bitmap.Dispose(); } this.bitmap = bitmap; UpdateImage(); count--; })); } } await Task.Delay(1); } capture.Release(); } catch (Exception e) { error = e.Message; } }
public void FireParticles() { int num = FireParticles(FireCountPerTime); if (num < FireCountPerTime) { } for (int i = 0; i < SubStates.Length; i++) { SubStates[i].OnParticleStateBorn(Effector.Get(false), this, i); } }
// Start is called before the first frame update void Awake() { effector = GetComponent <Effector>(); particleEffectors = new Effector[particles.Length]; particleGravities = new SimpleGravityParticle[particles.Length]; for (int i = 0; i < particles.Length; i++) { particleEffectors[i] = particles[i].GetComponent <Effector>(); particleGravities[i] = particles[i].GetComponent <SimpleGravityParticle>(); particleGravities[i].gravity = gravity; } originalScale = transform.localScale; }
public override IEnumerator TryAIUse(AIController ai, Effector effect) { if (Vector2Int.Distance(actor.location, ai.pc.location) < 1.5) { battle.Log(actor + " used " + skill.skillName); EightDir dir = EightDirExtensions.DirectionOf(ai.pc.location - actor.location); return(effect.ExecuteDirectionRoutine(dir)); } else { return(null); } }
protected override void ComposeAllEffectors(List <Effector> effList) { foreach (KeyValuePair <Reflex, ActionSet> pair in itemSets) { for (int i = 0; i < pair.Value.Actions.Count; ++i) { Effector eff = pair.Value.Actions[i] as Effector; if (eff != null) { effList.Add(eff); } } } }
protected Func <Vector2Int, bool> DefaultSelectRule(Effector effect) { return((Vector2Int loc) => { if (loc.x == map.size.x - 1 || loc.y == map.size.y - 1) { return false; } BattleEvent targetBattler = map.GetEventAt <BattleEvent>(loc); if (!actorEvent.CanPassAt(loc) && map.GetEventAt <BattleEvent>(loc) == null) { return false; } return DefaultUnitRule(effect)(targetBattler != null ? targetBattler.unit : null); }); }
protected override IEnumerator InternalExecuteRoutine(Effector effect, Result <bool> result) { Func <Vector2Int, bool> rangeRule = (Vector2Int loc) => { return(Vector2Int.Distance(loc, actor.location) <= radius); }; Vector2Int origin = new Vector2Int( (int)actorEvent.positionPx.x - Mathf.CeilToInt(radius), (int)actorEvent.positionPx.z - Mathf.CeilToInt(radius)); SelectionGrid grid = battle.SpawnSelectionGrid(); grid.ConfigureNewGrid(actor.location, Mathf.CeilToInt(radius), map.terrain, rangeRule, rangeRule); Result <Vector2Int> locResult = new Result <Vector2Int>(); battle.SpawnCursor(actor.location); yield return(battle.cursor.AwaitSelectionRoutine(locResult, _ => true, null, loc => { return loc == actor.location; })); battle.DespawnCursor(); Destroy(grid.gameObject); if (locResult.canceled) { result.Cancel(); } else { List <Vector2Int> cells = new List <Vector2Int>(); int r = Mathf.CeilToInt(radius); for (int y = locResult.value.y - r; y <= locResult.value.y + r; y += 1) { for (int x = locResult.value.x - r; x <= locResult.value.x + r; x += 1) { Vector2Int cell = new Vector2Int(x, y); if (DefaultSelectRule(effect)(cell)) { cells.Add(cell); } } } yield return(effect.ExecuteCellsRoutine(cells)); result.value = true; } }
/// <summary> /// Execute l'effecteur le plus approprie selon l'agent /// </summary> public void ExecuteMoves() { // Observe l’environnement CaptureSignals(); // Met A jour les croyance a partir des nouveaux fait observe et des croyances deja etablie InferenceEngine.InferenceCycle(ref _beliefs, _rules); if (_queuedActions.Count == 0) { PlanNextMove(); } Effector action = _queuedActions.Dequeue(); action.Execute(this); }
//Weapon - Shield public Item(int id, string title, Sprite image, Defs.ItemCategory category, int stackLimit, float weight, Defs.WeaponType weaponType, GameObject weaponObject, AudioClip[] windupSound, AudioClip[] strikeSound, Effector costEffector, Effector selfEffector, Effector selfOnHitEffector, Effector targetEffector, float windupTime, float strikeTime, float recoveryTime, AudioClip[] blockSound, int blockAngle) { //Required this.ID = id; this.Title = title; this.Image = image; this.Category = category; this.StackLimit = stackLimit; this.Weight = weight; //Effectors this.CostEffector = costEffector; this.SelfEffector = selfEffector; this.SelfOnHitEffector = selfOnHitEffector; this.TargetEffector = targetEffector; //Weapon Specific this.WeaponType = weaponType; this.WeaponObject = weaponObject; //General this.WindupSound = windupSound; this.StrikeSound = strikeSound; this.WindupTime = windupTime; this.StrikeTime = strikeTime; this.RecoveryTime = recoveryTime; //Shield this.BlockSound = blockSound; this.BlockAngle = blockAngle; }
public Actions Decide() { bool attack = false; bool attackNeutal = false; if (PlanetsNeedHealing()) { return(Actions.Heal); } if (PlanetsNotAtMaximmumLevel() && Random.value > 0.5f) { return(Actions.Upgrade); } if (Random.value > 0.4f) { if (Random.value > 0.5f) { attack = true; } else { attackNeutal = true; } } EventEntity objective; if (ThereAreNeutralPlanets() && !attack) { objective = Effector.GetNearestPlanet(map, myPlayer, true); if (myPlayer.GetCurrentUnitsNumber() > Effector.CountNecessaryUnitsToConquer(objective, myPlayer) * 1.5f || attackNeutal) { return(Actions.AttackNeutral); } } else { objective = Effector.GetNearestPlanet(map, myPlayer); if (myPlayer.GetCurrentUnitsNumber() > Effector.CountNecessaryUnitsToConquer(objective, myPlayer) * 1.5f || attack) { return(Actions.AttackEnemy); } } return(Actions.Wait); }
/*<summary> * This function takes an array of GameObjects from the collided weapon * Each GameObject should contain an Effector that will be cloned onto the Entity * </summary> */ public void takeEffects(GameObject[] weaponEffectors) { foreach (GameObject effectorObject in weaponEffectors) { Effector effect = effectorObject.GetComponent <Effector>(); //This switch case will add scripts to the gameObject depending on the type //and adds corresponding attributes of each found Effector (e.g. timeDuration) switch (effect.type) { case Effector.EffectType.Paralysis: gameObject.AddComponent <Paralysis>(); GetComponent <Paralysis>().timeDuration = effect.timeDuration; GetComponent <Paralysis>().type = effect.type; break; } } }
public override IEnumerator TryAIUse(AIController ai, Effector effect) { // 7drl hack if (Vector2Int.Distance(actor.location, ai.pc.location) < range && battler.CanSeeLocation(map.terrain, ai.pc.location)) { battle.Log(actor + " cast " + skill.skillName + "!"); return(effect.ExecuteCellsRoutine(new List <Vector2Int>() { ai.pc.location })); } else { return(null); } }
void Shoot() { if (target != null && towerProjectile != null) { Debug.Log("shooting"); GameObject projectile = Instantiate(towerProjectile, this.gameObject.transform.position, Quaternion.identity) as GameObject; projectile.transform.parent = this.gameObject.transform; projectile.transform.localScale = new Vector3(10, 5, 100); projectile.GetComponent <Projectile> ().target = target; projectile.GetComponent <Projectile> ().range = towerBody.range; Effector effector = projectile.AddComponent <Effector>() as Effector; effector.slowDuration = baseEffector.slowDuration; effector.slowPercentage = baseEffector.slowPercentage; } }
protected override IEnumerator InternalExecuteRoutine(Effector effect, Result <bool> result) { battle.SpawnCursor(actor.location); Result <Vector2Int> locResult = new Result <Vector2Int>(); yield return(battle.cursor.AwaitSelectionRoutine(locResult, _ => true, null, loc => { return loc == actor.location; })); if (locResult.canceled) { result.Cancel(); } else { result.value = true; } }
/// <summary> /// Execute l'effecteur le plus approprie selon l'agent /// </summary> /// <returns>Faux si l'agent n'a plus de mouvement</returns> public bool ExecuteAMove() { // Observe l’environnement CheckersState currentState = CaptureSignals(); // Construit l'arbre ? (Uniquement si pb de performance) // Recupere toute les actions possible // Defini le but actuel prioritaire // Pour toute les actions possible on recupere celle qui est associe a la mesure d'utilite la plus forte Effector nextMove = AlphaBetaSearch(currentState);//MinimaxDecision(currentState); // Execute le mouvement if (nextMove == null) { return(false); } nextMove.Execute(m_board); return(true); }
void _Prefix( ref Effector effector, EffectorLocation effectorLocation, Effector parentEffector, Bone[] bones ) { _Prefix( ref effector, effectorLocation, parentEffector, (bones != null && bones.Length > 0) ? bones[bones.Length - 1] : null ); }
public LimbIK( FullBodyIK fullBodyIK, LimbIKLocation limbIKLocation ) { Assert( fullBodyIK != null ); if( fullBodyIK == null ) { return; } _settings = fullBodyIK.settings; _internalValues = fullBodyIK.internalValues; _limbIKLocation = limbIKLocation; _limbIKType = FullBodyIK.ToLimbIKType( limbIKLocation ); _limbIKSide = FullBodyIK.ToLimbIKSide( limbIKLocation ); if( _limbIKType == LimbIKType.Leg ) { var legBones = (_limbIKSide == Side.Left) ? fullBodyIK.leftLegBones : fullBodyIK.rightLegBones; var legEffectors = (_limbIKSide == Side.Left) ? fullBodyIK.leftLegEffectors : fullBodyIK.rightLegEffectors; _beginBone = legBones.leg; _bendingBone = legBones.knee; _endBone = legBones.foot; _bendingEffector = legEffectors.knee; _endEffector = legEffectors.foot; } else if( _limbIKType == LimbIKType.Arm ) { var armBones = (_limbIKSide == Side.Left) ? fullBodyIK.leftArmBones : fullBodyIK.rightArmBones; var armEffectors = (_limbIKSide == Side.Left) ? fullBodyIK.leftArmEffectors : fullBodyIK.rightArmEffectors; _beginBone = armBones.arm; _bendingBone = armBones.elbow; _endBone = armBones.wrist; _bendingEffector = armEffectors.elbow; _endEffector = armEffectors.wrist; _PrepareRollBones( ref _armRollBones, armBones.armRoll ); _PrepareRollBones( ref _elbowRollBones, armBones.elbowRoll ); } _Prepare( fullBodyIK ); }
static void _DrawEffectorGizmo( Effector effector ) { if( effector != null ) { bool isFinger = (effector.bone != null && effector.bone.boneType == BoneType.HandFinger); float effectorSize = (isFinger ? _FingerEffectorGizmoSize : _EffectorGizmoSize); Gizmos.color = Color.green; Vector3 position = Vector3.zero; if( effector.transform != null ) { position = effector.transform.position; } else { position = effector._worldPosition; // Memo: Don't re-write internal flags. (Use _worldPosition directly.) } Gizmos.DrawWireSphere( position, effectorSize ); Gizmos.DrawWireSphere( position, effectorSize ); Gizmos.DrawWireSphere( position, effectorSize ); Gizmos.DrawWireSphere( position, effectorSize ); } }
void _Prefix( ref Effector effector, EffectorLocation effectorLocation ) { Assert( _effectors != null ); bool createEffectorTransform = this.settings.createEffectorTransform; Assert( rootTransform != null ); Effector.Prefix( _effectors, ref effector, effectorLocation, createEffectorTransform, rootTransform ); }
public BodyIK( FullBodyIK fullBodyIK, LimbIK[] limbIK ) { Assert( fullBodyIK != null ); _limbIK = limbIK; _settings = fullBodyIK.settings; _internalValues = fullBodyIK.internalValues; _hipsBone = _PrepareBone( fullBodyIK.bodyBones.hips ); _neckBone = _PrepareBone( fullBodyIK.headBones.neck ); _headBone = _PrepareBone( fullBodyIK.headBones.head ); _hipsEffector = fullBodyIK.bodyEffectors.hips; _neckEffector = fullBodyIK.headEffectors.neck; _headEffector = fullBodyIK.headEffectors.head; _eyesEffector = fullBodyIK.headEffectors.eyes; _armEffectors[0] = fullBodyIK.leftArmEffectors.arm; _armEffectors[1] = fullBodyIK.rightArmEffectors.arm; _elbowEffectors[0] = fullBodyIK.leftArmEffectors.elbow; _elbowEffectors[1] = fullBodyIK.rightArmEffectors.elbow; _wristEffectors[0] = fullBodyIK.leftArmEffectors.wrist; _wristEffectors[1] = fullBodyIK.rightArmEffectors.wrist; _kneeEffectors[0] = fullBodyIK.leftLegEffectors.knee; _kneeEffectors[1] = fullBodyIK.rightLegEffectors.knee; _footEffectors[0] = fullBodyIK.leftLegEffectors.foot; _footEffectors[1] = fullBodyIK.rightLegEffectors.foot; _spineBones = _PrepareSpineBones( fullBodyIK.bones ); if( _spineBones != null && _spineBones.Length > 0 ) { int spineLength = _spineBones.Length; _spineBone = _spineBones[0]; _spineUBone = _spineBones[spineLength - 1]; _spineEnabled = new bool[spineLength]; } // Memo: These should be pair bones.(Necessary each side bones.) _kneeBones = _PrepareBones( fullBodyIK.leftLegBones.knee, fullBodyIK.rightLegBones.knee ); _elbowBones = _PrepareBones( fullBodyIK.leftArmBones.elbow, fullBodyIK.rightArmBones.elbow ); _legBones = _PrepareBones( fullBodyIK.leftLegBones.leg, fullBodyIK.rightLegBones.leg ); _armBones = _PrepareBones( fullBodyIK.leftArmBones.arm, fullBodyIK.rightArmBones.arm ); _shoulderBones = _PrepareBones( fullBodyIK.leftArmBones.shoulder, fullBodyIK.rightArmBones.shoulder ); _nearArmBones = (_shoulderBones != null) ? _shoulderBones : _nearArmBones; _Prepare( fullBodyIK ); }
// Allocation only. void _PrepareBranch( int fingerType, Bone[] bones, Effector effector ) { if( _parentBone == null || bones == null || effector == null ) { return; } int boneLength = bones.Length; if( boneLength == 0 ) { return; } if( effector.bone != null && bones[boneLength - 1] == effector.bone ) { boneLength -= 1; if( boneLength == 0 ) { return; } } if( boneLength != 0 ) { if( bones[boneLength - 1] == null || bones[boneLength - 1].transform == null ) { boneLength -= 1; if( boneLength == 0 ) { return; } } } _FingerBranch fingerBranch = new _FingerBranch(); fingerBranch.effector = effector; fingerBranch.fingerLinks = new _FingerLink[boneLength]; for( int linkID = 0; linkID < boneLength; ++linkID ) { if( bones[linkID] == null || bones[linkID].transform == null ) { return; } _FingerLink fingerLink = new _FingerLink(); fingerLink.bone = bones[linkID]; fingerBranch.fingerLinks[linkID] = fingerLink; } _fingerBranches[fingerType] = fingerBranch; if( fingerType == (int)FingerType.Thumb ) { _thumbBranch = new _ThumbBranch(); _thumbBranch.thumbLinks = new _ThumbLink[boneLength]; for( int i = 0; i != boneLength; ++i ) { _thumbBranch.thumbLinks[i] = new _ThumbLink(); } } }
static Vector3 _GetEffectorPosition( InternalValues internalValues, Bone rootBone, Bone beginLinkBone, Effector effector, float link0ToEffectorLength, ref Matrix3x4 parentTransform ) { if( rootBone != null && beginLinkBone != null && effector != null ) { var effectorPosition = effector.worldPosition; if( effector.positionWeight < 1.0f - IKEpsilon ) { Vector3 endLinkPosition; if( internalValues.continuousSolverEnabled || internalValues.resetTransforms ) { endLinkPosition = parentTransform * (effector._defaultPosition - rootBone._defaultPosition); } else { endLinkPosition = effector.bone_worldPosition; } Vector3 beginLinkPosition = parentTransform * (beginLinkBone._defaultPosition - rootBone._defaultPosition); Vector3 moveFrom = endLinkPosition - beginLinkPosition; Vector3 moveTo = effectorPosition - beginLinkPosition; float lengthFrom = link0ToEffectorLength; // Optimized. float lengthTo = moveTo.magnitude; if( lengthFrom > IKEpsilon && lengthTo > IKEpsilon ) { Vector3 dirFrom = moveFrom * (1.0f / lengthFrom); Vector3 dirTo = moveTo * (1.0f / lengthTo); Vector3 dir = _LerpDir( ref dirFrom, ref dirTo, effector.positionWeight ); float len = Mathf.Lerp( lengthFrom, lengthTo, Mathf.Clamp01( 1.0f - (1.0f - effector.positionWeight) * _positionLerpRate ) ); return dir * len + beginLinkPosition; } } return effectorPosition; } return Vector3.zero; }
// Call from Awake() or Editor Scripts. // Memo: bone.transform is null yet. public static void Prefix( Effector[] effectors, ref Effector effector, EffectorLocation effectorLocation, bool createEffectorTransform, Transform parentTransform, Effector parentEffector = null, Bone bone = null, Bone leftBone = null, Bone rightBone = null ) { if( effector == null ) { effector = new Effector(); } if( !effector._isPresetted || effector._effectorLocation != effectorLocation || (int)effector._effectorType < 0 || (int)effector._effectorType >= (int)EffectorType.Max ) { effector._PresetEffectorLocation( effectorLocation ); } effector._parentEffector = parentEffector; effector._bone = bone; effector._leftBone = leftBone; effector._rightBone = rightBone; // Create or destroy effectorTransform. effector._PrefixTransform( createEffectorTransform, parentTransform ); if( effectors != null ) { effectors[(int)effectorLocation] = effector; } }
public void Prepare( Effector[] bendingEffectors, Effector[] endEffectors ) { Assert( bendingEffectors != null ); Assert( endEffectors != null ); for( int i = 0; i < 2; ++i ) { targetBeginPos[i] = beginPos[i]; targetBeginPosEnabled[i] = false; if( bendingEffectors[i] != null && bendingEffectors[i].bone != null && bendingEffectors[i].bone.transformIsAlive ) { bendingPosEnabled[i] = true; bendingPos[i] = bendingEffectors[i]._hidden_worldPosition; } else { bendingPosEnabled[i] = false; bendingPos[i] = new Vector3(); } if( endEffectors[i] != null && endEffectors[i].bone != null && endEffectors[i].bone.transformIsAlive ) { endPosEnabled[i] = true; endPos[i] = endEffectors[i]._hidden_worldPosition; } else { endPosEnabled[i] = false; endPos[i] = new Vector3(); } } }
void _Prefix( ref Effector effector, EffectorLocation effectorLocation, Effector parentEffector, Bone bone, Bone leftBone = null, Bone rightBone = null ) { Assert( _effectors != null ); bool createEffectorTransform = this.settings.createEffectorTransform; Effector.Prefix( _effectors, ref effector, effectorLocation, createEffectorTransform, null, parentEffector, bone, leftBone, rightBone ); }