Beispiel #1
0
 protected void ReplaceAllTemplateInstances(PathMarkerInstanceTemplate pm1, PathMarkerInstanceTemplate pm2)
 {
     for (int i = 0; i < LoadedPaths.Count; i++)
     {
         for (int j = 0; j < LoadedPaths [i].Templates.Count; j++)
         {
             if (LoadedPaths [i].Templates [j] == pm1)
             {
                 LoadedPaths [i].Templates [j] = pm2;
             }
         }
     }
     //now make sure the editors are up to date
     PathEditors.Clear();
     PathEditors.AddRange(PathParentTransform.GetComponentsInChildren <PathEditor> ());
     foreach (PathEditor editor in PathEditors)
     {
         foreach (SplineNode node in editor.spline.splineNodesArray)
         {
             PathMarkerTemplateEditor pmte = node.gameObject.GetComponent <PathMarkerTemplateEditor> ();
             if (pmte.Template == pm1)
             {
                 pmte.Template = pm2;
             }
         }
     }
 }
Beispiel #2
0
 public void AdjustMinimumHeight()
 {
     PathEditors.Clear();
     PathEditors.AddRange(PathParentTransform.GetComponentsInChildren <PathEditor> ());
     foreach (PathEditor pathEditor in PathEditors)
     {
         if (pathEditor.spline == null)
         {
             pathEditor.FindSpline();
         }
         foreach (SplineNode splineNode in pathEditor.spline.splineNodesArray)
         {
             //raycast to terrain
             //if terrain height is GREATER than pm height, adjust
             //otherwise leave it alone
             RaycastHit hit;
             if (Physics.Raycast(splineNode.Position + (Vector3.up * 100), Vector3.down, out hit, 150f, Globals.LayerSolidTerrain))
             {
                 if (splineNode.transform.position.y < hit.point.y)
                 {
                     Debug.Log("Adjusted spline node to height");
                     splineNode.transform.position = hit.point;
                     PathMarkerTemplateEditor pmte = splineNode.gameObject.GetOrAdd <PathMarkerTemplateEditor> ();
                     pmte.Template.Position = splineNode.transform.position;
                 }
             }
         }
     }
 }
Beispiel #3
0
        public void BuildSpline()
        {
            if (spline != null)
            {
                foreach (SplineNode existingNode in spline.splineNodesArray)
                {
                    GameObject.DestroyImmediate(existingNode.gameObject);
                }
                spline.splineNodesArray.Clear();
                GameObject.DestroyImmediate(spline.gameObject);
            }

            spline = gameObject.FindOrCreateChild("Spline").gameObject.GetOrAdd <Spline> ();
            //put the spline at the center of our path bounds so it's easy to select
            spline.transform.position = State.PathBounds.center;

            if (spline.splineNodesArray.Count != State.Templates.Count)
            {
                foreach (PathMarkerInstanceTemplate template in State.Templates)
                {
                    GameObject splineNode = spline.AddSplineNode();
                    splineNode.transform.parent   = spline.transform;
                    splineNode.transform.position = template.Position;
                    PathMarkerTemplateEditor pmte = splineNode.gameObject.AddComponent <PathMarkerTemplateEditor> ();
                    pmte.Template = template;
                }
            }
        }
Beispiel #4
0
 public void UpdateSplineNodes()
 {
     if (spline == null)
     {
         FindSpline();
     }
     for (int i = spline.splineNodesArray.LastIndex(); i >= 0; i--)
     {
         SplineNode node = spline.splineNodesArray [i];
         if (node == null)
         {
             spline.splineNodesArray.RemoveAt(i);
         }
         else
         {
             PathMarkerTemplateEditor template = node.gameObject.GetOrAdd <PathMarkerTemplateEditor> ();
             if (template.Template != null && template.Template.ID > 0)
             {
                 template.transform.position = template.Template.Position;
             }
         }
     }
 }
