Exemplo n.º 1
0
        private void ParseGene(ref GeneData newGene, string[] geneSubstrings)
        {
            // node,[Node type],[Bone Type],[Base depth],[Depth tolerance],[Grow Time]

            if (geneSubstrings.Length != 6)
            {
                newGene.IsValid = false;
                return;
            }
            try {
                newGene.IsMultyApplicable = geneSubstrings[0] == "stats";
                newGene.GeneType = geneSubstrings[0];
                newGene.Subtype = Convert.ToUInt16(geneSubstrings[1],16);
                newGene.ApplicantSubtype = Convert.ToUInt16(geneSubstrings[2],16);
                newGene.BaseDepth = Convert.ToUInt16(geneSubstrings[3],16);
                newGene.DepthTolerance = Convert.ToUInt16(geneSubstrings[4],16);
                newGene.GrowTime = Convert.ToUInt32(geneSubstrings[5],16) * 0.01f;
            } catch (Exception ex) {
                Debug.LogError(ex.Message);

                newGene.IsValid = false;
                return;
            }

            newGene.IsValid = true;
        }
Exemplo n.º 2
0
    bool GetIsApplicable(GeneData gene)
    {
        // Part Type check
        if (gene.GeneType != "node" && gene.GeneType != "stats")
        {
            return false;
        }

        // Subtype check
        if (gene.ApplicantSubtype != 0 && gene.ApplicantSubtype != Subtype) {
            return false;
        }

        // Generation check
        var gen = Generation;
        if (gen != gene.BaseDepth)
        {
            var actDistance = Mathf.Abs(gen - gene.BaseDepth);
            if (UnityEngine.Random.Range(0f, 1f) < actDistance / (gene.DepthTolerance + 1)) {
                return false;
            }
        }

        return true;
    }
Exemplo n.º 3
0
    private void AddNode(GeneData gene)
    {
        var slot = Slots.FirstOrDefault(s => !s.IsOccupied);

        if (slot == null) return;

        slot.IsOccupied = true;

        var nodePrefab = PrefabsManager.Instance.LoadPrefab(string.Format("{0}{1}", gene.GeneType, gene.Subtype));

        var newBody = (GameObject)Instantiate(nodePrefab,
                                              gameObject.transform.position,
                                              Quaternion.FromToRotation(Vector3.right, Vector3.up) *
            //Quaternion.AngleAxis(Random.Range(-slot.Angle, slot.Angle), Vector3.forward));
                                              Quaternion.AngleAxis(slot.Angle, Vector3.forward));

        newBody.transform.parent = gameObject.transform;
        newBody.SetActive(true);

        var hinge = newBody.AddComponent<HingeJoint2D>();
        hinge.connectedBody = gameObject.GetComponent<Rigidbody2D>();
        hinge.connectedAnchor = new Vector2(slot.X, slot.Y);
        hinge.limits = new JointAngleLimits2D { min = -1.0f, max = 1.0f };
        hinge.useLimits = true;

        newBody.AddComponent<HingeSmoothPos>();

        gameObject.SendMessage("OnChildAdded", newBody, SendMessageOptions.DontRequireReceiver);
    }
Exemplo n.º 4
0
    private void AddBone(GeneData gene)
    {
        var slot = Slots.FirstOrDefault(s => !s.IsOccupied);
        if (slot == null)
        {
            return;
        }

        slot.IsOccupied = true;

        var bonePrefab = PrefabsManager.Instance.LoadPrefab(string.Format("{0}{1}", gene.GeneType, gene.Subtype));
        var newBody = (GameObject)Instantiate(bonePrefab,
                                              gameObject.transform.position,
                                              gameObject.transform.rotation *
                                              Quaternion.AngleAxis(slot.Angle, Vector3.forward));
        newBody.transform.parent = gameObject.transform;
        newBody.SetActive(true);

        //var slide = newBody.AddComponent<SliderJoint2D>();
        var slide = newBody.AddComponent<HingeJoint2D>();
        slide.connectedBody = gameObject.GetComponent<Rigidbody2D>();
        slide.connectedAnchor = new Vector2(slot.X, slot.Y);
        //slide.limits = new JointTranslationLimits2D { min = -0.1f, max = 0.1f };
        slide.limits = new JointAngleLimits2D { min = -1.0f, max = 1.0f };
        slide.useLimits = true;

        gameObject.SendMessage("OnChildAdded", newBody, SendMessageOptions.DontRequireReceiver);
    }
Exemplo n.º 5
0
        private void ParseGene(ref GeneData newGene, string[] geneSubstrings)
        {
            // node,[Node type],[Bone Type],[Base depth],[Depth tolerance],[Grow Time]

            if (geneSubstrings.Length != 6)
            {
                newGene.IsValid = false;
                return;
            }
            try {
                newGene.IsMultyApplicable = geneSubstrings[0] == "stats";
                newGene.GeneType          = geneSubstrings[0];
                newGene.Subtype           = Convert.ToUInt16(geneSubstrings[1], 16);
                newGene.ApplicantSubtype  = Convert.ToUInt16(geneSubstrings[2], 16);
                newGene.BaseDepth         = Convert.ToUInt16(geneSubstrings[3], 16);
                newGene.DepthTolerance    = Convert.ToUInt16(geneSubstrings[4], 16);
                newGene.GrowTime          = Convert.ToUInt32(geneSubstrings[5], 16) * 0.01f;
            } catch (Exception ex) {
                Debug.LogError(ex.Message);

                newGene.IsValid = false;
                return;
            }

            newGene.IsValid = true;
        }
Exemplo n.º 6
0
        public GeneData ParseGene(string geneString)
        {
            var geneSubstrings = geneString.Split(GENE_VALUES_SEPARATORS, StringSplitOptions.RemoveEmptyEntries);

            var newGene = new GeneData();

            ParseGene(ref newGene, geneSubstrings);

            return newGene;
        }
Exemplo n.º 7
0
        public GeneData ParseGene(string geneString)
        {
            var geneSubstrings = geneString.Split(GENE_VALUES_SEPARATORS, StringSplitOptions.RemoveEmptyEntries);

            var newGene = new GeneData();

            ParseGene(ref newGene, geneSubstrings);

            return(newGene);
        }
Exemplo n.º 8
0
 private void AddJoint(GeneData gene)
 {
     //        float x, y;
     //        gene.FloatModifiers.TryGetValue("X", out x);
     //        gene.FloatModifiers.TryGetValue("Y", out y);
     //
     //        var slot = new ChildSlot { X = x, Y = y };
     //
     //        var newBody = (GameObject)Instantiate(BonePrefab,
     //                  gameObject.transform.position + new Vector3(slot.X, slot.Y),
     //                  gameObject.transform.rotation);
     //        newBody.transform.parent = gameObject.transform;
     //        newBody.SetActive(true);
     //
     //        var spring = newBody.AddComponent<SpringJoint2D>();
     //        spring.connectedBody = gameObject.GetComponent<Rigidbody2D>();
     //        spring.distance = 0.1f;
     //        spring.dampingRatio = 0.01f;
     //        spring.frequency = 10.0f;
     //
     //		gameObject.SendMessage("OnChildAdded", newBody, SendMessageOptions.DontRequireReceiver);
 }
Exemplo n.º 9
0
 private void AddStats(GeneData gene)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 10
0
    void OnApplyGene(GeneData gene)
    {
        if (!GetIsApplicable(gene)) return;

        switch (gene.GeneType.ToLower())
        {
            case "node":
                AddNode(gene);
                break;
            case "stats":
                AddStats(gene);
                break;
            default:
                break;
        }
    }