92 lines
3.2 KiB
C#
92 lines
3.2 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace CreatureControl {
|
|
|
|
/// <summary>
|
|
/// A rig or skeleton for a six-legged insect
|
|
/// </summary>
|
|
public class InsectRig : TargetRig {
|
|
/// <summary>
|
|
/// The left front leg
|
|
/// </summary>
|
|
public TargetLeg leftFrontLeg;
|
|
/// <summary>
|
|
/// The left middle leg
|
|
/// </summary>
|
|
public TargetLeg leftMiddleLeg;
|
|
/// <summary>
|
|
/// The left hind leg
|
|
/// </summary>
|
|
public TargetLeg leftBackLeg;
|
|
|
|
/// <summary>
|
|
/// The right front leg
|
|
/// </summary>
|
|
public TargetLeg rightFrontLeg;
|
|
/// <summary>
|
|
/// The right middle leg
|
|
/// </summary>
|
|
public TargetLeg rightMiddleLeg;
|
|
/// <summary>
|
|
/// The right hindLeg
|
|
/// </summary>
|
|
public TargetLeg rightBackLeg;
|
|
|
|
private TargetLeg[] _legs;
|
|
public TargetLeg[] legs {
|
|
get {
|
|
if (_legs == null) {
|
|
_legs = new TargetLeg[6];
|
|
_legs[0] = leftFrontLeg;
|
|
_legs[1] = leftMiddleLeg;
|
|
_legs[2] = leftBackLeg;
|
|
_legs[3] = rightFrontLeg;
|
|
_legs[4] = rightMiddleLeg;
|
|
_legs[5] = rightBackLeg;
|
|
}
|
|
return _legs;
|
|
}
|
|
}
|
|
|
|
public bool render;
|
|
|
|
public float legLength; // smalled leg length
|
|
|
|
public override void Pose() {
|
|
this.leftBackLeg.PoseLimb();
|
|
this.leftMiddleLeg.PoseLimb();
|
|
this.leftFrontLeg.PoseLimb();
|
|
this.rightBackLeg.PoseLimb();
|
|
this.rightMiddleLeg.PoseLimb();
|
|
this.rightFrontLeg.PoseLimb();
|
|
}
|
|
|
|
public override void MatchTo(Creature creature, ref bool somethingChanged) {
|
|
base.MatchTo(creature, ref somethingChanged);
|
|
if (creature is not Insect insect)
|
|
return;
|
|
|
|
if (this.leftFrontLeg != null && insect.leftFrontLeg != null)
|
|
this.leftFrontLeg.MatchTo(insect.leftFrontLeg);
|
|
if (this.leftMiddleLeg != null && insect.leftMiddleLeg != null)
|
|
this.leftMiddleLeg.MatchTo(insect.leftMiddleLeg);
|
|
if (this.leftBackLeg != null && insect.leftHindLeg != null)
|
|
this.leftBackLeg.MatchTo(insect.leftHindLeg);
|
|
|
|
if (this.rightFrontLeg != null && insect.rightFrontLeg != null)
|
|
this.rightFrontLeg.MatchTo(insect.rightFrontLeg);
|
|
if (this.rightMiddleLeg != null && insect.rightMiddleLeg != null)
|
|
this.rightMiddleLeg.MatchTo(insect.rightMiddleLeg);
|
|
if (this.rightBackLeg != null && insect.rightHindLeg != null)
|
|
this.rightBackLeg.MatchTo(insect.rightHindLeg);
|
|
}
|
|
|
|
public void ApplyRenderToChildren(bool value) {
|
|
// Find all renderers under this GameObject (including inactive)
|
|
var renderers = GetComponentsInChildren<Renderer>(true);
|
|
foreach (var r in renderers) r.enabled = value;
|
|
}
|
|
}
|
|
|
|
} |