Beispiel #5
0
        public void EditorRefresh()
        {
                        #if UNITY_EDITOR
            if (DoNotRefreshOrSave)
            {
                return;
            }

            if (!gameObject.activeSelf)
            {
                return;
            }

            if (spline == null)
            {
                if (!FindSpline())
                {
                    return;
                }
            }

            UnityEditor.EditorUtility.SetDirty(gameObject);
            AttachedTo.Clear();
            Bounds bounds = new Bounds();

            //then check against the spline nodes
            bool isEmpty = State.Templates.Count == 0;
            for (int i = 0; i < spline.splineNodesArray.Count; i++)
            {
                Vector3 splinePosition          = spline.splineNodesArray [i].transform.position + ChunkOffset;
                Vector3 splineRotation          = spline.splineNodesArray [i].transform.rotation.eulerAngles;
                PathMarkerTemplateEditor   pmit = spline.splineNodesArray [i].gameObject.GetOrAdd <PathMarkerTemplateEditor> ();
                PathMarkerInstanceTemplate pm   = pmit.Template;              //HERE
                if (isEmpty)
                {
                    pm.Position    = splinePosition;
                    pm.Rotation    = splineRotation;
                    pm.HasInstance = true;
                    if (string.IsNullOrEmpty(pm.PathName))
                    {
                        pm.PathName = Name;
                    }
                    State.Templates.Add(pm);                     //HERE
                }
            }

            if (IsAnExtension)
            {
                for (int i = 0; i < spline.splineNodesArray.Count; i++)
                {
                    Vector3 splinePosition          = spline.splineNodesArray [i].transform.position + ChunkOffset;
                    Vector3 splineRotation          = spline.splineNodesArray [i].transform.rotation.eulerAngles;
                    PathMarkerTemplateEditor   pmit = spline.splineNodesArray [i].gameObject.GetOrAdd <PathMarkerTemplateEditor> ();
                    PathMarkerInstanceTemplate pm   = pmit.Template;
                    pm.Position = splinePosition;
                    pm.Rotation = splineRotation;
                    if (AddToEnd)
                    {
                        State.Templates.Add(pm);
                    }
                    else
                    {
                        State.Templates.Insert(0, pm);
                    }
                }
                IsAnExtension = false;
            }

            //first check against the state templates
            for (int i = 0; i < State.Templates.Count; i++)
            {
                PathMarkerInstanceTemplate pm = State.Templates [i];
                pm.HasInstance = false;
                pm.Type        = PathMarkerType.None;
                //see if the template has a spline node counterpart
                for (int j = 0; j < spline.splineNodesArray.Count; j++)
                {
                    Vector3 statePosition  = spline.splineNodesArray [j].transform.position + ChunkOffset;
                    Vector3 splineRotation = spline.splineNodesArray [j].transform.rotation.eulerAngles;
                    float   distance       = Vector3.Distance(statePosition, State.Templates [i].Position);
                    //if it's within 0.25, we're fine
                    if (distance < 0.25f)
                    {
                        PathMarkerTemplateEditor pmEditor = spline.splineNodesArray [j].gameObject.GetOrAdd <PathMarkerTemplateEditor> ();
                        pmEditor.Template.HasInstance = true;
                        State.Templates [i]           = pmEditor.Template;
                        //pm.HasInstance = true;
                        //pm.Position = statePosition;
                        //pm.Rotation = splineRotation;
                        //PathMarkerTemplateEditor pmEditor = spline.splineNodesArray [j].gameObject.GetOrAdd <PathMarkerTemplateEditor> ();
                        //shared path marker??
                        //pmEditor.Template = pm;//HERE
                        break;
                    }
                }

                if (string.IsNullOrEmpty(pm.PathName) || pm.PathName == " ")
                {
                    pm.PathName = Name;
                }

                if (pm.Marker < 0)
                {
                    pm.Marker = gPM++;
                }

                if (pm.PathName != Name)
                {
                    //if the path's name is not our state name then it's a branch
                    if (!pm.Branches.ContainsKey(Name))
                    {
                        //add a branch to the template with the index of this path marker
                        pm.Branches.Add(Name, i);
                    }
                }

                if (i == 0)
                {
                    bounds = new Bounds(pm.Position, Vector3.one);
                }
                else
                {
                    bounds.Encapsulate(pm.Position);
                }

                if (RevealPath)
                {
                    pm.Revealable.RevealMethod = LocationRevealMethod.ByDefault;
                }
                else
                {
                    pm.Revealable.RevealMethod = LocationRevealMethod.None;
                }

                if (pm.Branches.ContainsKey(""))
                {
                    pm.Branches.Remove("");
                }

                if (pm.Branches.Count > 0)
                {
                    AttachedTo.AddRange(pm.Branches);
                    List <KeyValuePair <string, int> > orderedAttachedTo = new List <KeyValuePair <string, int> > ();
                    orderedAttachedTo.AddRange(AttachedTo.OrderBy(o => o.Value));
                    AttachedTo = orderedAttachedTo;
                    if (pm.Branches.Count > 1)
                    {
                        pm.Type |= PathMarkerType.Cross;
                        pm.Type &= ~PathMarkerType.Marker;                        //remove
                    }
                    else
                    {
                        pm.Type &= ~PathMarkerType.Cross;                        //remove
                        pm.Type |= PathMarkerType.Marker;
                    }
                }
                else
                {
                    pm.Type &= ~PathMarkerType.Cross;                    //remove
                    pm.Type |= PathMarkerType.Marker;
                }

                if (!Flags.Check((uint)(PathMarkerType.Path | PathMarkerType.Street | PathMarkerType.Road), (uint)pm.Type, Flags.CheckType.MatchAny))
                {
                    pm.Type |= PathMarkerType.Path;
                }
            }

            State.Bounds = bounds;
                        #endif
        }