Example #1
0
 public void RefreshTransform()
 {
     //gets the latest in-game position
     if (!mDestroyed)
     {
         if (tr == null)
         {
             tr = transform;
         }
         Props.Local.Transform.CopyFrom(tr);
         if (mAddedToGroupOnce)
         {
             //if we've never been added to a group then our chunk position will be meaningless
             //if we have, then we'll need it to show up correctly on a map etc
             WorldChunk chunk = Group.GetParentChunk();
             if (chunk != null)
             {
                 Props.Local.ChunkPosition = WorldChunk.WorldPositionToChunkPosition(chunk.ChunkBounds, tr.position - chunk.ChunkOffset);
             }
             else
             {
                 Props.Local.ChunkPosition = Vector3.zero;
             }
         }
     }
 }
Example #2
0
        //TODO move XML stuff into GameData
        public virtual void UpdateTriggerState(string triggerState, WorldChunk parentChunk, bool useLocalTransform)         //script props should have been updated by now
        {
            if (mHasTriggerStateField && !string.IsNullOrEmpty(triggerState))
            {
                object triggerStateValue = null;
                try {
                    if (XmlDeserializeFromString(triggerState, mTriggerStateField.FieldType, out triggerStateValue))
                    {
                        mTriggerStateField.SetValue(this, triggerStateValue);
                        //set the base state so we can access stuff like max times available
                        mBaseState = triggerStateValue as WorldTriggerState;
                        //save the script name so we can load it properly later
                        mBaseState.ScriptName = ScriptName;
                    }
                    else
                    {
                        Debug.Log("Couldn't deserialize " + triggerState + " from string");
                    }
                }
                catch (Exception e) {
                    Debug.LogError("Trigger init from save data error! E: " + e.ToString());
                }
            }

            InitializeFromState(parentChunk, useLocalTransform);
        }
Example #3
0
        protected void InitializeFromState(WorldChunk parentChunk, bool useLocalTransform)
        {
            ParentChunk = parentChunk;

            if (mHasTriggerStateField)
            {
                gameObject.layer = Globals.LayerNumTrigger;
                if (mBaseState == null)
                {
                    //Debug.Log ("Base state was null in trigger, not sure why");
                }
                gameObject.name = mBaseState.Name;
                CreateCollider(mBaseState.ColliderType);
                if (useLocalTransform)
                {
                    mBaseState.Transform.ApplyTo(transform);
                }
                else
                {
                    mBaseState.Transform.ApplyToWorld(transform);
                }

                mBaseState.trigger = this;
            }

            OnInitialized();
        }
Example #4
0
        public IEnumerator Initialize(Structure parentStructure, StructureTemplate template, StructureLoadPriority priority)
        {                       //if we're still doing another job (for some reason) wait for it to finish
            while (State != BuilderState.Dormant)
            {
                yield return(null);
            }

            Template = template;
            State    = BuilderState.Initialized;
            Priority = priority;

            gHelperTransform = gameObject.FindOrCreateChild("StructureBuilderHelper_" + name);

            ParentStructure = parentStructure;
            if (ParentStructure == null)
            {
                Debug.LogError("Parent structure null in builder, proceeding normally");
                State = BuilderState.Error;
                yield break;
            }
            if (ParentStructure.worlditem.Group == null)
            {
                Debug.Log("Parent structure worlditem group was null, proceeding normally");
                State = BuilderState.Error;
                yield break;
            }
            if (ParentStructure.StructureGroup == null)
            {
                Debug.Log("Parent structure StructureGroup was null, waiting until group exists");
                State = BuilderState.Error;
                yield break;
            }
            StructureBase  = parentStructure.StructureGroup.gameObject;
            StructureChunk = parentStructure.worlditem.Group.GetParentChunk();
            InteriorVariants.Clear();
            InteriorVariants.Add(ParentStructure.State.BaseInteriorVariant);
            InteriorVariants.AddRange(ParentStructure.State.AdditionalInteriorVariants);

            yield break;
        }
Example #5
0
        public void Update()
        {
                        #if UNITY_EDITOR
            if (spline != null)
            {
                if (UnityEditor.Selection.activeGameObject == gameObject || UnityEditor.Selection.activeGameObject == spline.gameObject)
                {
                    if (!spline.gameObject.activeSelf)
                    {
                        spline.enabled = true;
                        spline.gameObject.SetActive(true);
                    }
                }
                else
                {
                    if (spline.gameObject.activeSelf)
                    {
                        spline.enabled = false;
                        spline.gameObject.SetActive(false);
                    }
                }
            }

            if (Chunk == null && ChunkTransform == null)
            {
                Chunk = GameObject.FindObjectOfType <WorldChunk> ();
            }

            if (string.IsNullOrEmpty(Name))
            {
                Name = name;
            }
            else
            {
                name = Name;
            }

            PathColor = Colors.Saturate(Colors.ColorFromString(name, 100));
                        #endif
        }
