void Start() { //store bones in a list for easier access bones = new GameObject[] { Hip_Center, Spine, Neck, Head, Shoulder_Left, Elbow_Left, Wrist_Left, Hand_Left, Shoulder_Right, Elbow_Right, Wrist_Right, Hand_Right, Hip_Left, Knee_Left, Ankle_Left, Foot_Left, Hip_Right, Knee_Right, Ankle_Right, Foot_Right, Spine_Shoulder, Hand_Tip_Left, Thumb_Left, Hand_Tip_Right, Thumb_Right }; // array holding the skeleton lines lines = new LineRenderer[bones.Length]; initialPosition = transform.position; initialRotation = transform.rotation; // For the visual aspect. currentSphereManState = SphereManState.STANDARD; UpdateSphereManStatus(currentSphereManState); jointToIgnoreIndexes = jointToIgnoreIndexes ?? new List <int>(); }
/// <summary> /// Updates the appareance of the Sphere man according to its status. /// </summary> /// <param name="state">The new state of the sphereman.</param> public void UpdateSphereManStatus(SphereManState state) { currentSphereManState = state; /* If a skeleton has been generated, we unload it to force * the apparition of the adequate color of skeleton. */ if (skeletonLine != null) { for (int i = 0; i < bones.Length; i++) { if (lines[i] != null) { GameObject.Destroy(lines[i]); } } } // Each time, we load the adapted skeleton and spheres. switch (state) { case SphereManState.STANDARD: if (standardGestureMaterial != null) { UpdateBonesMaterial(standardGestureMaterial); } if (standardSkeletonLine != null) { standardSkeletonLine.gameObject.SetActive(true); skeletonLine = standardSkeletonLine; } if (validSkeletonLine != null) { validSkeletonLine.gameObject.SetActive(false); } if (wrongSkeletonLine != null) { wrongSkeletonLine.gameObject.SetActive(false); } break; case SphereManState.VALID: if (validGestureMaterial != null) { UpdateBonesMaterial(validGestureMaterial); } if (standardSkeletonLine != null) { standardSkeletonLine.gameObject.SetActive(false); } if (validSkeletonLine != null) { validSkeletonLine.gameObject.SetActive(true); skeletonLine = validSkeletonLine; } if (wrongSkeletonLine != null) { wrongSkeletonLine.gameObject.SetActive(false); } break; case SphereManState.WRONG: if (wrongGestureMaterial != null) { UpdateBonesMaterial(wrongGestureMaterial); } if (validSkeletonLine != null) { validSkeletonLine.gameObject.SetActive(false); } if (standardSkeletonLine != null) { standardSkeletonLine.gameObject.SetActive(false); } if (wrongSkeletonLine != null) { wrongSkeletonLine.gameObject.SetActive(true); skeletonLine = wrongSkeletonLine; } break; default: break; } }