Exemple #1
0
        void GetSegments()
        {
            if (allSegments.Length != targets.Length)
            {
                allSegments = new LevelSegment[targets.Length];
            }
            for (int i = 0; i < targets.Length; i++)
            {
                allSegments[i] = (LevelSegment)targets[i];
            }
            List <LevelSegment> sceneSegmentsList = new List <LevelSegment>();

            for (int i = 0; i < allSegments.Length; i++)
            {
#if UNITY_2018_3_OR_NEWER
                sceneSegmentsList.Add(allSegments[i]);
#else
                //In older versions of Unity, only use the objects in the scene
                if (IsSceneObject(allSegments[i].gameObject))
                {
                    sceneSegmentsList.Add(allSegments[i]);
                }
#endif
            }
            sceneSegments = sceneSegmentsList.ToArray();
            //Unpack the scene segments only
            if (!Application.isPlaying)
            {
                for (int i = 0; i < sceneSegments.Length; i++)
                {
                    if (!sceneSegments[i].unpacked)
                    {
                        sceneSegments[i].EditorUnpack();
                    }
                }
            }

#if DREAMTECK_SPLINES
            List <SplineComputer> comps = new List <SplineComputer>();
            for (int i = 0; i < sceneSegments.Length; i++)
            {
                List <Transform> children = new List <Transform>();
                SceneUtility.GetChildrenRecursively(sceneSegments[i].transform, ref children);
                for (int j = 1; j < children.Count; j++)
                {
                    SplineComputer comp = children[j].GetComponent <SplineComputer>();
                    if (comp != null)
                    {
                        comps.Add(comp);
                        DSSplineDrawer.RegisterComputer(comp);
                    }
                }
            }
            splines = comps.ToArray();
#endif
        }
Exemple #2
0
        private void OnDisable()
        {
#if DREAMTECK_SPLINES
            for (int i = 0; i < splines.Length; i++)
            {
                if (splines[i] != null)
                {
                    DSSplineDrawer.UnregisterComputer(splines[i]);
                }
            }
#endif
            if (propertyWindow != null)
            {
                propertyWindow.Close();
            }
        }
Exemple #3
0
        void OnSceneGUI()
        {
#if DREAMTECK_SPLINES
            for (int i = 0; i < splines.Length; i++)
            {
                if (splines[i] != null)
                {
                    DSSplineDrawer.DrawSplineComputer(splines[i]);
                }
            }
#endif

            if (Application.isPlaying)
            {
                for (int i = 0; i < sceneSegments.Length; i++)
                {
                    if (sceneSegments[i].drawCustomPaths)
                    {
                        LevelSegmentDebug.DrawCustomPaths(sceneSegments[i]);
                    }
                    if (sceneSegments[i].drawGeneratedSpline)
                    {
                        LevelSegmentDebug.DrawGeneratedSpline(sceneSegments[i]);
                    }
                    if (sceneSegments[i].drawGeneratedSamples)
                    {
                        LevelSegmentDebug.DrawGeneratedSamples(sceneSegments[i]);
                    }
                }
            }
            else
            {
                for (int i = 0; i < sceneSegments.Length; i++)
                {
                    if (sceneSegments[i].drawCustomPaths)
                    {
                        LevelSegmentDebug.DrawCustomPaths(sceneSegments[i]);
                    }
                    if (sceneSegments[i].type == LevelSegment.Type.Custom)
                    {
                        continue;
                    }
                    if (sceneSegments[i].drawBounds)
                    {
                        LevelSegmentDebug.DrawBounds(sceneSegments[i]);
                    }
                }

                if (sceneSegments.Length == 1 && selectedProperties.Count > 0)
                {
                    Handles.BeginGUI();
                    for (int i = 0; i < selectedProperties.Count; i++)
                    {
                        Vector2 screenPosition = HandleUtility.WorldToGUIPoint(sceneSegments[0].objectProperties[selectedProperties[i]].transform.transform.position);
                        DreamteckEditorGUI.Label(new Rect(screenPosition.x - 120 + sceneSegments[0].objectProperties[selectedProperties[i]].transform.transform.name.Length * 4, screenPosition.y, 120, 25), sceneSegments[0].objectProperties[selectedProperties[i]].transform.transform.name);
                    }
                    Handles.EndGUI();
                }
            }
            if (pathEditor != null)
            {
                pathEditor.DrawScene();
            }

            for (int i = 0; i < sceneSegments.Length; i++)
            {
                if (!sceneSegments[i].drawEntranceAndExit)
                {
                    continue;
                }
                if (sceneSegments[i].type == LevelSegment.Type.Custom)
                {
                    if (sceneSegments[i].customEntrance != null)
                    {
                        float handleSize = HandleUtility.GetHandleSize(sceneSegments[i].customEntrance.position);
                        Handles.color = ForeverPrefs.entranceColor;
                        Handles.DrawSolidDisc(sceneSegments[i].customEntrance.position, Camera.current.transform.position - sceneSegments[i].customEntrance.position, handleSize * 0.1f);
                        Handles.ArrowHandleCap(0, sceneSegments[i].customEntrance.position, sceneSegments[i].customEntrance.rotation, handleSize * 0.5f, EventType.Repaint);
                        Handles.Label(sceneSegments[i].customEntrance.position + Camera.current.transform.up * handleSize * 0.3f, "Entrance");
                    }
                    if (sceneSegments[i].customExit != null)
                    {
                        Handles.color = ForeverPrefs.exitColor;
                        float handleSize = HandleUtility.GetHandleSize(sceneSegments[i].customExit.position);
                        Handles.DrawSolidDisc(sceneSegments[i].customExit.position, Camera.current.transform.position - sceneSegments[i].customExit.position, handleSize * 0.1f);
                        Handles.ArrowHandleCap(0, sceneSegments[i].customExit.position, sceneSegments[i].customExit.rotation, handleSize * 0.5f, EventType.Repaint);
                        Handles.Label(sceneSegments[i].customExit.position + Camera.current.transform.up * HandleUtility.GetHandleSize(sceneSegments[i].customExit.position) * 0.3f, "Exit");
                    }
                }
            }
        }
