Exemple #1
0
 void DisableRotation(PathPosition pathPosition)
 {
     if (pathPosition)
     {
         pathPosition.OnPositionChanged -= SetRotation;
     }
 }
Exemple #2
0
 void EnableRotation(PathPosition pathPosition)
 {
     if (pathPosition)
     {
         pathPosition.OnPositionChanged += SetRotation;
     }
 }
Exemple #3
0
            public override void OnInspectorGUI()
            {
                //reset subscription in case path position gets changed
                foreach (PathRotation pr in targets)
                {
                    pr.DisableRotation(pr.PathPosition);
                }

                serializedObject.Update();

                EditorGUI.BeginChangeCheck();

                EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(_pathPosition)));

                EditorGUILayout.HelpBox("PathPosition rotation settings will be overriden at the following times:", MessageType.Info);

                EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(_rotateInEditMode)));
                EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(_rotateOnStart)));

                PathPosition.DrawRotationSettings(serializedObject.FindProperty(nameof(_rotate)));

                bool changed = EditorGUI.EndChangeCheck();

                serializedObject.ApplyModifiedProperties();

                if (changed)
                {
                    foreach (PathRotation pr in targets)
                    {
                        if (pr.RotateInEditMode && pr.PathPosition)
                        {
                            pr.SetRotation(pr.PathPosition.Position);
                        }
                    }
                }

                foreach (PathRotation pr in targets)
                {
                    if (!Application.IsPlaying(pr) && pr.RotateInEditMode)
                    {
                        pr.EnableRotation(pr.PathPosition);
                    }
                }
            }
Exemple #4
0
        public PathPosition GetFollowTarget()
        {
            if (string.IsNullOrEmpty(Tag))
            {
                return(null);
            }

            GameObject[] tagObjects = GameObject.FindGameObjectsWithTag(Tag);

            PathPosition followMe = null;

            foreach (GameObject go in tagObjects)
            {
                followMe = go.GetComponentInChildren <PathPosition>();
                if (followMe)
                {
                    break;
                }
            }

            return(followMe);
        }