コード例 #1
0
        public float EvaluateDemo()
        {
            var dna = new DynamicUMADna();

            dna._names = new string[1] {
                "DNAValue"
            };
            dna._values = new float[1] {
                _exampleDNAValue
            };
            return(_exampleEvaluator.Evaluate(dna));
        }
コード例 #2
0
        public DynamicUMADna ToDna()
        {
            var res = new DynamicUMADna();

            //Do names and values first
            res._names = new string[bDnaSettings.Length];
            for (int i = 0; i < bDnaSettings.Length; i++)
            {
                res._names[i] = bDnaSettings[i].name;
            }
            res._values = new float[bDnaSettings.Length];
            for (int ii = 0; ii < bDnaSettings.Length; ii++)
            {
                res._values[ii] = bDnaSettings[ii].value * (1f / 255f);
            }
            res.dnaAssetName = bDnaAssetName;
            //Then set the asset using dnaAsset.set so that everything is validated and any new dna gets added with default values
            //Usually we need to find the asset because the instance id in the recipe will not be the same in different sessions of Unity
            if ((bDnaAsset == null && bDnaAssetName != "") || (bDnaAssetName != "" && (bDnaAsset != null && bDnaAsset.name != bDnaAssetName)))
            {
                res.FindMissingDnaAsset(bDnaAssetName);
            }
            else if (bDnaAsset != null)
            {
                res.dnaAsset = bDnaAsset;
            }

            if (res.dnaAsset != null)
            {
                res.SetDnaTypeHash(res.dnaAsset.dnaTypeHash);
            }
            else
            {
                if (Debug.isDebugBuild)
                {
                    Debug.LogWarning("Deserialized DynamicUMADna with no matching asset!");
                }
            }

            return(res);
        }
コード例 #3
0
            //TODO check if this still screws up the incoming dnas values
            public UMADnaBase GetWeightedDNA(UMADnaBase incomingDna)
            {
                if (_masterWeightType == MasterWeightType.UseGlobalValue)
                {
                    return(incomingDna);
                }

                var masterWeight = GetWeight(incomingDna);
                var weightedDNA  = new DynamicUMADna();

                if (masterWeight > 0)
                {
                    weightedDNA._names = new string[incomingDna.Names.Length];
                    Array.Copy(incomingDna.Names, weightedDNA._names, incomingDna.Names.Length);
                    weightedDNA._values = new float[incomingDna.Values.Length];
                    Array.Copy(incomingDna.Values, weightedDNA._values, incomingDna.Values.Length);
                    for (int i = 0; i < incomingDna.Count; i++)
                    {
                        weightedDNA.SetValue(i, weightedDNA.GetValue(i) * masterWeight);
                    }
                }
                return(weightedDNA);
            }