using UnityEngine; using System.Collections.Generic; namespace BioIK { //[ExecuteInEditMode] [DisallowMultipleComponent] public class BioIK : MonoBehaviour { //public bool SolveInEditMode = false; [SerializeField] private bool UseThreading = true; [SerializeField] private int Generations = 2; [SerializeField] private int PopulationSize = 50; [SerializeField] private int Elites = 2; public float Smoothing = 0.5f; public float AnimationWeight = 0f; public float AnimationBlend = 0f; public MotionType MotionType = MotionType.Instantaneous; public float MaximumVelocity = 3f; public float MaximumAcceleration = 3f; public List Segments = new List(); public BioSegment Root = null; public Evolution Evolution = null; public double[] Solution = null; private bool Destroyed = false; //Custom Inspector Helpers public BioSegment SelectedSegment = null; public Vector2 Scroll = Vector2.zero; void Awake() { Refresh(); } void Start() { } void OnDestroy() { Destroyed = true; DeInitialise(); Utility.Cleanup(transform); } void OnEnable() { Initialise(); } void OnDisable() { DeInitialise(); } private void Initialise() { if(Evolution == null) { Evolution = new Evolution(new Model(this), PopulationSize, Elites, UseThreading); } } private void DeInitialise() { if(Evolution != null) { Evolution.Kill(); Evolution = null; } } void Update() { PrecaptureAnimation(Root); } void LateUpdate() { PostcaptureAnimation(Root); UpdateData(Root); for(int i=0; i GetChain(Transform start, Transform end) { BioSegment a = FindSegment(start); BioSegment b = FindSegment(end); if(a == null || b == null) { Debug.Log("Could not generate chain for given transforms"); return null; } return GetChain(a, b); } public List GetChain(BioSegment start, BioSegment end) { List chain = new List(); BioSegment segment = end; while(true) { chain.Add(segment); if(segment.Transform == transform || segment.Parent == null) { break; } else { segment = segment.Parent; } } chain.Reverse(); return chain; } public void UpdateData(BioSegment segment) { if(segment.Joint != null) { if(segment.Joint.enabled) { segment.Joint.UpdateData(); } } for(int i=0; i