Exemple #4
0
        void Write(LevelSegment segment, bool forceCopy)
        {
            //Check to see if we are currently editing the prefab and if yes (2018.3), just pack everything without rewriting
            bool   isPrefabInstance = false;
            Object prefabParent     = null;

#if UNITY_2018_3_OR_NEWER
            PrefabInstanceStatus instanceStatus = PrefabUtility.GetPrefabInstanceStatus(segment.gameObject);
            isPrefabInstance = instanceStatus == PrefabInstanceStatus.Connected;
            if (isPrefabInstance)
            {
                prefabParent = PrefabUtility.GetCorrespondingObjectFromSource(segment.gameObject);
            }
#else
            PrefabType prefabType = PrefabUtility.GetPrefabType(segment.gameObject);
            isPrefabInstance = prefabType == PrefabType.PrefabInstance;
            if (isPrefabInstance)
            {
                prefabParent = PrefabUtility.GetPrefabParent(segment.gameObject);
            }
#endif

            if (!forceCopy && prefabParent != null)
            {
                segment.EditorPack();
#if DREAMTECK_SPLINES
                for (int i = 0; i < splines.Length; i++)
                {
                    if (splines[i] != null)
                    {
                        DSSplineDrawer.UnregisterComputer(splines[i]);
                    }
                }
#endif
#if UNITY_2018_3_OR_NEWER
                Selection.activeGameObject = PrefabUtility.SaveAsPrefabAsset(segment.gameObject, AssetDatabase.GetAssetPath(prefabParent));
#else
                PrefabUtility.ReplacePrefab(segment.gameObject, prefabParent, ReplacePrefabOptions.ConnectToPrefab);
#endif
                Undo.DestroyObjectImmediate(segment.gameObject);
            }
            else
            {
                relativePath = EditorPrefs.GetString("LevelSegmentEditor.relativePath", "/");
                if (prefabParent != null)
                {
                    relativePath = AssetDatabase.GetAssetPath(prefabParent);
                    if (relativePath.StartsWith("Assets"))
                    {
                        relativePath = relativePath.Substring("Assets".Length);
                    }
                    relativePath = System.IO.Path.GetDirectoryName(relativePath);
                }
                string path = EditorUtility.SaveFilePanel("Save Prefab", Application.dataPath + relativePath, segment.name, "prefab");
                if (path.StartsWith(Application.dataPath) && System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(path)))
                {
                    relativePath = path.Substring(Application.dataPath.Length);
                    segment.EditorPack();
#if DREAMTECK_SPLINES
                    for (int i = 0; i < splines.Length; i++)
                    {
                        if (splines[i] != null)
                        {
                            DSSplineDrawer.UnregisterComputer(splines[i]);
                        }
                    }
#endif
#if UNITY_2018_3_OR_NEWER
                    if (isPrefabInstance)
                    {
                        PrefabUtility.UnpackPrefabInstance(segment.gameObject, PrefabUnpackMode.OutermostRoot, InteractionMode.AutomatedAction);
                    }
                    PrefabUtility.SaveAsPrefabAsset(segment.gameObject, "Assets" + relativePath);
#else
                    if (isPrefabInstance)
                    {
                        PrefabUtility.DisconnectPrefabInstance(segment.gameObject);
                    }
                    PrefabUtility.CreatePrefab("Assets" + relativePath, segment.gameObject);
#endif
                    Undo.DestroyObjectImmediate(segment.gameObject);
                    EditorPrefs.SetString("LevelSegmentEditor.relativePath", System.IO.Path.GetDirectoryName(relativePath));
                }
                else
                {
                    if (path != "" && !path.StartsWith(Application.dataPath))
                    {
                        EditorUtility.DisplayDialog("Path Error", "Please select a path inside this project's Assets folder", "OK");
                    }
                }
            }
        }