public void terminate()
    {
        type = WorldObjectTypes.Unassigned;
        detachObject ();

        componentManager.terminate ();
    }
    public void init(WorldCell cell)
    {
        type = WorldObjectTypes.TerrainCell;
        attachObject (cell);

        componentManager.init (this);
    }
Exemple #3
0
        public static WorldObjectData ReadWorldObjectData(this NetworkReader reader)
        {
            WorldObjectTypes objectType = (WorldObjectTypes)reader.ReadInt32();
            uint             key        = reader.ReadUInt32();
            bool             spawned    = reader.ReadBoolean();

            if (objectType == WorldObjectTypes.ZonneBloem)
            {
                TreeObjectData data = new TreeObjectData();
                data.SetObjectType(objectType);
                data.SetKey(key);
                data.SetInstantiated(spawned);
                data.SetTreeState((TreeObjectData.TreeStates)reader.ReadByte());
                return(data);
            }


            //Tree type.
            if (objectType == WorldObjectTypes.Artic)
            {
                IslandObjectData data = new IslandObjectData();
                data.SetObjectType(objectType);
                data.SetKey(key);
                data.SetInstantiated(spawned);
                data.SetTreeState((IslandObjectData.TreeStates)reader.ReadByte());
                return(data);
            }
            //Tree type.
            if (objectType == WorldObjectTypes.Dessert)
            {
                IslandObjectData data = new IslandObjectData();
                data.SetObjectType(objectType);
                data.SetKey(key);
                data.SetInstantiated(spawned);
                data.SetTreeState((IslandObjectData.TreeStates)reader.ReadByte());
                return(data);
            }
            //Tree type.
            if (objectType == WorldObjectTypes.Jungle)
            {
                IslandObjectData data = new IslandObjectData();
                data.SetObjectType(objectType);
                data.SetKey(key);
                data.SetInstantiated(spawned);
                data.SetTreeState((IslandObjectData.TreeStates)reader.ReadByte());
                return(data);
            }

            //Not supported by serializer.
            else
            {
                Debug.LogError("Serializer not written for type " + objectType.ToString());
                return(null);
            }
        }
Exemple #4
0
        public WorldObject InstantiateWorldObject(WorldObjectTypes objectType, Vector3 position, Quaternion rotation)
        {
            WorldObject prefab = ReturnPrefab(objectType);

            /* To keep the code simple WorldObjects will be added
             * only using position. */
            //Instantiate a new WorldObject using the position passed in from data.
            WorldObject wo = Instantiate(prefab, position, rotation);

            return(wo);
        }
Exemple #5
0
        /// <summary>
        /// Returns a prefab for a WorldObjectTypes.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private WorldObject ReturnPrefab(WorldObjectTypes type)
        {
            for (int i = 0; i < _prefabs.Length; i++)
            {
                if (_prefabs[i].ObjectType == type)
                {
                    return(_prefabs[i].Prefab);
                }
            }

            //Fall through, nothing found.
            return(null);
        }
Exemple #6
0
    private void CmdSpawnIsland(Vector3 position2, int island)
    {
        WorldObjectTypes value = (WorldObjectTypes)island;
        WorldObject      wo    = WorldObjectManager.Instance.InstantiateWorldObject(value, position2, Quaternion.identity);
        IslandObjectData data  = (IslandObjectData)wo.ReturnData();

        data.SetTreeState(IslandObjectData.TreeStates.Default);
        wo.UpdateData(data);
        wo.name = name + "Island";
        WorldObjectManager.Instance.InitializeWorldObject(wo, value);
        Transform node = wo.transform.Find("Node");

        string start = "http://86.91.184.42/addWeatherNode.php?naam=" + playerName + "&PosX=" + node.transform.position.x + "&PosY=" + node.transform.position.y + "&PosZ=" + node.transform.position.z + "";

        StartCoroutine(SetNode(start));
    }
Exemple #7
0
    private void InitIslands()
    {
        var json22 = new WebClient().DownloadString(getIsland);

        if (json22 != "")
        {
            dynamic jsonObj = JsonConvert.DeserializeObject <JArray>(json22);
            foreach (var obj in jsonObj)
            {
                if (obj.IslandType != 0)
                {
                    Vector3          pos   = new Vector3((float)obj.x, (float)obj.y, (float)obj.z);
                    WorldObjectTypes value = (WorldObjectTypes)obj.IslandType;
                    WorldObject      wo    = WorldObjectManager.Instance.InstantiateWorldObject(value, pos, Quaternion.identity);
                    IslandObjectData data  = (IslandObjectData)wo.ReturnData();
                    data.SetTreeState(IslandObjectData.TreeStates.Default);
                    wo.UpdateData(data);
                    wo.name = obj.naam + "Island";
                    WorldObjectManager.Instance.InitializeWorldObject(wo, value);
                }
            }
        }
    }
Exemple #8
0
        public void InitializeWorldObject(WorldObject wo, WorldObjectTypes objectType)
        {
            if (wo == null || wo.gameObject == null)
            {
                Debug.LogError("You must first InstantiateWorldObject, and use the result within InitializeWorldObject.");
                return;
            }

            WorldObjectData data = wo.ReturnData();

            data.SetKey(ReturnNextKey());
            data.SetObjectType(objectType);
            data.SetInstantiated(true);
            //Update WorldObjects data with newly generated data.
            wo.UpdateData(data);
            //Add to WorldObjects collection.
            _worldObjects[data.Key] = wo;
            //WorldObject was modified so do a dirty update.
            UpdateDirty(wo, DirtyUpdateReasons.Instantiated);
            //Generate new added WorldObject and send to clients.
            AddedWorldObjectData addedWorldObject = new AddedWorldObjectData(wo.transform.position, wo.transform.rotation, data);

            RpcAddWorldObject(new AddedWorldObjectData[] { addedWorldObject });
        }
Exemple #9
0
 /// <summary>
 /// Sets Type value.
 /// </summary>
 /// <param name="value"></param>
 public void SetObjectType(WorldObjectTypes value)
 {
     ObjectType = value;
 }
 public WorldObject(int x, int y, string id, int size = 1)
 {
     X          = x; Y = y; Size = size; Id = id;
     ObjectType = WorldObjectTypes.GENERIC;
 }