Ejemplo n.º 1
0
        public void LoadParams(ScatterParams sp)
        {
            //Debug.Log("<color=green>LOADING</color> params for " + idName);

            string[] p = PlayerPrefs.GetString(idName + BASIC_PARAMS).Split('~');
            sp.scaleX  = float.Parse(p[0]);
            sp.scaleY  = float.Parse(p[1]);
            sp.offsetX = float.Parse(p[2]);
            sp.offsetY = float.Parse(p[3]);

            string[]   c  = PlayerPrefs.GetString(idName + CURVE_PARAMS).Split('¬');
            Keyframe[] ks = new Keyframe[c.Length];

            for (int i = 0; i < c.Length; i++)
            {
                string[] cp = c[i].Split('~');
                ks[i] = new Keyframe(float.Parse(cp[0]), float.Parse(cp[1]), float.Parse(cp[2]), float.Parse(cp[3]));
            }

            sp.curve      = new AnimationCurve();
            sp.curve.keys = ks;
            sp.noiseMap   = GenerateTexture(sp);

            this.sp = sp;
        }
Ejemplo n.º 2
0
        public void LoadItemsAndProperties()
        {
            itemsAreLoaded = true;

            TextAsset sectionJSON = Resources.Load("Json/Items/Cnidarians") as TextAsset;
            string    str         = string.Format("{{\"items\":{0}}}", sectionJSON.text);

            itemsJSON = JsonUtility.FromJson <ItemsJSON>(str);

            foreach (var item in itemsJSON.items)
            {
                Item it = new Item();
                it.isUsed          = true;
                it.name            = item.IdItem;
                it.genus           = item.Genus;
                it.specie          = item.Specie;
                it.stageSexVar     = item.StageSexVar;
                it.path            = GetPathFromTypeOfObject(item.TypeOf);
                it.commonSize      = CentimetersToMeters(item.CommonSize);
                it.maxSize         = CentimetersToMeters(item.MaxSize);
                it.canRotateInX    = StringToBool(item.CanRotateInX);
                it.canRotateInY    = StringToBool(item.CanRotateInY);
                it.canRotateInZ    = StringToBool(item.CanRotateInZ);
                it.isAlign         = StringToBool(item.IsAlign);
                it.heightOffset    = CentimetersToMeters(item.HeightOffset);
                it.useCustomParams = false;
                it.item            = Resources.Load <GameObject>(string.Format("{0}{1}", it.path, item.IdItem));
                ScatterParams sp = new ScatterParams();
                it.scatterParams        = sp;
                it.scatterParams.isOpen = false;
                items.Add(it);
            }
        }
Ejemplo n.º 3
0
        public void SaveParams(ScatterParams sp, Item item)
        {
            string itemParams = string.Format("{0}~{1}~{2}~{3}", sp.scaleX.ToString(), sp.scaleY.ToString(), sp.offsetX.ToString(), sp.offsetY.ToString());

            PlayerPrefs.SetString(item.name + BASIC_PARAMS, itemParams);

            string itemCurve = string.Empty;

            Keyframe[] key = sp.curve.keys;

            for (int i = 0; i < key.Length; i++)
            {
                itemCurve += string.Format("{0}~{1}~{2}~{3}¬", key[i].time, key[i].value, key[i].inTangent, key[i].outTangent);
            }

            itemCurve = itemCurve.Remove(itemCurve.Length - 1);
            PlayerPrefs.SetString(item.name + CURVE_PARAMS, itemCurve);

            item.scatterParams.noiseMap = GenerateTexture(sp);
            item.scatterParams          = sp;

            Debug.Log(itemParams);
            Debug.Log(itemCurve);
            Debug.Log("<color=yellow>SAVING</color> parameters for " + item.name);
        }
Ejemplo n.º 4
0
        public void Init(Item item, STParameters STParams)
        {
            this.item     = item;
            this.STParams = STParams;
            this.sp       = item.scatterParams;

            sp.isOpen = true;
        }
Ejemplo n.º 5
0
        private Color CalculateColor(ScatterParams sp, int x, int y)
        {
            float xCoord = (float)x / ScatterTool.SIZEMAP * sp.scaleX + sp.offsetX;
            float yCoord = (float)y / ScatterTool.SIZEMAP * sp.scaleY + sp.offsetY;

            float sample = Mathf.PerlinNoise(xCoord, yCoord);

            sample = sp.curve.Evaluate(sample);
            return(new Color(sample, sample, sample));
        }
Ejemplo n.º 6
0
        public ScatterParams ResetParams(ScatterParams sp)
        {
            sp.scaleX   = 10;
            sp.scaleY   = 10;
            sp.offsetX  = 0;
            sp.offsetY  = 0;
            sp.curve    = AnimationCurve.Linear(0, 1, 1, 0);
            sp.noiseMap = GenerateTexture(sp);

            return(sp);
        }
Ejemplo n.º 7
0
        public void CopyParams(ScatterParams sp, string name)
        {
            copyIsActive = true;

            copyParams.scaleX  = sp.scaleX;
            copyParams.scaleY  = sp.scaleY;
            copyParams.offsetX = sp.offsetX;
            copyParams.offsetY = sp.offsetY;
            copyParams.curve   = sp.curve;

            Debug.Log(string.Format("<color=blue>COPYING</color> properties from {0}", name));
        }
Ejemplo n.º 8
0
        public Texture2D GenerateTexture(ScatterParams sp)
        {
            Texture2D noiseMap = new Texture2D(ScatterTool.SIZEMAP, ScatterTool.SIZEMAP);

            for (int x = 0; x < ScatterTool.SIZEMAP; x++)
            {
                for (int y = 0; y < ScatterTool.SIZEMAP; y++)
                {
                    Color color = CalculateColor(sp, x, y);
                    noiseMap.SetPixel(x, y, color);
                }
            }

            noiseMap.Apply();
            return(noiseMap);
        }
Ejemplo n.º 9
0
        public ScatterParams PasteParams(ScatterParams sp)
        {
            if (!copyIsActive)
            {
                return(sp);
            }

            sp.scaleX   = copyParams.scaleX;
            sp.scaleY   = copyParams.scaleY;
            sp.offsetX  = copyParams.offsetX;
            sp.offsetY  = copyParams.offsetY;
            sp.curve    = copyParams.curve;
            sp.noiseMap = GenerateTexture(sp);

            return(sp);
        }
Ejemplo n.º 10
0
        public ScatterParams InitItemParameters(Item item)
        {
            this.idName = item.name;

            sp        = new ScatterParams();
            sp.isOpen = false;

            if (!PlayerPrefs.HasKey(idName + BASIC_PARAMS))
            {
                //Debug.Log(idName + " <color=red>NO EXIST!</color> Creating new parameters...");
                sp = ResetParams(sp);
                SaveParams(sp, item);
            }
            else
            {
                LoadParams(sp);
            }

            return(sp);
        }
Ejemplo n.º 11
0
 private void Paste()
 {
     sp = STParams.PasteParams(sp);
     editorHasChanged = true;
 }
Ejemplo n.º 12
0
 private void ResetP()
 {
     sp = STParams.ResetParams(sp);
     editorHasChanged = true;
 }