Example #6
0
        public IEnumerator Initialize(MinorStructure minorParent, StructureTemplate template, StructureLoadPriority priority)
        {               //if we're still doing another job (for some reason) wait for it to finish
            while (State != BuilderState.Dormant)
            {
                yield return(null);
            }

            gHelperTransform = gameObject.FindOrCreateChild("StructureBuilderHelper_" + name);

            try {
                MinorParent    = minorParent;
                Template       = template;
                State          = BuilderState.Initialized;
                Priority       = priority;
                StructureChunk = MinorParent.Chunk;
                StructureBase  = MinorParent.StructureOwner.gameObject;
            } catch (Exception e) {
                Debug.LogException(e);
                State = BuilderState.Error;
            }
            yield break;
        }
Example #7
0
        public IEnumerator GenerateStructureItems()
        {
            yield return(null);

            Transform structureItems = null;
            WIGroup   group          = null;

            State = BuilderState.BuildingItems;
            WorldChunk chunk = null;

            switch (Mode)
            {
            case BuilderMode.Exterior:
            default:
                group          = ParentStructure.StructureGroup;
                chunk          = group.GetParentChunk();
                structureItems = group.gameObject.FindOrCreateChild("_ITEMS_EXT");
                var generateExtItems = StructureBuilder.GenerateExteriorItems(
                    ParentStructure,
                    Template.Exterior,
                    group,
                    structureItems);
                while (generateExtItems.MoveNext())
                {
                    /*if (chunk.TargetMode == ChunkMode.Unloaded) {
                     *              Debug.Log("Cancelling build, chunk is unloading");
                     *              yield break;
                     *      }*/
                    yield return(generateExtItems.Current);
                }
                break;

            case BuilderMode.Interior:
                for (int i = 0; i < InteriorVariants.Count; i++)
                {
                    int interiorVariant = InteriorVariants [i];
                    if (!ParentStructure.StructureGroupInteriors.ContainsKey(interiorVariant))
                    {
                        //Debug.Log ("Didn't find interior variant " + interiorVariant.ToString () + " in " + ParentStructure.name + " - waiting for a bit...");
                        double timeOut = WorldClock.RealTime + 10f;
                        while (ParentStructure != null && !ParentStructure.worlditem.Is(WIActiveState.Invisible) && !ParentStructure.StructureGroupInteriors.ContainsKey(interiorVariant))
                        {
                            //waiting for interior groups to spawn

                            /*if (chunk.TargetMode == ChunkMode.Unloaded) {
                             *              Debug.Log("Cancelling build, chunk is unloading");
                             *              yield break;
                             *      }*/
                            yield return(null);

                            if (WorldClock.RealTime > timeOut)
                            {
                                //Debug.Log ("Timed out waiting for interior group " + interiorVariant.ToString () + " in " + ParentStructure.name);
                                break;
                            }
                        }
                    }

                    try {
                        group          = ParentStructure.StructureGroupInteriors [interiorVariant];
                        structureItems = group.gameObject.FindOrCreateChild("_ITEMS_INT_" + interiorVariant.ToString());
                    } catch (Exception e) {
                        Debug.LogError(e.ToString());
                        continue;
                    }

                    if (!ParentStructure.State.InteriorsLoadedOnce.Contains(interiorVariant) && interiorVariant < Template.InteriorVariants.Count)
                    {
                        /*#if UNITY_EDITOR
                         * Debug.Log ("Generating items for interior variant " + interiorVariant.ToString ());
                         #endif*/
                        var generateIntItems = StructureBuilder.GenerateInteriorItems(
                            ParentStructure,
                            interiorVariant,
                            Template.InteriorVariants [interiorVariant],
                            group,
                            structureItems);
                        while (generateIntItems.MoveNext())
                        {
                            /*if (chunk.TargetMode == ChunkMode.Unloaded) {
                             *              Debug.Log("Cancelling build, unloading");
                             *              yield break;
                             *      }*/
                            yield return(generateIntItems.Current);
                        }
                    }

                    /*#if UNITY_EDITOR
                     * else {
                     *      Debug.Log ("Didn't generate items for interior variant "
                     + interiorVariant.ToString ()
                     + " because it has either been loaded once (" + ParentStructure.State.InteriorsLoadedOnce.Contains (interiorVariant).ToString()
                     + ") or it's out of range (" + (interiorVariant >= Template.InteriorVariants.Count).ToString () + ")");
                     + }
                     #endif*/

                    yield return(null);
                }
                break;

            case BuilderMode.Minor:
                //minor structures don't generate items
                break;
            }
        }
Example #8
0
        public void Initialize(WorldChunk parentChunk)
        {
            ParentChunk = parentChunk;

            OnInitialized();
        }